You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/10/12 05:22:39 UTC
git commit: Adding update kubernetes master/host commands to CLI
Repository: stratos
Updated Branches:
refs/heads/master 11eb753fe -> c79b23160
Adding update kubernetes master/host commands to CLI
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c79b2316
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c79b2316
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c79b2316
Branch: refs/heads/master
Commit: c79b2316020b674bd81ac746799a31e31e29b4be
Parents: 11eb753
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sun Oct 12 08:52:32 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sun Oct 12 08:52:32 2014 +0530
----------------------------------------------------------------------
.../apache/stratos/cli/StratosApplication.java | 6 +
.../commands/DeployKubernetesGroupCommand.java | 9 +-
.../commands/DeployKubernetesHostCommand.java | 9 +-
.../cli/commands/DeployPartitionCommand.java | 21 +---
.../commands/UpdateKubernetesHostCommand.java | 109 +++++++++++++++++++
.../commands/UpdateKubernetesMasterCommand.java | 109 +++++++++++++++++++
6 files changed, 238 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/c79b2316/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 5b0c633..cbc5200 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
@@ -201,6 +201,12 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new UndeployKubernetesHostCommand();
commands.put(command.getName(), command);
+ command = new UpdateKubernetesMasterCommand();
+ commands.put(command.getName(), command);
+
+ command = new UpdateKubernetesHostCommand();
+ commands.put(command.getName(), command);
+
if (logger.isDebugEnabled()) {
logger.debug("Created {} commands for the application. {}", commands.size(), commands.keySet());
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c79b2316/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
index e6f03fe..1f73bd3 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
@@ -95,14 +95,17 @@ public class DeployKubernetesGroupCommand implements Command<StratosCommandConte
return CliConstants.COMMAND_FAILED;
}
} catch (ParseException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error parsing arguments", 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/c79b2316/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
index 2650da1..a107a94 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
@@ -95,14 +95,17 @@ public class DeployKubernetesHostCommand implements Command<StratosCommandContex
return CliConstants.COMMAND_FAILED;
}
} catch (ParseException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error parsing arguments", 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/c79b2316/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java
index c00ce7b..5d84c19 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployPartitionCommand.java
@@ -24,6 +24,7 @@ import org.apache.stratos.cli.RestCommandLineService;
import org.apache.stratos.cli.StratosCommandContext;
import org.apache.stratos.cli.exception.CommandException;
import org.apache.stratos.cli.utils.CliConstants;
+import org.apache.stratos.cli.utils.CliUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
@@ -87,7 +88,7 @@ public class DeployPartitionCommand implements Command<StratosCommandContext> {
logger.trace("Resource path option is passed");
}
resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH);
- partionDeployment = readResource(resourcePath);
+ partionDeployment = CliUtils.readResource(resourcePath);
}
if (resourcePath == null) {
@@ -105,7 +106,6 @@ public class DeployPartitionCommand implements Command<StratosCommandContext> {
System.out.println(e.getMessage());
return CliConstants.COMMAND_FAILED;
} catch (IOException e) {
- //e.printStackTrace();
System.out.println("Invalid resource path");
return CliConstants.COMMAND_FAILED;
}
@@ -115,23 +115,6 @@ public class DeployPartitionCommand implements Command<StratosCommandContext> {
}
}
- 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/c79b2316/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
new file mode 100644
index 0000000..6be5a56
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesHostCommand.java
@@ -0,0 +1,109 @@
+/**
+ * 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;
+
+/**
+ * Update kubernetes host command.
+ */
+public class UpdateKubernetesHostCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployKubernetesGroupCommand.class);
+
+ private Options options;
+
+ public UpdateKubernetesHostCommand() {
+ options = new Options();
+ Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Kubernetes host resource path");
+ options.addOption(option);
+ }
+ @Override
+ public String getName() {
+ return "update-kubernetes-host";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Update 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)) {
+ 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);
+ 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/c79b2316/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
new file mode 100644
index 0000000..73d6b7f
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UpdateKubernetesMasterCommand.java
@@ -0,0 +1,109 @@
+/**
+ * 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;
+
+/**
+ * Update kubernetes master command.
+ */
+public class UpdateKubernetesMasterCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(DeployKubernetesGroupCommand.class);
+
+ private Options options;
+
+ public UpdateKubernetesMasterCommand() {
+ options = new Options();
+ Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Kubernetes master resource path");
+ options.addOption(option);
+ }
+ @Override
+ public String getName() {
+ return "update-kubernetes-master";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Update kubernetes master";
+ }
+
+ @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) {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.COMMAND_FAILED;
+ }
+ String resourceFileContent = CliUtils.readResource(resourcePath);
+ RestCommandLineService.getInstance().updateKubernetesMaster(resourceFileContent);
+ 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;
+ }
+ }
+}