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/11 09:32:12 UTC
[20/21] git commit: Deployment policy deployment using RESTful
service in CLI
Deployment policy deployment using RESTful service in 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/7e4c4d4b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/7e4c4d4b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/7e4c4d4b
Branch: refs/heads/master
Commit: 7e4c4d4bf31586d2b1420f73a15ce22fd2cd3c3c
Parents: 6d61d4b
Author: Manula Thantriwatte <ma...@apache.org>
Authored: Wed Dec 11 13:59:06 2013 +0530
Committer: Manula Thantriwatte <ma...@apache.org>
Committed: Wed Dec 11 13:59:06 2013 +0530
----------------------------------------------------------------------
.../stratos/cli/RestCommandLineService.java | 20 +++
.../apache/stratos/cli/StratosApplication.java | 5 +-
.../commands/AutoScalingDeploymentCommand.java | 141 -------------------
.../AutoscalingPolicyDeploymentCommand.java | 139 ++++++++++++++++++
.../commands/CartridgeDeploymentCommand.java | 1 -
.../DeploymentPolicyDeploymentCommand.java | 139 ++++++++++++++++++
.../apache/stratos/cli/utils/CliConstants.java | 5 +
7 files changed, 307 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7e4c4d4b/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 ebe0e3b..a4f28dc 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
@@ -54,6 +54,7 @@ public class RestCommandLineService {
private final String cartridgeDeploymentEndPoint = "/stratos/admin/cartridge/definition";
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 static class SingletonHolder {
private final static RestCommandLineService INSTANCE = new RestCommandLineService();
@@ -498,6 +499,25 @@ public class RestCommandLineService {
}
}
+ public void deployDeploymentPolicy (String deploymentPolicy) {
+ try {
+ String result = restClientService.doPost(restClientService.getUrl() + deploymentPolicyDeploymentEndPoint,
+ deploymentPolicy, restClientService.getUsername(), restClientService.getPassword());
+
+ System.out.println(result);
+
+ if (Integer.parseInt(result) == CliConstants.RESPONSE_AUTHORIZATION_FAIL) {
+ System.out.println("Invalid operations. Authorization failed");
+ }
+ else {
+ System.out.println("You have successfully deployed the deployment policy");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
private class CartridgeList {
private ArrayList<Cartridge> cartridge;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7e4c4d4b/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 9387d4a..b532479 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
@@ -114,7 +114,10 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new PartitionDeploymentCommand();
commands.put(command.getName(), command);
- command = new AutoScalingDeploymentCommand();
+ command = new AutoscalingPolicyDeploymentCommand();
+ commands.put(command.getName(), command);
+
+ command = new DeploymentPolicyDeploymentCommand();
commands.put(command.getName(), command);
command = new ListCommand();
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7e4c4d4b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoScalingDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoScalingDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoScalingDeploymentCommand.java
deleted file mode 100644
index a5b18c7..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoScalingDeploymentCommand.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * 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;
-import java.io.InputStreamReader;
-
-public class AutoScalingDeploymentCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(AutoScalingDeploymentCommand.class);
-
- private final Options options;
-
- public AutoScalingDeploymentCommand(){
- options = constructOptions();
- }
-
- private Options constructOptions() {
- final Options options = new Options();
-
- Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
- "Autoscaling policy deployment resource path");
- resourcePath.setArgName("resource path");
- options.addOption(resourcePath);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.AUTOSCALING_POLICY_DEPLOYMENT;
- }
-
- public String getDescription() {
- return "Add new autoscaling policy deployment";
- }
-
- 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("Autoscaling policy deployment");
- }
-
- if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Resource path option is passed");
- }
- resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- autoscalingPolicyDeployment = readResource(resourcePath);
- }
-
- if (resourcePath == null) {
- System.out.println("usage: " + getName() + " [-p <resource path>]");
- return CliConstants.BAD_ARGS_CODE;
- }
-
- System.out.println(autoscalingPolicyDeployment);
- RestCommandLineService.getInstance().deployAutoscalingPolicy(autoscalingPolicyDeployment);
- 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;
- } catch (IOException e) {
- //e.printStackTrace();
- System.out.println("Invalid resource path");
- return CliConstants.BAD_ARGS_CODE;
- }
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- 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/incubator-stratos/blob/7e4c4d4b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
new file mode 100644
index 0000000..76a6431
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
@@ -0,0 +1,139 @@
+/**
+ * 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 AutoscalingPolicyDeploymentCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(AutoscalingPolicyDeploymentCommand.class);
+
+ private final Options options;
+
+ public AutoscalingPolicyDeploymentCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Autoscaling policy deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.AUTOSCALING_POLICY_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new autoscaling policy deployment";
+ }
+
+ 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("Autoscaling policy deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ autoscalingPolicyDeployment = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+
+ RestCommandLineService.getInstance().deployAutoscalingPolicy(autoscalingPolicyDeployment);
+ 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;
+ } catch (IOException e) {
+ //e.printStackTrace();
+ System.out.println("Invalid resource path");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ }
+
+ 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/incubator-stratos/blob/7e4c4d4b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
index 5e6b304..650aef3 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
@@ -136,7 +136,6 @@ public class CartridgeDeploymentCommand implements Command<StratosCommandContext
}
}
- @Override
public Options getOptions() {
return options;
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/7e4c4d4b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyDeploymentCommand.java
new file mode 100644
index 0000000..62aabc8
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyDeploymentCommand.java
@@ -0,0 +1,139 @@
+/**
+ * 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 DeploymentPolicyDeploymentCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeploymentPolicyDeploymentCommand.class);
+
+ private final Options options;
+
+ public DeploymentPolicyDeploymentCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Deployment policy deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.DEPLOYMENT_POLICY_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new 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("Deployment policy deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ deploymentPolicyDeployment = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+
+ RestCommandLineService.getInstance().deployDeploymentPolicy(deploymentPolicyDeployment);
+ 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;
+ } catch (IOException e) {
+ //e.printStackTrace();
+ System.out.println("Invalid resource path");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ }
+
+ 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/incubator-stratos/blob/7e4c4d4b/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 e820c87..61f899e 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
@@ -84,6 +84,11 @@ public class CliConstants {
*/
public static final String AUTOSCALING_POLICY_DEPLOYMENT = "autoscaling-policy-deployment";
+ /**
+ * Deployment policy deployment
+ */
+ public static final String DEPLOYMENT_POLICY_DEPLOYMENT = "deployment-policy-deployment";
+
/**
* Give information of a cartridge.
*/