brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/4] brooklyn-library git commit: CouchDB installation fixes
Date Tue, 03 May 2016 10:22:50 GMT
Repository: brooklyn-library
Updated Branches:
  refs/heads/master cc5b4be60 -> 13b3f9c33


CouchDB installation fixes

- CouchDB is installed from source now
- CouchDB dependencies are installed by the official repos

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-library/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-library/commit/65171ba1
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-library/tree/65171ba1
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-library/diff/65171ba1

Branch: refs/heads/master
Commit: 65171ba15639b4f95117c31876b5fb9e80a38eb1
Parents: 6541b63
Author: Yavor Yanchev <yavor@yanchev.com>
Authored: Thu Apr 14 18:22:58 2016 +0300
Committer: Yavor Yanchev <yavor@yanchev.com>
Committed: Thu Apr 14 18:22:58 2016 +0300

----------------------------------------------------------------------
 .../entity/nosql/couchdb/CouchDBNode.java       |  10 +-
 .../nosql/couchdb/CouchDBNodeSshDriver.java     | 111 +++++++++++++++----
 2 files changed, 97 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/65171ba1/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNode.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNode.java
b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNode.java
index fa9506a..6d6eff4 100644
--- a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNode.java
+++ b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNode.java
@@ -22,6 +22,7 @@ import org.apache.brooklyn.api.catalog.Catalog;
 import org.apache.brooklyn.api.entity.ImplementedBy;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
 import org.apache.brooklyn.entity.webapp.WebAppService;
@@ -37,8 +38,15 @@ import org.apache.brooklyn.util.core.flags.SetFromFlag;
 @ImplementedBy(CouchDBNodeImpl.class)
 public interface CouchDBNode extends SoftwareProcess, WebAppService {
 
+    @SetFromFlag("downloadUrl")
+    AttributeSensorAndConfigKey<String, String> DOWNLOAD_URL = ConfigKeys.newSensorAndConfigKeyWithDefault(SoftwareProcess.DOWNLOAD_URL,
+            "http://www-eu.apache.org/dist/couchdb/source/${version}/apache-couchdb-${version}.tar.gz");
+
+    @SetFromFlag("archiveNameFormat")
+    ConfigKey<String> ARCHIVE_DIRECTORY_NAME_FORMAT = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.ARCHIVE_DIRECTORY_NAME_FORMAT,
"apache-couchdb-%s");
+    
     @SetFromFlag("version")
-    ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION,
"1.2.1");
+    ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION,
"1.6.1");
 
     @SetFromFlag("erlangVersion")
     ConfigKey<String> ERLANG_VERSION = ConfigKeys.newStringConfigKey("erlang.version",
"Erlang runtime version", "R15B");

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/65171ba1/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeSshDriver.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeSshDriver.java
b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeSshDriver.java
index 60c1f84..960bc2b 100644
--- a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeSshDriver.java
+++ b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/couchdb/CouchDBNodeSshDriver.java
@@ -18,7 +18,7 @@
  */
 package org.apache.brooklyn.entity.nosql.couchdb;
 
-import static org.apache.brooklyn.util.ssh.BashCommands.*;
+import static java.lang.String.format;
 
 import java.util.List;
 import java.util.Map;
@@ -27,15 +27,21 @@ import java.util.Set;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.OsDetails;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessSshDriver;
+import org.apache.brooklyn.entity.software.base.lifecycle.ScriptHelper;
 import org.apache.brooklyn.location.ssh.SshMachineLocation;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.net.Networking;
 import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.ssh.BashCommands;
+import org.apache.brooklyn.util.stream.Streams;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 /**
@@ -76,26 +82,85 @@ public class CouchDBNodeSshDriver extends AbstractSoftwareProcessSshDriver
imple
     @Override
     public void install() {
         log.info("Installing {}", entity);
-        List<String> commands = ImmutableList.<String>builder()
-                .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)
-                .body.append(commands)
-                .execute();
+       List<String> couchdbUrls = resolver.getTargets();
+       String coudhdbSaveAs = resolver.getFilename();
+
+       MutableMap<String, String> installGccPackageFlags = MutableMap.of(
+               "onlyifmissing", "gcc",
+               "yum", "gcc",
+               "apt", "gcc",
+               "zypper", "gcc gcc-c++",
+               "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", "js-devel openssl-devel libicu-devel libcurl-devel erlang-erts erlang-public_key
erlang-eunit erlang-sasl erlang-os_mon erlang-asn1 erlang-xmerl",
+               "apt", "erlang-nox erlang-dev libicu-dev libmozjs185-dev libcurl4-openssl-dev",
+               "zypper", "libopenssl-devel pcre-devel",
+               "port", "icu erlang spidermonkey curl");
+
+       List<String> cmds = Lists.newArrayList();
+
+       cmds.add(BashCommands.INSTALL_TAR);
+       cmds.add(BashCommands.alternatives(
+               BashCommands.ifExecutableElse0("apt-get", BashCommands.installPackage("build-essential")),
+               BashCommands.ifExecutableElse0("yum", BashCommands.sudo("yum -y --nogpgcheck
groupinstall \"Development Tools\""))));
+       cmds.add(BashCommands.installPackage(installGccPackageFlags, "couchdb-prerequisites-gcc"));
+       cmds.add(BashCommands.installPackage(installMakePackageFlags, "couchdb-prerequisites-make"));
+       cmds.add(BashCommands.installPackage(installPackageFlags, "couchdb-prerequisites"));
+       cmds.addAll(BashCommands.commandsToDownloadUrlsAs(couchdbUrls, coudhdbSaveAs));
+
+       cmds.add(format("tar xvzf %s", coudhdbSaveAs));
+       cmds.add(format("cd %s", getExpandedInstallDir()));
+
+       StringBuilder configureCommand = new StringBuilder("./configure")
+               .append(format(" --prefix=%s", getRunDir()))
+               .append(" --with-erlang=/usr/lib64/erlang/usr/include ");
+
+       cmds.addAll(ImmutableList.of(
+               configureCommand.toString(),
+               "make install"));
+
+       ScriptHelper script = newScript(INSTALLING)
+               .body.append(cmds)
+               .header.prepend("set -x")
+               .gatherOutput()
+               .failOnNonZeroResultCode(false);
+
+       int result = script.execute();
+
+       if (result != 0) {
+           String notes = "likely an error building couchdb. consult the brooklyn log ssh
output for further details.\n"+
+                   "note that this Brooklyn couchdb driver compiles couchdb from source.
" +
+                   "it attempts to install common prerequisites but this does not always
succeed.\n";
+           OsDetails os = getMachine().getOsDetails();
+           if (os.isMac()) {
+               notes += "deploying to Mac OS X, you will require Xcode and Xcode command-line
tools, and on " +
+                       "some versions the pcre library (e.g. using macports, sudo port install
pcre).\n";
+           }
+           if (os.isWindows()) {
+               notes += "this couchdb driver is not designed for windows, unless cygwin is
installed, and you are patient.\n";
+           }
+
+           if (!script.getResultStderr().isEmpty()) {
+               notes += "\n" + "STDERR\n" + script.getResultStderr()+"\n";
+               Streams.logStreamTail(log, "STDERR of problem in "+Tasks.current(), Streams.byteArrayOfString(script.getResultStderr()),
1024);
+           }
+           if (!script.getResultStdout().isEmpty()) {
+               notes += "\n" + "STDOUT\n" + script.getResultStdout()+"\n";
+               Streams.logStreamTail(log, "STDOUT of problem in "+Tasks.current(), Streams.byteArrayOfString(script.getResultStdout()),
1024);
+           }
+
+           Tasks.setExtraStatusDetails(notes.trim());
+
+           throw new IllegalStateException("Installation of couchdb failed (shell returned
non-zero result "+result+")");
+       }
+
     }
 
     @Override
@@ -129,7 +194,7 @@ public class CouchDBNodeSshDriver extends AbstractSoftwareProcessSshDriver
imple
     public void launch() {
         log.info("Launching  {}", entity);
         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()))))
+                .body.append(String.format("nohup ./bin/couchdb -p %s -a %s -o couchdb-console.log
-e couchdb-error.log -b &", getPidFile(), Os.mergePathsUnix(getRunDir(), getCouchDBConfigFileName())))
                 .execute();
     }
 
@@ -138,14 +203,14 @@ public class CouchDBNodeSshDriver extends AbstractSoftwareProcessSshDriver
imple
     @Override
     public boolean isRunning() {
         return newScript(MutableMap.of(USE_PID_FILE, false), CHECK_RUNNING)
-                .body.append(sudo(String.format("couchdb -p %s -s", getPidFile())))
+                .body.append(String.format("./bin/couchdb -p %s -s", getPidFile()))
                 .execute() == 0;
     }
 
     @Override
     public void stop() {
         newScript(MutableMap.of(USE_PID_FILE, false), STOPPING)
-                .body.append(sudo(String.format("couchdb -p %s -k", getPidFile())))
+                .body.append(String.format("./bin/couchdb -p %s -k", getPidFile()))
                 .failOnNonZeroResultCode()
                 .execute();
     }


Mime
View raw message