You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/03/10 11:10:53 UTC

[1/3] stratos git commit: CLI commands added to add, list, describe, update and remove application policies

Repository: stratos
Updated Branches:
  refs/heads/master 210a84bcb -> 1e79490e4


CLI commands added to add, list, describe, update and remove application policies


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

Branch: refs/heads/master
Commit: 9851602f3b902f904c3af56272e50e2dd3d1899d
Parents: fa8f659
Author: Dinithi <di...@wso2.com>
Authored: Tue Mar 10 13:06:55 2015 +0530
Committer: Dinithi <di...@wso2.com>
Committed: Tue Mar 10 13:06:55 2015 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     |  91 ++++++++++++
 .../apache/stratos/cli/StratosApplication.java  |  15 ++
 .../commands/AddApplicationPolicyCommand.java   | 138 +++++++++++++++++++
 .../DescibeApplicationPolicyCommand.java        |  72 ++++++++++
 .../ListApplicationPoliciesCommand.java         |  65 +++++++++
 .../RemoveApplicationPolicyCommand.java         |  72 ++++++++++
 .../UpdateApplicationPolicyCommand.java         | 120 ++++++++++++++++
 7 files changed, 573 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/9851602f/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 cf1d023..31a712c 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
@@ -47,6 +47,7 @@ import org.apache.stratos.common.beans.kubernetes.KubernetesHostBean;
 import org.apache.stratos.common.beans.kubernetes.KubernetesMasterBean;
 import org.apache.stratos.common.beans.partition.NetworkPartitionBean;
 import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
+import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean;
 import org.apache.stratos.common.beans.topology.ClusterBean;
 import org.slf4j.Logger;
@@ -77,6 +78,7 @@ public class RestCommandLineService {
 
     private static final String ENDPOINT_DEPLOY_CARTRIDGE = API_CONTEXT + "/cartridges";
     private static final String ENDPOINT_DEPLOY_AUTOSCALING_POLICY = API_CONTEXT + "/autoscalingPolicies";
+    private static final String ENDPOINT_DEPLOY_APPLICATION_POLICY = API_CONTEXT + "/applicationPolicies";
     private static final String ENDPOINT_DEPLOY_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies";
     private static final String ENDPOINT_DEPLOY_KUBERNETES_CLUSTER = API_CONTEXT + "/kubernetesClusters";
     private static final String ENDPOINT_DEPLOY_KUBERNETES_HOST = API_CONTEXT + "/kubernetesClusters/{kubernetesClusterId}/minion";
@@ -94,9 +96,11 @@ public class RestCommandLineService {
     private static final String ENDPOINT_REMOVE_NETWORK_PARTITION = API_CONTEXT + "/networkPartitions/{id}";
     private static final String ENDPOINT_REMOVE_AUTOSCALINGPOLICY = API_CONTEXT + "/autoscalingPolicies/{policyId}";
     private static final String ENDPOINT_REMOVE_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies/{policyId}";
+    private static final String ENDPOINT_REMOVE_APPLICATION_POLICY = API_CONTEXT + "/applicationPolicies/{policyId}";
 
     private static final String ENDPOINT_LIST_AUTOSCALING_POLICIES = API_CONTEXT + "/autoscalingPolicies";
     private static final String ENDPOINT_LIST_DEPLOYMENT_POLICIES = API_CONTEXT + "/deploymentPolicies";
+    private static final String ENDPOINT_LIST_APPLICATION_POLICIES = API_CONTEXT + "/applicationPolicies";
     private static final String ENDPOINT_LIST_CARTRIDGES = API_CONTEXT + "/cartridges";
     private static final String ENDPOINT_LIST_CARTRIDGE_GROUPS = API_CONTEXT + "/cartridgeGroups";
     private static final String ENDPOINT_LIST_TENANTS = API_CONTEXT + "/tenants";
@@ -114,6 +118,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 + "/deploymentPolicies/{deploymentPolicyId}";
+    private static final String ENDPOINT_GET_APPLICATION_POLICY = API_CONTEXT + "/applicationPolicies/{applicationPolicyId}";
     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}";
@@ -131,6 +136,7 @@ public class RestCommandLineService {
     private static final String ENDPOINT_APPLICATION_SIGNUP = API_CONTEXT + "/applications/{applicationId}/signup";
 
     private static final String ENDPOINT_UPDATE_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies";
+    private static final String ENDPOINT_UPDATE_APPLICATION_POLICY = API_CONTEXT + "/applicationPolicies";
     private static final String ENDPOINT_UPDATE_AUTOSCALING_POLICY = API_CONTEXT + "/autoscalingPolicies";
     private static final String ENDPOINT_UPDATE_USER = API_CONTEXT + "/users";
     private static final String ENDPOINT_UPDATE_TENANT = API_CONTEXT + "/tenants";
@@ -1032,6 +1038,28 @@ public class RestCommandLineService {
     }
 
     /**
+     * Describe application policy
+     * @throws CommandException
+     */
+    public void describeApplicationPolicy(String applicationPolicyId) throws CommandException {
+        try {
+            ApplicationPolicyBean policy = (ApplicationPolicyBean) restClient.getEntity(ENDPOINT_GET_APPLICATION_POLICY,
+                    ApplicationPolicyBean.class, "{applicationPolicyId}", applicationPolicyId, "application policy");
+
+            if (policy == null) {
+                System.out.println("Application policy not found: " + applicationPolicyId);
+                return;
+            }
+
+            System.out.println("Application policy: " + applicationPolicyId);
+            System.out.println(getGson().toJson(policy));
+        } catch (Exception e) {
+            String message = "Error in describing application policy: " + applicationPolicyId;
+            printError(message, e);
+        }
+    }
+
+    /**
      * Describe autoscaling policy
      * @throws CommandException
      */
@@ -1673,6 +1701,14 @@ public class RestCommandLineService {
     }
 
     /**
+     * Deploy application policy
+     * @throws CommandException
+     */
+    public void addApplicationPolicy(String applicationPolicy) throws CommandException {
+        restClient.deployEntity(ENDPOINT_DEPLOY_APPLICATION_POLICY, applicationPolicy, "application policy");
+    }
+
+    /**
      * Update deployment policy
      * @throws CommandException
      */
@@ -1726,4 +1762,59 @@ public class RestCommandLineService {
         }
     }
 
+    /**
+     * List application policies
+     * @throws CommandException
+     */
+    public void listApplicationPolicies() throws CommandException {
+        try {
+            Type listType = new TypeToken<ArrayList<ApplicationPolicyBean>>() {
+            }.getType();
+            List<ApplicationPolicyBean> list = (List<ApplicationPolicyBean>) restClient.listEntity(ENDPOINT_LIST_APPLICATION_POLICIES,
+                    listType, "application policies");
+
+            if ((list == null) || (list == null) || (list.size() == 0)) {
+                System.out.println("No application policies found");
+                return;
+            }
+
+            RowMapper<ApplicationPolicyBean> rowMapper = new RowMapper<ApplicationPolicyBean>() {
+
+                public String[] getData(ApplicationPolicyBean policy) {
+                    String[] data = new String[3];
+                    data[0] = policy.getId();
+                    data[1] = String.valueOf(policy.getNetworkPartitions().length);
+                    data[2] = policy.getAlgorithm();
+                    return data;
+                }
+            };
+
+            ApplicationPolicyBean[] array = new ApplicationPolicyBean[list.size()];
+            array = list.toArray(array);
+
+            System.out.println("Application policies found:");
+            CliUtils.printTable(array, rowMapper, "ID", "No of Network partitions","algorithm");
+        } catch (Exception e) {
+            String message = "Could not list application policies";
+            printError(message, e);
+        }
+    }
+
+    /**
+     * Delete application policy
+     * @throws CommandException
+     */
+    public void deleteApplicationPolicy(String policyId) {
+        restClient.deleteEntity(ENDPOINT_REMOVE_APPLICATION_POLICY.replace("{policyId}", policyId), policyId,
+                "application policy");
+    }
+
+    /**
+     * Update application policy
+     * @throws CommandException
+     */
+    public void updateApplicationPolicy(String applicationPolicy) throws CommandException {
+        restClient.updateEntity(ENDPOINT_UPDATE_APPLICATION_POLICY, applicationPolicy, "application policy");
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/9851602f/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 a735914..adf36e7 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
@@ -279,6 +279,21 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new DeleteApplicationSignupCommand();
         commands.put(command.getName(),command);
 
+        command = new AddApplicationPolicyCommand();
+        commands.put(command.getName(),command);
+
+        command = new ListApplicationPoliciesCommand();
+        commands.put(command.getName(),command);
+
+        command = new DescibeApplicationPolicyCommand();
+        commands.put(command.getName(),command);
+
+        command = new RemoveApplicationPolicyCommand();
+        commands.put(command.getName(),command);
+
+        command = new UpdateApplicationPolicyCommand();
+        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/9851602f/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddApplicationPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddApplicationPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddApplicationPolicyCommand.java
new file mode 100644
index 0000000..c7c3989
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddApplicationPolicyCommand.java
@@ -0,0 +1,138 @@
+/**
+ *  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;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class AddApplicationPolicyCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(AddApplicationPolicyCommand.class);
+
+    private final Options options;
+
+    public AddApplicationPolicyCommand(){
+        options = constructOptions();
+    }
+
+    private Options constructOptions() {
+        final Options options = new Options();
+
+        Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+                "Application policy resource path");
+        resourcePath.setArgName("resource path");
+        options.addOption(resourcePath);
+
+        return options;
+    }
+
+    public String getName() {
+        return "add-application-policy";
+    }
+
+    public String getDescription() {
+        return "Add application policy deployment";
+    }
+
+    public String getArgumentSyntax() {
+        return null;
+    }
+
+    public int execute(StratosCommandContext context, String[] args,Option[] already_parsed_opts) throws CommandException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Executing {} command...", getName());
+        }
+
+        if (args != null && args.length > 0) {
+            String resourcePath = null;
+            String applicationPolicyDeployment = null;
+
+            final CommandLineParser parser = new GnuParser();
+            CommandLine commandLine;
+
+            try {
+                commandLine = parser.parse(options, args);
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Application policy deployment");
+                }
+
+                if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Resource path option is passed");
+                    }
+                    resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+                    applicationPolicyDeployment = readResource(resourcePath);
+                }
+
+                if (resourcePath == null) {
+                    System.out.println("usage: " + getName() + " [-p <resource path>]");
+                    return CliConstants.COMMAND_FAILED;
+                }
+
+                RestCommandLineService.getInstance().addApplicationPolicy(applicationPolicyDeployment);
+                return CliConstants.COMMAND_SUCCESSFULL;
+
+            } catch (ParseException e) {
+                if (logger.isErrorEnabled()) {
+                    logger.error("Error parsing arguments", e);
+                }
+                System.out.println(e.getMessage());
+                return CliConstants.COMMAND_FAILED;
+            } catch (IOException e) {
+                System.out.println("Invalid resource path");
+                return CliConstants.COMMAND_FAILED;
+            }
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.COMMAND_FAILED;
+        }
+    }
+
+    private String readResource(String fileName) throws IOException {
+        BufferedReader br = new BufferedReader(new FileReader(fileName));
+        try {
+            StringBuilder sb = new StringBuilder();
+            String line = br.readLine();
+
+            while (line != null) {
+                sb.append(line);
+                sb.append("\n");
+                line = br.readLine();
+            }
+            return sb.toString();
+        } finally {
+            br.close();
+        }
+    }
+
+    public Options getOptions() {
+        return options;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/9851602f/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescibeApplicationPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescibeApplicationPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescibeApplicationPolicyCommand.java
new file mode 100644
index 0000000..5ceaeee
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescibeApplicationPolicyCommand.java
@@ -0,0 +1,72 @@
+/**
+ *  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.Option;
+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 DescibeApplicationPolicyCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(DescibeApplicationPolicyCommand.class);
+
+    @Override
+    public String getName() {
+        return "describe-application-policy";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Describing the application Policy";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return "[application-policy-id]";
+    }
+
+    @Override
+    public Options getOptions() {
+        return null;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args, Option[] already_parsed_opts) throws CommandException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Executing {} command...", getName());
+        }
+        if (args != null && args.length == 1) {
+            String applicationPolicyId = args[0];
+            if (logger.isDebugEnabled()) {
+                logger.debug("Getting application policy {}", applicationPolicyId);
+            }
+            RestCommandLineService.getInstance().describeApplicationPolicy(applicationPolicyId);
+            return CliConstants.COMMAND_SUCCESSFULL;
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.COMMAND_FAILED;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/9851602f/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java
new file mode 100644
index 0000000..c12adc1
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.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 ListApplicationPoliciesCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(ListApplicationPoliciesCommand.class);
+
+    public ListApplicationPoliciesCommand() {
+    }
+
+    public String getName() {
+        return "list-application-policies";
+    }
+
+    public String getDescription() {
+        return "List available application 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().listApplicationPolicies();
+            return CliConstants.COMMAND_SUCCESSFULL;
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.COMMAND_FAILED;
+        }
+    }
+
+    public Options getOptions() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/9851602f/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveApplicationPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveApplicationPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveApplicationPolicyCommand.java
new file mode 100644
index 0000000..db6d297
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveApplicationPolicyCommand.java
@@ -0,0 +1,72 @@
+/**
+ *  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.Option;
+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 RemoveApplicationPolicyCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(RemoveApplicationPolicyCommand.class);
+
+    @Override
+    public String getName() {
+        return "remove-application-policy";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Remove application policy";
+    }
+
+    @Override
+    public String getArgumentSyntax() {
+        return "[Application-policy Id]";
+    }
+
+    @Override
+    public Options getOptions() {
+        return null;
+    }
+
+    @Override
+    public int execute(StratosCommandContext context, String[] args,Option[] already_parsed_opts) 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 application-policy Id {}", id);
+            }
+            RestCommandLineService.getInstance().deleteApplicationPolicy(id);
+            return CliConstants.COMMAND_SUCCESSFULL;
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.COMMAND_FAILED;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/9851602f/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateApplicationPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateApplicationPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateApplicationPolicyCommand.java
new file mode 100644
index 0000000..88d13b5
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateApplicationPolicyCommand.java
@@ -0,0 +1,120 @@
+/**
+ *  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.apache.stratos.cli.utils.CliUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class UpdateApplicationPolicyCommand implements Command<StratosCommandContext> {
+    private static final Logger logger = LoggerFactory.getLogger(UpdateApplicationPolicyCommand.class);
+
+    private final Options options;
+
+    public UpdateApplicationPolicyCommand(){
+        options = constructOptions();
+    }
+
+    public Options getOptions() {
+        return options;
+    }
+
+    private Options constructOptions() {
+        final Options options = new Options();
+
+        Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+                "Application policy resource path");
+        resourcePath.setArgName("resource path");
+        options.addOption(resourcePath);
+
+        return options;
+    }
+
+    public String getName() {
+        return "update-application-policy";
+    }
+
+    public String getDescription() {
+        return "Update application policy";
+    }
+
+    public String getArgumentSyntax() {
+        return null;
+    }
+
+    public int execute(StratosCommandContext context, String[] args, Option[] already_parsed_opts) throws CommandException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Executing {} command...", getName());
+        }
+
+        if (args != null && args.length > 0) {
+            String resourcePath = null;
+            String applicationPolicyDeployment = null;
+
+            final CommandLineParser parser = new GnuParser();
+            CommandLine commandLine;
+
+            try {
+                commandLine = parser.parse(options, args);
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Updating application policy");
+                }
+
+                if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Resource path option is passed");
+                    }
+                    resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+                    applicationPolicyDeployment = CliUtils.readResource(resourcePath);
+                }
+
+                if (resourcePath == null) {
+                    System.out.println("usage: " + getName() + " [-p <resource path>]");
+                    return CliConstants.COMMAND_FAILED;
+                }
+
+                RestCommandLineService.getInstance().updateApplicationPolicy(applicationPolicyDeployment);
+                return CliConstants.COMMAND_SUCCESSFULL;
+
+            } catch (ParseException e) {
+                if (logger.isErrorEnabled()) {
+                    logger.error("Error parsing arguments", e);
+                }
+                System.out.println(e.getMessage());
+                return CliConstants.COMMAND_FAILED;
+            } catch (IOException ignore) {
+                System.out.println("Invalid resource path");
+                return CliConstants.COMMAND_FAILED;
+            }
+        } else {
+            context.getStratosApplication().printUsage(getName());
+            return CliConstants.COMMAND_FAILED;
+        }
+    }
+}


[2/3] stratos git commit: Merge branch 'master' of https://github.com/apache/stratos

Posted by ra...@apache.org.
Merge branch 'master' of https://github.com/apache/stratos


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

Branch: refs/heads/master
Commit: 60384b15c5eb39be8a7e63cfb75e215f59fb0a56
Parents: 9851602 210a84b
Author: Dinithi <di...@wso2.com>
Authored: Tue Mar 10 15:20:30 2015 +0530
Committer: Dinithi <di...@wso2.com>
Committed: Tue Mar 10 15:20:30 2015 +0530

----------------------------------------------------------------------
 .../parser/DefaultApplicationParser.java             | 15 +++++++++------
 .../stratos/autoscaler/monitor/MonitorFactory.java   | 11 ++++-------
 .../cloud/controller/util/CloudControllerUtil.java   |  7 ++++++-
 3 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------



[3/3] stratos git commit: Changed List-application-policies command

Posted by ra...@apache.org.
Changed List-application-policies command


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

Branch: refs/heads/master
Commit: 1e79490e4d0ac58ef2d66eb38bd1872d14767fe8
Parents: 60384b1
Author: Dinithi <di...@wso2.com>
Authored: Tue Mar 10 15:32:52 2015 +0530
Committer: Dinithi <di...@wso2.com>
Committed: Tue Mar 10 15:32:52 2015 +0530

----------------------------------------------------------------------
 .../stratos/cli/commands/ListApplicationPoliciesCommand.java      | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/1e79490e/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java
index c12adc1..a17ab12 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListApplicationPoliciesCommand.java
@@ -19,6 +19,7 @@
 
 package org.apache.stratos.cli.commands;
 
+import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.stratos.cli.Command;
 import org.apache.stratos.cli.RestCommandLineService;
@@ -46,7 +47,7 @@ public class ListApplicationPoliciesCommand implements Command<StratosCommandCon
         return null;
     }
 
-    public int execute(StratosCommandContext context, String[] args) throws CommandException {
+    public int execute(StratosCommandContext context, String[] args,Option[] already_parsed_opts) throws CommandException {
         if (logger.isDebugEnabled()) {
             logger.debug("Executing {} command...", getName());
         }