[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.3.x@1483381 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/918e31a1 Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/918e31a1 Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/918e31a1 Branch: refs/heads/cellar-2.3.x Commit: 918e31a18def0d8fae36ed14e3c9ec7570caa91a Parents: f675c67 Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68> Authored: Thu May 16 14:12:52 2013 +0000 Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68> Committed: Thu May 16 14:12:52 2013 +0000 ---------------------------------------------------------------------- .../management/internal/CellarMBeanImpl.java | 130 +++++++++++-------- .../cellar/shell/consumer/ConsumerSupport.java | 9 +- .../cellar/shell/handler/HandlersSupport.java | 9 +- .../cellar/shell/producer/ProducerSupport.java | 14 +- 4 files changed, 101 insertions(+), 61 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/918e31a1/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 a7c34b5..b0caa9b 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 @@ -118,11 +118,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()) { @@ -134,8 +134,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); } } @@ -148,13 +148,16 @@ 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); @@ -165,13 +168,16 @@ 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); @@ -186,19 +192,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); } @@ -209,13 +215,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); @@ -226,13 +236,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); @@ -247,19 +261,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); } @@ -270,13 +284,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); @@ -287,13 +305,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/918e31a1/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 92cce9f..f60a45d 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 @@ -49,7 +49,14 @@ public abstract class ConsumerSupport extends ClusterCommandSupport { } } } else { - recipientList = clusterManager.listNodes(); + if (status == null) { + // in case of status display, select all nodes + recipientList = clusterManager.listNodes(); + } else { + // in case of status change, select only the local node + recipientList = new HashSet<Node>(); + recipientList.add(clusterManager.getNode()); + } } if (recipientList.size() < 1) { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/918e31a1/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 8a076eb..8b908e9 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 @@ -48,7 +48,14 @@ public abstract class HandlersSupport extends ClusterCommandSupport { } } } else { - recipientList = clusterManager.listNodes(); + if (status == null) { + // in case of status display, select all nodes + recipientList = clusterManager.listNodes(); + } else { + // in case of status change, select only the local node + recipientList = new HashSet<Node>(); + recipientList.add(clusterManager.getNode()); + } } if (recipientList.size() < 1) { http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/918e31a1/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 38e2e84..1287e42 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 @@ -19,10 +19,7 @@ import org.apache.karaf.cellar.core.control.ProducerSwitchResult; import org.apache.karaf.cellar.core.control.SwitchStatus; import org.apache.karaf.cellar.shell.ClusterCommandSupport; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * Abstract cluster event producer shell command support. @@ -49,7 +46,14 @@ public abstract class ProducerSupport extends ClusterCommandSupport { } } } else { - recipientList = clusterManager.listNodes(); + if (status == null) { + // in case of status display, select all nodes + recipientList = clusterManager.listNodes(); + } else { + // in case of status change, select only the local node + recipientList = new HashSet<Node>(); + recipientList.add(clusterManager.getNode()); + } } if (recipientList.size() < 1) {
