Repository: camel Updated Branches: refs/heads/master 2efb85f1d -> efbccd439
CAMEL-10986: Add master route policy Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/efbccd43 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/efbccd43 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/efbccd43 Branch: refs/heads/master Commit: efbccd4399e54d0bf05f7c13484d5a2a7925990f Parents: 2efb85f Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Mar 13 10:01:39 2017 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Mar 13 10:01:39 2017 +0100 ---------------------------------------------------------------------- .../policy/MasterRoutePolicy.java | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/efbccd43/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/policy/MasterRoutePolicy.java ---------------------------------------------------------------------- diff --git a/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/policy/MasterRoutePolicy.java b/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/policy/MasterRoutePolicy.java index 437cf2a..aa80095 100644 --- a/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/policy/MasterRoutePolicy.java +++ b/components/camel-zookeeper-master/src/main/java/org/apache/camel/component/zookeepermaster/policy/MasterRoutePolicy.java @@ -18,9 +18,15 @@ package org.apache.camel.component.zookeepermaster.policy; import java.util.concurrent.atomic.AtomicBoolean; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.Route; +import org.apache.camel.api.management.ManagedAttribute; +import org.apache.camel.api.management.ManagedOperation; +import org.apache.camel.api.management.ManagedResource; import org.apache.camel.component.zookeepermaster.CamelNodeState; import org.apache.camel.component.zookeepermaster.ContainerIdFactory; import org.apache.camel.component.zookeepermaster.DefaultContainerIdFactory; @@ -37,6 +43,7 @@ import org.apache.curator.framework.CuratorFramework; * is controlled by this route policy which will start/stop the route accordingly to being * the master in the zookeeper cluster group. */ +@ManagedResource(description = "Managed MasterRoutePolicy") public class MasterRoutePolicy extends RoutePolicySupport implements CamelContextAware { private CuratorFramework curator; @@ -77,6 +84,7 @@ public class MasterRoutePolicy extends RoutePolicySupport implements CamelContex this.zkRoot = zkRoot; } + @ManagedAttribute(description = "The name of the cluster group to use") public String getGroupName() { return groupName; } @@ -110,6 +118,7 @@ public class MasterRoutePolicy extends RoutePolicySupport implements CamelContex this.curator = curator; } + @ManagedAttribute(description = "Timeout in millis to use when connecting to the zookeeper ensemble") public int getMaximumConnectionTimeout() { return maximumConnectionTimeout; } @@ -121,6 +130,7 @@ public class MasterRoutePolicy extends RoutePolicySupport implements CamelContex this.maximumConnectionTimeout = maximumConnectionTimeout; } + @ManagedAttribute(description = "The url for the zookeeper ensemble") public String getZooKeeperUrl() { return zooKeeperUrl; } @@ -143,6 +153,51 @@ public class MasterRoutePolicy extends RoutePolicySupport implements CamelContex this.zooKeeperPassword = zooKeeperPassword; } + @ManagedAttribute(description = "Are we connected to ZooKeeper") + public boolean isConnected() { + if (groupListener == null) { + return false; + } + return groupListener.getGroup().isConnected(); + } + + @ManagedAttribute(description = "Are we the master") + public boolean isMaster() { + if (groupListener == null) { + return false; + } + return groupListener.getGroup().isMaster(); + } + + @ManagedOperation(description = "Information about all the slaves") + public String slaves() { + if (groupListener == null) { + return null; + } + try { + return new ObjectMapper() + .enable(SerializationFeature.INDENT_OUTPUT) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .writeValueAsString(groupListener.getGroup().slaves()); + } catch (Exception e) { + return null; + } + } + + @ManagedOperation(description = "Information about the last event in the cluster group") + public String lastEvent() { + if (groupListener == null) { + return null; + } + Object event = groupListener.getGroup().getLastState(); + return event != null ? event.toString() : null; + } + + @ManagedOperation(description = "Information about this node") + public String thisNode() { + return thisNodeState != null ? thisNodeState.toString() : null; + } + @Override public void onInit(Route route) { super.onInit(route);