brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/4] incubator-brooklyn git commit: Rabbit mq management flag
Date Wed, 08 Apr 2015 09:26:26 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master a9e6fc8e6 -> 3c6ffc483


Rabbit mq management flag

Add flag enableManagementPlugin defaulting to false


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

Branch: refs/heads/master
Commit: 497f99b2af7c72c5b8a440b2fe4d6fa16411369c
Parents: 1f14917
Author: Duncan Grant <duncan.grant@cloudsoftcorp.com>
Authored: Tue Apr 7 10:45:46 2015 +0100
Committer: Duncan Grant <duncan.grant@cloudsoftcorp.com>
Committed: Tue Apr 7 10:57:51 2015 +0100

----------------------------------------------------------------------
 software/messaging/pom.xml                      |  1 +
 .../entity/messaging/rabbit/RabbitBroker.java   | 30 ++++++++---
 .../messaging/rabbit/RabbitBrokerImpl.java      | 24 ++++++---
 .../messaging/rabbit/RabbitSshDriver.java       | 54 ++++++++++++--------
 .../entity/messaging/rabbit/rabbitmq.config     |  5 ++
 5 files changed, 79 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/497f99b2/software/messaging/pom.xml
----------------------------------------------------------------------
diff --git a/software/messaging/pom.xml b/software/messaging/pom.xml
index 5c95a0b..8730164 100644
--- a/software/messaging/pom.xml
+++ b/software/messaging/pom.xml
@@ -57,6 +57,7 @@
                             <exclude>src/main/resources/brooklyn/entity/messaging/kafka/server.properties</exclude>
                             <exclude>src/main/resources/brooklyn/entity/messaging/kafka/zookeeper.properties</exclude>
                             <exclude>src/main/resources/brooklyn/entity/messaging/storm/storm.yaml</exclude>
+                            <exclude>src/main/resources/brooklyn/entity/messaging/rabbit/rabbitmq.config</exclude>
                         </excludes>
                     </configuration>
                 </plugin>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/497f99b2/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBroker.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBroker.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBroker.java
index 54fd741..f883aec 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBroker.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBroker.java
@@ -18,8 +18,6 @@
  */
 package brooklyn.entity.messaging.rabbit;
 
-import java.util.Map;
-
 import brooklyn.catalog.Catalog;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.basic.ConfigKeys;
@@ -27,13 +25,13 @@ import brooklyn.entity.basic.SoftwareProcess;
 import brooklyn.entity.messaging.MessageBroker;
 import brooklyn.entity.messaging.amqp.AmqpServer;
 import brooklyn.entity.proxying.ImplementedBy;
-import brooklyn.event.basic.BasicAttributeSensorAndConfigKey;
-import brooklyn.event.basic.BasicConfigKey;
-import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
+import brooklyn.event.AttributeSensor;
+import brooklyn.event.basic.*;
 import brooklyn.util.flags.SetFromFlag;
-
 import com.google.common.annotations.Beta;
 
+import java.util.Map;
+
 /**
  * An {@link brooklyn.entity.Entity} that represents a single Rabbit MQ broker instance,
using AMQP 0-9-1.
  */
@@ -50,7 +48,12 @@ public interface RabbitBroker extends SoftwareProcess, MessageBroker, AmqpServer
     
     @SetFromFlag("erlangVersion")
     public static final BasicConfigKey<String> ERLANG_VERSION = new BasicConfigKey<String>(String.class,
"erlang.version", "Erlang runtime version", "R15B");
-    
+
+    @SetFromFlag("rabbitmqConfigTemplateUrl")
+    ConfigKey<String> CONFIG_TEMPLATE_URL = ConfigKeys.newStringConfigKey(
+            "rabbitmq.templateUrl", "Template file (in freemarker format) for the rabbitmq.config
config file",
+            "classpath://brooklyn/entity/messaging/rabbit/rabbitmq.config");
+
     @SetFromFlag("amqpPort")
     public static final PortAttributeSensorAndConfigKey AMQP_PORT = AmqpServer.AMQP_PORT;
 
@@ -60,7 +63,18 @@ public interface RabbitBroker extends SoftwareProcess, MessageBroker, AmqpServer
     @SetFromFlag("amqpVersion")
     public static final BasicAttributeSensorAndConfigKey<String> AMQP_VERSION = new
BasicAttributeSensorAndConfigKey<String>(
             AmqpServer.AMQP_VERSION, AmqpServer.AMQP_0_9_1);
-    
+
+    @SetFromFlag("managmentPort")
+    public static final PortAttributeSensorAndConfigKey MANAGEMENT_PORT = new PortAttributeSensorAndConfigKey(
+                    "rabbitmq.management.port", "Port on which management interface will
be available", "15672+");
+
+    public static AttributeSensor<String> MANAGEMENT_URL = Sensors.newStringSensor(
+            "rabbitmq.management.url", "Management URL is only available if management plugin
flag is true");
+
+    @SetFromFlag("enableManagementPlugin")
+    public static final ConfigKey<Boolean> ENABLE_MANAGEMENT_PLUGIN = ConfigKeys.newBooleanConfigKey(
+            "rabbitmq.management.plugin", "Management plugin will be enabled", false);
+
     RabbitQueue createQueue(Map properties);
 
     // TODO required by RabbitDestination due to close-coupling between that and RabbitBroker;
how best to improve?

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/497f99b2/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBrokerImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBrokerImpl.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBrokerImpl.java
index 91b6d06..0184e73 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBrokerImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitBrokerImpl.java
@@ -18,16 +18,16 @@
  */
 package brooklyn.entity.messaging.rabbit;
 
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.SoftwareProcessImpl;
 import brooklyn.entity.proxying.EntitySpec;
-
 import com.google.common.base.Objects.ToStringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+import static java.lang.String.format;
 
 /**
  * An {@link brooklyn.entity.Entity} that represents a single Rabbit MQ broker instance,
using AMQP 0-9-1.
@@ -70,7 +70,7 @@ public class RabbitBrokerImpl extends SoftwareProcessImpl implements RabbitBroke
 
     public void setBrokerUrl() {
         String urlFormat = "amqp://guest:guest@%s:%d/%s";
-        setAttribute(BROKER_URL, String.format(urlFormat, getAttribute(HOSTNAME), getAttribute(AMQP_PORT),
getAttribute(VIRTUAL_HOST_NAME)));
+        setAttribute(BROKER_URL, format(urlFormat, getAttribute(HOSTNAME), getAttribute(AMQP_PORT),
getAttribute(VIRTUAL_HOST_NAME)));
     }
 
     public RabbitQueue createQueue(Map properties) {
@@ -92,6 +92,8 @@ public class RabbitBrokerImpl extends SoftwareProcessImpl implements RabbitBroke
         connectServiceUpIsRunning();
 
         setBrokerUrl();
+
+        setAttribute(MANAGEMENT_URL, format("http://%s:%s/", getAttribute(HOSTNAME), getAttribute(MANAGEMENT_PORT)));
     }
 
     @Override
@@ -100,6 +102,14 @@ public class RabbitBrokerImpl extends SoftwareProcessImpl implements
RabbitBroke
         disconnectServiceUpIsRunning();
     }
 
+    public boolean getEnableManagementPlugin() {
+        return getConfig(ENABLE_MANAGEMENT_PLUGIN);
+    }
+
+    public Integer getManagementPort() {
+        return getAttribute(MANAGEMENT_PORT);
+    }
+
     @Override
     protected ToStringHelper toStringHelper() {
         return super.toStringHelper().add("amqpPort", getAmqpPort());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/497f99b2/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitSshDriver.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitSshDriver.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitSshDriver.java
index 3219a06..534edb5 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitSshDriver.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/rabbit/RabbitSshDriver.java
@@ -18,26 +18,25 @@
  */
 package brooklyn.entity.messaging.rabbit;
 
-import static brooklyn.util.ssh.BashCommands.*;
-import static java.lang.String.format;
-
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.base.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver;
 import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.lifecycle.ScriptHelper;
 import brooklyn.entity.messaging.amqp.AmqpServer;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.net.Networking;
 import brooklyn.util.os.Os;
-
+import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+import static brooklyn.util.ssh.BashCommands.*;
+import static java.lang.String.format;
 
 /**
  * TODO javadoc
@@ -52,7 +51,7 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver implements
         "6", "6-8",
         "7", "7-5"
     );
-    
+
     public RabbitSshDriver(RabbitBrokerImpl entity, SshMachineLocation machine) {
         super(entity, machine);
     }
@@ -75,7 +74,7 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver implements
         resolver = Entities.newDownloader(this);
         setExpandedInstallDir(Os.mergePaths(getInstallDir(), resolver.getUnpackedDirectoryName(format("rabbitmq_server-%s",
getVersion()))));
     }
-    
+
     @Override
     public void install() {
         List<String> urls = resolver.getTargets();
@@ -124,11 +123,20 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver
implements
     @Override
     public void customize() {
         Networking.checkPortsValid(MutableMap.of("amqpPort", getAmqpPort()));
-        newScript(CUSTOMIZING)
-                .body.append(
-                    format("cp -R %s/* .", getExpandedInstallDir())
-                )
-                .execute();
+        copyTemplate(entity.getConfig(RabbitBroker.CONFIG_TEMPLATE_URL), getConfigPath()
+ ".config");
+        ScriptHelper scriptHelper = newScript(CUSTOMIZING);
+
+        scriptHelper.body.append(
+                format("cp -R %s/* .", getExpandedInstallDir())
+        );
+
+        if (entity.getConfig(RabbitBroker.ENABLE_MANAGEMENT_PLUGIN)) {
+            scriptHelper.body.append(
+                    "./sbin/rabbitmq-plugins enable rabbitmq_management"
+            );
+        }
+
+        scriptHelper.execute();
     }
 
     @Override
@@ -155,8 +163,9 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver
implements
             ).execute();
     }
 
+
     public String getPidFile() { return "rabbitmq.pid"; }
-    
+
     @Override
     public boolean isRunning() {
         return newScript(MutableMap.of("usePidFile", false), CHECK_RUNNING)
@@ -164,7 +173,6 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver
implements
                 .execute() == 0;
     }
 
-
     @Override
     public void stop() {
         newScript(MutableMap.of("usePidFile", false), STOPPING)
@@ -172,6 +180,7 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver
implements
                 .execute();
     }
 
+
     @Override
     public void kill() {
         stop(); // TODO No pid file to easily do `kill -9`
@@ -186,6 +195,11 @@ public class RabbitSshDriver extends AbstractSoftwareProcessSshDriver
implements
                 .put("RABBITMQ_NODENAME", getEntity().getId())
                 .put("RABBITMQ_NODE_PORT", getAmqpPort().toString())
                 .put("RABBITMQ_PID_FILE", getRunDir()+"/"+getPidFile())
+                .put("RABBITMQ_CONFIG_FILE", getConfigPath())
                 .build();
     }
+
+    private String getConfigPath() {
+        return getInstallDir() + "/rabbitmq";
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/497f99b2/software/messaging/src/main/resources/brooklyn/entity/messaging/rabbit/rabbitmq.config
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/resources/brooklyn/entity/messaging/rabbit/rabbitmq.config
b/software/messaging/src/main/resources/brooklyn/entity/messaging/rabbit/rabbitmq.config
new file mode 100644
index 0000000..b4428f0
--- /dev/null
+++ b/software/messaging/src/main/resources/brooklyn/entity/messaging/rabbit/rabbitmq.config
@@ -0,0 +1,5 @@
+[
+<#if entity.enableManagementPlugin>
+    {rabbitmq_mochiweb, [{listeners, [{mgmt, [{port, ${entity.managementPort?c}}]}]}]}
+</#if>
+].
\ No newline at end of file


Mime
View raw message