[wsas-java-dev] svn commit r1734 - trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering

svn at wso2.org svn at wso2.org
Tue Apr 3 07:18:52 PDT 2007


Author: azeez
Date: Tue Apr  3 07:18:44 2007
New Revision: 1734

Modified:
   trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManagerClient.java
Log:
Started implementation of command line client NodeManagement



Modified: trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManagerClient.java
==============================================================================
--- trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManagerClient.java	(original)
+++ trunk/wsas/java/modules/clustering/src/org/wso2/wsas/clustering/NodeManagerClient.java	Tue Apr  3 07:18:44 2007
@@ -17,100 +17,120 @@
 
 import org.apache.axis2.AxisFault;
 
-import java.rmi.RemoteException;
-
 /**
  * 
  */
 public class NodeManagerClient {
     private NodeManagerStub stub;
 
-    public NodeManagerClient() throws AxisFault {
-//        System.setProperty("axis2.xml",
-//                           "/home/azeez/projects/wso2wsas/modules/samples/CommodityQuote/conf/axis2.xml");
-//        System.out.println("---" + System.getProperty("axis2.xml"));
-
-//        ConfigurationContext configContext =
-//                    ConfigurationContextFactory
-//                            .createConfigurationContextFromFileSystem(".",
-//                                                                      "/home/azeez/projects/wso2wsas/modules/samples/CommodityQuote/conf/axis2.xml");
-        stub = new NodeManagerStub("http://10.100.1.118:9762/services/WSO2WSASNodeManager");
-//        stub = new NodeManagerStub(configContext, "https://10.100.1.225:9443/soap/NodeManager");
+    public NodeManagerClient(String nodeManagerEPR) throws AxisFault {
+        stub = new NodeManagerStub(nodeManagerEPR);
     }
 
-    private void reload() {
-        try {
-            NodeManagerStub.ReloadConfigurationResponse r = stub.reloadConfiguration();
-            if (r.get_return()) {
-                System.out.println("Reload response successful");
-                NodeManagerStub.CommitResponse commitResponse = stub.commit();
-                if (commitResponse.get_return()) {
-                    System.out.println("Successfully committed");
-                } else {
-                    System.out.println("Commit failed");
-                }
+    private void reloadConfiguration() throws Exception {
+        NodeManagerStub.ReloadConfigurationResponse r = stub.reloadConfiguration();
+        if (r.get_return()) {
+            NodeManagerStub.CommitResponse commitResponse = stub.commit();
+            if (commitResponse.get_return()) {
+                System.out.println("Successfully committed");
+            } else {
+                System.out.println("Commit failed");
             }
-        } catch (RemoteException e) {
-            e.printStackTrace();
-        } catch (ReloadConfigurationFaultException e) {
-            e.printStackTrace();
-        } catch (CommitFaultException e) {
-            e.printStackTrace();
         }
     }
 
-    private void loadServiceGroup() {
-        try {
-            NodeManagerStub.LoadServiceGroup req = new NodeManagerStub.LoadServiceGroup();
-            req.setServiceGroupName("echo");
-            NodeManagerStub.LoadServiceGroupResponse resp = stub.loadServiceGroup(req);
-            if (resp.get_return()) {
-                NodeManagerStub.CommitResponse commitResponse = stub.commit();
-                if (commitResponse.get_return()) {
-                    System.out.println("Successfully committed");
-                } else {
-                    System.out.println("Commit failed");
-                }
+    private void loadServiceGroup(String serviceGroupName) throws Exception {
+        NodeManagerStub.LoadServiceGroup req = new NodeManagerStub.LoadServiceGroup();
+        req.setServiceGroupName(serviceGroupName);
+        NodeManagerStub.LoadServiceGroupResponse resp = stub.loadServiceGroup(req);
+        if (resp.get_return()) {
+            NodeManagerStub.CommitResponse commitResponse = stub.commit();
+            if (commitResponse.get_return()) {
+                System.out.println("Successfully committed");
+            } else {
+                System.out.println("Commit failed");
             }
-        } catch (RemoteException e) {
-            e.printStackTrace();
-        } catch (CommitFaultException e) {
-            e.printStackTrace();
-        } catch (LoadServiceGroupFaultException e) {
-            e.printStackTrace();
         }
     }
 
-    private void unloadServiceGroup() {
-        try {
-            NodeManagerStub.UnloadServiceGroup req = new NodeManagerStub.UnloadServiceGroup();
-            req.setServiceGroupName("echo");
-            NodeManagerStub.UnloadServiceGroupResponse resp = stub.unloadServiceGroup(req);
-            if (resp.get_return()) {
-                NodeManagerStub.CommitResponse commitResponse = stub.commit();
-                if (commitResponse.get_return()) {
-                    System.out.println("Successfully committed");
-                } else {
-                    System.out.println("Commit failed");
-                }
+    private void unloadServiceGroup(String serviceGroupName) throws Exception {
+        NodeManagerStub.UnloadServiceGroup req = new NodeManagerStub.UnloadServiceGroup();
+        req.setServiceGroupName(serviceGroupName);
+        NodeManagerStub.UnloadServiceGroupResponse resp = stub.unloadServiceGroup(req);
+        if (resp.get_return()) {
+            NodeManagerStub.CommitResponse commitResponse = stub.commit();
+            if (commitResponse.get_return()) {
+                System.out.println("Successfully committed");
+            } else {
+                System.out.println("Commit failed");
             }
-        } catch (RemoteException e) {
-            e.printStackTrace();
-        } catch (CommitFaultException e) {
-            e.printStackTrace();
-        } catch (UnloadServiceGroupFaultException e) {
-            e.printStackTrace();
         }
     }
 
+    private void applyServicePolicy() throws Exception {
+        // TODO
+    }
+
+    /**
+     * Usage: admin --epr <epr> --operation <reloadConfig | loadSG | unloadSG | applyPolicy>
+     *
+     * @param args
+     */
     public static void main(String[] args) {
         try {
-            NodeManagerClient adminClient = new NodeManagerClient();
-            adminClient.reload();
-//            adminClient.loadServiceGroup();
-//            adminClient.unloadServiceGroup();
-        } catch (AxisFault axisFault) {
-            axisFault.printStackTrace();
+            String epr = getParam("--epr", args);
+            NodeManagerClient client = new NodeManagerClient(epr);
+
+            String operation = getParam("--operation", args);
+
+            if (operation.equals("reloadconfig")) {
+                client.reloadConfiguration();
+            } else if (operation.equals("loadsg")) {
+                client.loadServiceGroup(getParam("--service-group", args));
+            } else if (operation.equals("unloadsg")) {
+                client.unloadServiceGroup(getParam("--service-group", args));
+            } else if (operation.equals("applypolicy")) {
+                client.applyServicePolicy();
+            } else {
+                printUsage();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
+
+    private static void printUsage() {
+        System.out.println("usage: admin --epr <epr> --operation <reloadconfig|loadsg|unloadsg|applypolicy> [options]");
+        System.out.println("options: --service-group <ServiceGroupName>");
+    }
+
+    /**
+     * This will check the given parameter in the array and will return, if
+     * available
+     *
+     * @param param
+     * @param args
+     * @return String
+     */
+    private static String getParam(String param, String[] args) {
+        if ((param == null) || "".equals(param)) {
+            return null;
+        }
+
+        for (int i = 0; i < args.length; i = i + 2) {
+            String arg = args[i];
+            if (param.equalsIgnoreCase(arg) && (args.length >= (i + 1))) {
+                if (args.length == i + 1) {
+                    System.err.println("Invalid value specified for option " + arg);
+                    printUsage();
+                    System.exit(1);
+                }
+                return args[i + 1];
+            }
         }
+        printUsage();
+        System.exit(1);
+        return null;
     }
 }




More information about the Wsas-java-dev mailing list