brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [22/50] brooklyn-library git commit: Wait for JMX availability before setting SERVICE_UP
Date Mon, 01 Feb 2016 17:46:40 GMT
Wait for JMX availability before setting SERVICE_UP


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

Branch: refs/heads/0.5.0
Commit: 2ca3ea75ca987d2e42388999ab734557d791b439
Parents: c143706
Author: Andrew Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Wed Mar 20 20:08:36 2013 +0000
Committer: Andrew Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Fri Apr 19 10:36:06 2013 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/messaging/kafka/Kafka.java  |  1 -
 .../entity/messaging/kafka/KafkaBrokerImpl.java | 28 +++++++++++++++++---
 .../messaging/kafka/KafkaZookeeperImpl.java     | 25 +++++++++++++++--
 .../messaging/kafka/KafkaIntegrationTest.groovy |  2 --
 4 files changed, 47 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/2ca3ea75/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/Kafka.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/Kafka.java b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/Kafka.java
index 7f26f8e..a0e4eef 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/Kafka.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/Kafka.java
@@ -17,7 +17,6 @@ package brooklyn.entity.messaging.kafka;
 
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.SoftwareProcess;
-import brooklyn.event.basic.BasicAttributeSensor;
 import brooklyn.event.basic.BasicAttributeSensorAndConfigKey;
 import brooklyn.event.basic.BasicConfigKey;
 import brooklyn.util.flags.SetFromFlag;

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/2ca3ea75/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
index ae21118..0abdf45 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
@@ -15,12 +15,15 @@
  */
 package brooklyn.entity.messaging.kafka;
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,12 +32,13 @@ import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.SoftwareProcessImpl;
 import brooklyn.entity.messaging.MessageBroker;
-import brooklyn.event.basic.BasicAttributeSensor;
 import brooklyn.event.feed.function.FunctionFeed;
 import brooklyn.event.feed.function.FunctionPollConfig;
 import brooklyn.event.feed.jmx.JmxAttributePollConfig;
 import brooklyn.event.feed.jmx.JmxFeed;
+import brooklyn.event.feed.jmx.JmxHelper;
 import brooklyn.util.MutableMap;
+import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.base.Functions;
 import com.google.common.base.Objects.ToStringHelper;
@@ -93,13 +97,29 @@ public class KafkaBrokerImpl extends SoftwareProcessImpl implements MessageBroke
         return ports;
     }
 
+    private ObjectName socketServerStatsMbean = JmxHelper.createObjectName("kafka:type=kafka.SocketServerStats");
     private volatile FunctionFeed functionFeed;
     private volatile JmxFeed jmxFeed;
 
     @Override
-    protected void connectSensors() {
-        String socketServerStatsMbean = "kafka:type=kafka.SocketServerStats";
+    public void waitForServiceUp(long duration, TimeUnit units) {
+        super.waitForServiceUp(duration, units);
+
+        // Wait for the MBean to exist
+        JmxHelper helper = null;
+        try {
+            helper = new JmxHelper(this);
+            helper.connect();
+            helper.assertMBeanExistsEventually(socketServerStatsMbean, units.toMillis(duration));
+        } catch (IOException e) {
+            throw Exceptions.propagate(e);
+        } finally {
+            if (helper != null) helper.disconnect();
+        }
+    }
 
+    @Override
+    protected void connectSensors() {
         functionFeed = FunctionFeed.builder()
                 .entity(this)
                 .poll(new FunctionPollConfig<Object, Boolean>(SERVICE_UP)

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/2ca3ea75/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaZookeeperImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaZookeeperImpl.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaZookeeperImpl.java
index d941411..a572a75 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaZookeeperImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaZookeeperImpl.java
@@ -15,12 +15,15 @@
  */
 package brooklyn.entity.messaging.kafka;
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 
+import javax.management.ObjectName;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,7 +34,9 @@ import brooklyn.event.feed.function.FunctionFeed;
 import brooklyn.event.feed.function.FunctionPollConfig;
 import brooklyn.event.feed.jmx.JmxAttributePollConfig;
 import brooklyn.event.feed.jmx.JmxFeed;
+import brooklyn.event.feed.jmx.JmxHelper;
 import brooklyn.util.MutableMap;
+import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
@@ -76,13 +81,29 @@ public class KafkaZookeeperImpl extends SoftwareProcessImpl implements
KafkaZook
         return ports;
     }
 
+    private ObjectName zookeeperMbean = JmxHelper.createObjectName("org.apache.ZooKeeperService:name0=StandaloneServer_port-1");
     private volatile FunctionFeed functionFeed;
     private volatile JmxFeed jmxFeed;
 
     @Override
-    protected void connectSensors() {
-        String zookeeperMbean = "org.apache.ZooKeeperService:name0=StandaloneServer_port-1";
+    public void waitForServiceUp(long duration, TimeUnit units) {
+        super.waitForServiceUp(duration, units);
+
+        // Wait for the MBean to exist
+        JmxHelper helper = null;
+        try {
+            helper = new JmxHelper(this);
+            helper.connect();
+            helper.assertMBeanExistsEventually(zookeeperMbean, units.toMillis(duration));
+        } catch (IOException e) {
+            throw Exceptions.propagate(e);
+        } finally {
+            if (helper != null) helper.disconnect();
+        }
+    }
 
+    @Override
+    protected void connectSensors() {
         functionFeed = FunctionFeed.builder()
                 .entity(this)
                 .poll(new FunctionPollConfig<Object, Boolean>(SERVICE_UP)

http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/2ca3ea75/software/messaging/src/test/java/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.groovy
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.groovy
b/software/messaging/src/test/java/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.groovy
index cbfb410..89f5773 100644
--- a/software/messaging/src/test/java/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.groovy
+++ b/software/messaging/src/test/java/brooklyn/entity/messaging/kafka/KafkaIntegrationTest.groovy
@@ -117,8 +117,6 @@ public class KafkaIntegrationTest {
 
         Entities.dumpInfo(cluster);
 
-        Thread.sleep(5000l);
-
         KafkaSupport support = new KafkaSupport(cluster.getZookeeper());
         support.sendMessage("brooklyn", "TEST_MESSAGE")
         List<String> messages = support.getMessage("brooklyn");


Mime
View raw message