You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2014/12/01 16:57:39 UTC

[6/7] incubator-brooklyn git commit: [BROOKLYN-92] Support for brokerName. Changes suggested by PR reviewer

[BROOKLYN-92] Support for brokerName. Changes suggested by PR reviewer


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

Branch: refs/heads/master
Commit: 039068a86a11b0cdfc16b9594f70011e022d1808
Parents: c3c6e3b
Author: Hadrian Zbarcea <ha...@apache.org>
Authored: Fri Nov 28 22:27:11 2014 -0500
Committer: Hadrian Zbarcea <ha...@apache.org>
Committed: Fri Nov 28 22:27:11 2014 -0500

----------------------------------------------------------------------
 .../entity/messaging/activemq/ActiveMQBroker.java    |  4 ++--
 .../messaging/activemq/ActiveMQDestinationImpl.java  | 15 ++++++---------
 .../messaging/activemq/ActiveMQIntegrationTest.java  | 12 ++++++------
 3 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/039068a8/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQBroker.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQBroker.java b/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQBroker.java
index 9eb7c11..6727934 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQBroker.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQBroker.java
@@ -57,8 +57,8 @@ public interface ActiveMQBroker extends SoftwareProcess, MessageBroker, UsesJmx,
         "http://www.mirrorservice.org/sites/ftp.apache.org/activemq");
 
     @SetFromFlag("brokerName")
-    public static final AttributeSensorAndConfigKey<String,String> BROKER_NAME = new BasicAttributeSensorAndConfigKey<String>(
-            String.class, "activemq.brokerName", "ActiveMQ Broker Name", "localhost");
+    public static final AttributeSensorAndConfigKey<String,String> BROKER_NAME = 
+        ConfigKeys.newStringSensorAndConfigKey("activemq.brokerName", "ActiveMQ Broker Name", "localhost");
 
     @SetFromFlag("openWirePort")
     public static final PortAttributeSensorAndConfigKey OPEN_WIRE_PORT = new PortAttributeSensorAndConfigKey("openwire.port", "OpenWire port", "61616+");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/039068a8/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQDestinationImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQDestinationImpl.java b/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQDestinationImpl.java
index e5afee5..fb86982 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQDestinationImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/activemq/ActiveMQDestinationImpl.java
@@ -23,6 +23,7 @@ import javax.management.ObjectName;
 
 import com.google.common.base.Preconditions;
 
+import brooklyn.entity.Entity;
 import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.messaging.jms.JMSDestinationImpl;
 import brooklyn.event.feed.jmx.JmxFeed;
@@ -33,7 +34,6 @@ public abstract class ActiveMQDestinationImpl extends JMSDestinationImpl impleme
     protected ObjectName brokerMBeanName;
     protected transient JmxHelper jmxHelper;
     protected volatile JmxFeed jmxFeed;
-    protected String brokerName;
 
     public ActiveMQDestinationImpl() {
     }
@@ -41,9 +41,9 @@ public abstract class ActiveMQDestinationImpl extends JMSDestinationImpl impleme
     @Override
     public void onManagementStarting() {
         super.onManagementStarting();
-        
-        getBrokerName();
-        Preconditions.checkNotNull(brokerName, "ActiveMQ broker name must be specified");
+
+        String brokerName = getBrokerName();
+        Preconditions.checkArgument(brokerName != null && !brokerName.isEmpty(), "ActiveMQ brokerName attribute must be specified");
 
         try {
             brokerMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName);
@@ -59,10 +59,7 @@ public abstract class ActiveMQDestinationImpl extends JMSDestinationImpl impleme
     }
     
     protected String getBrokerName() {
-        if (brokerName == null) {
-            EntityLocal parent = (EntityLocal)getParent();
-            brokerName = parent != null ? parent.getAttribute(ActiveMQBroker.BROKER_NAME) : null;
-        }
-        return brokerName;
+        Preconditions.checkNotNull(getParent(), "JMS Destination must have a broker parent");
+        return getParent().getAttribute(ActiveMQBroker.BROKER_NAME);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/039068a8/software/messaging/src/test/java/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java b/software/messaging/src/test/java/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
index a7cd334..2434fda 100644
--- a/software/messaging/src/test/java/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
+++ b/software/messaging/src/test/java/brooklyn/entity/messaging/activemq/ActiveMQIntegrationTest.java
@@ -80,7 +80,7 @@ public class ActiveMQIntegrationTest {
         activeMQ = app.createAndManageChild(EntitySpec.create(ActiveMQBroker.class));
 
         activeMQ.start(ImmutableList.of(testLocation));
-        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 60*1000), activeMQ, Startable.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ, Startable.SERVICE_UP, true);
         log.info("JMX URL is "+activeMQ.getAttribute(UsesJmx.JMX_URL));
         activeMQ.stop();
         assertFalse(activeMQ.getAttribute(Startable.SERVICE_UP));
@@ -96,7 +96,7 @@ public class ActiveMQIntegrationTest {
             .configure("jmxPort", "11099+"));
        
         activeMQ.start(ImmutableList.of(testLocation));
-        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 60*1000), activeMQ, Startable.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ, Startable.SERVICE_UP, true);
         log.info("JMX URL is "+activeMQ.getAttribute(UsesJmx.JMX_URL));
         activeMQ.stop();
         assertFalse(activeMQ.getAttribute(Startable.SERVICE_UP));
@@ -109,7 +109,7 @@ public class ActiveMQIntegrationTest {
             .configure("brokerName", "bridge"));
 
         activeMQ.start(ImmutableList.of(testLocation));
-        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 60*1000), activeMQ, Startable.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ, Startable.SERVICE_UP, true);
         log.info("JMX URL is "+activeMQ.getAttribute(UsesJmx.JMX_URL));
         activeMQ.stop();
         assertFalse(activeMQ.getAttribute(Startable.SERVICE_UP));
@@ -122,11 +122,11 @@ public class ActiveMQIntegrationTest {
         ActiveMQBroker activeMQ2 = app.createAndManageChild(EntitySpec.create(ActiveMQBroker.class));
 
         activeMQ1.start(ImmutableList.of(testLocation));
-        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 60*1000), activeMQ1, Startable.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ1, Startable.SERVICE_UP, true);
         log.info("JMX URL is "+activeMQ1.getAttribute(UsesJmx.JMX_URL));
 
         activeMQ2.start(ImmutableList.of(testLocation));
-        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 60*1000), activeMQ2, Startable.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ2, Startable.SERVICE_UP, true);
         log.info("JMX URL is "+activeMQ2.getAttribute(UsesJmx.JMX_URL));
     }
 
@@ -177,7 +177,7 @@ public class ActiveMQIntegrationTest {
             .configure(UsesJmx.JMX_AGENT_MODE, mode));
         
         activeMQ.start(ImmutableList.of(testLocation));
-        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 60*1000), activeMQ, Startable.SERVICE_UP, true);
+        EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ, Startable.SERVICE_UP, true);
 
         String jmxUrl = activeMQ.getAttribute(UsesJmx.JMX_URL);
         log.info("JMX URL ("+mode+") is "+jmxUrl);