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/11 15:27:54 UTC
[1/3] Refactoring CLI commands with a proper naming convention
Repository: stratos
Updated Branches:
refs/heads/container-autoscaling 70a9cca24 -> c9df250a1
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java
new file mode 100644
index 0000000..6881b9f
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java
@@ -0,0 +1,307 @@
+/**
+ * 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.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.stratos.cli.RestCommandLineService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.stratos.cli.Command;
+import org.apache.stratos.cli.StratosCommandContext;
+import org.apache.stratos.cli.exception.CommandException;
+import org.apache.stratos.cli.utils.CliConstants;
+
+public class SubscribeCartridgeCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(ListSubscribedCartridgesCommand.class);
+
+ private final Options options;
+
+ public SubscribeCartridgeCommand() {
+ options = constructOptions();
+ }
+
+ /**
+ * Construct Options.
+ *
+ * @return Options expected from command-line.
+ */
+ private Options constructOptions() {
+ final Options options = new Options();
+ //Option policyOption = new Option(CliConstants.POLICY_OPTION, CliConstants.POLICY_LONG_OPTION, true,
+ // "Auto-scaling policy.\nPlease use \"" + CliConstants.POLICIES_ACTION
+ // + "\" command to view the available policies.");
+ //policyOption.setArgName("policy name");
+ //options.addOption(policyOption);
+
+ Option autoscaling = new Option(CliConstants.AUTOSCALING_POLICY_OPTION, CliConstants.AUTOSCALING_POLICY_LONG_OPTION,
+ true, "Auto-scaling policy");
+ autoscaling.setArgName("auto-scaling-policy");
+ options.addOption(autoscaling);
+
+ Option deployment = new Option(CliConstants.DEPLOYMENT_POLICY_OPTION, CliConstants.DEPLOYMENT_POLICY_LONG_OPTION,
+ true, "Deployment-policy");
+ deployment.setArgName("deployment-policy");
+ options.addOption(deployment);
+
+ Option removeOnTermination = new Option(CliConstants.REMOVE_ON_TERMINATION_OPTION, CliConstants.REMOVE_ON_TERMINATION_LONG_OPTION,
+ true, "Remove-on-termination");
+ removeOnTermination.setArgName("remove-on-termination");
+ options.addOption(removeOnTermination);
+
+ Option size = new Option(CliConstants.VOLUME_SIZE_OPTION, CliConstants.VOLUME_SIZE_LONG_OPTION, true, "Volume-size");
+ size.setArgName("volume-size");
+ options.addOption(size);
+
+ Option volumeId = new Option(CliConstants.VOLUME_ID_OPTION, CliConstants.VOLUME_ID_LONG_OPTION, true, "Volume-id");
+ volumeId.setArgName("volume-id");
+ options.addOption(volumeId);
+
+ Option persistance = new Option(CliConstants.PERSISTANCE_VOLUME_OPTION, CliConstants.PERSISTANCE_VOLUME_LONG_OPTION,
+ true, "Persistance-volume");
+ persistance.setArgName("persistance-volume");
+ options.addOption(persistance);
+
+ Option urlOption = new Option(CliConstants.REPO_URL_OPTION, CliConstants.REPO_URL_LONG_OPTION, true,
+ "GIT repository URL");
+ urlOption.setArgName("url");
+ options.addOption(urlOption);
+
+ //options.addOption(CliConstants.PRIVATE_REPO_OPTION, CliConstants.PRIVATE_REPO_LONG_OPTION, false,
+ // "Private repository");
+
+ Option usernameOption = new Option(CliConstants.USERNAME_OPTION, CliConstants.USERNAME_LONG_OPTION, true,
+ "GIT repository username");
+ usernameOption.setArgName("username");
+ options.addOption(usernameOption);
+
+ Option passwordOption = new Option(CliConstants.PASSWORD_OPTION, CliConstants.PASSWORD_LONG_OPTION, true,
+ "GIT repository password");
+ passwordOption.setArgName("password");
+ passwordOption.setOptionalArg(true);
+ options.addOption(passwordOption);
+
+ Option upstreamCommitsEnabledOption = new Option(CliConstants.ENABLE_COMMITS_OPTION, CliConstants.ENABLE_COMMITS_LONG_OPTION, true,
+ "Enable Git commit upstream");
+ upstreamCommitsEnabledOption.setArgName("enable-commits");
+ upstreamCommitsEnabledOption.setOptionalArg(true);
+ options.addOption(upstreamCommitsEnabledOption);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.SUBSCRIBE_ACTION;
+ }
+
+ public String getDescription() {
+ return "Subscribe to a cartridge";
+ }
+
+ public String getArgumentSyntax() {
+ return "[Cartridge type] [Cartridge alias]";
+ }
+
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing {} command...", getName());
+ }
+ if (args != null && args.length > 0) {
+ String[] remainingArgs = null;
+ String type = null;
+ String alias = null;
+ String policy = null;
+ String asPolicy = null;
+ String depPolicy = null;
+ String repoURL = null, username = "", password = "";
+ String size = null;
+ String volumeID = null;
+
+ boolean removeOnTermination = false;
+ boolean privateRepo = false;
+ boolean persistanceMapping = false;
+ boolean commitsEnabled = false;
+ boolean isMultiTenant = false;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+ try {
+ commandLine = parser.parse(options, args);
+ remainingArgs = commandLine.getArgs();
+ if (remainingArgs != null && remainingArgs.length == 2) {
+ // Get type
+ type = remainingArgs[0];
+ alias = remainingArgs[1];
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ // This will check the subscribe cartridge type is multi tenant or single tenant
+ isMultiTenant = RestCommandLineService.getInstance().isMultiTenant(type);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Subscribing to {} cartridge with alias {}", type, alias);
+ }
+ if (commandLine.hasOption(CliConstants.AUTOSCALING_POLICY_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Autoscaling policy option is passed");
+ }
+ asPolicy = commandLine.getOptionValue(CliConstants.AUTOSCALING_POLICY_OPTION);
+ }
+ if (commandLine.hasOption(CliConstants.DEPLOYMENT_POLICY_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Deployment policy option is passed");
+ }
+ depPolicy = commandLine.getOptionValue(CliConstants.DEPLOYMENT_POLICY_OPTION);
+ }
+ if (commandLine.hasOption(CliConstants.REPO_URL_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("RepoURL option is passed");
+ }
+ repoURL = commandLine.getOptionValue(CliConstants.REPO_URL_OPTION);
+ }
+ if (commandLine.hasOption(CliConstants.VOLUME_SIZE_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Volume size option is passed");
+
+ }
+ size = commandLine.getOptionValue(CliConstants.VOLUME_SIZE_OPTION);
+ }
+
+ if (commandLine.hasOption(CliConstants.VOLUME_ID_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Volume id option is passed");
+
+ }
+ volumeID = commandLine.getOptionValue(CliConstants.VOLUME_ID_OPTION);
+ }
+
+
+ if (commandLine.hasOption(CliConstants.REMOVE_ON_TERMINATION_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Remove on termination option is passed");
+
+ }
+
+ String optionValue = commandLine.getOptionValue(CliConstants.REMOVE_ON_TERMINATION_OPTION);
+ if (optionValue.equals("true")) {
+ removeOnTermination = true;
+ } else if (optionValue.equals("false")) {
+ removeOnTermination = false;
+ } else {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Invalid remove on termination option value");
+ }
+ System.out.println("Invalid remove on termination option value.");
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+ if (commandLine.hasOption(CliConstants.PERSISTANCE_VOLUME_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Persistance volume option is passed");
+
+ }
+
+ String optionValue = commandLine.getOptionValue(CliConstants.PERSISTANCE_VOLUME_OPTION);
+ if (optionValue.equals("true")) {
+ persistanceMapping = true;
+ } else if (optionValue.equals("false")) {
+ persistanceMapping = false;
+ } else {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Invalid persistance mapping option value");
+ }
+ System.out.println("Invalid persistance mapping option value.");
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ }
+ if (commandLine.hasOption(CliConstants.USERNAME_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Username option is passed");
+ }
+ username = commandLine.getOptionValue(CliConstants.USERNAME_OPTION);
+ }
+ if (commandLine.hasOption(CliConstants.PASSWORD_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Password option is passed");
+ }
+ password = commandLine.getOptionValue(CliConstants.PASSWORD_OPTION);
+ }
+ if (commandLine.hasOption(CliConstants.ENABLE_COMMITS_OPTION)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Upstream git commits are enabled");
+ }
+ commitsEnabled = true;
+ }
+
+ if ( ! isMultiTenant && depPolicy == null) {
+ System.out.println("Deployment policy is required.");
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ if ( ! isMultiTenant && asPolicy == null) {
+ System.out.println("Autoscaling policy is required.");
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ if ((!persistanceMapping) && ((size != null) || removeOnTermination)) {
+ System.out.println("You have to enable persistance mapping in cartridge subscription");
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ if (StringUtils.isNotBlank(username) && StringUtils.isBlank(password)) {
+ password = context.getApplication().getInput("GIT Repository Password", '*');
+ }
+
+ RestCommandLineService.getInstance().subscribe(type, alias, repoURL, privateRepo, username,
+ password, asPolicy, depPolicy, size, removeOnTermination,
+ persistanceMapping, commitsEnabled, volumeID);
+
+ 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;
+ }
+ } else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+
+ public Options getOptions() {
+ return options;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
deleted file mode 100644
index e8eca38..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
+++ /dev/null
@@ -1,310 +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.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.stratos.cli.RestCommandLineService;
-import org.apache.stratos.cli.beans.cartridge.Cartridge;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.stratos.cli.Command;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-
-import java.util.ArrayList;
-
-public class SubscribeCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(ListSubscribedCartridgesCommand.class);
-
- private final Options options;
-
- public SubscribeCommand() {
- options = constructOptions();
- }
-
- /**
- * Construct Options.
- *
- * @return Options expected from command-line.
- */
- private Options constructOptions() {
- final Options options = new Options();
- //Option policyOption = new Option(CliConstants.POLICY_OPTION, CliConstants.POLICY_LONG_OPTION, true,
- // "Auto-scaling policy.\nPlease use \"" + CliConstants.POLICIES_ACTION
- // + "\" command to view the available policies.");
- //policyOption.setArgName("policy name");
- //options.addOption(policyOption);
-
- Option autoscaling = new Option(CliConstants.AUTOSCALING_POLICY_OPTION, CliConstants.AUTOSCALING_POLICY_LONG_OPTION,
- true, "Auto-scaling policy");
- autoscaling.setArgName("auto-scaling-policy");
- options.addOption(autoscaling);
-
- Option deployment = new Option(CliConstants.DEPLOYMENT_POLICY_OPTION, CliConstants.DEPLOYMENT_POLICY_LONG_OPTION,
- true, "Deployment-policy");
- deployment.setArgName("deployment-policy");
- options.addOption(deployment);
-
- Option removeOnTermination = new Option(CliConstants.REMOVE_ON_TERMINATION_OPTION, CliConstants.REMOVE_ON_TERMINATION_LONG_OPTION,
- true, "Remove-on-termination");
- removeOnTermination.setArgName("remove-on-termination");
- options.addOption(removeOnTermination);
-
- Option size = new Option(CliConstants.VOLUME_SIZE_OPTION, CliConstants.VOLUME_SIZE_LONG_OPTION, true, "Volume-size");
- size.setArgName("volume-size");
- options.addOption(size);
-
- Option volumeId = new Option(CliConstants.VOLUME_ID_OPTION, CliConstants.VOLUME_ID_LONG_OPTION, true, "Volume-id");
- volumeId.setArgName("volume-id");
- options.addOption(volumeId);
-
- Option persistance = new Option(CliConstants.PERSISTANCE_VOLUME_OPTION, CliConstants.PERSISTANCE_VOLUME_LONG_OPTION,
- true, "Persistance-volume");
- persistance.setArgName("persistance-volume");
- options.addOption(persistance);
-
- Option urlOption = new Option(CliConstants.REPO_URL_OPTION, CliConstants.REPO_URL_LONG_OPTION, true,
- "GIT repository URL");
- urlOption.setArgName("url");
- options.addOption(urlOption);
-
- //options.addOption(CliConstants.PRIVATE_REPO_OPTION, CliConstants.PRIVATE_REPO_LONG_OPTION, false,
- // "Private repository");
-
- Option usernameOption = new Option(CliConstants.USERNAME_OPTION, CliConstants.USERNAME_LONG_OPTION, true,
- "GIT repository username");
- usernameOption.setArgName("username");
- options.addOption(usernameOption);
-
- Option passwordOption = new Option(CliConstants.PASSWORD_OPTION, CliConstants.PASSWORD_LONG_OPTION, true,
- "GIT repository password");
- passwordOption.setArgName("password");
- passwordOption.setOptionalArg(true);
- options.addOption(passwordOption);
-
- Option upstreamCommitsEnabledOption = new Option(CliConstants.ENABLE_COMMITS_OPTION, CliConstants.ENABLE_COMMITS_LONG_OPTION, true,
- "Enable Git commit upstream");
- upstreamCommitsEnabledOption.setArgName("enable-commits");
- upstreamCommitsEnabledOption.setOptionalArg(true);
- options.addOption(upstreamCommitsEnabledOption);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.SUBSCRIBE_ACTION;
- }
-
- public String getDescription() {
- return "Subscribe to a cartridge";
- }
-
- public String getArgumentSyntax() {
- return "[Cartridge type] [Cartridge alias]";
- }
-
- public int execute(StratosCommandContext context, String[] args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing {} command...", getName());
- }
- if (args != null && args.length > 0) {
- String[] remainingArgs = null;
- String type = null;
- String alias = null;
- String policy = null;
- String asPolicy = null;
- String depPolicy = null;
- String repoURL = null, username = "", password = "";
- String size = null;
- String volumeID = null;
-
- boolean removeOnTermination = false;
- boolean privateRepo = false;
- boolean persistanceMapping = false;
- boolean commitsEnabled = false;
- boolean isMultiTenant = false;
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
- try {
- commandLine = parser.parse(options, args);
- remainingArgs = commandLine.getArgs();
- if (remainingArgs != null && remainingArgs.length == 2) {
- // Get type
- type = remainingArgs[0];
- alias = remainingArgs[1];
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
-
- // This will check the subscribe cartridge type is multi tenant or single tenant
- isMultiTenant = RestCommandLineService.getInstance().isMultiTenant(type);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Subscribing to {} cartridge with alias {}", type, alias);
- }
- if (commandLine.hasOption(CliConstants.AUTOSCALING_POLICY_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Autoscaling policy option is passed");
- }
- asPolicy = commandLine.getOptionValue(CliConstants.AUTOSCALING_POLICY_OPTION);
- }
- if (commandLine.hasOption(CliConstants.DEPLOYMENT_POLICY_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Deployment policy option is passed");
- }
- depPolicy = commandLine.getOptionValue(CliConstants.DEPLOYMENT_POLICY_OPTION);
- }
- if (commandLine.hasOption(CliConstants.REPO_URL_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("RepoURL option is passed");
- }
- repoURL = commandLine.getOptionValue(CliConstants.REPO_URL_OPTION);
- }
- if (commandLine.hasOption(CliConstants.VOLUME_SIZE_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Volume size option is passed");
-
- }
- size = commandLine.getOptionValue(CliConstants.VOLUME_SIZE_OPTION);
- }
-
- if (commandLine.hasOption(CliConstants.VOLUME_ID_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Volume id option is passed");
-
- }
- volumeID = commandLine.getOptionValue(CliConstants.VOLUME_ID_OPTION);
- }
-
-
- if (commandLine.hasOption(CliConstants.REMOVE_ON_TERMINATION_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Remove on termination option is passed");
-
- }
-
- String optionValue = commandLine.getOptionValue(CliConstants.REMOVE_ON_TERMINATION_OPTION);
- if (optionValue.equals("true")) {
- removeOnTermination = true;
- } else if (optionValue.equals("false")) {
- removeOnTermination = false;
- } else {
- if (logger.isTraceEnabled()) {
- logger.trace("Invalid remove on termination option value");
- }
- System.out.println("Invalid remove on termination option value.");
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
- if (commandLine.hasOption(CliConstants.PERSISTANCE_VOLUME_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Persistance volume option is passed");
-
- }
-
- String optionValue = commandLine.getOptionValue(CliConstants.PERSISTANCE_VOLUME_OPTION);
- if (optionValue.equals("true")) {
- persistanceMapping = true;
- } else if (optionValue.equals("false")) {
- persistanceMapping = false;
- } else {
- if (logger.isTraceEnabled()) {
- logger.trace("Invalid persistance mapping option value");
- }
- System.out.println("Invalid persistance mapping option value.");
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
-
- }
- if (commandLine.hasOption(CliConstants.USERNAME_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Username option is passed");
- }
- username = commandLine.getOptionValue(CliConstants.USERNAME_OPTION);
- }
- if (commandLine.hasOption(CliConstants.PASSWORD_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Password option is passed");
- }
- password = commandLine.getOptionValue(CliConstants.PASSWORD_OPTION);
- }
- if (commandLine.hasOption(CliConstants.ENABLE_COMMITS_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Upstream git commits are enabled");
- }
- commitsEnabled = true;
- }
-
- if ( ! isMultiTenant && depPolicy == null) {
- System.out.println("Deployment policy is required.");
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
-
- if ( ! isMultiTenant && asPolicy == null) {
- System.out.println("Autoscaling policy is required.");
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
-
- if ((!persistanceMapping) && ((size != null) || removeOnTermination)) {
- System.out.println("You have to enable persistance mapping in cartridge subscription");
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
-
- if (StringUtils.isNotBlank(username) && StringUtils.isBlank(password)) {
- password = context.getApplication().getInput("GIT Repository Password", '*');
- }
-
- RestCommandLineService.getInstance().subscribe(type, alias, repoURL, privateRepo, username,
- password, asPolicy, depPolicy, size, removeOnTermination,
- persistanceMapping, commitsEnabled, volumeID);
-
- 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;
- }
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- public Options getOptions() {
- return options;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribedCartridgeInfoCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribedCartridgeInfoCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribedCartridgeInfoCommand.java
deleted file mode 100644
index cc002a3..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribedCartridgeInfoCommand.java
+++ /dev/null
@@ -1,101 +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.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.lang3.StringUtils;
-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 SubscribedCartridgeInfoCommand implements Command<StratosCommandContext>{
-
- private static final Logger logger = LoggerFactory.getLogger(SubscribedCartridgeInfoCommand.class);
-
- private final Options options;
-
- public SubscribedCartridgeInfoCommand() {
- options = constructOptions();
- }
-
- /**
- * Construct Options.
- *
- * @return Options expected from command-line.
- */
- private Options constructOptions() {
-
- final Options options = new Options();
- return options;
- }
-
- @Override
- public String getName() {
- return CliConstants.LIST_INFO_ACTION;
- }
-
- @Override
- public String getDescription() {
- return "List subscribed cartridges with details";
- }
-
- @Override
- public String getArgumentSyntax() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Options getOptions() {
- return options;
- }
-
- @Override
- public int execute(StratosCommandContext context, String[] args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing {} command...", getName());
- }
-
- if (args != null && args.length > 0) {
- String alias = args[0];
-
- if(StringUtils.isBlank(alias)){
- System.out.println("Please specify a non blank alias.");
- return CliConstants.BAD_ARGS_CODE;
- }
- else{
- RestCommandLineService.getInstance().listSubscribedCartridgeInfo(alias);
- return CliConstants.SUCCESSFUL_CODE;
- }
- }else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
index f866813..ba06e8e 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
@@ -36,17 +36,17 @@ public class SyncCommand implements Command<StratosCommandContext> {
@Override
public String getName() {
- return CliConstants.SYNC_ACTION;
+ return "synchronize-artifacts";
}
@Override
public String getDescription() {
- return "Synchronize GIT repository for the subscribed cartridge";
+ return "Synchronize artifacts with Git repository for cartridge subscriptions";
}
@Override
public String getArgumentSyntax() {
- return "[Cartridge alias]";
+ return "[cartridge-subscription-alias]";
}
@Override
@@ -57,14 +57,14 @@ public class SyncCommand implements Command<StratosCommandContext> {
if (args != null && args.length == 1) {
String alias = args[0];
if (logger.isDebugEnabled()) {
- logger.debug("Synchronizing repository for alias {}", alias);
+ logger.debug("Synchronizing repository for cartridge subscription alias {}", alias);
}
RestCommandLineService.getInstance().sync(alias);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
@@ -72,5 +72,4 @@ public class SyncCommand implements Command<StratosCommandContext> {
public Options getOptions() {
return null;
}
-
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
index ffa8be2..ef8aa48 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
@@ -28,8 +28,6 @@ import org.apache.stratos.cli.utils.CliConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
/**
* Un-deploy kubernetes group command.
*/
@@ -68,11 +66,11 @@ public class UndeployKubernetesGroupCommand implements Command<StratosCommandCon
if ((args == null) || (args.length <= 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
String groupId = args[0];
RestCommandLineService.getInstance().undeployKubernetesGroup(groupId);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployCartridgeDefinitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployCartridgeDefinitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployCartridgeDefinitionCommand.java
index 52f2a9a..9af7b36 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployCartridgeDefinitionCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployCartridgeDefinitionCommand.java
@@ -61,10 +61,10 @@ public class UndeployCartridgeDefinitionCommand implements Command<StratosComman
logger.debug("Getting undeploy cartridge definition info {}", id);
}
RestCommandLineService.getInstance().undeployCartrigdeDefinition(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
index 6ddda4f..45a0f6c 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
@@ -66,11 +66,11 @@ public class UndeployKubernetesHostCommand implements Command<StratosCommandCont
if ((args == null) || (args.length <= 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
String hostId = args[0];
RestCommandLineService.getInstance().undeployKubernetesHost(hostId);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java
index c830052..37e1a76 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java
@@ -61,10 +61,10 @@ public class UndeployServiceDefinitionCommand implements Command<StratosCommandC
logger.debug("Getting undeploy miltitenant service info {}", id);
}
RestCommandLineService.getInstance().undeployService(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnsubscribeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnsubscribeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnsubscribeCommand.java
index e63c799..c56db7d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnsubscribeCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnsubscribeCommand.java
@@ -36,7 +36,7 @@ public class UnsubscribeCommand implements Command<StratosCommandContext> {
private static final Logger logger = LoggerFactory.getLogger(UnsubscribeCommand.class);
- private final Options options;;
+ private final Options options;
public UnsubscribeCommand() {
options = constructOptions();
@@ -92,7 +92,7 @@ public class UnsubscribeCommand implements Command<StratosCommandContext> {
logger.debug("Unsubscribe: not enough arguments");
}
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
if (commandLine.hasOption(CliConstants.FORCE_OPTION)) {
@@ -109,17 +109,17 @@ public class UnsubscribeCommand implements Command<StratosCommandContext> {
//CommandLineService.getInstance().unsubscribe(alias);
RestCommandLineService.getInstance().unsubscribe(alias);
}
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/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 cebed60..730efb6 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
@@ -34,8 +34,8 @@ public class CliConstants {
public static final String STRATOS_SHELL_PROMPT = "stratos> ";
- public static final int SUCCESSFUL_CODE = 0;
- public static final int BAD_ARGS_CODE = 1;
+ public static final int COMMAND_SUCCESSFULL = 0;
+ public static final int COMMAND_FAILED = 1;
public static final int ERROR_CODE = 2;
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliUtils.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliUtils.java
new file mode 100644
index 0000000..1733f22
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliUtils.java
@@ -0,0 +1,147 @@
+/**
+ * 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.utils;
+
+import org.apache.http.HttpResponse;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.SocketException;
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+public class CliUtils {
+
+ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("Resources");
+
+ public static <T> void printTable(T[] data, RowMapper<T> mapper, String... headers) {
+ if (data == null) {
+ return;
+ }
+ // The maximum number of columns
+ // All data String[] length must be equal to this
+ int columns = headers.length;
+ int rows = data.length + 1;
+
+ String[][] table = new String[rows][columns];
+ table[0] = headers;
+
+ for (int i = 0; i < data.length; i++) {
+ T t = data[i];
+ table[i + 1] = mapper.getData(t);
+ }
+
+ // Find the maximum length of a string in each column
+ int[] lengths = new int[columns];
+ for (int i = 0; i < table.length; i++) {
+ for (int j = 0; j < table[i].length; j++) {
+ lengths[j] = Math.max(table[i][j].length(), lengths[j]);
+ }
+ }
+
+ // The border rows
+ String borders[] = new String[lengths.length];
+ // Generate a format string for each column
+ String[] formats = new String[lengths.length];
+ for (int i = 0; i < lengths.length; i++) {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("+");
+ for (int j = 0; j < lengths[i] + 2; j++) {
+ stringBuilder.append("-");
+ }
+ boolean finalColumn = (i + 1 == lengths.length);
+ if (finalColumn) {
+ stringBuilder.append("+\n");
+ }
+ borders[i] = stringBuilder.toString();
+ formats[i] = "| %1$-" + lengths[i] + "s " + (finalColumn ? "|\n" : "");
+ }
+
+ // Print the table
+ for (int i = 0; i < table.length; i++) {
+ for (int j = 0; j < table[i].length; j++) {
+ System.out.print(borders[j]);
+ }
+ for (int j = 0; j < table[i].length; j++) {
+ System.out.format(formats[j], table[i][j]);
+ }
+ if (i + 1 == table.length) {
+ for (int j = 0; j < table[i].length; j++) {
+ System.out.print(borders[j]);
+ }
+ }
+ }
+ }
+
+ public static String getMessage(String key, Object... args) {
+ String message = BUNDLE.getString(key);
+ if (args != null && args.length > 0) {
+ message = MessageFormat.format(message, args);
+ }
+ return message;
+ }
+
+ public static 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();
+ }
+ }
+
+ /**
+ * Extract HTTP response body as a string
+ * @param response
+ * @return
+ */
+ public static String getHttpResponseString (HttpResponse response) {
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
+
+ String output;
+ String result = "";
+
+ while ((output = reader.readLine()) != null) {
+ result += output;
+ }
+
+ return result;
+ } catch (SocketException e) {
+ System.out.println("Connection problem");
+ return null;
+ } catch (NullPointerException e) {
+ System.out.println("Null value return from server");
+ return null;
+ } catch (IOException e) {
+ System.out.println("IO error");
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
deleted file mode 100644
index ed00a0d..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
+++ /dev/null
@@ -1,147 +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.utils;
-
-import org.apache.http.HttpResponse;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.SocketException;
-import java.text.MessageFormat;
-import java.util.ResourceBundle;
-
-public class CommandLineUtils {
-
- private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("Resources");
-
- public static <T> void printTable(T[] data, RowMapper<T> mapper, String... headers) {
- if (data == null) {
- return;
- }
- // The maximum number of columns
- // All data String[] length must be equal to this
- int columns = headers.length;
- int rows = data.length + 1;
-
- String[][] table = new String[rows][columns];
- table[0] = headers;
-
- for (int i = 0; i < data.length; i++) {
- T t = data[i];
- table[i + 1] = mapper.getData(t);
- }
-
- // Find the maximum length of a string in each column
- int[] lengths = new int[columns];
- for (int i = 0; i < table.length; i++) {
- for (int j = 0; j < table[i].length; j++) {
- lengths[j] = Math.max(table[i][j].length(), lengths[j]);
- }
- }
-
- // The border rows
- String borders[] = new String[lengths.length];
- // Generate a format string for each column
- String[] formats = new String[lengths.length];
- for (int i = 0; i < lengths.length; i++) {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append("+");
- for (int j = 0; j < lengths[i] + 2; j++) {
- stringBuilder.append("-");
- }
- boolean finalColumn = (i + 1 == lengths.length);
- if (finalColumn) {
- stringBuilder.append("+\n");
- }
- borders[i] = stringBuilder.toString();
- formats[i] = "| %1$-" + lengths[i] + "s " + (finalColumn ? "|\n" : "");
- }
-
- // Print the table
- for (int i = 0; i < table.length; i++) {
- for (int j = 0; j < table[i].length; j++) {
- System.out.print(borders[j]);
- }
- for (int j = 0; j < table[i].length; j++) {
- System.out.format(formats[j], table[i][j]);
- }
- if (i + 1 == table.length) {
- for (int j = 0; j < table[i].length; j++) {
- System.out.print(borders[j]);
- }
- }
- }
- }
-
- public static String getMessage(String key, Object... args) {
- String message = BUNDLE.getString(key);
- if (args != null && args.length > 0) {
- message = MessageFormat.format(message, args);
- }
- return message;
- }
-
- public static 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();
- }
- }
-
- /**
- * Extract HTTP response body as a string
- * @param response
- * @return
- */
- public static String getHttpResponseString (HttpResponse response) {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
-
- String output;
- String result = "";
-
- while ((output = reader.readLine()) != null) {
- result += output;
- }
-
- return result;
- } catch (SocketException e) {
- System.out.println("Connection problem");
- return null;
- } catch (NullPointerException e) {
- System.out.println("Null value return from server");
- return null;
- } catch (IOException e) {
- System.out.println("IO error");
- return null;
- }
- }
-}
[2/3] Refactoring CLI commands with a proper naming convention
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
index 2886e52..2650da1 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
@@ -25,7 +25,7 @@ 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.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,7 +75,7 @@ public class DeployKubernetesHostCommand implements Command<StratosCommandContex
if ((args == null) || (args.length <= 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
try {
@@ -85,24 +85,24 @@ public class DeployKubernetesHostCommand implements Command<StratosCommandContex
String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
if (resourcePath == null) {
System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
- String resourceFileContent = CommandLineUtils.readResource(resourcePath);
+ String resourceFileContent = CliUtils.readResource(resourcePath);
RestCommandLineService.getInstance().deployKubernetesHost(resourceFileContent);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
} catch (IOException e) {
System.out.println("Invalid resource path");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java
new file mode 100644
index 0000000..c00ce7b
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.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 DeployPartitionCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployPartitionCommand.class);
+
+ private final Options options;
+
+ public DeployPartitionCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Partition deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.PARTITION_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new partition 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 partionDeployment = null;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+
+ try {
+ commandLine = parser.parse(options, args);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Partition deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ partionDeployment = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployPartition(partionDeployment);
+ 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) {
+ //e.printStackTrace();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java
new file mode 100644
index 0000000..4961bfa
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.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 DeployServiceCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployServiceCommand.class);
+
+ private final Options options;
+
+ public DeployServiceCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Deploy Service resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.DEPLOY_SERVICE_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new deploy service";
+ }
+
+ 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 deployServiceDeployment = null;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+
+ try {
+ commandLine = parser.parse(options, args);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Deploy Service Deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ deployServiceDeployment = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployService(deployServiceDeployment);
+ 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) {
+ //e.printStackTrace();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceDeploymentCommand.java
deleted file mode 100644
index 95d9647..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceDeploymentCommand.java
+++ /dev/null
@@ -1,139 +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;
-
-public class DeployServiceDeploymentCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(DeployServiceDeploymentCommand.class);
-
- private final Options options;
-
- public DeployServiceDeploymentCommand(){
- options = constructOptions();
- }
-
- private Options constructOptions() {
- final Options options = new Options();
-
- Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
- "Deploy Service resource path");
- resourcePath.setArgName("resource path");
- options.addOption(resourcePath);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.DEPLOY_SERVICE_DEPLOYMENT;
- }
-
- public String getDescription() {
- return "Add new deploy service";
- }
-
- 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 deployServiceDeployment = null;
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
-
- try {
- commandLine = parser.parse(options, args);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Deploy Service Deployment");
- }
-
- if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Resource path option is passed");
- }
- resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- deployServiceDeployment = readResource(resourcePath);
- }
-
- if (resourcePath == null) {
- System.out.println("usage: " + getName() + " [-p <resource path>]");
- return CliConstants.BAD_ARGS_CODE;
- }
-
- RestCommandLineService.getInstance().deployService(deployServiceDeployment);
- 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/stratos/blob/c9df250a/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
deleted file mode 100644
index 1072029..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyCommand.java
+++ /dev/null
@@ -1,66 +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.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/stratos/blob/c9df250a/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
deleted file mode 100644
index 75fe52a..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeploymentPolicyDeploymentCommand.java
+++ /dev/null
@@ -1,138 +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;
-
-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/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
index 195b417..a7e6945 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeAutoScalingPolicyCommand.java
@@ -61,10 +61,10 @@ public class DescribeAutoScalingPolicyCommand implements Command<StratosCommandC
logger.debug("Getting Autoscale policy info {}", id);
}
RestCommandLineService.getInstance().describeAutoScalingPolicy(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
index 3ae2b42..cb4608e 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeCartridgeCommand.java
@@ -61,10 +61,10 @@ public class DescribeCartridgeCommand implements Command<StratosCommandContext>
logger.debug("Getting cartridge info {}", id);
}
RestCommandLineService.getInstance().describeAvailableCartridges(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/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 ce31127..fe44e26 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
@@ -61,10 +61,10 @@ public class DescribeDeploymentPolicyCommand implements Command<StratosCommandCo
logger.debug("Getting Deployment policy info {}", id);
}
RestCommandLineService.getInstance().describeDeploymentPolicies(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
index 950a957..3709f4d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribePartitionCommand.java
@@ -61,10 +61,10 @@ public class DescribePartitionCommand implements Command<StratosCommandContext>
logger.debug("Getting Partition info {}", id);
}
RestCommandLineService.getInstance().describePartition(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java
index 1dbd7d4..4605113 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ExitCommand.java
@@ -26,11 +26,6 @@ import org.apache.stratos.cli.StratosCommandContext;
import org.apache.stratos.cli.exception.CommandException;
import org.apache.stratos.cli.utils.CliConstants;
-import java.io.File;
-
-import static org.apache.stratos.cli.utils.CliConstants.STRATOS_DIR;
-import static org.apache.stratos.cli.utils.CliConstants.STRATOS_HISTORY_DIR;
-
public class ExitCommand implements Command<StratosCommandContext> {
private static final Logger logger = LoggerFactory.getLogger(ExitCommand.class);
@@ -60,10 +55,10 @@ public class ExitCommand implements Command<StratosCommandContext> {
logger.debug("Executing {} command...", getName());
}
if (args == null || args.length == 0) {
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/HelpCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/HelpCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/HelpCommand.java
index 0593b4e..2257f11 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/HelpCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/HelpCommand.java
@@ -55,13 +55,13 @@ public class HelpCommand implements Command<StratosCommandContext> {
}
if (args == null || args.length == 0) {
context.getStratosApplication().printHelp();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else if (args != null && args.length == 1) {
context.getStratosApplication().printHelp(args[0]);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/InfoCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/InfoCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/InfoCommand.java
index d3c071a..a15e215 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/InfoCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/InfoCommand.java
@@ -60,10 +60,10 @@ public class InfoCommand implements Command<StratosCommandContext> {
logger.debug("Getting info {}", alias);
}
CommandLineService.getInstance().info(alias);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllTenants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllTenants.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllTenants.java
index f9f7e09..1540c7c 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllTenants.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllTenants.java
@@ -52,10 +52,10 @@ public class ListAllTenants implements Command<StratosCommandContext> {
}
if (args == null || args.length == 0) {
RestCommandLineService.getInstance().listAllTenants();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllUsers.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllUsers.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllUsers.java
index bea160e..6638cc7 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllUsers.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllUsers.java
@@ -52,10 +52,10 @@ public class ListAllUsers implements Command<StratosCommandContext> {
}
if (args == null || args.length == 0) {
RestCommandLineService.getInstance().listAllUsers();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
new file mode 100644
index 0000000..779b8bd
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
@@ -0,0 +1,66 @@
+/**
+ * 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 ListAutoscalePolicyCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(ListAutoscalePolicyCommand.class);
+
+ public ListAutoscalePolicyCommand() {
+ }
+
+ public String getName() {
+ return CliConstants.LIST_AUTOSCALE_POLICY;
+ }
+
+ public String getDescription() {
+ return "List available autoscaling 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().listAutoscalePolicies();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
new file mode 100644
index 0000000..372a23a
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgeSubscriptionsCommand.java
@@ -0,0 +1,95 @@
+/**
+ * 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.commons.lang3.StringUtils;
+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 ListCartridgeSubscriptionsCommand implements Command<StratosCommandContext>{
+
+ private static final Logger logger = LoggerFactory.getLogger(ListCartridgeSubscriptionsCommand.class);
+
+ private final Options options;
+
+ public ListCartridgeSubscriptionsCommand() {
+ options = constructOptions();
+ }
+
+ /**
+ * Construct Options.
+ *
+ * @return Options expected from command-line.
+ */
+ private Options constructOptions() {
+
+ final Options options = new Options();
+ return options;
+ }
+
+ @Override
+ public String getName() {
+ return "list-cartridge-subscriptions";
+ }
+
+ @Override
+ public String getDescription() {
+ return "List cartridge subscriptions";
+ }
+
+ @Override
+ public String getArgumentSyntax() {
+ return null;
+ }
+
+ @Override
+ public Options getOptions() {
+ return options;
+ }
+
+ @Override
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing {} command...", getName());
+ }
+
+ if (args != null && args.length > 0) {
+ String alias = args[0];
+
+ if(StringUtils.isBlank(alias)){
+ System.out.println("Please specify a non blank alias");
+ return CliConstants.COMMAND_FAILED;
+ }
+ else{
+ RestCommandLineService.getInstance().listSubscribedCartridgeInfo(alias);
+ return CliConstants.COMMAND_SUCCESSFULL;
+ }
+ }else {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
index 3874d41..d1e9a8f 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListCartridgesCommand.java
@@ -53,10 +53,10 @@ public class ListCartridgesCommand implements Command<StratosCommandContext> {
if (args == null || args.length == 0) {
//CommandLineService.getInstance().listAvailableCartridges();
RestCommandLineService.getInstance().listAvailableCartridges();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
index 7580c56..127e0a5 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
@@ -52,10 +52,10 @@ public class ListDeployServiceCommand implements Command<StratosCommandContext>
}
if (args == null || args.length == 0) {
RestCommandLineService.getInstance().listDeployServices();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
new file mode 100644
index 0000000..16f09ae
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeploymentPolicyCommand.java
@@ -0,0 +1,66 @@
+/**
+ * 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 ListDeploymentPolicyCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(ListAutoscalePolicyCommand.class);
+
+ public ListDeploymentPolicyCommand() {
+ }
+
+ 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.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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java
index 146df48..22a8e05 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java
@@ -53,10 +53,10 @@ public class ListKubernetesGroupsCommand implements Command<StratosCommandContex
}
if ((args == null) || (args.length == 0)) {
RestCommandLineService.getInstance().listKubernetesGroups();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java
index 43062e7..1b6831e 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java
@@ -53,11 +53,11 @@ public class ListKubernetesHostsCommand implements Command<StratosCommandContext
}
if ((args == null) || (args.length == 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
} else {
String groupId = args[0];
RestCommandLineService.getInstance().listKubernetesHosts(groupId);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
index 4ce5ac7..cbdf039 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListMemberCommand.java
@@ -110,27 +110,27 @@ public class ListMemberCommand implements Command<StratosCommandContext> {
if (type == null) {
System.out.println("Cartridge type is required.");
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
if (alias == null) {
System.out.println("alis is required...");
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
RestCommandLineService.getInstance().listMembersOfCluster(type, alias);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListPartitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListPartitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListPartitionCommand.java
new file mode 100644
index 0000000..ce75bfd
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListPartitionCommand.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.*;
+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 ListPartitionCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(ListPartitionCommand.class);
+
+ public ListPartitionCommand(){
+ }
+
+ public String getName() {
+ return CliConstants.LIST_PARTITION;
+ }
+
+ public String getDescription() {
+ return "List available partitions";
+ }
+
+ 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().listPartitions();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
index 080a72c..0911c7d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListSubscribedCartridgesCommand.java
@@ -74,7 +74,7 @@ public class ListSubscribedCartridgesCommand implements Command<StratosCommandCo
if (args == null || args.length == 0) {
RestCommandLineService.getInstance().listSubscribedCartridges(false);
//CommandLineService.getInstance().listSubscribedCartridges(false);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else if (args != null && args.length > 0) {
String[] remainingArgs = null;
boolean full = false;
@@ -85,7 +85,7 @@ public class ListSubscribedCartridgesCommand implements Command<StratosCommandCo
remainingArgs = commandLine.getArgs();
if (!(remainingArgs == null || remainingArgs.length == 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
if (commandLine.hasOption(CliConstants.FULL_OPTION)) {
@@ -99,17 +99,17 @@ public class ListSubscribedCartridgesCommand implements Command<StratosCommandCo
}
RestCommandLineService.getInstance().listSubscribedCartridges(full);
//CommandLineService.getInstance().listSubscribedCartridges(full);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionCommand.java
deleted file mode 100644
index 4e5f4a8..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionCommand.java
+++ /dev/null
@@ -1,65 +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;
-
-public class PartitionCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(PartitionCommand.class);
-
- public PartitionCommand(){
- }
-
- public String getName() {
- return CliConstants.LIST_PARTITION;
- }
-
- public String getDescription() {
- return "List available partitions";
- }
-
- 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().listPartitions();
- 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/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionDeploymentCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionDeploymentCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionDeploymentCommand.java
deleted file mode 100644
index b1e5989..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PartitionDeploymentCommand.java
+++ /dev/null
@@ -1,138 +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;
-
-public class PartitionDeploymentCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(PartitionDeploymentCommand.class);
-
- private final Options options;
-
- public PartitionDeploymentCommand(){
- options = constructOptions();
- }
-
- private Options constructOptions() {
- final Options options = new Options();
-
- Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
- "Partition deployment resource path");
- resourcePath.setArgName("resource path");
- options.addOption(resourcePath);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.PARTITION_DEPLOYMENT;
- }
-
- public String getDescription() {
- return "Add new partition 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 partionDeployment = null;
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
-
- try {
- commandLine = parser.parse(options, args);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Partition deployment");
- }
-
- if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Resource path option is passed");
- }
- resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- partionDeployment = readResource(resourcePath);
- }
-
- if (resourcePath == null) {
- System.out.println("usage: " + getName() + " [-p <resource path>]");
- return CliConstants.BAD_ARGS_CODE;
- }
-
- RestCommandLineService.getInstance().deployPartition(partionDeployment);
- 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/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PoliciesCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PoliciesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PoliciesCommand.java
deleted file mode 100644
index b63f400..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/PoliciesCommand.java
+++ /dev/null
@@ -1,71 +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.Options;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.stratos.cli.Command;
-import org.apache.stratos.cli.CommandLineService;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-
-public class PoliciesCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(PoliciesCommand.class);
-
- public PoliciesCommand() {
- }
-
- @Override
- public String getName() {
- return CliConstants.POLICIES_ACTION;
- }
-
- @Override
- public String getDescription() {
- return "List available policies";
- }
-
- @Override
- public String getArgumentSyntax() {
- return null;
- }
-
- @Override
- 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().listAvailablePolicies();
- return CliConstants.SUCCESSFUL_CODE;
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- @Override
- public Options getOptions() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDomainMappingCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDomainMappingCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDomainMappingCommand.java
deleted file mode 100644
index 06e6b11..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/RemoveDomainMappingCommand.java
+++ /dev/null
@@ -1,75 +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.stratos.cli.Command;
-import org.apache.stratos.cli.CommandLineService;
-import org.apache.stratos.cli.StratosCommandContext;
-import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CliConstants;
-import org.apache.commons.cli.Options;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class RemoveDomainMappingCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(RemoveDomainMappingCommand.class);
-
- public RemoveDomainMappingCommand() {
- }
-
- @Override
- public String getName() {
- return CliConstants.REMOVE_DOMAIN_MAPPING_ACTION;
- }
-
- @Override
- public String getDescription() {
- return "Remove domain mapping for the subscribed cartridge";
- }
-
- @Override
- public String getArgumentSyntax() {
- return "[Cartridge alias]";
- }
-
- @Override
- public int execute(StratosCommandContext context, String[] args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing {} command...", getName());
- }
- if (args != null && args.length == 1) {
- String alias = args[0];
- if (logger.isDebugEnabled()) {
- logger.debug("Removing domain mapping for {}", alias);
- }
- CommandLineService.getInstance().removeDomainMapping(alias);
- return CliConstants.SUCCESSFUL_CODE;
- } else {
- context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
- }
- }
-
- @Override
- public Options getOptions() {
- return null;
- }
-
-}
[3/3] git commit: Refactoring CLI commands with a proper naming
convention
Posted by im...@apache.org.
Refactoring CLI commands with a proper naming convention
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c9df250a
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c9df250a
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c9df250a
Branch: refs/heads/container-autoscaling
Commit: c9df250a1a08563f8ae4064156dd2570bf2bb6b8
Parents: 70a9cca
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat Oct 11 18:57:40 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat Oct 11 18:57:40 2014 +0530
----------------------------------------------------------------------
.../apache/stratos/cli/CommandLineService.java | 12 +-
.../java/org/apache/stratos/cli/RestClient.java | 6 +-
.../stratos/cli/RestCommandLineService.java | 125 ++++----
.../apache/stratos/cli/StratosApplication.java | 30 +-
.../cli/commands/ActivateTenantCommand.java | 4 +-
.../cli/commands/AddDomainMappingCommand.java | 6 +-
.../stratos/cli/commands/AddTenantCommand.java | 8 +-
.../stratos/cli/commands/AddUserCommand.java | 8 +-
.../cli/commands/AutoscalePolicyCommand.java | 66 ----
.../AutoscalingPolicyDeploymentCommand.java | 138 ---------
.../commands/CartridgeDeploymentCommand.java | 140 ---------
.../cli/commands/DeactivateTenantCommand.java | 4 +-
.../cli/commands/DeleteTenantCommand.java | 4 +-
.../stratos/cli/commands/DeleteUserCommand.java | 4 +-
.../DeployAutoscalingPolicyCommand.java | 138 +++++++++
.../cli/commands/DeployCartridgeCommand.java | 140 +++++++++
.../commands/DeployDeploymentPolicyCommand.java | 138 +++++++++
.../commands/DeployKubernetesGroupCommand.java | 16 +-
.../commands/DeployKubernetesHostCommand.java | 16 +-
.../cli/commands/DeployPartitionCommand.java | 138 +++++++++
.../cli/commands/DeployServiceCommand.java | 139 +++++++++
.../DeployServiceDeploymentCommand.java | 139 ---------
.../cli/commands/DeploymentPolicyCommand.java | 66 ----
.../DeploymentPolicyDeploymentCommand.java | 138 ---------
.../DescribeAutoScalingPolicyCommand.java | 4 +-
.../cli/commands/DescribeCartridgeCommand.java | 4 +-
.../DescribeDeploymentPolicyCommand.java | 4 +-
.../cli/commands/DescribePartitionCommand.java | 4 +-
.../stratos/cli/commands/ExitCommand.java | 9 +-
.../stratos/cli/commands/HelpCommand.java | 6 +-
.../stratos/cli/commands/InfoCommand.java | 4 +-
.../stratos/cli/commands/ListAllTenants.java | 4 +-
.../stratos/cli/commands/ListAllUsers.java | 4 +-
.../commands/ListAutoscalePolicyCommand.java | 66 ++++
.../ListCartridgeSubscriptionsCommand.java | 95 ++++++
.../cli/commands/ListCartridgesCommand.java | 4 +-
.../cli/commands/ListDeployServiceCommand.java | 4 +-
.../commands/ListDeploymentPolicyCommand.java | 66 ++++
.../commands/ListKubernetesGroupsCommand.java | 4 +-
.../commands/ListKubernetesHostsCommand.java | 4 +-
.../stratos/cli/commands/ListMemberCommand.java | 10 +-
.../cli/commands/ListPartitionCommand.java | 65 ++++
.../ListSubscribedCartridgesCommand.java | 10 +-
.../stratos/cli/commands/PartitionCommand.java | 65 ----
.../commands/PartitionDeploymentCommand.java | 138 ---------
.../stratos/cli/commands/PoliciesCommand.java | 71 -----
.../commands/RemoveDomainMappingCommand.java | 75 -----
.../cli/commands/SubscribeCartridgeCommand.java | 307 ++++++++++++++++++
.../stratos/cli/commands/SubscribeCommand.java | 310 -------------------
.../SubscribedCartridgeInfoCommand.java | 101 ------
.../stratos/cli/commands/SyncCommand.java | 13 +-
.../UnDeployKubernetesGroupCommand.java | 6 +-
.../UndeployCartridgeDefinitionCommand.java | 4 +-
.../commands/UndeployKubernetesHostCommand.java | 4 +-
.../UndeployServiceDefinitionCommand.java | 4 +-
.../cli/commands/UnsubscribeCommand.java | 10 +-
.../apache/stratos/cli/utils/CliConstants.java | 4 +-
.../org/apache/stratos/cli/utils/CliUtils.java | 147 +++++++++
.../stratos/cli/utils/CommandLineUtils.java | 147 ---------
59 files changed, 1616 insertions(+), 1784 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
index 3939a4d..efc7021 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/CommandLineService.java
@@ -39,7 +39,7 @@ import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.lang3.StringUtils;
import org.apache.stratos.cli.exception.CommandException;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.apache.stratos.cli.utils.RowMapper;
import org.apache.stratos.manager.dto.Cartridge;
import org.apache.stratos.manager.dto.PolicyDefinition;
@@ -209,7 +209,7 @@ public class CommandLineService {
}
System.out.println("Subscribed Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
+ CliUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
System.out.println();
@@ -243,7 +243,7 @@ public class CommandLineService {
};
System.out.println("Available Multi-Tenant Cartridges:");
- CommandLineUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
+ CliUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
System.out.println();
Cartridge[] singleTenantCatridges = stub.getAvailableCartridges(false);
@@ -256,7 +256,7 @@ public class CommandLineService {
}
System.out.println("Available Single-Tenant Cartridges:");
- CommandLineUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
+ CliUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
System.out.println();
} catch (ApplicationManagementServiceADCExceptionException e) {
handleException("cannot.list.available.cartridges", e);
@@ -287,7 +287,7 @@ public class CommandLineService {
}
};
- CommandLineUtils.printTable(policies, policyMapper, "Policy Name", "Description", "Default");
+ CliUtils.printTable(policies, policyMapper, "Policy Name", "Description", "Default");
System.out.println();
} catch (RemoteException e) {
handleException(e);
@@ -542,7 +542,7 @@ public class CommandLineService {
if (logger.isDebugEnabled()) {
logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
}
- String message = CommandLineUtils.getMessage(key, args);
+ String message = CliUtils.getMessage(key, args);
if (logger.isErrorEnabled()) {
logger.error(message);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
index 48488e5..af2cb6f 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
@@ -31,7 +31,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.stratos.cli.exception.ExceptionMapper;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -222,7 +222,7 @@ public class RestClient implements GenericRestClient {
}
private void printError(HttpResponse response) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (StringUtils.isNotBlank(resultString)) {
// Response body found, try to extract exception information
boolean exceptionMapperInstanceFound = false;
@@ -275,7 +275,7 @@ public class RestClient implements GenericRestClient {
printError(response);
return null;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
return gson.fromJson(resultString, responseJsonClass);
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/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 af8c214..7fd7d53 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
@@ -18,11 +18,7 @@
*/
package org.apache.stratos.cli;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.ConnectException;
-import java.net.SocketException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -42,7 +38,6 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.HttpTransportProperties;
-import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.DefaultHttpClient;
@@ -65,7 +60,7 @@ import org.apache.stratos.cli.beans.topology.Member;
import org.apache.stratos.cli.exception.CommandException;
import org.apache.stratos.cli.exception.ExceptionMapper;
import org.apache.stratos.cli.utils.CliConstants;
-import org.apache.stratos.cli.utils.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.apache.stratos.cli.utils.RowMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -243,7 +238,7 @@ public class RestCommandLineService {
response = restClient.doGet(httpClient, endpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return null;
}
@@ -277,7 +272,7 @@ public class RestCommandLineService {
response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return null;
@@ -319,7 +314,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return;
}
@@ -393,7 +388,7 @@ public class RestCommandLineService {
cartridges = multiTelentCartridgeList.getCartridge().toArray(cartridges);
System.out.println("Available Multi-Tenant Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted");
+ CliUtils.printTable(cartridges, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted");
System.out.println();
}
@@ -410,7 +405,7 @@ public class RestCommandLineService {
cartridges1 = singleTeneCartridgetList.getCartridge().toArray(cartridges1 );
System.out.println("Available Single-Tenant Cartridges:");
- CommandLineUtils.printTable(cartridges1, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted", "Accessibility");
+ CliUtils.printTable(cartridges1, cartridgeMapper, "Type", "Name", "Description", "Version", "Multitenanted", "Accessibility");
System.out.println();
}
} catch (Exception e) {
@@ -427,7 +422,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return;
}
@@ -470,7 +465,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listSubscribedCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -547,7 +542,7 @@ public class RestCommandLineService {
}
System.out.println("Subscribed Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
+ CliUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
System.out.println();
} catch (Exception e) {
@@ -565,7 +560,7 @@ public class RestCommandLineService {
+ listSubscribedCartridgeInfoRestEndpoint + alias);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -649,7 +644,7 @@ public class RestCommandLineService {
+ listClusterRestEndpoint + "lb");
String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
- String resultStringCluster = CommandLineUtils.getHttpResponseString(responseCluster);
+ String resultStringCluster = CliUtils.getHttpResponseString(responseCluster);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -730,7 +725,7 @@ public class RestCommandLineService {
+"clusterId/"+ m.getLbClusterId());
String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
- String resultStringCluster = CommandLineUtils.getHttpResponseString(responseCluster);
+ String resultStringCluster = CliUtils.getHttpResponseString(responseCluster);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -760,13 +755,13 @@ public class RestCommandLineService {
Gson gson = new Gson();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return null;
}
- Cluster cluster = getClusterObjectFromString(CommandLineUtils.getHttpResponseString(response));
+ Cluster cluster = getClusterObjectFromString(CliUtils.getHttpResponseString(response));
if (cluster == null) {
System.out.println("No existing subscriptions found for alias " + alias);
@@ -850,13 +845,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return null;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return null;
@@ -891,13 +886,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return null;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return null;
@@ -961,13 +956,13 @@ public class RestCommandLineService {
String responseCode = "" + response.getStatusLine().getStatusCode();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String subscriptionOutput = CommandLineUtils.getHttpResponseString(response);
+ String subscriptionOutput = CliUtils.getHttpResponseString(response);
if (subscriptionOutput == null) {
System.out.println("Error in response");
@@ -1032,7 +1027,7 @@ public class RestCommandLineService {
System.out.println("Tenant added successfully");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1072,7 +1067,7 @@ public class RestCommandLineService {
System.out.println("User added successfully");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1100,7 +1095,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully delete " + tenantDomain + " tenant");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1128,7 +1123,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully deleted " + userName + " user");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1156,7 +1151,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully deactivate " + tenantDomain + " tenant");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1184,7 +1179,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully activate " + tenantDomain + " tenant");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1204,7 +1199,7 @@ public class RestCommandLineService {
+ listAllTenantRestEndPoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1254,7 +1249,7 @@ public class RestCommandLineService {
}
System.out.println("Available Tenants:" );
- CommandLineUtils.printTable(tenants, tenantInfoMapper, "Domain", "Tenant ID", "Email", "State", "Created Date");
+ CliUtils.printTable(tenants, tenantInfoMapper, "Domain", "Tenant ID", "Email", "State", "Created Date");
System.out.println();
} catch (Exception e) {
@@ -1272,7 +1267,7 @@ public class RestCommandLineService {
+ listAllUserRestEndPoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1319,7 +1314,7 @@ public class RestCommandLineService {
}
System.out.println("Available Tenants:" );
- CommandLineUtils.printTable(users, userInfoMapper, "Username", "Role");
+ CliUtils.printTable(users, userInfoMapper, "Username", "Role");
System.out.println();
} catch (Exception e) {
@@ -1344,7 +1339,7 @@ public class RestCommandLineService {
System.out.println("You have successfully unsubscribed " + alias + " cartridge");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1372,7 +1367,7 @@ public class RestCommandLineService {
System.out.println("You have successfully deployed the cartridge");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1400,7 +1395,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully undeploy " + id + " cartridge");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1420,7 +1415,7 @@ public class RestCommandLineService {
+ partitionDeploymentEndPoint, partitionDefinition);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1457,7 +1452,7 @@ public class RestCommandLineService {
System.out.println("You have successfully deployed the autoscaling policy");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1485,7 +1480,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully deploy the multi-tenant service cluster");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1513,7 +1508,7 @@ public class RestCommandLineService {
System.out.println("You have succesfully undeploy multi-tenant service cluster");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1538,13 +1533,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1582,7 +1577,7 @@ public class RestCommandLineService {
}
System.out.println("Available Deploy Services :");
- CommandLineUtils.printTable(definitionArry, deployServiceMapper, "Cartridge Type", "Deployment Policy Name",
+ CliUtils.printTable(definitionArry, deployServiceMapper, "Cartridge Type", "Deployment Policy Name",
"Autoscaling Policy Name", "Cluster Domain", "Tenant Range", "Accessibility");
System.out.println();
@@ -1609,7 +1604,7 @@ public class RestCommandLineService {
System.out.println("You have successfully deployed the deployment policy");
return;
} else {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -1629,7 +1624,7 @@ public class RestCommandLineService {
+ listParitionRestEndPoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -1677,7 +1672,7 @@ public class RestCommandLineService {
}
System.out.println("Available Partitions:" );
- CommandLineUtils.printTable(partitions, partitionMapper, "ID", "Provider", "Accessibilty");
+ CliUtils.printTable(partitions, partitionMapper, "ID", "Provider", "Accessibilty");
System.out.println();
} catch (Exception e) {
@@ -1700,13 +1695,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
@@ -1744,7 +1739,7 @@ public class RestCommandLineService {
}
System.out.println("Available Auto-scaling Policies:");
- CommandLineUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
+ CliUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
} catch (Exception e) {
handleException("Exception in listing autoscale policies", e);
@@ -1766,13 +1761,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1809,7 +1804,7 @@ public class RestCommandLineService {
}
System.out.println("Available Deployment Policies:");
- CommandLineUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
+ CliUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
System.out.println();
} catch (Exception e) {
@@ -1832,13 +1827,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1880,13 +1875,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1923,13 +1918,13 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
@@ -1978,7 +1973,7 @@ public class RestCommandLineService {
KubernetesGroup[] array = new KubernetesGroup[list.getKubernetesGroup().size()];
array = list.getKubernetesGroup().toArray(array);
System.out.println("Available kubernetes groups:" );
- CommandLineUtils.printTable(array, partitionMapper, "Group ID", "Description");
+ CliUtils.printTable(array, partitionMapper, "Group ID", "Description");
} else {
System.out.println("No kubernetes groups found");
return;
@@ -2016,7 +2011,7 @@ public class RestCommandLineService {
KubernetesHost[] array = new KubernetesHost[list.getKubernetesHost().size()];
array = list.getKubernetesHost().toArray(array);
System.out.println("Available kubernetes hosts:" );
- CommandLineUtils.printTable(array, partitionMapper, "Host ID", "Hostname", "IP Address");
+ CliUtils.printTable(array, partitionMapper, "Host ID", "Hostname", "IP Address");
} else {
System.out.println("No kubernetes hosts found");
return;
@@ -2053,7 +2048,7 @@ public class RestCommandLineService {
} else {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
@@ -2215,7 +2210,7 @@ public class RestCommandLineService {
logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
}
- String message = CommandLineUtils.getMessage(key, args);
+ String message = CliUtils.getMessage(key, args);
if (logger.isErrorEnabled()) {
logger.error(message);
@@ -2247,7 +2242,7 @@ public class RestCommandLineService {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
if (resultString == null) {
return false;
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/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 b76edcb..5df597d 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
@@ -96,7 +96,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new ExitCommand();
commands.put(command.getName(), command);
- command = new SubscribeCommand();
+ command = new SubscribeCartridgeCommand();
commands.put(command.getName(), command);
command = new UnsubscribeCommand();
@@ -126,16 +126,16 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new ActivateTenantCommand();
commands.put(command.getName(), command);
- command = new CartridgeDeploymentCommand();
+ command = new DeployCartridgeCommand();
commands.put(command.getName(), command);
- command = new PartitionDeploymentCommand();
+ command = new DeployPartitionCommand();
commands.put(command.getName(), command);
- command = new AutoscalingPolicyDeploymentCommand();
+ command = new DeployAutoscalingPolicyCommand();
commands.put(command.getName(), command);
- command = new DeployServiceDeploymentCommand();
+ command = new DeployServiceCommand();
commands.put(command.getName(), command);
command = new UndeployServiceDefinitionCommand();
@@ -147,19 +147,19 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new UndeployCartridgeDefinitionCommand();
commands.put(command.getName(), command);
- command = new DeploymentPolicyDeploymentCommand();
+ command = new DeployDeploymentPolicyCommand();
commands.put(command.getName(), command);
command = new ListSubscribedCartridgesCommand();
commands.put(command.getName(), command);
- command = new PartitionCommand();
+ command = new ListPartitionCommand();
commands.put(command.getName(), command);
- command = new AutoscalePolicyCommand();
+ command = new ListAutoscalePolicyCommand();
commands.put(command.getName(), command);
- command = new DeploymentPolicyCommand();
+ command = new ListDeploymentPolicyCommand();
commands.put(command.getName(), command);
command = new ListMemberCommand();
@@ -177,7 +177,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new DescribeAutoScalingPolicyCommand();
commands.put(command.getName(), command);
- command = new SubscribedCartridgeInfoCommand();
+ command = new ListCartridgeSubscriptionsCommand();
commands.put(command.getName(), command);
command = new SyncCommand();
@@ -292,14 +292,14 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
}
if (commandLine.hasOption(CliConstants.HELP_ACTION)) {
printHelp();
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments when trying to login", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
@@ -312,7 +312,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
Command<StratosCommandContext> command = commands.get(action);
if (command == null) {
printHelp();
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
boolean loginRequired = !CliConstants.HELP_ACTION.equals(action);
@@ -355,7 +355,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
promptLoop();
}
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
private boolean login(String usernameInput, String passwordInput, boolean validateLogin) {
@@ -427,7 +427,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
Command<StratosCommandContext> command = commands.get(action);
if (command == null) {
System.out.println(action + ": command not found.");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
try {
return command.execute(context, actionArgs);
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
index 84acbc1..35fa624 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java
@@ -61,10 +61,10 @@ public class ActivateTenantCommand implements Command<StratosCommandContext> {
logger.debug("Getting deactivate tenant info {}", id);
}
RestCommandLineService.getInstance().activateTenant(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
index daafc61..773e64f 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddDomainMappingCommand.java
@@ -68,14 +68,14 @@ public class AddDomainMappingCommand implements Command<StratosCommandContext> {
if (StringUtils.isBlank(domainToDisplay)) {
System.out.println("Error adding domain mapping.");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
} else {
System.out.format("Your own domain is added. Please CNAME it to systems domain %s.%n", domainToDisplay);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
index b185f7d..3b9b218 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddTenantCommand.java
@@ -150,23 +150,23 @@ public class AddTenantCommand implements Command<StratosCommandContext> {
if (admin == null || firstName == null || lastaName == null || password == null || domain == null || email == null) {
System.out.println("usage: " + getName() + " [-u <user name>] [-f <first name>] [-l <last name>] [-p <password>] [-d <domain name>] [-e <email>]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
RestCommandLineService.getInstance().addTenant(admin, firstName, lastaName, password, domain, email);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
index 331eca4..2eff5cc 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddUserCommand.java
@@ -165,23 +165,23 @@ public class AddUserCommand implements Command<StratosCommandContext> {
if (userName == null || credential == null || role == null || firstName == null || lastName == null || email == null) {
System.out.println("usage: " + getName() + " [-u <user name>] [-p <credential>] [-r <role>] [-f <first name>] [-l <last name>] [-e <email>] [-pr <profile name>]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
RestCommandLineService.getInstance().addUser(userName, credential, role, firstName, lastName, email, profileName);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/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
deleted file mode 100644
index 9c3b4ba..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalePolicyCommand.java
+++ /dev/null
@@ -1,66 +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.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 AutoscalePolicyCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(AutoscalePolicyCommand.class);
-
- public AutoscalePolicyCommand() {
- }
-
- public String getName() {
- return CliConstants.LIST_AUTOSCALE_POLICY;
- }
-
- public String getDescription() {
- return "List available autoscaling 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().listAutoscalePolicies();
- 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/stratos/blob/c9df250a/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
deleted file mode 100644
index ae44391..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AutoscalingPolicyDeploymentCommand.java
+++ /dev/null
@@ -1,138 +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;
-
-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/stratos/blob/c9df250a/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
deleted file mode 100644
index e60461c..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/CartridgeDeploymentCommand.java
+++ /dev/null
@@ -1,140 +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;
-
-public class CartridgeDeploymentCommand implements Command<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(CartridgeDeploymentCommand.class);
-
- private final Options options;
-
- public CartridgeDeploymentCommand(){
- options = constructOptions();
- }
-
- private Options constructOptions() {
- final Options options = new Options();
-
- Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
- "Cartridge deployment resource path");
- resourcePath.setArgName("resource path");
- options.addOption(resourcePath);
-
- return options;
- }
-
- public String getName() {
- return CliConstants.CARTRIDGE_DEPLOYMENT;
- }
-
- public String getDescription() {
- return "Add new cartridge 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 cartridgeDeploymentJSON = null;
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
-
- try {
- commandLine = parser.parse(options, args);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Cartridge deployment");
- }
-
- if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Resource path option is passed");
- }
- resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- cartridgeDeploymentJSON = readResource(resourcePath);
- }
-
- if (resourcePath == null) {
- System.out.println("usage: " + getName() + " [-p <resource path>]");
- return CliConstants.BAD_ARGS_CODE;
- }
-
- RestCommandLineService.getInstance().deployCartridgeDefinition(cartridgeDeploymentJSON);
- 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/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
index 83adf1f..ee9e15a 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java
@@ -61,10 +61,10 @@ public class DeactivateTenantCommand implements Command<StratosCommandContext> {
logger.debug("Getting deactivate tenant info {}", id);
}
RestCommandLineService.getInstance().deactivateTenant(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
index 50b4a85..3c0b3f5 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteTenantCommand.java
@@ -61,10 +61,10 @@ public class DeleteTenantCommand implements Command<StratosCommandContext> {
logger.debug("Getting delete tenant info {}", id);
}
RestCommandLineService.getInstance().deleteTenant(id);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
index 9be1f26..2bf3e2d 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeleteUserCommand.java
@@ -61,10 +61,10 @@ public class DeleteUserCommand implements Command<StratosCommandContext> {
logger.debug("Getting delete user info {}", username);
}
RestCommandLineService.getInstance().deleteUser(username);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.java
new file mode 100644
index 0000000..f6aa2ba
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.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 DeployAutoscalingPolicyCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployAutoscalingPolicyCommand.class);
+
+ private final Options options;
+
+ public DeployAutoscalingPolicyCommand(){
+ 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.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployAutoscalingPolicy(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 e) {
+ //e.printStackTrace();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java
new file mode 100644
index 0000000..6982fc1
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.java
@@ -0,0 +1,140 @@
+/**
+ * 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 DeployCartridgeCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployCartridgeCommand.class);
+
+ private final Options options;
+
+ public DeployCartridgeCommand(){
+ options = constructOptions();
+ }
+
+ private Options constructOptions() {
+ final Options options = new Options();
+
+ Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Cartridge deployment resource path");
+ resourcePath.setArgName("resource path");
+ options.addOption(resourcePath);
+
+ return options;
+ }
+
+ public String getName() {
+ return CliConstants.CARTRIDGE_DEPLOYMENT;
+ }
+
+ public String getDescription() {
+ return "Add new cartridge 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 cartridgeDeploymentJSON = null;
+
+ final CommandLineParser parser = new GnuParser();
+ CommandLine commandLine;
+
+ try {
+ commandLine = parser.parse(options, args);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Cartridge deployment");
+ }
+
+ if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Resource path option is passed");
+ }
+ resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
+ cartridgeDeploymentJSON = readResource(resourcePath);
+ }
+
+ if (resourcePath == null) {
+ System.out.println("usage: " + getName() + " [-p <resource path>]");
+ return CliConstants.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployCartridgeDefinition(cartridgeDeploymentJSON);
+ 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) {
+ //e.printStackTrace();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.java
new file mode 100644
index 0000000..f444894
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployDeploymentPolicyCommand.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 DeployDeploymentPolicyCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployDeploymentPolicyCommand.class);
+
+ private final Options options;
+
+ public DeployDeploymentPolicyCommand(){
+ 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.COMMAND_FAILED;
+ }
+
+ RestCommandLineService.getInstance().deployDeploymentPolicy(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 e) {
+ //e.printStackTrace();
+ 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/c9df250a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
index 7b0ad24..e6f03fe 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
@@ -25,7 +25,7 @@ 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.CommandLineUtils;
+import org.apache.stratos.cli.utils.CliUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,7 +75,7 @@ public class DeployKubernetesGroupCommand implements Command<StratosCommandConte
if ((args == null) || (args.length <= 0)) {
context.getStratosApplication().printUsage(getName());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
try {
@@ -85,24 +85,24 @@ public class DeployKubernetesGroupCommand implements Command<StratosCommandConte
String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
if (resourcePath == null) {
System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
- String resourceFileContent = CommandLineUtils.readResource(resourcePath);
+ String resourceFileContent = CliUtils.readResource(resourcePath);
RestCommandLineService.getInstance().deployKubernetesGroup(resourceFileContent);
- return CliConstants.SUCCESSFUL_CODE;
+ return CliConstants.COMMAND_SUCCESSFULL;
} else {
System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
} catch (ParseException e) {
if (logger.isErrorEnabled()) {
logger.error("Error parsing arguments", e);
}
System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
} catch (IOException e) {
System.out.println("Invalid resource path");
- return CliConstants.BAD_ARGS_CODE;
+ return CliConstants.COMMAND_FAILED;
}
}
}