You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/12/18 13:30:32 UTC
[41/50] git commit: [KARAF-2142] Change the state only of the local
node when using producer, consumer, handler commands or MBeans
[KARAF-2142] Change the state only of the local node when using producer, consumer, handler commands or MBeans
git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/branches/cellar-2.2.x@1483425 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/eceb9609
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/eceb9609
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/eceb9609
Branch: refs/heads/cellar-2.2.x
Commit: eceb9609c37e5299961576408a93ab96b3165050
Parents: 29423e9
Author: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Thu May 16 15:59:14 2013 +0000
Committer: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Thu May 16 15:59:14 2013 +0000
----------------------------------------------------------------------
.../management/internal/CellarMBeanImpl.java | 131 +++++++++++--------
.../cellar/shell/consumer/ConsumerSupport.java | 9 +-
.../cellar/shell/handler/HandlersSupport.java | 9 +-
.../cellar/shell/producer/ProducerSupport.java | 9 +-
4 files changed, 96 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/eceb9609/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
----------------------------------------------------------------------
diff --git a/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java b/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
index 3e5f370..883c076 100644
--- a/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
+++ b/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
@@ -116,11 +116,11 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
Map<Node, ManageHandlersResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Handler", "Karaf Cellar cluster event handler",
- new String[]{ "node", "handler", "status", "local" },
- new String[]{ "Node hosting event handler", "Name of the event handler", "Current status of the event handler", "True if the node is local" },
- new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN });
+ new String[]{"node", "handler", "status", "local"},
+ new String[]{"Node hosting event handler", "Name of the event handler", "Current status of the event handler", "True if the node is local"},
+ new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Handlers", "Table of Karaf Cellar cluster event handlers",
- compositeType, new String[]{ "node", "handler" });
+ compositeType, new String[]{"node", "handler"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Map.Entry<Node, ManageHandlersResult> handlersResultEntry : results.entrySet()) {
@@ -132,8 +132,8 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
String status = handlerEntry.getValue();
boolean local = (node.equals(clusterManager.getNode()));
CompositeDataSupport data = new CompositeDataSupport(compositeType,
- new String[]{ "node", "handler", "status", "local" },
- new Object[]{ node.getId(), handler, status, local });
+ new String[]{"node", "handler", "status", "local"},
+ new Object[]{node.getId(), handler, status, local});
table.put(data);
}
}
@@ -145,13 +145,17 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
public void handlerStart(String handlerId, String nodeId) throws Exception {
ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
- Node node = clusterManager.findNodeById(nodeId);
- if (node == null) {
- throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
- }
-
Set<Node> nodes = new HashSet<Node>();
- nodes.add(node);
+
+ if (nodeId == null || nodeId.isEmpty()) {
+ nodes.add(clusterManager.getNode());
+ } else {
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+ nodes.add(node);
+ }
command.setHandlerName(handlerId);
command.setDestination(nodes);
@@ -161,13 +165,18 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
public void handlerStop(String handlerId, String nodeId) throws Exception {
ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
- Node node = clusterManager.findNodeById(nodeId);
- if (node == null) {
- throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
- }
Set<Node> nodes = new HashSet<Node>();
- nodes.add(node);
+
+ if (nodeId == null || nodeId.isEmpty()) {
+ nodes.add(clusterManager.getNode());
+ } else {
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+ nodes.add(node);
+ }
command.setHandlerName(handlerId);
command.setDestination(nodes);
@@ -181,19 +190,19 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Consumer", "Karaf Cellar cluster event consumer",
- new String[]{ "node", "status", "local" },
- new String[]{ "Node hosting event consumer", "Current status of the event consumer", "True if the node is local" },
- new OpenType[]{ SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN });
+ new String[]{"node", "status", "local"},
+ new String[]{"Node hosting event consumer", "Current status of the event consumer", "True if the node is local"},
+ new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Consumers", "Table of Karaf Cellar cluster event consumers",
- compositeType, new String[]{ "node" });
+ compositeType, new String[]{"node"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Node node : results.keySet()) {
boolean local = (node.equals(clusterManager.getNode()));
ConsumerSwitchResult consumerSwitchResult = results.get(node);
CompositeDataSupport data = new CompositeDataSupport(compositeType,
- new String[]{ "node", "status", "local" },
- new Object[]{ node.getId(), consumerSwitchResult.getStatus(), local });
+ new String[]{"node", "status", "local"},
+ new Object[]{node.getId(), consumerSwitchResult.getStatus(), local});
table.put(data);
}
@@ -203,13 +212,17 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
public void consumerStart(String nodeId) throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
- Node node = clusterManager.findNodeById(nodeId);
- if (node == null) {
- throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
- }
-
Set<Node> nodes = new HashSet<Node>();
- nodes.add(node);
+
+ if (nodeId == null || nodeId.isEmpty()) {
+ nodes.add(clusterManager.getNode());
+ } else {
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+ nodes.add(node);
+ }
command.setDestination(nodes);
command.setStatus(SwitchStatus.ON);
@@ -219,13 +232,17 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
public void consumerStop(String nodeId) throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
- Node node = clusterManager.findNodeById(nodeId);
- if (node == null) {
- throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
- }
-
Set<Node> nodes = new HashSet<Node>();
- nodes.add(node);
+
+ if (nodeId == null || nodeId.isEmpty()) {
+ nodes.add(clusterManager.getNode());
+ } else {
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+ nodes.add(node);
+ }
command.setDestination(nodes);
command.setStatus(SwitchStatus.OFF);
@@ -239,19 +256,19 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
Map<Node, ProducerSwitchResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer",
- new String[]{ "node", "status", "local" },
- new String[]{ "Node hosting event producer", "Current status of the event producer", "True if the node is local" },
- new OpenType[]{ SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN });
+ new String[]{"node", "status", "local"},
+ new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"},
+ new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers",
- compositeType, new String[]{ "node" });
+ compositeType, new String[]{"node"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Node node : results.keySet()) {
boolean local = (node.equals(clusterManager.getNode()));
ProducerSwitchResult producerSwitchResult = results.get(node);
CompositeDataSupport data = new CompositeDataSupport(compositeType,
- new String[]{ "node", "status", "local" },
- new Object[]{ node.getId(), producerSwitchResult.getStatus(), local });
+ new String[]{"node", "status", "local"},
+ new Object[]{node.getId(), producerSwitchResult.getStatus(), local});
table.put(data);
}
@@ -261,13 +278,17 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
public void producerStop(String nodeId) throws Exception {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
- Node node = clusterManager.findNodeById(nodeId);
- if (node == null) {
- throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
- }
-
Set<Node> nodes = new HashSet<Node>();
- nodes.add(node);
+
+ if (nodeId == null || nodeId.isEmpty()) {
+ nodes.add(clusterManager.getNode());
+ } else {
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+ }
+ nodes.add(node);
+ }
command.setDestination(nodes);
command.setStatus(SwitchStatus.OFF);
@@ -277,13 +298,17 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean {
public void producerStart(String nodeId) throws Exception {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
- Node node = clusterManager.findNodeById(nodeId);
- if (node == null) {
- throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist)");
- }
-
Set<Node> nodes = new HashSet<Node>();
- nodes.add(node);
+
+ if (nodeId == null || nodeId.isEmpty()) {
+ nodes.add(clusterManager.getNode());
+ } else {
+ Node node = clusterManager.findNodeById(nodeId);
+ if (node == null) {
+ throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist)");
+ }
+ nodes.add(node);
+ }
command.setDestination(nodes);
command.setStatus(SwitchStatus.ON);
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/eceb9609/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java b/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
index 267be4b..0bea2f4 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
@@ -34,9 +34,8 @@ public abstract class ConsumerSupport extends ClusterCommandSupport {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
// looking for nodes and check if exist
- Set<Node> recipientList;
+ Set<Node> recipientList = new HashSet<Node>();
if (nodeIds != null && !nodeIds.isEmpty()) {
- recipientList = new HashSet<Node>();
for (String nodeId : nodeIds) {
Node node = clusterManager.findNodeById(nodeId);
if (node == null) {
@@ -46,7 +45,11 @@ public abstract class ConsumerSupport extends ClusterCommandSupport {
}
}
} else {
- recipientList = clusterManager.listNodes();
+ if (status == null) {
+ recipientList = clusterManager.listNodes();
+ } else {
+ recipientList.add(clusterManager.getNode());
+ }
}
if (recipientList.size() < 1) {
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/eceb9609/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java b/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
index d632d27..e817594 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
@@ -33,9 +33,8 @@ public abstract class HandlersSupport extends ClusterCommandSupport {
ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
// looking for nodes and check if exist
- Set<Node> recipientList;
+ Set<Node> recipientList = new HashSet<Node>();
if (nodeIds != null && !nodeIds.isEmpty()) {
- recipientList = new HashSet<Node>();
for (String nodeId : nodeIds) {
Node node = clusterManager.findNodeById(nodeId);
if (node == null) {
@@ -45,7 +44,11 @@ public abstract class HandlersSupport extends ClusterCommandSupport {
}
}
} else {
- recipientList = clusterManager.listNodes();
+ if (status == null) {
+ recipientList = clusterManager.listNodes();
+ } else {
+ recipientList.add(clusterManager.getNode());
+ }
}
if (recipientList.size() < 1) {
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/eceb9609/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java b/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
index fee1ad8..0d1482e 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
@@ -34,9 +34,8 @@ public abstract class ProducerSupport extends ClusterCommandSupport {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
// looking for nodes and check if exist
- Set<Node> recipientList;
+ Set<Node> recipientList = new HashSet<Node>();
if (nodeIds != null && !nodeIds.isEmpty()) {
- recipientList = new HashSet<Node>();
for (String nodeId : nodeIds) {
Node node = clusterManager.findNodeById(nodeId);
if (node == null) {
@@ -46,7 +45,11 @@ public abstract class ProducerSupport extends ClusterCommandSupport {
}
}
} else {
- recipientList = clusterManager.listNodes();
+ if (status == null) {
+ recipientList = clusterManager.listNodes();
+ } else {
+ recipientList.add(clusterManager.getNode());
+ }
}
if (recipientList.size() < 1) {