You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ma...@apache.org on 2013/12/18 06:43:47 UTC

[1/2] git commit: Add list-deployment-policy command to CLI

Updated Branches:
  refs/heads/master 45815379c -> 4b63fc9fd


Add list-deployment-policy command to CLI


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

Branch: refs/heads/master
Commit: 45a57867e89367f96f407d50548b555c7b6dd742
Parents: 676d64a
Author: Manula Thantriwatte <ma...@apache.org>
Authored: Wed Dec 18 11:12:38 2013 +0530
Committer: Manula Thantriwatte <ma...@apache.org>
Committed: Wed Dec 18 11:12:38 2013 +0530

----------------------------------------------------------------------
 .../apache/stratos/cli/DeploymentPolicy.java    | 31 +++++++++
 .../stratos/cli/RestCommandLineService.java     | 66 ++++++++++++++++++++
 .../apache/stratos/cli/StratosApplication.java  |  3 +
 .../cli/commands/AutoscalePolicyCommand.java    |  3 -
 .../cli/commands/DeploymentPolicyCommand.java   | 48 ++++++++++++++
 .../apache/stratos/cli/utils/CliConstants.java  |  9 ++-
 6 files changed, 155 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/45a57867/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/DeploymentPolicy.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/DeploymentPolicy.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/DeploymentPolicy.java
new file mode 100644
index 0000000..e4d7d1e
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/DeploymentPolicy.java
@@ -0,0 +1,31 @@
+/**
+ *  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;
+
+public class DeploymentPolicy {
+    private String id;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/45a57867/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 175ffe7..3c3ab8f 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
@@ -64,6 +64,7 @@ public class RestCommandLineService {
     private final String deploymentPolicyDeploymentEndPoint = "/stratos/admin/policy/deployment";
     private final String listParitionRestEndPoint = "/stratos/admin/partition";
     private final String listAutoscalePolicyRestEndPoint = "/stratos/admin/policy/autoscale";
+    private final String listDeploymentPolicyRestEndPoint = "/stratos/admin/policy/deployment";
 
     private static class SingletonHolder {
 		private final static RestCommandLineService INSTANCE = new RestCommandLineService();
@@ -758,6 +759,71 @@ public class RestCommandLineService {
         }
     }
 
+    public void listDeploymentPolicies() throws CommandException {
+        try {
+            HttpResponse response = restClientService.doGet(restClientService.getUrl() + listDeploymentPolicyRestEndPoint,
+                    restClientService.getUsername(), restClientService.getPassword());
+
+            String responseCode = "" + response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in list 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 policyList = gson.fromJson(resultString, DeploymentPolicyList.class);
+
+            if (policyList == null) {
+                System.out.println("Deployment policy list is empty");
+                return;
+            }
+
+            RowMapper<DeploymentPolicy> partitionMapper = new RowMapper<DeploymentPolicy>() {
+
+                public String[] getData(DeploymentPolicy policy) {
+                    String[] data = new String[3];
+                    data[0] = policy.getId();
+                    return data;
+                }
+            };
+
+            DeploymentPolicy[] policyArry = new DeploymentPolicy[policyList.getDeploymentPolicy().size()];
+            policyArry = policyList.getDeploymentPolicy().toArray(policyArry);
+
+            System.out.println("Available Deployment Policies:");
+            CommandLineUtils.printTable(policyArry, partitionMapper, "ID");
+            System.out.println();
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private class DeploymentPolicyList {
+        private ArrayList<DeploymentPolicy> deploymentPolicy;
+
+
+        public ArrayList<DeploymentPolicy> getDeploymentPolicy() {
+            return deploymentPolicy;
+        }
+
+        public void setDeploymentPolicy(ArrayList<DeploymentPolicy> deploymentPolicy) {
+            this.deploymentPolicy = deploymentPolicy;
+        }
+
+        DeploymentPolicyList() {
+            deploymentPolicy = new ArrayList<DeploymentPolicy>();
+        }
+    }
+
     // This class convert JSON string to autoscalepolicylist object
     private class AutoscalePolicyList {
         private ArrayList<AutoscalePolicy> autoscalePolicy;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/45a57867/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 9cfed5b..195b99f 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
@@ -128,6 +128,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
 
         command = new AutoscalePolicyCommand();
         commands.put(command.getName(), command);
+
+        command = new DeploymentPolicyCommand();
+        commands.put(command.getName(), command);
 		
 		//command = new InfoCommand();
 		//commands.put(command.getName(), command);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/45a57867/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
index bdca727..b579ee0 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
@@ -9,9 +9,6 @@ import org.apache.stratos.cli.utils.CliConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * Created by manula on 12/12/13.
- */
 public class AutoscalePolicyCommand implements Command<StratosCommandContext> {
 
     private static final Logger logger = LoggerFactory.getLogger(AutoscalePolicyCommand.class);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/45a57867/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyCommand.java
new file mode 100644
index 0000000..6b0d54d
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyCommand.java
@@ -0,0 +1,48 @@
+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 DeploymentPolicyCommand implements Command<StratosCommandContext> {
+
+    private static final Logger logger = LoggerFactory.getLogger(AutoscalePolicyCommand.class);
+
+    public DeploymentPolicyCommand() {
+    }
+
+    public String getName() {
+        return CliConstants.LIST_DEPLOYMENT_POLICIES;
+    }
+
+    public String getDescription() {
+        return "List available deployment policies";
+    }
+
+    public String getArgumentSyntax() {
+        return null;
+    }
+
+    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Executing {} command...", getName());
+        }
+        if (args == null || args.length == 0) {
+            //CommandLineService.getInstance().listAvailableCartridges();
+            RestCommandLineService.getInstance().listDeploymentPolicies();
+            return CliConstants.SUCCESSFUL_CODE;
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.BAD_ARGS_CODE;
+        }
+    }
+
+    public Options getOptions() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/45a57867/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 382a82b..44ca6db 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
@@ -62,7 +62,7 @@ public class CliConstants {
 	/**
 	 * List the available cartridges
 	 */
-	public static final String CARTRIDGES_ACTION = "list-available-cartridges";
+	public static final String CARTRIDGES_ACTION = "list-cartridges";
 
     /**
      * List the available autoscaling policies
@@ -87,7 +87,12 @@ public class CliConstants {
     /**
      * List partitions
      */
-    public static final String LIST_PARTITION = "list-available-partitions";
+    public static final String LIST_PARTITION = "list-partitions";
+
+    /**
+     * List deployment policies
+     */
+    public static final String LIST_DEPLOYMENT_POLICIES = "list-deployment-policies";
 
     /**
      * Autoscaling policy deployment


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

Posted by ma...@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/4b63fc9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/4b63fc9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/4b63fc9f

Branch: refs/heads/master
Commit: 4b63fc9fdcf7bcfbc80e524c8f0031188dae4998
Parents: 45a5786 4581537
Author: Manula Thantriwatte <ma...@apache.org>
Authored: Wed Dec 18 11:13:10 2013 +0530
Committer: Manula Thantriwatte <ma...@apache.org>
Committed: Wed Dec 18 11:13:10 2013 +0530

----------------------------------------------------------------------
 .../stratos/adc/mgt/payload/BasicPayloadData.java    |  4 ++--
 .../receiver/StratosManagerTopologyReceiver.java     | 15 +++++++++++++++
 .../cloud/controller/CloudControllerClient.java      |  3 +++
 3 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------