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 2014/10/24 15:39:46 UTC

[1/2] git commit: Adding update autoscaling/deployment policy commands CLI

Repository: stratos
Updated Branches:
  refs/heads/master 752832f73 -> db94b095e


Adding update autoscaling/deployment policy commands CLI


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

Branch: refs/heads/master
Commit: 824f344d7e69ca47f24aa48ce01791ac5074ca05
Parents: d39f5f7
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Oct 24 19:09:26 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Oct 24 19:09:26 2014 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     |  23 +++-
 .../apache/stratos/cli/StratosApplication.java  |   8 +-
 .../UpdateAutoscalingPolicyCommand.java         | 122 +++++++++++++++++++
 .../commands/UpdateDeploymentPolicyCommand.java | 122 +++++++++++++++++++
 4 files changed, 273 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/824f344d/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 98319c1..64df59e 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
@@ -117,7 +117,10 @@ public class RestCommandLineService {
     private static final String ENDPOINT_DEACTIVATE_TENANT = "/stratos/admin/tenant/deactivate";
 
     private static final String ENDPOINT_UPDATE_SUBSCRIPTION_PROPERTIES = "/stratos/admin/subscriptions/{alias}/properties";
-    
+    private static final String ENDPOINT_UPDATE_DEPLOYMENT_POLICY = "/stratos/admin/policy/deployment";
+    private static final String ENDPOINT_UPDATE_AUTOSCALING_POLICY = "/stratos/admin/policy/autoscale";
+
+
     private static class SingletonHolder {
         private final static RestCommandLineService INSTANCE = new RestCommandLineService();
     }
@@ -1221,6 +1224,15 @@ public class RestCommandLineService {
         restClient.deployEntity(ENDPOINT_DEPLOY_AUTOSCALING_POLICY, autoScalingPolicy, "autoscaling policy");
     }
 
+    /**
+     * Update autoscaling policy
+     * @param autoScalingPolicy
+     * @throws CommandException
+     */
+    public void updateAutoscalingPolicy(String autoScalingPolicy) throws CommandException {
+        restClient.updateEntity(ENDPOINT_UPDATE_AUTOSCALING_POLICY, autoScalingPolicy, "autoscaling policy");
+    }
+
     // This method helps to deploy multi-tenant service cluster
     public void deployService(String serviceDefinition) throws CommandException {
         restClient.deployEntity(ENDPOINT_DEPLOY_SERVICE, serviceDefinition, "service");
@@ -1274,6 +1286,15 @@ public class RestCommandLineService {
         restClient.deployEntity(ENDPOINT_DEPLOY_DEPLOYMENT_POLICY, deploymentPolicy, "deployment policy");
     }
 
+    /**
+     * Update deployment policy
+     * @param deploymentPolicy
+     * @throws CommandException
+     */
+    public void updateDeploymentPolicy(String deploymentPolicy) throws CommandException {
+        restClient.updateEntity(ENDPOINT_UPDATE_DEPLOYMENT_POLICY, deploymentPolicy, "deployment policy");
+    }
+
     // This method list available partitons
     public void listPartitions() throws CommandException {
         try {

http://git-wip-us.apache.org/repos/asf/stratos/blob/824f344d/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 507b007..a528e61 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
@@ -210,7 +210,13 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
         command = new UpdateSubscriptionPropertiesCommand();
         commands.put(command.getName(), command);
 
-		if (logger.isDebugEnabled()) {
+        command = new UpdateAutoscalingPolicyCommand();
+        commands.put(command.getName(), command);
+
+        command = new UpdateDeploymentPolicyCommand();
+        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/824f344d/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateAutoscalingPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateAutoscalingPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateAutoscalingPolicyCommand.java
new file mode 100644
index 0000000..1154b07
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateAutoscalingPolicyCommand.java
@@ -0,0 +1,122 @@
+/**
+ *  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.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class UpdateAutoscalingPolicyCommand implements Command<StratosCommandContext> {
+
+    private static final Logger logger = LoggerFactory.getLogger(UpdateAutoscalingPolicyCommand.class);
+
+    private final Options options;
+
+    public UpdateAutoscalingPolicyCommand(){
+        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,
+                "Autoscaling policy resource path");
+        resourcePath.setArgName("resource path");
+        options.addOption(resourcePath);
+
+        return options;
+    }
+
+    public String getName() {
+        return "update-autoscaling-policy";
+    }
+
+    public String getDescription() {
+        return "Update autoscaling policy";
+    }
+
+    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) {
+            String resourcePath = null;
+            String autoscalingPolicyDeployment = null;
+
+            final CommandLineParser parser = new GnuParser();
+            CommandLine commandLine;
+
+            try {
+                commandLine = parser.parse(options, args);
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Updating autoscaling policy");
+                }
+
+                if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Resource path option is passed");
+                    }
+                    resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+                    autoscalingPolicyDeployment = CliUtils.readResource(resourcePath);
+                }
+
+                if (resourcePath == null) {
+                    System.out.println("usage: " + getName() + " [-p <resource path>]");
+                    return CliConstants.COMMAND_FAILED;
+                }
+
+                RestCommandLineService.getInstance().updateAutoscalingPolicy(autoscalingPolicyDeployment);
+                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;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/824f344d/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateDeploymentPolicyCommand.java
new file mode 100644
index 0000000..f8d487c
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateDeploymentPolicyCommand.java
@@ -0,0 +1,122 @@
+/**
+ *  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.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class UpdateDeploymentPolicyCommand implements Command<StratosCommandContext> {
+
+    private static final Logger logger = LoggerFactory.getLogger(UpdateDeploymentPolicyCommand.class);
+
+    private final Options options;
+
+    public UpdateDeploymentPolicyCommand(){
+        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,
+                "Deployment policy resource path");
+        resourcePath.setArgName("resource path");
+        options.addOption(resourcePath);
+
+        return options;
+    }
+
+    public String getName() {
+        return "update-deployment-policy";
+    }
+
+    public String getDescription() {
+        return "Update deployment policy";
+    }
+
+    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) {
+            String resourcePath = null;
+            String deploymentPolicyDeployment = null;
+
+            final CommandLineParser parser = new GnuParser();
+            CommandLine commandLine;
+
+            try {
+                commandLine = parser.parse(options, args);
+
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Updating deployment policy");
+                }
+
+                if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+                    if (logger.isTraceEnabled()) {
+                        logger.trace("Resource path option is passed");
+                    }
+                    resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+                    deploymentPolicyDeployment = CliUtils.readResource(resourcePath);
+                }
+
+                if (resourcePath == null) {
+                    System.out.println("usage: " + getName() + " [-p <resource path>]");
+                    return CliConstants.COMMAND_FAILED;
+                }
+
+                RestCommandLineService.getInstance().updateDeploymentPolicy(deploymentPolicyDeployment);
+                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/2] git commit: Merge remote-tracking branch 'origin/master'

Posted by im...@apache.org.
Merge remote-tracking branch 'origin/master'


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

Branch: refs/heads/master
Commit: db94b095e8e806850da07061af649f0477ca622a
Parents: 824f344 752832f
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Oct 24 19:09:39 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Oct 24 19:09:39 2014 +0530

----------------------------------------------------------------------
 products/load-balancer/modules/distribution/pom.xml | 16 ++++++++++++++++
 .../modules/distribution/src/main/assembly/bin.xml  |  3 +++
 2 files changed, 19 insertions(+)
----------------------------------------------------------------------