http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/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 deleted file mode 100644 index a6b6c74..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnsubscribeCommand.java +++ /dev/null @@ -1,132 +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.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; - -@Deprecated -public class UnsubscribeCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(UnsubscribeCommand.class); - - private final Options options; - - public UnsubscribeCommand() { - options = constructOptions(); - } - - /** - * Construct Options. - * - * @return Options expected from command-line. - */ - private Options constructOptions() { - final Options options = new Options(); - Option forceOption = new Option(CliConstants.FORCE_OPTION, CliConstants.FORCE_LONG_OPTION, false, - "Never prompt for confirmation"); - options.addOption(forceOption); - return options; - } - - @Override - public String getName() { - return CliConstants.UNSUBSCRIBE_ACTION; - } - - @Override - public String getDescription() { - return "Unsubscribe from a 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 > 0) { - String[] remainingArgs = null; - String alias = null; - boolean force = false; - final CommandLineParser parser = new GnuParser(); - CommandLine commandLine; - try { - commandLine = parser.parse(options, args); - remainingArgs = commandLine.getArgs(); - if (remainingArgs != null && remainingArgs.length == 1) { - // Get alias - alias = remainingArgs[0]; - } else { - if (logger.isDebugEnabled()) { - logger.debug("Unsubscribe: not enough arguments"); - } - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - - if (commandLine.hasOption(CliConstants.FORCE_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Force option is passed"); - } - force = true; - } - if (logger.isDebugEnabled()) { - logger.debug("Unsubscribing {}, Force Option: {}", alias, force); - } - if (force || context.getApplication().getConfirmation("Are you sure you want to unsubscribe?")) { - System.out.format("Unsubscribing the cartridge %s%n", alias); - //CommandLineService.getInstance().unsubscribe(alias); - RestCommandLineService.getInstance().unsubscribe(alias); - } - 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; - } - } - - @Override - public Options getOptions() { - return options; - } - -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesHostCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesHostCommand.java index 6be5a56..078fa5c 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesHostCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesHostCommand.java @@ -41,9 +41,15 @@ public class UpdateKubernetesHostCommand implements Command<StratosCommandContex public UpdateKubernetesHostCommand() { options = new Options(); - Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + Option clusterIdOption = new Option(CliConstants.CLUSTER_ID_OPTION, CliConstants.CLUSTER_ID_LONG_OPTION, true, + "Kubernetes cluster id"); + Option hostIdOption = new Option(CliConstants.HOST_ID_OPTION, CliConstants.HOST_ID_LONG_OPTION, true, + "Kubernetes host id"); + Option resourcePathOption = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, "Kubernetes host resource path"); - options.addOption(option); + options.addOption(clusterIdOption); + options.addOption(hostIdOption); + options.addOption(resourcePathOption); } @Override public String getName() { @@ -57,7 +63,7 @@ public class UpdateKubernetesHostCommand implements Command<StratosCommandContex @Override public String getArgumentSyntax() { - return null; + return null; } @Override @@ -70,23 +76,42 @@ public class UpdateKubernetesHostCommand implements Command<StratosCommandContex if (logger.isDebugEnabled()) { logger.debug("Executing command: ", getName()); } - + if ((args == null) || (args.length <= 0)) { context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } - + try { CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); - if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) { - String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); + + if((commandLine.hasOption(CliConstants.RESOURCE_PATH)) && (commandLine.hasOption(CliConstants.HOST_ID_OPTION)) + && (commandLine.hasOption(CliConstants.CLUSTER_ID_OPTION))) { + + // get cluster id arg value + String clusterId = commandLine.getOptionValue(CliConstants.CLUSTER_ID_OPTION); + if (clusterId == null) { + context.getStratosApplication().printUsage(getName()); + return CliConstants.COMMAND_FAILED; + } + + // get host id arg value + String hostId = commandLine.getOptionValue(CliConstants.HOST_ID_OPTION); + if (hostId == null) { + context.getStratosApplication().printUsage(getName()); + return CliConstants.COMMAND_FAILED; + } + + // get resource path arg value + String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); if (resourcePath == null) { context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } String resourceFileContent = CliUtils.readResource(resourcePath); - RestCommandLineService.getInstance().updateKubernetesHost(resourceFileContent); + + RestCommandLineService.getInstance().updateKubernetesHost(resourceFileContent, clusterId, hostId); return CliConstants.COMMAND_SUCCESSFULL; } else { context.getStratosApplication().printUsage(getName()); http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesMasterCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesMasterCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesMasterCommand.java index 73d6b7f..3186be4 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesMasterCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesMasterCommand.java @@ -41,9 +41,12 @@ public class UpdateKubernetesMasterCommand implements Command<StratosCommandCont public UpdateKubernetesMasterCommand() { options = new Options(); - Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + Option resourcePathOption = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, "Kubernetes master resource path"); - options.addOption(option); + Option clusterIdOption = new Option(CliConstants.CLUSTER_ID_OPTION, CliConstants.CLUSTER_ID_LONG_OPTION, true, + "Kubernetes cluster id"); + options.addOption(clusterIdOption); + options.addOption(resourcePathOption); } @Override public String getName() { @@ -57,7 +60,7 @@ public class UpdateKubernetesMasterCommand implements Command<StratosCommandCont @Override public String getArgumentSyntax() { - return null; + return null; } @Override @@ -70,7 +73,7 @@ public class UpdateKubernetesMasterCommand implements Command<StratosCommandCont if (logger.isDebugEnabled()) { logger.debug("Executing command: ", getName()); } - + if ((args == null) || (args.length <= 0)) { context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; @@ -79,19 +82,30 @@ public class UpdateKubernetesMasterCommand implements Command<StratosCommandCont try { CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); - if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) { - String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); + if((commandLine.hasOption(CliConstants.RESOURCE_PATH)) && (commandLine.hasOption(CliConstants.CLUSTER_ID_OPTION))) { + + // get cluster id arg value + String clusterId = commandLine.getOptionValue(CliConstants.CLUSTER_ID_OPTION); + if (clusterId == null) { + context.getStratosApplication().printUsage(getName()); + return CliConstants.COMMAND_FAILED; + } + + // get resource path arg value + String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); if (resourcePath == null) { context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } String resourceFileContent = CliUtils.readResource(resourcePath); - RestCommandLineService.getInstance().updateKubernetesMaster(resourceFileContent); + + RestCommandLineService.getInstance().updateKubernetesMaster(resourceFileContent, clusterId); return CliConstants.COMMAND_SUCCESSFULL; } else { context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } + } catch (ParseException e) { logger.error("Error parsing arguments", e); System.out.println(e.getMessage()); http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/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 d77ce7d..1c616e9 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 @@ -303,7 +303,14 @@ public class CliConstants { // Deployment options public static final String RESOURCE_PATH = "p"; public static final String RESOURCE_PATH_LONG_OPTION = "resource-path"; - + + // Kubernetes options + public static final String CLUSTER_ID_OPTION = "c"; + public static final String CLUSTER_ID_LONG_OPTION = "cluster-id"; + + public static final String HOST_ID_OPTION = "h"; + public static final String HOST_ID_LONG_OPTION = "host-id"; + public static final String RESPONSE_INTERNAL_SERVER_ERROR = "500"; public static final String RESPONSE_AUTHORIZATION_FAIL = "403"; public static final String RESPONSE_NO_CONTENT = "204";
