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:23:03 UTC
[28/50] [abbrv] 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/trunk@1483413 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/4c5d87a3
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/4c5d87a3
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/4c5d87a3
Branch: refs/heads/master
Commit: 4c5d87a38028c500432b77b70865bb22b2802ff9
Parents: 3ca8c65
Author: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Thu May 16 15:39:02 2013 +0000
Committer: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Thu May 16 15:39:02 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, 101 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4c5d87a3/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 0ae453f..ea6406a 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
@@ -119,11 +119,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()) {
@@ -135,8 +135,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);
}
}
@@ -149,13 +149,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);
@@ -166,13 +170,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);
@@ -187,19 +194,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);
}
@@ -210,13 +217,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);
@@ -227,13 +238,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);
@@ -248,19 +263,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);
}
@@ -271,13 +286,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);
@@ -288,13 +307,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/4c5d87a3/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 572f7ab..17f7cc3 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/4c5d87a3/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 ddde493..bcbc67c 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/4c5d87a3/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 34f1bb0..84fd040 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
@@ -49,7 +49,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) {