brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [4/8] git commit: Added config keys required for clustering
Date Wed, 09 Jul 2014 14:45:10 GMT
Added config keys required for clustering


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

Branch: refs/heads/master
Commit: e409c68dcbf3337a8f1e6adba9c87953eff9f691
Parents: 62c7d20
Author: Martin Harris <github@nakomis.com>
Authored: Fri May 30 14:52:54 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Tue Jun 17 10:19:58 2014 +0100

----------------------------------------------------------------------
 .../nosql/elasticsearch/ElasticSearchNode.java  | 21 +++++++-
 .../elasticsearch/ElasticSearchNodeImpl.java    |  2 +
 .../ElasticSearchNodeSshDriver.java             | 51 ++++++++++++++++++--
 3 files changed, 68 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e409c68d/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
index 32ec9af..1eb4fda 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
@@ -8,6 +8,7 @@ import brooklyn.entity.proxying.ImplementedBy;
 import brooklyn.entity.webapp.WebAppServiceConstants;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.basic.BasicAttributeSensorAndConfigKey;
+import brooklyn.event.basic.BasicAttributeSensorAndConfigKey.StringAttributeSensorAndConfigKey;
 import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
 import brooklyn.event.basic.Sensors;
 import brooklyn.location.basic.PortRanges;
@@ -25,12 +26,28 @@ public interface ElasticSearchNode extends SoftwareProcess, DatastoreMixins.HasD
     BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new BasicAttributeSensorAndConfigKey<String>(
             SoftwareProcess.DOWNLOAD_URL, "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${version}.tar.gz");
     
+    @SetFromFlag("dataDir")
+    ConfigKey<String> DATA_DIR = ConfigKeys.newStringConfigKey("elasticsearch.data.dir",
"Directory for writing data files", null);
+    
+    @SetFromFlag("logDir")
+    ConfigKey<String> LOG_DIR = ConfigKeys.newStringConfigKey("elasticsearch.log.dir",
"Directory for writing log files", null);
+    
+    @SetFromFlag("configFileUrl")
+    ConfigKey<String> TEMPLATE_CONFIGURATION_URL = ConfigKeys.newStringConfigKey(
+            "elasticsearch.template.configuration.url", "URL where the elasticsearch configuration
file (in freemarker format) can be found");
+    
     @SetFromFlag("httpPort")
     PortAttributeSensorAndConfigKey HTTP_PORT = new PortAttributeSensorAndConfigKey(WebAppServiceConstants.HTTP_PORT,
PortRanges.fromString("9200+"));
     
+    @SetFromFlag("nodeName")
+    StringAttributeSensorAndConfigKey NODE_NAME = new StringAttributeSensorAndConfigKey("elasticsearch.node.name",

+            "Node name (or randomly selected if not set", null);
+    
+    @SetFromFlag("clusterName")
+    StringAttributeSensorAndConfigKey CLUSTER_NAME = new StringAttributeSensorAndConfigKey("elasticsearch.cluster.name",

+            "Cluster name (or elasticsearch selected if not set", null);
+    
     AttributeSensor<String> NODE_ID = Sensors.newStringSensor("elasticsearch.node.id");
-    AttributeSensor<String> NODE_NAME = Sensors.newStringSensor("elasticsearch.node.name");
-    AttributeSensor<String> CLUSTER_NAME = Sensors.newStringSensor("elasticsearch.cluster.name");
     AttributeSensor<Integer> DOCUMENT_COUNT = Sensors.newIntegerSensor("elasticsearch.docs.count");
     AttributeSensor<Integer> STORE_BYTES = Sensors.newIntegerSensor("elasticsearch.store.bytes");
     AttributeSensor<Integer> GET_TOTAL = Sensors.newIntegerSensor("elasticsearch.get.total");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e409c68d/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java
index f25d0bf..062e14b 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeImpl.java
@@ -82,6 +82,8 @@ public class ElasticSearchNodeImpl extends SoftwareProcessImpl implements
Elasti
             .poll(new HttpPollConfig<Integer>(SEARCH_QUERY_TIME_IN_MILLIS)
                 .onSuccess(HttpValueFunctions.chain(getFirstNode, JsonFunctions.walk("indices",
"search", "query_time_in_millis"), JsonFunctions.cast(Integer.class)))
                 .onFailureOrException(Functions.<Integer>constant(null)))
+            .poll(new HttpPollConfig<String>(CLUSTER_NAME)
+                .onSuccess(HttpValueFunctions.jsonContents("cluster_name", String.class)))
             .build();
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e409c68d/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
index f3846ca..3a695cb 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
@@ -2,18 +2,23 @@ package brooklyn.entity.nosql.elasticsearch;
 
 import static java.lang.String.format;
 
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.List;
 
-import com.google.common.collect.ImmutableList;
-
+import brooklyn.config.ConfigKey;
 import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.drivers.downloads.DownloadResolver;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.util.collections.MutableMap;
+import brooklyn.util.net.Urls;
+import brooklyn.util.os.Os;
 import brooklyn.util.ssh.BashCommands;
 
+import com.google.common.collect.ImmutableList;
+
 public class ElasticSearchNodeSshDriver extends AbstractSoftwareProcessSshDriver implements
ElasticSearchNodeDriver {
 
     public ElasticSearchNodeSshDriver(EntityLocal entity, SshMachineLocation machine) {
@@ -38,20 +43,58 @@ public class ElasticSearchNodeSshDriver extends AbstractSoftwareProcessSshDriver
 
     @Override
     public void customize() {
-        // TODO Auto-generated method stub
+        newScript(CUSTOMIZING).execute();  //create the directory
+        
+        String configFileUrl = entity.getConfig(ElasticSearchNode.TEMPLATE_CONFIGURATION_URL);
+        
+        if (configFileUrl == null) {
+            return;
+        }
+
+        String configScriptContents = processTemplate(configFileUrl);
+        Reader configContents = new StringReader(configScriptContents);
 
+        getMachine().copyTo(configContents, Urls.mergePaths(getRunDir(), getConfigFile()));
     }
 
     @Override
     public void launch() {
         String pidFile = getRunDir() + "/" + AbstractSoftwareProcessSshDriver.PID_FILENAME;
         entity.setAttribute(ElasticSearchNode.PID_FILE, pidFile);
+        StringBuilder commandBuilder = new StringBuilder()
+            .append(String.format("%s/bin/elasticsearch -d -p %s", getExpandedInstallDir(),
pidFile));
+        if (entity.getConfig(ElasticSearchNode.TEMPLATE_CONFIGURATION_URL) != null) {
+            commandBuilder.append(" -Des.config=" + Os.mergePaths(getRunDir(), getConfigFile()));
+        }
+        appendConfigIfPresent(commandBuilder, ElasticSearchNode.DATA_DIR, "es.path.data",
Os.mergePaths(getRunDir(), "data"));
+        appendConfigIfPresent(commandBuilder, ElasticSearchNode.LOG_DIR, "es.path.logs",
Os.mergePaths(getRunDir(), "logs"));
+        appendConfigIfPresent(commandBuilder, ElasticSearchNode.NODE_NAME.getConfigKey(),
"es.node.name");
+        appendConfigIfPresent(commandBuilder, ElasticSearchNode.CLUSTER_NAME.getConfigKey(),
"es.cluster.name");
+        commandBuilder.append(" > out.log 2> err.log < /dev/null");
         newScript(MutableMap.of("usePidFile", false), LAUNCHING)
             .updateTaskAndFailOnNonZeroResultCode()
-            .body.append(String.format("%s/bin/elasticsearch -d -p %s > out.log 2>
err.log < /dev/null", getExpandedInstallDir(), pidFile))
+            .body.append(commandBuilder.toString())
             .execute();
     }
     
+    private void appendConfigIfPresent(StringBuilder builder, ConfigKey<String> configKey,
String parameter) {
+        appendConfigIfPresent(builder, configKey, parameter, null);
+    }
+    
+    private void appendConfigIfPresent(StringBuilder builder, ConfigKey<String> configKey,
String parameter, String defaultValue) {
+        String config = entity.getConfig(configKey);
+        if (config == null && defaultValue != null) {
+            config = defaultValue;
+        }
+        if (config != null) {
+            builder.append(String.format(" -D%s=%s", parameter, config));
+        }
+    }
+    
+    public String getConfigFile() {
+        return "elasticsearch.yaml";
+    }
+    
     @Override
     public boolean isRunning() {
         return newScript(MutableMap.of("usePidFile", true), CHECK_RUNNING).execute() == 0;


Mime
View raw message