karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1483381 - in /karaf/cellar/branches/cellar-2.3.x: management/src/main/java/org/apache/karaf/cellar/management/internal/ shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ shell/src/main/java/org/apache/karaf/cellar/shell/handler/ ...
Date Thu, 16 May 2013 14:12:52 GMT
Author: jbonofre
Date: Thu May 16 14:12:52 2013
New Revision: 1483381

URL: http://svn.apache.org/r1483381
Log:
[KARAF-2142] Change the state only of the local node when using producer, consumer, handler
commands or MBeans

Modified:
    karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
    karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
    karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
    karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java

Modified: karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java?rev=1483381&r1=1483380&r2=1483381&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
(original)
+++ karaf/cellar/branches/cellar-2.3.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
Thu May 16 14:12:52 2013
@@ -118,11 +118,11 @@ public class CellarMBeanImpl extends Sta
         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 Sta
                     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 Sta
     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 Sta
     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 Sta
         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 Sta
     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 Sta
     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 Sta
         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 Sta
     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 Sta
     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);

Modified: karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java?rev=1483381&r1=1483380&r2=1483381&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
Thu May 16 14:12:52 2013
@@ -49,7 +49,14 @@ public abstract class ConsumerSupport ex
                 }
             }
         } 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) {

Modified: karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java?rev=1483381&r1=1483380&r2=1483381&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
Thu May 16 14:12:52 2013
@@ -48,7 +48,14 @@ public abstract class HandlersSupport ex
                 }
             }
         } 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) {

Modified: karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java?rev=1483381&r1=1483380&r2=1483381&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.3.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
Thu May 16 14:12:52 2013
@@ -19,10 +19,7 @@ import org.apache.karaf.cellar.core.cont
 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 ex
                 }
             }
         } 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) {



Mime
View raw message