Updated Branches: refs/heads/master afe62c5c9 -> a2971ef9c
STRATOS-433 - CLI command for support undeploy cartridge definition Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/a2971ef9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/a2971ef9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/a2971ef9 Branch: refs/heads/master Commit: a2971ef9c5ba1602d829af5a86a6a829e02067c0 Parents: afe62c5 Author: Manula Thantriwatte <[email protected]> Authored: Wed Feb 12 12:24:35 2014 +0530 Committer: Manula Thantriwatte <[email protected]> Committed: Wed Feb 12 12:24:35 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 28 +++++++- .../apache/stratos/cli/StratosApplication.java | 3 + .../UndeployCartridgeDefinitionCommand.java | 70 ++++++++++++++++++++ .../apache/stratos/cli/utils/CliConstants.java | 4 ++ 4 files changed, 104 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2971ef9/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 9b78895..7b88c0f 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 @@ -879,6 +879,31 @@ public class RestCommandLineService { } } + // This method helps to undeploy cartridge definitions + public void undeployCartrigdeDefinition (String id) throws CommandException{ + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpResponse response = restClientService.doDelete(httpClient, restClientService.getUrl() + + cartridgeDeploymentEndPoint + "/" + id, restClientService.getUsername(), restClientService.getPassword()); + + String responseCode = "" + response.getStatusLine().getStatusCode(); + if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) { + System.out.println("Invalid operations. Authorization failed"); + return; + } else if (responseCode.equals(CliConstants.RESPONSE_NO_CONTENT)) { + System.out.println("You have succesfully undeploy " + id + " cartridge"); + return; + } else { + System.out.println("Error occured while undeploy " + id + " cartridge"); + } + + } catch (Exception e) { + handleException("Exception in undeploying " + id + "cartridge", e); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } + // This method helps to deploy partitions public void deployPartition (String partitionDefinition) throws CommandException{ DefaultHttpClient httpClient = new DefaultHttpClient(); @@ -1271,7 +1296,7 @@ public class RestCommandLineService { } } - // This method list deployment policies + // This method list deployment policies public void describePartition(String id) throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); try { @@ -1342,6 +1367,7 @@ public class RestCommandLineService { } } + // This method describe about auto scaling policies public void describeAutoScalingPolicy(String id) throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); try { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2971ef9/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 ac0d31d..3dbb0c7 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 @@ -117,6 +117,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new UndeployServiceDefinitionCommand(); commands.put(command.getName(), command); + command = new UndeployCartridgeDefinitionCommand(); + commands.put(command.getName(), command); + command = new DeploymentPolicyDeploymentCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2971ef9/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 new file mode 100644 index 0000000..acf5877 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployCartridgeDefinitionCommand.java @@ -0,0 +1,70 @@ +/** + * 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 UndeployCartridgeDefinitionCommand implements Command<StratosCommandContext> { + private static final Logger logger = LoggerFactory.getLogger(UndeployCartridgeDefinitionCommand.class); + + @Override + public String getName() { + return CliConstants.UNDEPLOY_CARTRIDGE_DEFINITION; + } + + @Override + public String getDescription() { + return "Undeploy Cartridge Definition"; + } + + @Override + public String getArgumentSyntax() { + return "[ID]"; + } + + @Override + public Options getOptions() { + 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 == 1) { + String id = args[0]; + if (logger.isDebugEnabled()) { + logger.debug("Getting undeploy cartridge definition info {}", id); + } + RestCommandLineService.getInstance().undeployCartrigdeDefinition(id); + return CliConstants.SUCCESSFUL_CODE; + } else { + context.getStratosApplication().printUsage(getName()); + return CliConstants.BAD_ARGS_CODE; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a2971ef9/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 c6cd646..6c0aee3 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 @@ -150,6 +150,10 @@ public class CliConstants { * undeploy deploy service */ public static final String UNDEPLOY_SERVICE = "undeploy-service"; + /** + * undeploy cartridge definition + */ + public static final String UNDEPLOY_CARTRIDGE_DEFINITION = "undeploy-cartridge"; /** * describe the deployment policy */
