Skip to content

Commit

Permalink
Merge pull request brooklyncentral#1322 from grkvlt/fix/various-entities
Browse files Browse the repository at this point in the history
Fixing various entities for SLES
  • Loading branch information
brooklyn-images committed Apr 14, 2014
2 parents 175a6ec + 9069f9b commit 47aa588
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ protected boolean checkForAndInstallJava6or7() {
} else {
// Let's hope not!
if (version.isPresent()) {
log.debug("Found Java version {} on {}@{}. Going to install Java 7.",
log.debug("Found old Java version {} on {}@{}. Going to install latest Java version.",
new Object[]{version.get(), getEntity(), getLocation()});
}
return tryJavaInstall("7", BashCommands.installJava7OrFail()) == 0;
return tryJavaInstall("latest", BashCommands.installJava7Or6OrFail()) == 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
/*
* Copyright 2012-2014 by Cloudsoft Corporation Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brooklyn.entity.messaging.rabbit;

import static brooklyn.util.ssh.BashCommands.installPackage;
import static brooklyn.util.ssh.BashCommands.*;
import static java.lang.String.format;

import java.util.List;
Expand All @@ -16,7 +31,6 @@
import brooklyn.location.basic.SshMachineLocation;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.net.Networking;
import brooklyn.util.ssh.BashCommands;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -51,15 +65,20 @@ public void install() {
List<String> urls = resolver.getTargets();
String saveAs = resolver.getFilename();
setExpandedInstallDir(getInstallDir()+"/"+resolver.getUnpackedDirectoryName(format("rabbitmq_server-%s", getVersion())));

List<String> commands = ImmutableList.<String>builder()
.add(installPackage(// NOTE only 'port' states the version of Erlang used, maybe remove this constraint?
.add(ifExecutableElse0("zypper", chainGroup(
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/SLE_11_SP3 erlang_sles_11")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_11.4 erlang_suse_11")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_12.3 erlang_suse_12")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_13.1 erlang_suse_13")))))
.add(installPackage( // NOTE only 'port' states the version of Erlang used, maybe remove this constraint?
ImmutableMap.of(
"apt", "erlang-nox erlang-dev",
"port", "erlang@"+getErlangVersion()+"+ssl"),
"erlang"))
.addAll(BashCommands.commandsToDownloadUrlsAs(urls, saveAs))
.add(BashCommands.installExecutable("tar"))
.addAll(commandsToDownloadUrlsAs(urls, saveAs))
.add(installExecutable("tar"))
.add(format("tar xvzf %s",saveAs))
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 by Cloudsoft Corp.
* Copyright 2012-2014 by Cloudsoft Corporation Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,13 +27,19 @@
/**
* An {@link brooklyn.entity.Entity} that represents a CouchDB node in a {@link CouchDBCluster}.
*/
@Catalog(name="CouchDB Node", description="Apache CouchDB is a database that uses JSON for documents, JavaScript for MapReduce queries, and regular HTTP for an API", iconUrl="classpath:///couchdb-logo.png")
@Catalog(name="CouchDB Node",
description="Apache CouchDB is a database that uses JSON for documents, JavaScript for MapReduce queries, " +
"and regular HTTP for an API",
iconUrl="classpath:///couchdb-logo.png")
@ImplementedBy(CouchDBNodeImpl.class)
public interface CouchDBNode extends SoftwareProcess, WebAppService {

@SetFromFlag("version")
ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "1.2.1");

@SetFromFlag("erlangVersion")
ConfigKey<String> ERLANG_VERSION = ConfigKeys.newStringConfigKey("erlang.version", "Erlang runtime version", "R15B");

@SetFromFlag("clusterName")
BasicAttributeSensorAndConfigKey<String> CLUSTER_NAME = CouchDBCluster.CLUSTER_NAME;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 by Cloudsoft Corp.
* Copyright 2012-2014 by Cloudsoft Corporation Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,9 +15,9 @@
*/
package brooklyn.entity.nosql.couchdb;

import brooklyn.entity.java.JavaSoftwareProcessDriver;
import brooklyn.entity.basic.SoftwareProcessDriver;

public interface CouchDBNodeDriver extends JavaSoftwareProcessDriver {
public interface CouchDBNodeDriver extends SoftwareProcessDriver {

Integer getHttpPort();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 by Cloudsoft Corp.
* Copyright 2012-2014 by Cloudsoft Corporation Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,20 +15,22 @@
*/
package brooklyn.entity.nosql.couchdb;

import java.io.ByteArrayInputStream;
import static brooklyn.util.ssh.BashCommands.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import brooklyn.entity.java.JavaSoftwareProcessSshDriver;
import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver;
import brooklyn.entity.basic.Attributes;
import brooklyn.location.Location;
import brooklyn.location.basic.SshMachineLocation;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.net.Networking;
import brooklyn.util.ssh.BashCommands;
import brooklyn.util.os.Os;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -37,16 +39,17 @@
/**
* Start a {@link CouchDBNode} in a {@link Location} accessible over ssh.
*/
public class CouchDBNodeSshDriver extends JavaSoftwareProcessSshDriver implements CouchDBNodeDriver {
public class CouchDBNodeSshDriver extends AbstractSoftwareProcessSshDriver implements CouchDBNodeDriver {

private static final Logger log = LoggerFactory.getLogger(CouchDBNodeSshDriver.class);

public CouchDBNodeSshDriver(CouchDBNodeImpl entity, SshMachineLocation machine) {
super(entity, machine);

entity.setAttribute(Attributes.LOG_FILE_LOCATION, getLogFileLocation());
}

@Override
protected String getLogFileLocation() { return String.format("%s/couchdb.log", getRunDir()); }
public String getLogFileLocation() { return Os.mergePathsUnix(getRunDir(), "couchdb.log"); }

@Override
public Integer getHttpPort() { return entity.getAttribute(CouchDBNode.HTTP_PORT); }
Expand All @@ -66,21 +69,34 @@ public CouchDBNodeSshDriver(CouchDBNodeImpl entity, SshMachineLocation machine)
@Override
public String getCouchDBConfigFileName() { return entity.getAttribute(CouchDBNode.COUCHDB_CONFIG_FILE_NAME); }

public String getErlangVersion() { return entity.getConfig(CouchDBNode.ERLANG_VERSION); }

@Override
public void install() {
log.info("Installing {}", entity);
List<String> commands = ImmutableList.<String>builder()
.add(BashCommands.installPackage("erlang"))
.add(BashCommands.installPackage("couchdb"))
.add("which service && sudo service couchdb stop")
.add(ifExecutableElse0("zypper", chainGroup( // SLES 11 not supported, would require building from source
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_11.4 erlang_suse_11")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_12.3 erlang_suse_12")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/devel:/languages:/erlang/openSUSE_13.1 erlang_suse_13")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/server:/database/openSUSE_11.4 db_suse_11")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/server:/database/openSUSE_12.3 db_suse_12")),
ok(sudo("zypper --non-interactive addrepo http://download.opensuse.org/repositories/server:/database/openSUSE_13.1 db_suse_13")))))
.add(installPackage( // NOTE only 'port' states the version of Erlang used, maybe remove this constraint?
ImmutableMap.of(
"apt", "erlang-nox erlang-dev",
"port", "erlang@"+getErlangVersion()+"+ssl"),
"erlang"))
.add(installPackage("couchdb"))
.add(ifExecutableElse0("service", sudo("service couchdb stop")))
.build();

newScript(INSTALLING)
.failOnNonZeroResultCode()
.body.append(commands)
.execute();
}

@Override
public Set<Integer> getPortsUsed() {
Set<Integer> result = Sets.newLinkedHashSet(super.getPortsUsed());
result.addAll(getPortMap().values());
Expand All @@ -101,36 +117,33 @@ public void customize() {
newScript(CUSTOMIZING).execute();

// Copy the configuration files across
String configFileContents = processTemplate(getCouchDBConfigTemplateUrl());
String destinationConfigFile = String.format("%s/%s", getRunDir(), getCouchDBConfigFileName());
getMachine().copyTo(new ByteArrayInputStream(configFileContents.getBytes()), destinationConfigFile);
String uriFileContents = processTemplate(getCouchDBUriTemplateUrl());
String destinationUriFile = String.format("%s/couch.uri", getRunDir());
getMachine().copyTo(new ByteArrayInputStream(uriFileContents.getBytes()), destinationUriFile);
String destinationConfigFile = Os.mergePathsUnix(getRunDir(), getCouchDBConfigFileName());
copyTemplate(getCouchDBConfigTemplateUrl(), destinationConfigFile);
String destinationUriFile = Os.mergePathsUnix(getRunDir(), "couch.uri");
copyTemplate(getCouchDBUriTemplateUrl(), destinationUriFile);
}

@Override
public void launch() {
log.info("Launching {}", entity);
newScript(MutableMap.of("usePidFile", false), LAUNCHING)
.body.append(String.format("sudo nohup couchdb -p %s -a %s/%s -o couchdb-console.log -e couchdb-error.log -b &", getPidFile(), getRunDir(), getCouchDBConfigFileName()))
.failOnNonZeroResultCode()
newScript(MutableMap.of(USE_PID_FILE, false), LAUNCHING)
.body.append(sudo(String.format("nohup couchdb -p %s -a %s -o couchdb-console.log -e couchdb-error.log -b &", getPidFile(), Os.mergePathsUnix(getRunDir(), getCouchDBConfigFileName()))))
.execute();
}

public String getPidFile() { return String.format("%s/couchdb.pid", getRunDir()); }
public String getPidFile() { return Os.mergePathsUnix(getRunDir(), "couchdb.pid"); }

@Override
public boolean isRunning() {
return newScript(MutableMap.of("usePidFile", false), CHECK_RUNNING)
.body.append(String.format("sudo couchdb -p %s -s", getPidFile()))
return newScript(MutableMap.of(USE_PID_FILE, false), CHECK_RUNNING)
.body.append(sudo(String.format("couchdb -p %s -s", getPidFile())))
.execute() == 0;
}

@Override
public void stop() {
newScript(MutableMap.of("usePidFile", false), STOPPING)
.body.append(String.format("sudo couchdb -p %s -k", getPidFile()))
newScript(MutableMap.of(USE_PID_FILE, false), STOPPING)
.body.append(sudo(String.format("couchdb -p %s -k", getPidFile())))
.failOnNonZeroResultCode()
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,18 @@ public void install() {
"onlyifmissing", "gcc",
"yum", "gcc",
"apt", "gcc",
"zypper", "gcc",
"port", null);
MutableMap<String, String> installMakePackageFlags = MutableMap.of(
"onlyifmissing", "make",
"yum", "make",
"apt", "make",
"zypper", "make",
"port", null);
MutableMap<String, String> installPackageFlags = MutableMap.of(
"yum", "openssl-devel pcre-devel",
"apt", "libssl-dev zlib1g-dev libpcre3-dev",
"zypper", "libopenssl-devel pcre-devel",
"port", null);

String stickyModuleVersion = entity.getConfig(NginxController.STICKY_VERSION);
Expand Down
Loading

0 comments on commit 47aa588

Please sign in to comment.