Author: bdekruijff at gmail.com
Date: Tue Jan 11 12:32:13 2011
New Revision: 590

Log:
[sandbox] refactored for naming consistency and added exceptions

Modified:
   
sandbox/bdekruijff/fabrictest/src/main/java/org/amdatu/core/fabrictest/shell/FabricManagerCommand.java

Modified: 
sandbox/bdekruijff/fabrictest/src/main/java/org/amdatu/core/fabrictest/shell/FabricManagerCommand.java
==============================================================================
--- 
sandbox/bdekruijff/fabrictest/src/main/java/org/amdatu/core/fabrictest/shell/FabricManagerCommand.java
      (original)
+++ 
sandbox/bdekruijff/fabrictest/src/main/java/org/amdatu/core/fabrictest/shell/FabricManagerCommand.java
      Tue Jan 11 12:32:13 2011
@@ -21,6 +21,7 @@
 import java.util.Hashtable;
 import java.util.StringTokenizer;
 
+import org.amdatu.core.fabric.FabricException;
 import org.amdatu.core.fabric.FabricManagerService;
 import org.apache.felix.shell.Command;
 
@@ -52,18 +53,23 @@
             return;
         }
         String command = st.nextToken();
-        if (command.equals("create")) {
-            executeCreateCommand(rejoinRemainingTokens(st), out, err);
-            return;
+        try {
+            if (command.equals("create")) {
+                executeCreateCommand(rejoinRemainingTokens(st), out, err);
+                return;
+            }
+            if (command.equals("remove")) {
+                executeRemoveCommand(rejoinRemainingTokens(st), out, err);
+                return;
+            }
+            out.print(getUsage());
         }
-        if (command.equals("remove")) {
-            executeRemoveCommand(rejoinRemainingTokens(st), out, err);
-            return;
+        catch (FabricException e) {
+            err.println("Fabric command failed: " + e.getMessage());
         }
-        out.print(getUsage());
     }
 
-    private void executeCreateCommand(String s, PrintStream out, PrintStream 
err) {
+    private void executeCreateCommand(String s, PrintStream out, PrintStream 
err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() < 1) {
             out.print("fman create 
<clusterchannel|servicegroup|discovery|distribution|fabric> [...]\n");
@@ -94,7 +100,7 @@
         return;
     }
 
-    private void executeRemoveCommand(String s, PrintStream out, PrintStream 
err) {
+    private void executeRemoveCommand(String s, PrintStream out, PrintStream 
err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() < 2) {
             out.print("fman remove 
<clusterchannel|discovery|distribution|fabric> <clusterchannel>\n");
@@ -125,7 +131,7 @@
         return;
     }
 
-    private void executeClusterMemberCreateCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeClusterMemberCreateCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() < 1) {
             out.print("fman create clusterchannel <clusterChannelName> 
[options]\n");
@@ -155,7 +161,7 @@
         out.println("Failed to create clusterchannel: " + clusterChannelName);
     }
 
-    private void executeClusterMemberRemoveCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeClusterMemberRemoveCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 1) {
             out.print("fman remove clusterchannel <clusterChannelName>\n");
@@ -168,7 +174,7 @@
         out.println("Failed to remove clusterchannel: " + clusterChannelName);
     }
 
-    private void executeFabricCreateCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeFabricCreateCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() < 3) {
             out.print("fman create fabric <clusterChannelName> 
<serviceGroupname> [clusterChannelOptions]\n");
@@ -202,7 +208,7 @@
         out.println("Failed to create fabric: " + clusterChannelName + "/" + 
serviceGroupName);
     }
 
-    private void executeFabricRemoveCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeFabricRemoveCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 3) {
             out.print("fman remove fabric <clusterChannelname> 
<serviceGroupName> \n");
@@ -221,7 +227,7 @@
         m_fabricManagerService.removeClusterChannel(clusterChannelName);
     }
 
-    private void executeServiceGroupCreateCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeServiceGroupCreateCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 2) {
             out.print("fman create servicegroup <clusterChannelName> 
<serviceGroupName>\n");
@@ -239,7 +245,7 @@
         out.println("Failed to create servicegroup: " + clusterChannelName + 
"/" + serviceGroupName);
     }
 
-    private void executeServiceGroupRemoveCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeServiceGroupRemoveCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 2) {
             out.print("fman remove servicegroup <clusterChannelName> 
<serviceGroupName>\n");
@@ -256,7 +262,7 @@
         m_fabricManagerService.removeDistribution(clusterChannelName, 
serviceGroupName);
     }
 
-    private void executeDiscoveryCreateCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeDiscoveryCreateCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 2) {
             out.print("fman create discovery <clusterChannelName> 
<serviceGroupName>");
@@ -271,7 +277,7 @@
         out.println("Failed to create discovery: " + clusterChannelName + "/" 
+ serviceGroupName);
     }
 
-    private void executeDiscoveryRemoveCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeDiscoveryRemoveCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 3) {
             out.print("fman remove discovery <clusterChannelName> 
<serviceGroupName>");
@@ -285,7 +291,7 @@
         out.println("Failed to remove discovery: " + clusterChannelName + "/" 
+ serviceGroupName);
     }
 
-    private void executeDistributionCreateCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeDistributionCreateCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 3) {
             out.print("fman create distribution <clusterChannelName> 
<serviceGroupName>");
@@ -300,7 +306,7 @@
         out.println("Failed to create distribution: " + clusterChannelName + 
"/" + serviceGroupName);
     }
 
-    private void executeDistributionRemoveCommand(String s, PrintStream out, 
PrintStream err) {
+    private void executeDistributionRemoveCommand(String s, PrintStream out, 
PrintStream err) throws FabricException {
         StringTokenizer st = new StringTokenizer(s, " ");
         if (st.countTokens() != 3) {
             out.print("fman remove distribution <clusterChannelName> 
<serviceGroupName>");

Reply via email to