You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/02/20 09:27:35 UTC

stratos git commit: CLI commands added to list deployment policies and describe deployment policy.

Repository: stratos
Updated Branches:
  refs/heads/4.1.0-beta-deployment-policy-fix 85547a63b -> 134f79e3a


CLI commands added to list deployment policies and describe deployment policy.


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

Branch: refs/heads/4.1.0-beta-deployment-policy-fix
Commit: 134f79e3ab48784d5c8c675684db00b4c1b7e55e
Parents: 85547a6
Author: Dinithi <di...@wso2.com>
Authored: Thu Feb 19 16:26:27 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Feb 20 13:57:31 2015 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     | 54 +++++++++++++---
 .../apache/stratos/cli/StratosApplication.java  |  6 ++
 .../DescribeDeploymentPolicyCommand.java        |  6 +-
 .../commands/ListDeploymentPoliciesCommand.java | 65 ++++++++++++++++++++
 4 files changed, 120 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/134f79e3/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 c48cc83..d2f8f52 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
@@ -110,7 +110,7 @@ public class RestCommandLineService {
 
     private static final String ENDPOINT_GET_APPLICATION = API_CONTEXT + "/applications/{appId}";
     private static final String ENDPOINT_GET_AUTOSCALING_POLICY = API_CONTEXT + "/autoscalingPolicies/{id}";
-    private static final String ENDPOINT_GET_DEPLOYMENT_POLICY = API_CONTEXT + "/applications/{applicationId}/deploymentPolicy";
+    private static final String ENDPOINT_GET_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies/{deploymentPolicyId}";
     private static final String ENDPOINT_GET_CARTRIDGE = API_CONTEXT + "/cartridges/{cartridgeType}";
     private static final String ENDPOINT_GET_CARTRIDGE_OF_TENANT = API_CONTEXT + "/subscriptions/{id}/cartridges";
     private static final String ENDPOINT_GET_KUBERNETES_GROUP = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}";
@@ -561,7 +561,7 @@ public class RestCommandLineService {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClient.doPut(httpClient, restClient.getBaseURL()
-                    + ENDPOINT_DEACTIVATE_TENANT.replace("{tenantDomain}", tenantDomain),"");
+                    + ENDPOINT_DEACTIVATE_TENANT.replace("{tenantDomain}", tenantDomain), "");
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
@@ -593,7 +593,7 @@ public class RestCommandLineService {
         DefaultHttpClient httpClient = new DefaultHttpClient();
         try {
             HttpResponse response = restClient.doPut(httpClient, restClient.getBaseURL()
-                    + ENDPOINT_ACTIVATE_TENANT .replace("{tenantDomain}", tenantDomain), "");
+                    + ENDPOINT_ACTIVATE_TENANT.replace("{tenantDomain}", tenantDomain), "");
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
 
@@ -812,20 +812,20 @@ public class RestCommandLineService {
      * Describe deployment policy
      * @throws CommandException
      */
-    public void describeDeploymentPolicy(String applicationId) throws CommandException {
+    public void describeDeploymentPolicy(String deploymentPolicyId) throws CommandException {
         try {
             DeploymentPolicyBean policy = (DeploymentPolicyBean) restClient.getEntity(ENDPOINT_GET_DEPLOYMENT_POLICY,
-                    DeploymentPolicyBean.class, "{applicationId}", applicationId, "deployment policy");
+                    DeploymentPolicyBean.class, "{deploymentPolicyId}", deploymentPolicyId, "deployment policy");
 
             if (policy == null) {
-                System.out.println("Deployment policy not found: " + applicationId);
+                System.out.println("Deployment policy not found: " + deploymentPolicyId);
                 return;
             }
 
-            System.out.println("Deployment policy: " + applicationId);
+            System.out.println("Deployment policy: " + deploymentPolicyId);
             System.out.println(getGson().toJson(policy));
         } catch (Exception e) {
-            String message = "Error in describing deployment policy: " + applicationId;
+            String message = "Error in describing deployment policy: " + deploymentPolicyId;
             printError(message, e);
         }
     }
@@ -1384,4 +1384,42 @@ public class RestCommandLineService {
         restClient.deleteEntity(ENDPOINT_REMOVE_DEPLOYMENT_POLICY.replace("{policyId}", policyId), policyId,
                 "deployment policy");
     }
+
+    /**
+     * List deployment policies
+     * @throws CommandException
+     */
+    public void listDeploymentPolicies() throws CommandException {
+        try {
+            Type listType = new TypeToken<ArrayList<DeploymentPolicyBean>>() {
+            }.getType();
+            List<DeploymentPolicyBean> list = (List<DeploymentPolicyBean>) restClient.listEntity(ENDPOINT_LIST_DEPLOYMENT_POLICIES,
+                    listType, "deployment policies");
+
+            if ((list == null) || (list == null) || (list.size() == 0)) {
+                System.out.println("No deployment policies found");
+                return;
+            }
+
+            RowMapper<DeploymentPolicyBean> rowMapper = new RowMapper<DeploymentPolicyBean>() {
+
+                public String[] getData(DeploymentPolicyBean policy) {
+                    String[] data = new String[2];
+                    data[0] = policy.getId();
+                    data[1] = String.valueOf(policy.getNetworkPartition().size());
+                    return data;
+                }
+            };
+
+            DeploymentPolicyBean[] array = new DeploymentPolicyBean[list.size()];
+            array = list.toArray(array);
+
+            System.out.println("Deployment policies found:");
+            CliUtils.printTable(array, rowMapper, "ID", "Accessibility");
+        } catch (Exception e) {
+            String message = "Could not list deployment policies";
+            printError(message, e);
+        }
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/134f79e3/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 410162a..f5b45f9 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
@@ -234,6 +234,12 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new DescribeNetworkPartitionCommand();
         commands.put(command.getName(), command);
 
+        command = new ListDeploymentPoliciesCommand();
+        commands.put(command.getName(), command);
+
+        command = new DescribeDeploymentPolicyCommand();
+        commands.put(command.getName(), command);
+
         if (logger.isDebugEnabled()) {
             logger.debug("Created {} commands for the application. {}", commands.size(), commands.keySet());
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/134f79e3/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
index 017bd0c..3995a85 100644
--- 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
@@ -56,11 +56,11 @@ public class DescribeDeploymentPolicyCommand implements Command<StratosCommandCo
 			logger.debug("Executing {} command...", getName());
 		}
 		if (args != null && args.length == 1) {
-			String applicationId = args[0];
+			String deploymentPolicyId = args[0];
 			if (logger.isDebugEnabled()) {
-				logger.debug("Getting deployment policy {}", applicationId);
+				logger.debug("Getting deployment policy {}", deploymentPolicyId);
 			}
-			 RestCommandLineService.getInstance().describeDeploymentPolicy(applicationId);
+			 RestCommandLineService.getInstance().describeDeploymentPolicy(deploymentPolicyId);
 			return CliConstants.COMMAND_SUCCESSFULL;
 		} else {
 			context.getStratosApplication().printUsage(getName());

http://git-wip-us.apache.org/repos/asf/stratos/blob/134f79e3/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPoliciesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPoliciesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPoliciesCommand.java
new file mode 100644
index 0000000..a9cb6fb
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPoliciesCommand.java
@@ -0,0 +1,65 @@
+/**
+ *  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 ListDeploymentPoliciesCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(ListDeploymentPoliciesCommand.class);
+
+    public ListDeploymentPoliciesCommand() {
+    }
+
+    public String getName() {
+        return "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) {
+            RestCommandLineService.getInstance().listDeploymentPolicies();
+            return CliConstants.COMMAND_SUCCESSFULL;
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.COMMAND_FAILED;
+        }
+    }
+
+    public Options getOptions() {
+        return null;
+    }
+}