You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2014/01/29 09:13:01 UTC

[1/2] git commit: adding support to describe policies, parition and cartirdge

Updated Branches:
  refs/heads/master 32796ae0e -> 2f741cb0e


adding support to describe policies, parition and cartirdge


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/4c293dd3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/4c293dd3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/4c293dd3

Branch: refs/heads/master
Commit: 4c293dd34f34241ea49da1fcde890873c667a326
Parents: c7f24b5
Author: rekathiru <rt...@gmail.com>
Authored: Wed Jan 29 13:42:21 2014 +0530
Committer: rekathiru <rt...@gmail.com>
Committed: Wed Jan 29 13:42:21 2014 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     | 257 ++++++++++++++++++-
 .../apache/stratos/cli/StratosApplication.java  |  45 ++--
 .../autoscaler/partition/PartitionGroup.java    |  54 ++++
 .../policy/deployment/DeploymentPolicy.java     |  27 ++
 .../DescribeAutoScalingPolicyCommand.java       |  70 +++++
 .../cli/commands/DescribeCartridgeCommand.java  |  70 +++++
 .../DescribeDeploymentPolicyCommand.java        |  70 +++++
 .../cli/commands/DescribePartitionCommand.java  |  70 +++++
 .../stratos/cli/commands/ListMemberCommand.java | 136 ++++++++++
 .../apache/stratos/cli/utils/CliConstants.java  |  33 +++
 10 files changed, 806 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
index e064f8e..987eccd 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
@@ -63,8 +63,9 @@ public class RestCommandLineService {
     // REST endpoints
     private final String initializeEndpoint = "/stratos/admin/init";
     private final String listAvailableCartridgesRestEndpoint = "/stratos/admin/cartridge/list";
+    private final String describeAvailableCartridgeRestEndpoint = "/stratos/admin/cartridge/list/";
     private final String listSubscribedCartridgesRestEndpoint = "/stratos/admin/cartridge/list/subscribed";
-    private final String listClusterRestEndpoint = "/cluster/";
+    private final String listClusterRestEndpoint = "/stratos/admin/cluster";
     private final String subscribCartridgeRestEndpoint = "/stratos/admin/cartridge/subscribe";
     private final String addTenantEndPoint = "/stratos/admin/tenant";
     private final String unsubscribeTenantEndPoint = "/stratos/admin/cartridge/unsubscribe";
@@ -72,8 +73,11 @@ public class RestCommandLineService {
     private final String partitionDeploymentEndPoint = "/stratos/admin/policy/deployment/partition";
     private final String autoscalingPolicyDeploymentEndPoint = "/stratos/admin/policy/autoscale";
     private final String deploymentPolicyDeploymentEndPoint = "/stratos/admin/policy/deployment";
+    private final String describeParitionRestEndPoint = "/stratos/admin/partition/";
     private final String listParitionRestEndPoint = "/stratos/admin/partition";
+    private final String describeAutoscalePolicyRestEndPoint = "/stratos/admin/policy/autoscale/";
     private final String listAutoscalePolicyRestEndPoint = "/stratos/admin/policy/autoscale";
+    private final String describeDeploymentPolicyRestEndPoint = "/stratos/admin/policy/deployment/";
     private final String listDeploymentPolicyRestEndPoint = "/stratos/admin/policy/deployment";
 
     private static class SingletonHolder {
@@ -273,6 +277,48 @@ public class RestCommandLineService {
         }
     }
 
+    // List currently available multi tenant and single tenant cartridges
+    public void describeAvailableCartridges(String type) throws CommandException {
+        DefaultHttpClient httpClient = new DefaultHttpClient();
+        try {
+            HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() + listAvailableCartridgesRestEndpoint,
+                    restClientService.getUsername(), restClientService.getPassword());
+
+            String responseCode = "" + response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occured while listing available cartridges");
+                return;
+            }
+
+            String resultString = getHttpResponseString(response);
+            if (resultString == null) {
+                return;
+            }
+
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
+
+            if (cartridgeList == null) {
+                System.out.println("Available cartridge list is null");
+                return;
+            }
+
+            for (Cartridge tmp : cartridgeList.getCartridge()) {
+                if(tmp.getCartridgeType().equalsIgnoreCase(type)) {
+                    System.out.println("The cartridge is:");
+                    System.out.println(gson.toJson(tmp));
+                    return;
+                }
+            }
+            System.out.println("No matching cartridge found...");
+        } catch (Exception e) {
+            handleException("Exception in listing available cartridges", e);
+        } finally {
+            httpClient.getConnectionManager().shutdown();
+        }
+    }
+
     // List subscribe cartridges
     public void listSubscribedCartridges(final boolean full) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
@@ -353,8 +399,7 @@ public class RestCommandLineService {
     public void listMembersOfCluster(String cartridgeType, String alias) throws CommandException {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
-            HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() + listClusterRestEndpoint
-                    + cartridgeType + "/" + alias ,
+            HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() + listClusterRestEndpoint,
                     restClientService.getUsername(), restClientService.getPassword());
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -776,11 +821,9 @@ public class RestCommandLineService {
             RowMapper<Partition> partitionMapper = new RowMapper<Partition>() {
 
                 public String[] getData(Partition partition) {
-                    String[] data = new String[4];
+                    String[] data = new String[2];
                     data[0] = partition.getId();
                     data[1] = partition.getProvider();
-                    data[2] = "" + partition.getPartitionMax();
-                    data[3] = "" + partition.getPartitionMin();
                     return data;
                 }
             };
@@ -789,7 +832,7 @@ public class RestCommandLineService {
             partitions = partitionList.getPartition().toArray(partitions);
 
             System.out.println("Available Partitions:" );
-            CommandLineUtils.printTable(partitions, partitionMapper, "ID", "Provider", "PartitionMax", "PartitionMin");
+            CommandLineUtils.printTable(partitions, partitionMapper, "ID", "Provider");
             System.out.println();
 
         } catch (Exception e) {
@@ -821,7 +864,6 @@ public class RestCommandLineService {
                 System.out.println("Response content is empty");
                 return;
             }
-            System.out.println(resultString);
             GsonBuilder gsonBuilder = new GsonBuilder();
             Gson gson = gsonBuilder.create();
             AutoscalePolicyList policyList = gson.fromJson(resultString, AutoscalePolicyList.class);
@@ -906,6 +948,205 @@ public class RestCommandLineService {
         }
     }
 
+    // This method list deployment policies
+    public void describeDeploymentPolicies(String id) throws CommandException {
+        DefaultHttpClient httpClient = new DefaultHttpClient();
+        try {
+            HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
+                    + listDeploymentPolicyRestEndPoint,
+                    restClientService.getUsername(), restClientService.getPassword());
+
+            String responseCode = "" + response.getStatusLine().getStatusCode();
+            if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
+                System.out.println("Invalid operations. Authorization failed");
+                return;
+            } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occured while listing deployment policies");
+                return;
+            }
+
+            String resultString = getHttpResponseString(response);
+            if (resultString == null) {
+                System.out.println("Response content is empty");
+                return;
+            }
+
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            DeploymentPolicyList deploymentPolicyList = gson.fromJson(resultString, DeploymentPolicyList.class);
+
+            if (deploymentPolicyList == null) {
+                System.out.println("Deployment policy list is empty");
+                return;
+            }
+            for (DeploymentPolicy policy : deploymentPolicyList.getDeploymentPolicy()) {
+                if(policy.getId().equals(id)) {
+                    System.out.println("The Deployment policy is: \n");
+                    System.out.println(gson.toJson(policy));
+                    return;
+                }
+            }
+
+            System.out.println("No matching Deployment policy found");
+
+            /*RowMapper<DeploymentPolicy> partitionMapper = new RowMapper<DeploymentPolicy>() {
+
+                public String[] getData(DeploymentPolicy policy) {
+                    String[] data = new String[1];
+                    data[0] = policy.getId();
+                    return data;
+                }
+            };
+
+            DeploymentPolicy[] deploymentPolicies = new DeploymentPolicy[1];
+            deploymentPolicies[0] = deploymentPolicy;
+
+            System.out.println("The Deployment policy is: \n");
+            System.out.println(resultString);*/
+            //CommandLineUtils.printTable(deploymentPolicies, partitionMapper, "ID");
+
+        } catch (Exception e) {
+            handleException("Exception in listing deployment polices", e);
+        } finally {
+            httpClient.getConnectionManager().shutdown();
+        }
+    }
+
+
+
+ // This method list deployment policies
+    public void describePartition(String id) throws CommandException {
+        DefaultHttpClient httpClient = new DefaultHttpClient();
+        try {
+            HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
+                    + listParitionRestEndPoint,
+                    restClientService.getUsername(), restClientService.getPassword());
+
+            String responseCode = "" + response.getStatusLine().getStatusCode();
+            if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
+                System.out.println("Invalid operations. Authorization failed");
+                return;
+            } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occured while listing deployment policies");
+                return;
+            }
+            String resultString = getHttpResponseString(response);
+            if (resultString == null) {
+                System.out.println("Response content is empty");
+                return;
+            }
+
+
+           if (resultString == null) {
+               System.out.println("Response content is empty");
+               return;
+           }
+
+           GsonBuilder gsonBuilder = new GsonBuilder();
+           Gson gson = gsonBuilder.create();
+           PartitionList partitionList = gson.fromJson(resultString, PartitionList.class);
+
+            for (Partition partition : partitionList.getPartition()) {
+                if(partition.getId().equals(id)) {
+                    System.out.println("The Partition is:");
+                    System.out.println(gson.toJson(partition));
+                    return;
+                }
+            }
+            System.out.println("No matching partition found...");
+
+
+            /*GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            Partition partition = gson.fromJson(resultString, Partition.class);
+
+            if (partition == null) {
+                System.out.println("Deployment policy list is empty");
+                return;
+            }
+            RowMapper<Partition> partitionMapper = new RowMapper<Partition>() {
+
+                public String[] getData(Partition policy) {
+                    String[] data = new String[1];
+                    data[0] = policy.getId();
+                    return data;
+                }
+            };
+
+            System.out.println("The Partition is:");
+            System.out.println(resultString);
+            System.out.println(resultString);  */
+            //CommandLineUtils.printTable(deploymentPolicies, partitionMapper, "ID");
+
+        } catch (Exception e) {
+            handleException("Exception in listing deployment polices", e);
+        } finally {
+            httpClient.getConnectionManager().shutdown();
+        }
+    }
+
+    public void describeAutoScalingPolicy(String id) throws CommandException {
+        DefaultHttpClient httpClient = new DefaultHttpClient();
+        try {
+            HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
+                    + listAutoscalePolicyRestEndPoint,
+                    restClientService.getUsername(), restClientService.getPassword());
+
+            String responseCode = "" + response.getStatusLine().getStatusCode();
+            if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
+                System.out.println("Invalid operations. Authorization failed");
+                return;
+            } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occured while listing deployment policies");
+                return;
+            }
+
+            String resultString = getHttpResponseString(response);
+            if (resultString == null) {
+                System.out.println("Response content is empty");
+                return;
+            }
+
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            AutoscalePolicyList policyList = gson.fromJson(resultString, AutoscalePolicyList.class);
+
+            if (policyList == null) {
+                System.out.println("Deployment policy list is empty");
+                return;
+            }
+            for(AutoscalePolicy policy : policyList.getAutoscalePolicy()) {
+               if(policy.getId().equalsIgnoreCase(id)) {
+                   System.out.println("Autoscaling policy is:");
+                   System.out.println(gson.toJson(policy));
+                   return;
+               }
+            }
+            System.out.println("No matching Autoscale Policy found...");
+
+
+            /*RowMapper<AutoscalePolicy> partitionMapper = new RowMapper<AutoscalePolicy>() {
+
+                public String[] getData(AutoscalePolicy policy) {
+                    String[] data = new String[1];
+                    data[0] = policy.getId();
+                    return data;
+                }
+            };
+
+            System.out.println("The Autoscaling Policy is: \n");
+            System.out.println(resultString);*/
+            //CommandLineUtils.printTable(deploymentPolicies, partitionMapper, "ID");
+
+        } catch (Exception e) {
+            handleException("Exception in listing deployment polices", e);
+        } finally {
+            httpClient.getConnectionManager().shutdown();
+        }
+    }
+
+
+
     // This class convert JSON string to deploymentpolicylist object
     private class DeploymentPolicyList {
         private ArrayList<DeploymentPolicy> deploymentPolicy;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
index dd2bda5..6e19c56 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/StratosApplication.java
@@ -18,31 +18,28 @@
  */
 package org.apache.stratos.cli;
 
-import static org.apache.stratos.cli.utils.CliConstants.STRATOS_DIR;
-import static org.apache.stratos.cli.utils.CliConstants.STRATOS_HISTORY_DIR;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.util.*;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.*;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.text.StrTokenizer;
 import org.apache.commons.validator.routines.UrlValidator;
 import org.apache.log4j.Level;
 import org.apache.log4j.LogManager;
 import org.apache.stratos.cli.commands.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.stratos.cli.completer.CommandCompleter;
 import org.apache.stratos.cli.exception.CommandException;
 import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.apache.stratos.cli.utils.CliConstants.STRATOS_DIR;
+import static org.apache.stratos.cli.utils.CliConstants.STRATOS_HISTORY_DIR;
 
 public class StratosApplication extends CommandLineApplication<StratosCommandContext> {
 
@@ -129,8 +126,20 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new DeploymentPolicyCommand();
         commands.put(command.getName(), command);
 		
-		//command = new InfoCommand();
-		//commands.put(command.getName(), command);
+		command = new ListMemberCommand();
+		commands.put(command.getName(), command);
+
+        command = new DescribeCartridgeCommand();
+        commands.put(command.getName(), command);
+
+        command = new DescribePartitionCommand();
+        commands.put(command.getName(), command);
+
+        command = new DescribeDeploymentPolicyCommand();
+        commands.put(command.getName(), command);
+
+        command = new DescribeAutoScalingPolicyCommand();
+        commands.put(command.getName(), command);
 		
 		//command = new AddDomainMappingCommand();
 		//commands.put(command.getName(), command);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/partition/PartitionGroup.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/partition/PartitionGroup.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/partition/PartitionGroup.java
new file mode 100644
index 0000000..16910e2
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/partition/PartitionGroup.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cli.beans.autoscaler.partition;
+
+import java.util.List;
+
+public class PartitionGroup {
+    private String id;
+
+    private String partitionAlgo;
+
+    //partition Ids
+    private List<Partition> partition;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getPartitionAlgo() {
+        return partitionAlgo;
+    }
+
+    public void setPartitionAlgo(String partitionAlgo) {
+        this.partitionAlgo = partitionAlgo;
+    }
+
+    public List<Partition> getPartition() {
+        return partition;
+    }
+
+    public void setPartition(List<Partition> partition) {
+        this.partition = partition;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/policy/deployment/DeploymentPolicy.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/policy/deployment/DeploymentPolicy.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/policy/deployment/DeploymentPolicy.java
index 42611e7..1899d89 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/policy/deployment/DeploymentPolicy.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/autoscaler/policy/deployment/DeploymentPolicy.java
@@ -18,9 +18,20 @@
  */
 package org.apache.stratos.cli.beans.autoscaler.policy.deployment;
 
+import org.apache.stratos.cli.beans.autoscaler.partition.Partition;
+import org.apache.stratos.cli.beans.autoscaler.partition.PartitionGroup;
+
+import java.util.List;
+
 public class DeploymentPolicy {
     private String id;
 
+     //partition groups
+     private List<PartitionGroup> partitionGroup;
+
+    //partitions
+    private List<Partition> partition;
+
     public String getId() {
         return id;
     }
@@ -28,4 +39,20 @@ public class DeploymentPolicy {
     public void setId(String id) {
         this.id = id;
     }
+
+    public List<PartitionGroup> getPartitionGroup() {
+        return partitionGroup;
+    }
+
+    public void setPartitionGroup(List<PartitionGroup> partitionGroup) {
+        this.partitionGroup = partitionGroup;
+    }
+
+    public List<Partition> getPartition() {
+        return partition;
+    }
+
+    public void setPartition(List<Partition> partition) {
+        this.partition = partition;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
new file mode 100644
index 0000000..903e048
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
@@ -0,0 +1,70 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DescribeAutoScalingPolicyCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(DescribeAutoScalingPolicyCommand.class);
+
+    @Override
+    public String getName() {
+        return CliConstants.DESCRIBE_AUTO_SCALING_POLICY;
+    }
+
+    @Override
+    public String getDescription() {
+        return "Describing the Autoscaling policy";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return "[ID]";
+    }
+
+    @Override
+    public Options getOptions() {
+        return null;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+        if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length == 1) {
+			String id = args[0];
+			if (logger.isDebugEnabled()) {
+				logger.debug("Getting Autoscale policy info {}", id);
+			}
+			 RestCommandLineService.getInstance().describeAutoScalingPolicy(id);
+			return CliConstants.SUCCESSFUL_CODE;
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
new file mode 100644
index 0000000..3ae2b42
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
@@ -0,0 +1,70 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DescribeCartridgeCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(DescribeAutoScalingPolicyCommand.class);
+
+    @Override
+    public String getName() {
+        return CliConstants.DESCRIBE_CARTRIDGE;
+    }
+
+    @Override
+    public String getDescription() {
+        return "Describing the cartridge";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return "[Cartridge-Type]";
+    }
+
+    @Override
+    public Options getOptions() {
+        return null;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+        if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length == 1) {
+			String id = args[0];
+			if (logger.isDebugEnabled()) {
+				logger.debug("Getting cartridge info {}", id);
+			}
+			 RestCommandLineService.getInstance().describeAvailableCartridges(id);
+			return CliConstants.SUCCESSFUL_CODE;
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
new file mode 100644
index 0000000..606cd44
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
@@ -0,0 +1,70 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DescribeDeploymentPolicyCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(DescribeDeploymentPolicyCommand.class);
+
+    @Override
+    public String getName() {
+        return CliConstants.DESCRIBE_DEPLOYMENT_POLICY;
+    }
+
+    @Override
+    public String getDescription() {
+        return "Describing the Deployment Policy";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return "[ID]";
+    }
+
+    @Override
+    public Options getOptions() {
+        return null;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+        if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length == 1) {
+			String id = args[0];
+			if (logger.isDebugEnabled()) {
+				logger.debug("Getting Deployment policy info {}", id);
+			}
+			 RestCommandLineService.getInstance().describeDeploymentPolicies(id);
+			return CliConstants.SUCCESSFUL_CODE;
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
new file mode 100644
index 0000000..950a957
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
@@ -0,0 +1,70 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.stratos.cli.commands;
+
+import org.apache.commons.cli.Options;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DescribePartitionCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(DescribePartitionCommand.class);
+
+    @Override
+    public String getName() {
+        return CliConstants.DESCRIBE_PARTITION;
+    }
+
+    @Override
+    public String getDescription() {
+        return "Describing the partition";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return "[Id]";
+    }
+
+    @Override
+    public Options getOptions() {
+        return null;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+        if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length == 1) {
+			String id = args[0];
+			if (logger.isDebugEnabled()) {
+				logger.debug("Getting Partition info {}", id);
+			}
+			 RestCommandLineService.getInstance().describePartition(id);
+			return CliConstants.SUCCESSFUL_CODE;
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
new file mode 100644
index 0000000..4ce5ac7
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
@@ -0,0 +1,136 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+
+ *  http://www.apache.org/licenses/LICENSE-2.0
+
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.stratos.cli.commands;
+
+import org.apache.commons.cli.*;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ListMemberCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(ListMemberCommand.class);
+
+
+    private final Options options;
+
+	public ListMemberCommand() {
+		options = constructOptions();
+	}
+
+	/**
+	 * Construct Options.
+	 *
+	 * @return Options expected from command-line.
+	 */
+	private Options constructOptions() {
+		final Options options = new Options();
+
+        Option type = new Option(CliConstants.CARTRIDGE_TYPE_OPTION, CliConstants.CARTRIDGE_TYPE_LONG_OPTION,
+                true, "Cartridge Type");
+        type.setArgName("cartridge-type");
+        options.addOption(type);
+
+        Option alias = new Option(CliConstants.ALIAS_OPTION, CliConstants.ALIAS_LONG_OPTION,
+                true, "subscription alias");
+        alias.setArgName("alias");
+        options.addOption(alias);
+
+        return options;
+	}
+    @Override
+    public String getName() {
+        return CliConstants.LIST_MEMBERS;
+    }
+
+    @Override
+    public String getDescription() {
+        return "List of members in a cluster";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return null;
+    }
+
+    @Override
+    public Options getOptions() {
+        return options;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+        if (logger.isDebugEnabled()) {
+			logger.debug("Executing {} command...", getName());
+		}
+		if (args != null && args.length > 0) {
+			String type = null;
+			String alias = null;
+
+			final CommandLineParser parser = new GnuParser();
+			CommandLine commandLine;
+			try {
+				commandLine = parser.parse(options, args);
+				if (logger.isDebugEnabled()) {
+					logger.debug("Subscribing to {} cartridge with alias {}", type, alias);
+				}
+
+                if (commandLine.hasOption(CliConstants.CARTRIDGE_TYPE_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Autoscaling policy option is passed");
+                    }
+                    type = commandLine.getOptionValue(CliConstants.CARTRIDGE_TYPE_OPTION);
+                }
+                if (commandLine.hasOption(CliConstants.ALIAS_OPTION)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Deployment policy option is passed");
+                    }
+                    alias = commandLine.getOptionValue(CliConstants.ALIAS_OPTION);
+                }
+
+                if (type == null) {
+                    System.out.println("Cartridge type is required.");
+                    context.getStratosApplication().printUsage(getName());
+                    return CliConstants.BAD_ARGS_CODE;
+                }
+
+                if (alias == null) {
+                    System.out.println("alis is required...");
+                    context.getStratosApplication().printUsage(getName());
+                    return CliConstants.BAD_ARGS_CODE;
+                }
+                RestCommandLineService.getInstance().listMembersOfCluster(type, alias);
+
+				return CliConstants.SUCCESSFUL_CODE;
+			} catch (ParseException e) {
+				if (logger.isErrorEnabled()) {
+					logger.error("Error parsing arguments", e);
+				}
+				System.out.println(e.getMessage());
+				return CliConstants.BAD_ARGS_CODE;
+			}
+		} else {
+			context.getStratosApplication().printUsage(getName());
+			return CliConstants.BAD_ARGS_CODE;
+		}
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4c293dd3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
index 44ca6db..5ba8d88 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
@@ -95,6 +95,16 @@ public class CliConstants {
     public static final String LIST_DEPLOYMENT_POLICIES = "list-deployment-policies";
 
     /**
+     * List members
+     */
+    public static final String LIST_MEMBERS = "list-members";
+
+     /**
+     * List members with LB
+     */
+    public static final String LIST_MEMBERS_WITH_LB = "list-lb-members";
+
+    /**
      * Autoscaling policy deployment
      */
     public static final String AUTOSCALING_POLICY_DEPLOYMENT = "deploy-autoscaling-policy";
@@ -114,6 +124,23 @@ public class CliConstants {
 	 */
 	public static final String SYNC_ACTION = "sync";
 
+     /**
+     * Describe the cartridge
+     */
+    public static final String DESCRIBE_CARTRIDGE = "describe-cartridge";
+     /**
+     * Describe the partition
+     */
+    public static final String DESCRIBE_PARTITION = "describe-partition";
+     /**
+     * describe the auto scaling policy
+     */
+    public static final String DESCRIBE_AUTO_SCALING_POLICY = "describe-autoscaling-policy";
+     /**
+     * describe the deployment policy
+     */
+    public static final String DESCRIBE_DEPLOYMENT_POLICY = "describe-deployment-policy";
+
 	/**
 	 * Domain mapping
 	 */
@@ -162,6 +189,12 @@ public class CliConstants {
 	
 	public static final String DATA_ALIAS_OPTION = "d";
 	public static final String DATA_ALIAS_LONG_OPTION = "data-alias";
+
+    public static final String ALIAS_OPTION = "a";
+	public static final String ALIAS_LONG_OPTION = "alias";
+
+    public static final String CARTRIDGE_TYPE_OPTION = "t";
+	public static final String CARTRIDGE_TYPE_LONG_OPTION = "cartridge-type";
 	
 	public static final String FULL_OPTION = "f";
 	public static final String FULL_LONG_OPTION = "full";


[2/2] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by re...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/2f741cb0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/2f741cb0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/2f741cb0

Branch: refs/heads/master
Commit: 2f741cb0e4259348ab0c07244d5165d014e1fd45
Parents: 4c293dd 32796ae
Author: rekathiru <rt...@gmail.com>
Authored: Wed Jan 29 13:42:53 2014 +0530
Committer: rekathiru <rt...@gmail.com>
Committed: Wed Jan 29 13:42:53 2014 +0530

----------------------------------------------------------------------
 .../src/main/resources/conf/cloud-controller.xml                   | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------