Skip to content

Commit

Permalink
This closes #1123
Browse files Browse the repository at this point in the history
  • Loading branch information
ahgittin committed Jan 19, 2016
2 parents 717c79b + c8911e6 commit 0fa772a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@
public interface RabbitBroker extends SoftwareProcess, MessageBroker, AmqpServer {

@SetFromFlag("version")
public static final ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "2.8.7");
public static final ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "3.6.0");

@SetFromFlag("downloadUrl")
public static final BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new BasicAttributeSensorAndConfigKey<String>(
SoftwareProcess.DOWNLOAD_URL, "http://www.rabbitmq.com/releases/rabbitmq-server/v${version}/rabbitmq-server-generic-unix-${version}.tar.gz");
SoftwareProcess.DOWNLOAD_URL, "http://www.rabbitmq.com/releases/rabbitmq-server/v${version}/rabbitmq-server-generic-unix-${version}.tar.xz");

@SetFromFlag("erlangVersion")
public static final BasicConfigKey<String> ERLANG_VERSION = new BasicConfigKey<String>(String.class, "erlang.version", "Erlang runtime version", "R15B");
public static final BasicConfigKey<String> ERLANG_VERSION = new BasicConfigKey<String>(String.class, "erlang.version", "Erlang runtime version", "18.2");

@SetFromFlag("erlangDebRepoUrl")
public static final BasicConfigKey<String> ERLANG_DEB_REPO_URL = new BasicConfigKey<String>(String.class, "erlang.deb.repo.url",
"Deb file used to configure an external Erlang repository which provides up to date packages for Ubuntu/Debian",
"http://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb");

@SetFromFlag("rabbitmqConfigTemplateUrl")
ConfigKey<String> CONFIG_TEMPLATE_URL = ConfigKeys.newStringConfigKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

Expand All @@ -39,6 +38,7 @@
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.net.Networking;
import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.text.Strings;

/**
* TODO javadoc
Expand Down Expand Up @@ -81,40 +81,32 @@ public void preInstall() {
public void install() {
List<String> urls = resolver.getTargets();
String saveAs = resolver.getFilename();
// Version and architecture are only required for download of epel package on RHEL/Centos systems so pick sensible
// defaults if unavailable
String osMajorVersion = getMachine().getOsDetails().getVersion();
if (Strings.isNullOrEmpty(osMajorVersion)) {
osMajorVersion = "7";
} else {
osMajorVersion = osMajorVersion.indexOf(".") > 0 ? osMajorVersion.substring(0, osMajorVersion.indexOf('.')) : osMajorVersion;
if (!CENTOS_VERSION_TO_EPEL_VERSION.keySet().contains(osMajorVersion)) {
osMajorVersion = "7";
}
}
String epelVersion = CENTOS_VERSION_TO_EPEL_VERSION.get(osMajorVersion);
String osArchitecture = getMachine().getOsDetails().getArch();
if (Strings.isNullOrEmpty(osArchitecture)) {
osArchitecture = "x86_64";
}


List<String> commands = ImmutableList.<String>builder()
// EPEL repository for erlang install required on some Centos distributions
.add(chainGroup("which yum", sudo("yum -y update ca-certificates"), sudo("rpm -Uvh --replacepkgs " +
format("http://download.fedoraproject.org/pub/epel/%s/%s/epel-release-%s.noarch.rpm", osMajorVersion, osArchitecture, epelVersion))))
.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")))))
// RabbitMQ recommends Erlang 18. Release notes state:
// ====
// Minimum required Erlang version is R16B03 for plain ("just TCP") connections for all protocols
// and 17.5 for TLS ones (18.x is recommended for both).
// ====
//
// The recommended provider for up to date Erlang versions is Erlang Solutions now.
// Supported platforms by Erlang Solutions are: CentOS, RHEL, Ubuntu and Debian.
//
// New Erlang versions for SUSE are provided via the openSUSE repositories
//
// EPEL 6 provides only packages for Erlang 14, but EPEL 7 - Erlang 16
//
.add(ifExecutableElse0("apt-get", getAptRepository()))
.add(ifExecutableElse0("yum", getYumRepository()))
.add(ifExecutableElse0("zypper", getZypperRepository()))
.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"))
"erlang"))
.addAll(commandsToDownloadUrlsAs(urls, saveAs))
.add(installExecutable("tar"))
.add(format("tar xvzf %s",saveAs))
.add(format("tar xvf %s",saveAs))
.build();

newScript(INSTALLING).
Expand Down Expand Up @@ -147,9 +139,9 @@ public void launch() {
newScript(MutableMap.of("usePidFile", false), LAUNCHING)
.body.append(
"nohup ./sbin/rabbitmq-server > console-out.log 2> console-err.log &",
"for i in {1..30}\n" +
"for i in {1..60}\n" +
"do\n" +
" grep 'broker running' console-out.log && exit\n" +
" grep 'Starting broker... completed' console-out.log && exit\n" +
" sleep 1\n" +
"done",
"echo \"Couldn't determine if rabbitmq-server is running\"",
Expand All @@ -166,7 +158,6 @@ public void configure() {
).execute();
}


public String getPidFile() { return "rabbitmq.pid"; }

@Override
Expand All @@ -183,7 +174,6 @@ public void stop() {
.execute();
}


@Override
public void kill() {
stop(); // TODO No pid file to easily do `kill -9`
Expand All @@ -205,4 +195,69 @@ public Map<String, String> getShellEnvironment() {
private String getConfigPath() {
return getRunDir() + "/rabbitmq";
}

private String getYumRepository() {
String yumRepoFileName = "erlang_solutions.repo";

// Version and architecture are only required for download of epel package on RHEL/Centos systems so pick sensible
// defaults if unavailable
//
// EPEL is still required as it is a prerequisite for the packages provided by Erlang Solutions

String osMajorVersion = getMachine().getOsDetails().getVersion();
if (Strings.isBlank(osMajorVersion)) {
osMajorVersion = "7";
} else {
osMajorVersion = osMajorVersion.indexOf(".") > 0 ? osMajorVersion.substring(0, osMajorVersion.indexOf('.')) : osMajorVersion;
if (!CENTOS_VERSION_TO_EPEL_VERSION.keySet().contains(osMajorVersion)) {
osMajorVersion = "7";
}
}
String epelVersion = CENTOS_VERSION_TO_EPEL_VERSION.get(osMajorVersion);
String osArchitecture = getMachine().getOsDetails().getArch();
if (Strings.isBlank(osArchitecture)) {
osArchitecture = "x86_64";
}

// Erlang Solutions provide separate packages for RHEL and CentOS, but they are hosted in a single repo.
// E.g. - http://packages.erlang-solutions.com/rpm/centos/6/x86_64/
//
// Erlang Solutions created a repo configuration RPM which can NOT be used on RedHat, because it has explicit checks for CentOS.
//
// Bellow we are creating a repo file that works for CentOS and RedHat
return chainGroup(
sudo("yum -y update ca-certificates"),
sudo("rpm -Uvh --replacepkgs " + format("http://download.fedoraproject.org/pub/epel/%s/%s/epel-release-%s.noarch.rpm", osMajorVersion, osArchitecture, epelVersion)),
"( cat << 'EOF_BROOKLYN'\n"
+ "[erlang-solutions]\n"
+ "name=Centos / RHEL " + osMajorVersion + " - $basearch - Erlang Solutions\n"
+ "baseurl=http://packages.erlang-solutions.com/rpm/centos/" + osMajorVersion + "/$basearch\n"
+ "gpgcheck=0\n"
+ "gpgkey=http://packages.erlang-solutions.com/debian/erlang_solutions.asc\n"
+ "enabled=1\n"
+ "EOF_BROOKLYN\n"
+ ") > " + yumRepoFileName,
sudo(format("mv %s /etc/yum.repos.d/", yumRepoFileName)),
sudo(format("chown root:root /etc/yum.repos.d/%s", yumRepoFileName))
);
}

private String getAptRepository() {
String debFileName = "erlang-repo.deb";

return chainGroup(
INSTALL_WGET,
format("wget --quiet -O %s %s", debFileName, entity.getConfig(RabbitBroker.ERLANG_DEB_REPO_URL)),
sudo(format("dpkg -i %s", debFileName))
);
}

private String getZypperRepository() {
return 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")));
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
<#if entity.enableManagementPlugin>
{rabbit, [{loopback_users, []}]},
{rabbitmq_mochiweb, [{listeners, [{mgmt, [{port, ${entity.managementPort?c}}]}]}]}
</#if>
].

0 comments on commit 0fa772a

Please sign in to comment.