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 2012/05/04 09:14:10 UTC

svn commit: r1333782 - /karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java

Author: jbonofre
Date: Fri May  4 07:14:10 2012
New Revision: 1333782

URL: http://svn.apache.org/viewvc?rev=1333782&view=rev
Log:
[KARAF-1316] Check if nodes exist in the cluster:consumer-* commands

Modified:
    karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java

Modified: karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java?rev=1333782&r1=1333781&r2=1333782&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java Fri May  4 07:14:10 2012
@@ -19,29 +19,49 @@ 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;
 
 public abstract class ConsumerSupport extends ClusterCommandSupport {
 
-    protected static final String OUTPUT_FORMAT = "%-20s %s";
+    protected static final String HEADER_FORMAT = " %-30s   %-5s";
+    protected static final String OUTPUT_FORMAT = "[%-30s] [%-5s]";
+
+    protected Object doExecute(List<String> nodeIds, SwitchStatus status) throws Exception {
 
-    protected Object doExecute(List<String> nodes, SwitchStatus status) throws Exception {
         ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
-        Set<Node> recipientList = clusterManager.listNodes(nodes);
 
-        if (recipientList != null && !recipientList.isEmpty()) {
-            command.setDestination(recipientList);
+        // looking for nodes and check if exist
+        Set<Node> recipientList;
+        if (nodeIds != null && !nodeIds.isEmpty()) {
+            recipientList = new HashSet<Node>();
+            for (String nodeId : nodeIds) {
+                Node node = clusterManager.findNodeById(nodeId);
+                if (node == null) {
+                    System.err.println("Cluster node " + nodeId + " doesn't exist");
+                } else {
+                    recipientList.add(node);
+                }
+            }
+        } else {
+            recipientList = clusterManager.listNodes();
+        }
+
+        if (recipientList.size() < 1) {
+            return null;
         }
 
+
+        command.setDestination(recipientList);
         command.setStatus(status);
 
         Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
         if (results == null || results.isEmpty()) {
             System.out.println("No result received within given timeout");
         } else {
-            System.out.println(String.format(OUTPUT_FORMAT, "Node", "Status"));
+            System.out.println(String.format(HEADER_FORMAT, "Node", "Status"));
             for (Node node : results.keySet()) {
                 ConsumerSwitchResult result = results.get(node);
                 System.out.println(String.format(OUTPUT_FORMAT, node.getId(), result.getStatus()));