stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [1/3] Refactoring CLI commands with a proper naming convention
Date Sat, 11 Oct 2014 13:34:07 GMT
Repository: stratos
Updated Branches:
  refs/heads/master fd0f922a0 -> 70d646b74


http://git-wip-us.apache.org/repos/asf/stratos/blob/70d646b7/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/70d646b7/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 0e78b5b..0000000
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCommand.java
+++ /dev/null
@@ -1,358 +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.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-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 resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
-                "Cartridge deployment resource path");
-        resourcePath.setArgName("resource path");
-        options.addOption(resourcePath);
-
-        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;
-            String resourcePath = null;
-            String subscriptionJson = 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 if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) {
-                    if (logger.isTraceEnabled()) {
-                        logger.trace("Resource path option is passed");
-                    }
-                    try {
-                        resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
-                        subscriptionJson = readResource(resourcePath);
-                    } catch (IOException e) {
-                        // e.printStackTrace();
-                        System.out.println("Invalid resource path");
-                        return CliConstants.BAD_ARGS_CODE;
-                    }
-                    
-                    if (resourcePath == null) {
-                        System.out.println("usage: " + getName() + " [-p <resource path>]");
-                        return CliConstants.BAD_ARGS_CODE;
-                    }
-
-                    RestCommandLineService.getInstance().subscribe(subscriptionJson);
-                    return CliConstants.SUCCESSFUL_CODE;
-                    
-                } 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;
-		}
-	}
-    
-    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/70d646b7/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/70d646b7/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/70d646b7/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 96b81e8..57b8ef4 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/70d646b7/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/70d646b7/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/70d646b7/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/70d646b7/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/70d646b7/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/70d646b7/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/70d646b7/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;
-        }
-    }
-}


Mime
View raw message