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 10:30:55 UTC

svn commit: r1333812 - /karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java

Author: jbonofre
Date: Fri May  4 08:30:55 2012
New Revision: 1333812

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


Conflicts:

	shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java

Modified:
    karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java

Modified: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java?rev=1333812&r1=1333811&r2=1333812&view=diff
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java (original)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java Fri May  4 08:30:55 2012
@@ -30,22 +30,43 @@ public abstract class GroupSupport exten
     protected static final String OUTPUT_FORMAT = "%1s %-20s %s";
 
     protected Object doExecute(ManageGroupAction action, String group, Group source, Collection<String> nodes) throws Exception {
-     return doExecute(action, group, source, nodes, true);
+        return doExecute(action, group, source, nodes, true);
     }
 
-    protected Object doExecute(ManageGroupAction action, String group, Group source, Collection<String> nodes,Boolean supressOutput) throws Exception {
+    /**
+     * Executes the command.
+     *
+     * @param action
+     * @param group
+     * @param nodeIds
+     * @param suppressOutput
+     * @return
+     * @throws Exception
+     */
+    protected Object doExecute(ManageGroupAction action, String group, Group source, Collection<String> nodeIds, Boolean suppressOutput) throws Exception {
+
         ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
-        Set<Node> recipientList = clusterManager.listNodes(nodes);
 
-        //Set the recipient list
-        if (recipientList != null && !recipientList.isEmpty()) {
-            command.setDestination(recipientList);
+        // looking for nodes and check if exist
+        Set<Node> recipientList = new HashSet<Node>();
+        if (nodeIds != null && !nodeIds.isEmpty()) {
+            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 {
-            Set<Node> recipients = new HashSet<Node>();
-            recipients.add(clusterManager.getNode());
-            command.setDestination(recipients);
+            recipientList.add(clusterManager.getNode());
         }
 
+        if (recipientList.size() < 1) {
+            return null;
+        }
+
+        command.setDestination(recipientList);
         command.setAction(action);
 
         if (group != null) {
@@ -57,29 +78,29 @@ public abstract class GroupSupport exten
         }
 
         Map<Node, ManageGroupResult> results = executionContext.execute(command);
-        if(!supressOutput) {
-        if (results == null || results.isEmpty()) {
-            System.out.println("No result received within given timeout");
-        } else {
-            System.out.println(String.format(OUTPUT_FORMAT, " ", "Node", "Group"));
-            for (Node node : results.keySet()) {
-                ManageGroupResult result = results.get(node);
-                if (result != null && result.getGroups() != null) {
-                    for (Group g : result.getGroups()) {
-                        if (g.getNodes() != null && !g.getNodes().isEmpty()) {
-                            for (Node member : g.getNodes()) {
-                                String name = g.getName();
-                                String mark = " ";
-                                if (member.equals(clusterManager.getNode()))
-                                    mark = "*";
-                                System.out.println(String.format(OUTPUT_FORMAT, mark, member.getId(), name));
-                            }
-                        } else System.out.println(String.format(OUTPUT_FORMAT, "", "", g.getName()));
+        if (!suppressOutput) {
+            if (results == null || results.isEmpty()) {
+                System.out.println("No result received within given timeout");
+            } else {
+                System.out.println(String.format(OUTPUT_FORMAT, " ", "Node", "Group"));
+                for (Node node : results.keySet()) {
+                    ManageGroupResult result = results.get(node);
+                    if (result != null && result.getGroups() != null) {
+                        for (Group g : result.getGroups()) {
+                            if (g.getNodes() != null && !g.getNodes().isEmpty()) {
+                                for (Node member : g.getNodes()) {
+                                    String name = g.getName();
+                                    String mark = " ";
+                                    if (member.equals(clusterManager.getNode()))
+                                        mark = "*";
+                                    System.out.println(String.format(OUTPUT_FORMAT, mark, member.getId(), name));
+                                }
+                            } else System.out.println(String.format(OUTPUT_FORMAT, "", "", g.getName()));
+                        }
                     }
                 }
             }
         }
-        }
         return null;
     }