Renaming deploy commands to add
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/aa503270 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/aa503270 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/aa503270 Branch: refs/heads/4.1.0-test Commit: aa50327024b20b6e0713817a5f324d6c80613ef0 Parents: 7295c88 Author: Imesh Gunaratne <[email protected]> Authored: Wed Dec 17 16:09:33 2014 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Wed Dec 17 16:09:33 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 12 +- .../apache/stratos/cli/StratosApplication.java | 14 +- .../commands/AddAutoscalingPolicyCommand.java | 138 ++++++++++++++++++ .../cli/commands/AddCartridgeCommand.java | 140 +++++++++++++++++++ .../cli/commands/AddCartridgeGroupCommand.java | 111 +++++++++++++++ .../cli/commands/AddKubernetesGroupCommand.java | 112 +++++++++++++++ .../DeployAutoscalingPolicyCommand.java | 138 ------------------ .../cli/commands/DeployCartridgeCommand.java | 140 ------------------- .../commands/DeployKubernetesGroupCommand.java | 112 --------------- .../commands/DeployKubernetesHostCommand.java | 128 ----------------- .../cli/commands/DeployServiceGroupCommand.java | 111 --------------- .../stratos/cli/commands/ListAllTenants.java | 65 --------- .../stratos/cli/commands/ListAllUsers.java | 65 --------- .../stratos/cli/commands/ListTenants.java | 65 +++++++++ .../apache/stratos/cli/commands/ListUsers.java | 65 +++++++++ .../commands/UpdateKubernetesHostCommand.java | 2 +- .../commands/UpdateKubernetesMasterCommand.java | 2 +- .../cli/commands/addKubernetesHostCommand.java | 128 +++++++++++++++++ .../apache/stratos/cli/utils/CliConstants.java | 4 +- 19 files changed, 776 insertions(+), 776 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 61f5e2b..36b0128 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 @@ -559,7 +559,7 @@ public class RestCommandLineService { } // This method helps to list all tenants - public void listAllTenants() throws CommandException { + public void listTenants() throws CommandException { try { Type listType = new TypeToken<ArrayList<TenantInfoBean>>() { }.getType(); @@ -628,7 +628,7 @@ public class RestCommandLineService { } // This method helps to deploy cartridge definitions - public void deployCartridgeDefinition(String cartridgeDefinition) throws CommandException { + public void addCartridge(String cartridgeDefinition) throws CommandException { restClient.deployEntity(ENDPOINT_DEPLOY_CARTRIDGE, cartridgeDefinition, "cartridge"); } @@ -638,7 +638,7 @@ public class RestCommandLineService { } // This method helps to deploy autoscalling polices - public void deployAutoscalingPolicy(String autoScalingPolicy) throws CommandException { + public void addAutoscalingPolicy(String autoScalingPolicy) throws CommandException { restClient.deployEntity(ENDPOINT_DEPLOY_AUTOSCALING_POLICY, autoScalingPolicy, "autoscaling policy"); } @@ -764,7 +764,7 @@ public class RestCommandLineService { } } - public void deployKubernetesCluster(String entityBody) { + public void addKubernetesCluster(String entityBody) { restClient.deployEntity(ENDPOINT_DEPLOY_KUBERNETES_CLUSTER, entityBody, "kubernetes cluster"); } @@ -802,7 +802,7 @@ public class RestCommandLineService { restClient.undeployEntity(ENDPOINT_UNDEPLOY_KUBERNETES_CLUSTER, "kubernetes cluster", clusterId); } - public void deployKubernetesHost(String entityBody, String clusterId) throws CommandException { + public void addKubernetesHost(String entityBody, String clusterId) throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); try { HttpResponse response = restClient.doPut(httpClient, restClient.getBaseURL() @@ -901,7 +901,7 @@ public class RestCommandLineService { } // This method helps to deploy service groups - public void deployServiceGroup (String entityBody) { + public void addCartridgeGroup(String entityBody) { restClient.deployEntity(ENDPOINT_DEPLOY_SERVICE_GROUP, entityBody, "service group"); } http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 0298742..5af9fc5 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 @@ -102,10 +102,10 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeleteUserCommand(); commands.put(command.getName(), command); - command = new ListAllUsers(); + command = new ListUsers(); commands.put(command.getName(), command); - command = new ListAllTenants(); + command = new ListTenants(); commands.put(command.getName(), command); command = new DeactivateTenantCommand(); @@ -114,10 +114,10 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new ActivateTenantCommand(); commands.put(command.getName(), command); - command = new DeployCartridgeCommand(); + command = new AddCartridgeCommand(); commands.put(command.getName(), command); - command = new DeployAutoscalingPolicyCommand(); + command = new AddAutoscalingPolicyCommand(); commands.put(command.getName(), command); command = new ListApplicationsCommand(); @@ -141,7 +141,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new SyncCommand(); commands.put(command.getName(), command); - command = new DeployKubernetesGroupCommand(); + command = new AddKubernetesGroupCommand(); commands.put(command.getName(), command); command = new ListKubernetesGroupsCommand(); @@ -150,7 +150,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new ListKubernetesHostsCommand(); commands.put(command.getName(), command); - command = new DeployKubernetesHostCommand(); + command = new AddKubernetesHostCommand(); commands.put(command.getName(), command); command = new UnDeployKubernetesGroupCommand(); @@ -165,7 +165,7 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new UpdateKubernetesHostCommand(); commands.put(command.getName(), command); - command = new DeployServiceGroupCommand(); + command = new AddCartridgeGroupCommand(); commands.put(command.getName(), command); command = new DescribeServiceGroupCommand(); http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddAutoscalingPolicyCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddAutoscalingPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddAutoscalingPolicyCommand.java new file mode 100644 index 0000000..019d047 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddAutoscalingPolicyCommand.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 AddAutoscalingPolicyCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(AddAutoscalingPolicyCommand.class); + + private final Options options; + + public AddAutoscalingPolicyCommand(){ + 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 resource path"); + resourcePath.setArgName("resource path"); + options.addOption(resourcePath); + + return options; + } + + public String getName() { + return "add-autoscaling-policy"; + } + + public String getDescription() { + return "Add 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().addAutoscalingPolicy(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/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeCommand.java new file mode 100644 index 0000000..1367fef --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeCommand.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 AddCartridgeCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(AddCartridgeCommand.class); + + private final Options options; + + public AddCartridgeCommand(){ + options = constructOptions(); + } + + private Options constructOptions() { + final Options options = new Options(); + + Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + "Cartridge resource path"); + resourcePath.setArgName("resource path"); + options.addOption(resourcePath); + + return options; + } + + public String getName() { + return "add-cartridge"; + } + + public String getDescription() { + return "Add 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 cartridgeJson = 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); + cartridgeJson = readResource(resourcePath); + } + + if (resourcePath == null) { + System.out.println("usage: " + getName() + " [-p <resource path>]"); + return CliConstants.COMMAND_FAILED; + } + + RestCommandLineService.getInstance().addCartridge(cartridgeJson); + 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/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeGroupCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeGroupCommand.java new file mode 100644 index 0000000..46c3bf3 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddCartridgeGroupCommand.java @@ -0,0 +1,111 @@ +/** + * 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.apache.stratos.cli.utils.CliUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; + +/** + * Deploy service group command. + */ +public class AddCartridgeGroupCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(AddCartridgeGroupCommand.class); + + private Options options; + + public AddCartridgeGroupCommand() { + options = new Options(); + Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + "Cartridge group resource path"); + option.setArgName("resource path"); + options.addOption(option); + } + + @Override + public String getName() { + return "add-cartridge-group"; + } + + @Override + public String getDescription() { + return "Add cartridge group"; + } + + @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)) { + 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 (resourcePath == null) { + System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); + return CliConstants.COMMAND_FAILED; + } + String resourceFileContent = CliUtils.readResource(resourcePath); + RestCommandLineService.getInstance().addCartridgeGroup(resourceFileContent); + return CliConstants.COMMAND_SUCCESSFULL; + } else { + System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); + return CliConstants.COMMAND_FAILED; + } + } catch (ParseException e) { + logger.error("Error parsing arguments", e); + System.out.println(e.getMessage()); + return CliConstants.COMMAND_FAILED; + } catch (IOException e) { + System.out.println("Invalid resource path"); + return CliConstants.COMMAND_FAILED; + } catch (Exception e) { + String message = "Unknown error occurred: " + e.getMessage(); + System.out.println(message); + logger.error(message, e); + return CliConstants.COMMAND_FAILED; + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddKubernetesGroupCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddKubernetesGroupCommand.java new file mode 100644 index 0000000..41054ec --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/AddKubernetesGroupCommand.java @@ -0,0 +1,112 @@ +/** + * 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.apache.stratos.cli.utils.CliUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * Deploy kubernetes group command. + */ +public class AddKubernetesGroupCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(AddKubernetesGroupCommand.class); + + private Options options; + + public AddKubernetesGroupCommand() { + options = new Options(); + Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + "Kubernetes group resource path"); + option.setArgName("resource path"); + options.addOption(option); + } + + @Override + public String getName() { + return "add-kubernetes-group"; + } + + @Override + public String getDescription() { + return "Add kubernetes group"; + } + + @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)) { + 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 (resourcePath == null) { + System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); + return CliConstants.COMMAND_FAILED; + } + String resourceFileContent = CliUtils.readResource(resourcePath); + RestCommandLineService.getInstance().addKubernetesCluster(resourceFileContent); + return CliConstants.COMMAND_SUCCESSFULL; + } else { + System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); + return CliConstants.COMMAND_FAILED; + } + } catch (ParseException e) { + logger.error("Error parsing arguments", e); + System.out.println(e.getMessage()); + return CliConstants.COMMAND_FAILED; + } catch (IOException e) { + System.out.println("Invalid resource path"); + return CliConstants.COMMAND_FAILED; + } catch (Exception e) { + String message = "Unknown error occurred: " + e.getMessage(); + System.out.println(message); + logger.error(message, e); + return CliConstants.COMMAND_FAILED; + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 deleted file mode 100644 index f6aa2ba..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployAutoscalingPolicyCommand.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 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/aa503270/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 deleted file mode 100644 index 6982fc1..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployCartridgeCommand.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 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/aa503270/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 deleted file mode 100644 index 320fe68..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java +++ /dev/null @@ -1,112 +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.apache.stratos.cli.utils.CliUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -/** - * Deploy kubernetes group command. - */ -public class DeployKubernetesGroupCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(DeployKubernetesGroupCommand.class); - - private Options options; - - public DeployKubernetesGroupCommand() { - options = new Options(); - Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, - "Kubernetes group resource path"); - option.setArgName("resource path"); - options.addOption(option); - } - - @Override - public String getName() { - return "deploy-kubernetes-group"; - } - - @Override - public String getDescription() { - return "Deploy kubernetes group"; - } - - @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)) { - 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 (resourcePath == null) { - System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); - return CliConstants.COMMAND_FAILED; - } - String resourceFileContent = CliUtils.readResource(resourcePath); - RestCommandLineService.getInstance().deployKubernetesCluster(resourceFileContent); - return CliConstants.COMMAND_SUCCESSFULL; - } else { - System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); - return CliConstants.COMMAND_FAILED; - } - } catch (ParseException e) { - logger.error("Error parsing arguments", e); - System.out.println(e.getMessage()); - return CliConstants.COMMAND_FAILED; - } catch (IOException e) { - System.out.println("Invalid resource path"); - return CliConstants.COMMAND_FAILED; - } catch (Exception e) { - String message = "Unknown error occurred: " + e.getMessage(); - System.out.println(message); - logger.error(message, e); - return CliConstants.COMMAND_FAILED; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 deleted file mode 100644 index 235929d..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java +++ /dev/null @@ -1,128 +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.apache.stratos.cli.utils.CliUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -/** - * Deploy kubernetes host command. - */ -public class DeployKubernetesHostCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(DeployKubernetesHostCommand.class); - - private Options options; - - public DeployKubernetesHostCommand() { - options = new Options(); - Option resourcePathOption = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, - "Kubernetes host resource path"); - resourcePathOption.setArgName("resource path"); - Option clusterIdOption = new Option(CliConstants.CLUSTER_ID_OPTION, CliConstants.CLUSTER_ID_LONG_OPTION, true, - "Kubernetes cluster id"); - clusterIdOption.setArgName("cluster id"); - options.addOption(clusterIdOption); - options.addOption(resourcePathOption); - } - - @Override - public String getName() { - return "deploy-kubernetes-host"; - } - - @Override - public String getDescription() { - return "Deploy kubernetes host"; - } - - @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)) { - 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)) && (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().deployKubernetesHost(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()); - return CliConstants.COMMAND_FAILED; - } catch (IOException e) { - System.out.println("Invalid resource path"); - return CliConstants.COMMAND_FAILED; - } catch (Exception e) { - String message = "Unknown error occurred: " + e.getMessage(); - System.out.println(message); - logger.error(message, e); - return CliConstants.COMMAND_FAILED; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceGroupCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceGroupCommand.java deleted file mode 100644 index c59da2e..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceGroupCommand.java +++ /dev/null @@ -1,111 +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.apache.stratos.cli.utils.CliUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.io.IOException; - -/** - * Deploy service group command. - */ -public class DeployServiceGroupCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(DeployServiceGroupCommand.class); - - private Options options; - - public DeployServiceGroupCommand() { - options = new Options(); - Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, - "Service group resource path"); - option.setArgName("resource path"); - options.addOption(option); - } - - @Override - public String getName() { - return "deploy-service-group"; - } - - @Override - public String getDescription() { - return "Deploy service group"; - } - - @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)) { - 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 (resourcePath == null) { - System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); - return CliConstants.COMMAND_FAILED; - } - String resourceFileContent = CliUtils.readResource(resourcePath); - RestCommandLineService.getInstance().deployServiceGroup(resourceFileContent); - return CliConstants.COMMAND_SUCCESSFULL; - } else { - System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); - return CliConstants.COMMAND_FAILED; - } - } catch (ParseException e) { - logger.error("Error parsing arguments", e); - System.out.println(e.getMessage()); - return CliConstants.COMMAND_FAILED; - } catch (IOException e) { - System.out.println("Invalid resource path"); - return CliConstants.COMMAND_FAILED; - } catch (Exception e) { - String message = "Unknown error occurred: " + e.getMessage(); - System.out.println(message); - logger.error(message, e); - return CliConstants.COMMAND_FAILED; - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 deleted file mode 100644 index 1540c7c..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllTenants.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.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 ListAllTenants implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(ListAllTenants.class); - - public ListAllTenants(){ - } - - public String getName() { - return CliConstants.LIST_TENANTS; - } - - public String getDescription() { - return "List available tenants"; - } - - 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().listAllTenants(); - 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/aa503270/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 deleted file mode 100644 index 6638cc7..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAllUsers.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.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 ListAllUsers implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(ListAllUsers.class); - - public ListAllUsers(){ - } - - public String getName() { - return CliConstants.LIST_USERS; - } - - public String getDescription() { - return "List available users"; - } - - 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().listAllUsers(); - 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/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListTenants.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListTenants.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListTenants.java new file mode 100644 index 0000000..da19061 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListTenants.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.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 ListTenants implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(ListTenants.class); + + public ListTenants(){ + } + + public String getName() { + return CliConstants.LIST_TENANTS; + } + + public String getDescription() { + return "List available tenants"; + } + + 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().listTenants(); + 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/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListUsers.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListUsers.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListUsers.java new file mode 100644 index 0000000..e7ac8d4 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListUsers.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.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 ListUsers implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(ListUsers.class); + + public ListUsers(){ + } + + public String getName() { + return CliConstants.LIST_USERS; + } + + public String getDescription() { + return "List available users"; + } + + 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().listAllUsers(); + 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/aa503270/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 078fa5c..0688d65 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 @@ -35,7 +35,7 @@ import java.io.IOException; */ public class UpdateKubernetesHostCommand implements Command<StratosCommandContext> { - private static final Logger logger = LoggerFactory.getLogger(DeployKubernetesGroupCommand.class); + private static final Logger logger = LoggerFactory.getLogger(AddKubernetesGroupCommand.class); private Options options; http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 3186be4..4c52f37 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 @@ -35,7 +35,7 @@ import java.io.IOException; */ public class UpdateKubernetesMasterCommand implements Command<StratosCommandContext> { - private static final Logger logger = LoggerFactory.getLogger(DeployKubernetesGroupCommand.class); + private static final Logger logger = LoggerFactory.getLogger(AddKubernetesGroupCommand.class); private Options options; http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/addKubernetesHostCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/addKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/addKubernetesHostCommand.java new file mode 100644 index 0000000..60ca1f8 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/addKubernetesHostCommand.java @@ -0,0 +1,128 @@ +/** + * 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.apache.stratos.cli.utils.CliUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * Deploy kubernetes host command. + */ +public class AddKubernetesHostCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(AddKubernetesHostCommand.class); + + private Options options; + + public AddKubernetesHostCommand() { + options = new Options(); + Option resourcePathOption = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + "Kubernetes host resource path"); + resourcePathOption.setArgName("resource path"); + Option clusterIdOption = new Option(CliConstants.CLUSTER_ID_OPTION, CliConstants.CLUSTER_ID_LONG_OPTION, true, + "Kubernetes cluster id"); + clusterIdOption.setArgName("cluster id"); + options.addOption(clusterIdOption); + options.addOption(resourcePathOption); + } + + @Override + public String getName() { + return "add-kubernetes-host"; + } + + @Override + public String getDescription() { + return "Add kubernetes host"; + } + + @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)) { + 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)) && (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().addKubernetesHost(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()); + return CliConstants.COMMAND_FAILED; + } catch (IOException e) { + System.out.println("Invalid resource path"); + return CliConstants.COMMAND_FAILED; + } catch (Exception e) { + String message = "Unknown error occurred: " + e.getMessage(); + System.out.println(message); + logger.error(message, e); + return CliConstants.COMMAND_FAILED; + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/aa503270/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 19482c3..b81b601 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 @@ -128,12 +128,12 @@ public class CliConstants { /** * Autoscaling policy deployment */ - public static final String AUTOSCALING_POLICY_DEPLOYMENT = "deploy-autoscaling-policy"; + public static final String AUTOSCALING_POLICY_DEPLOYMENT = "add-autoscaling-policy"; /** * Deploy, deployment service */ - public static final String DEPLOY_SERVICE_DEPLOYMENT = "deploy-service"; + public static final String DEPLOY_SERVICE_DEPLOYMENT = "add-service"; /** * Deployment policy deployment
