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/10 16:00:43 UTC
git commit: Adding kubernetes group and host deploy and undeploy
commands to cli
Repository: stratos
Updated Branches:
refs/heads/master 7ba9d8789 -> 0f41d0137
Adding kubernetes group and host deploy and undeploy 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/0f41d013
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/0f41d013
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/0f41d013
Branch: refs/heads/master
Commit: 0f41d0137558afe4cbe4c3bb346ff8d40f4157d8
Parents: 7ba9d87
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Oct 10 19:30:30 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Oct 10 19:30:30 2014 +0530
----------------------------------------------------------------------
.../apache/stratos/cli/GenericRestClient.java | 4 +-
.../java/org/apache/stratos/cli/RestClient.java | 35 ++--
.../stratos/cli/RestCommandLineService.java | 187 ++++++++++++++++++-
.../apache/stratos/cli/StratosApplication.java | 58 ++----
.../commands/DeployKubernetesGroupCommand.java | 108 +++++++++++
.../commands/DeployKubernetesHostCommand.java | 108 +++++++++++
.../UnDeployKubernetesGroupCommand.java | 78 ++++++++
.../commands/UndeployKubernetesHostCommand.java | 76 ++++++++
.../stratos/cli/utils/CommandLineUtils.java | 20 ++
9 files changed, 615 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/GenericRestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/GenericRestClient.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/GenericRestClient.java
index 15bc3d6..5b843a3 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/GenericRestClient.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/GenericRestClient.java
@@ -21,6 +21,8 @@ package org.apache.stratos.cli;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.DefaultHttpClient;
+import java.io.IOException;
+
public interface GenericRestClient {
/**
@@ -49,5 +51,5 @@ public interface GenericRestClient {
public HttpResponse doDelete(DefaultHttpClient httpClient, String resourcePath);
- public void doPut();
+ public HttpResponse doPut(DefaultHttpClient httpClient, String resourcePath, String jsonParamString) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
index a33dbf1..899d666 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
@@ -19,6 +19,7 @@
package org.apache.stratos.cli;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import org.apache.http.HttpResponse;
@@ -26,6 +27,7 @@ import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
@@ -58,15 +60,12 @@ public class RestClient implements GenericRestClient{
* This should be REST endpoint
* @param jsonParamString
* The json string which should be executed from the post request
- * @param username
- * User name for basic auth
- * @param password
- * Password for basic auth
* @return The HttpResponse
* @throws org.apache.http.client.ClientProtocolException and IOException
* if any errors occur when executing the request
*/
- public HttpResponse doPost(DefaultHttpClient httpClient, String resourcePath, String jsonParamString) throws Exception{
+ public HttpResponse doPost(DefaultHttpClient httpClient, String resourcePath, String jsonParamString)
+ throws ClientProtocolException, ConnectException {
try {
HttpPost postRequest = new HttpPost(resourcePath);
@@ -105,10 +104,6 @@ public class RestClient implements GenericRestClient{
* This should be httpClient which used to connect to rest endpoint
* @param resourcePath
* This should be REST endpoint
- * @param username
- * User name for basic auth
- * @param password
- * Password for basic auth
* @return The HttpResponse
* @throws org.apache.http.client.ClientProtocolException and IOException
* if any errors occur when executing the request
@@ -169,8 +164,24 @@ public class RestClient implements GenericRestClient{
}
}
- public void doPut() {
- // Not implemented
- }
+ public HttpResponse doPut(DefaultHttpClient httpClient, String resourcePath, String jsonParamString) throws IOException {
+ HttpPut httpPutRequest = new HttpPut(resourcePath);
+
+ StringEntity input = new StringEntity(jsonParamString);
+ input.setContentType("application/json");
+ httpPutRequest.setEntity(input);
+
+ String userPass = username + ":" + password;
+ String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+ httpPutRequest.addHeader("Authorization", basicAuth);
+ httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
+
+ HttpParams params = httpClient.getParams();
+ HttpConnectionParams.setConnectionTimeout(params, TIME_OUT_PARAM);
+ HttpConnectionParams.setSoTimeout(params, TIME_OUT_PARAM);
+
+ HttpResponse response = httpClient.execute(httpPutRequest);
+ return response;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/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 52da7a1..04eabc1 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
@@ -42,6 +42,7 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.HttpTransportProperties;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.DefaultHttpClient;
@@ -99,6 +100,16 @@ public class RestCommandLineService {
private final String listAllUserRestEndPoint = "/stratos/admin/user/list";
private final String getListAvailableCartridgeInfoRestEndPoint = "/stratos/admin/cartridge/available/info";
+ private final String deployKubernetesGroup = "/stratos/admin/kubernetes/deploy/group";
+ private final String deployKubernetesHost = "/stratos/admin/kubernetes/deploy/host";
+ private final String undeployKubernetesGroup = "/stratos/admin/kubernetes/group/{id}";
+ private final String undeployKubernetesHost = "/stratos/admin/kubernetes/host/{id}";
+ private final String updateKubernetesMaster = "/stratos/admin/kubernetes/update/master";
+ private final String updateKubernetesHost = "/stratos/admin/kubernetes/update/host";
+ private final String listKubernetesGroup = "/stratos/admin/kubernetes/group";
+ private final String getKubernetesGroup = "/stratos/admin/kubernetes/group/{id}";
+ private final String getKubernetesHost = "/stratos/admin/kubernetes/hosts/{id}";
+ private final String getKubernetesMaster = "/stratos/admin/kubernetes/master/{id}";
private static class SingletonHolder {
private final static RestCommandLineService INSTANCE = new RestCommandLineService();
@@ -1937,7 +1948,181 @@ public class RestCommandLineService {
httpClient.getConnectionManager().shutdown();
}
}
-
+
+ public void deployKubernetesGroup(String entityBody) {
+ deployEntity(deployKubernetesGroup, entityBody, "kubernetes group");
+ }
+
+ public void undeployKubernetesGroup(String groupId) {
+ undeployEntity(undeployKubernetesGroup, "kubernetes group", groupId);
+ }
+
+ public void deployKubernetesHost(String entityBody) {
+ deployEntity(deployKubernetesHost, entityBody, "kubernetes host");
+ }
+
+ public void undeployKubernetesHost(String hostId) {
+ undeployEntity(undeployKubernetesHost, "kubernetes host", hostId);
+ }
+
+ public void updateKubernetesMaster(String entityBody) {
+ updateEntity(updateKubernetesMaster, entityBody, "kubernetes master");
+ }
+
+ public void updateKubernetesHost(String entityBody) {
+ updateEntity(updateKubernetesHost, entityBody, "kubernetes host");
+ }
+
+ private void deployEntity(String serviceEndpoint, String entityBody, String entityName) {
+ try {
+ int responseCode = executePost(serviceEndpoint, entityBody);
+ if(responseCode == 201) {
+ System.out.println(String.format("Successfully deployed %s", entityName));
+ }
+ } catch (Exception e) {
+ System.out.println(String.format("Error in deploying %s", entityName));
+ }
+ }
+
+ private void undeployEntity(String serviceEndpoint, String entityName, String entityId) {
+ try {
+ int responseCode = executeDelete(serviceEndpoint, entityId);
+ if(responseCode == 404) {
+ System.out.println(String.format("%s not found", StringUtils.capitalize(entityName)));
+ } else if(responseCode == 204) {
+ System.out.println(String.format("Successfully un-deployed %s", entityName));
+ }
+ } catch (Exception e) {
+ System.out.println(String.format("Error in un-deploying %s", entityName));
+ }
+ }
+
+ private void updateEntity(String serviceEndpoint, String entityBody, String entityName) {
+ try {
+ int responseCode = executePut(serviceEndpoint, entityBody);
+ if(responseCode == 404) {
+ System.out.println(String.format("%s not found", StringUtils.capitalize(entityName)));
+ } else if(responseCode == 200) {
+ System.out.println(String.format("Successfully updated %s", entityName));
+ }
+ } catch (Exception e) {
+ System.out.println(String.format("Error in updating %s", entityName));
+ }
+ }
+
+ private void deleteEntity(String serviceEndpoint, String identifier, String entityName) {
+ try {
+ int responseCode = executeDelete(serviceEndpoint, identifier);
+ if(responseCode == 200) {
+ System.out.println(String.format("Successfully deleted %s", entityName));
+ }
+ } catch (Exception e) {
+ System.out.println(String.format("Error in deleting %s", entityName));
+ }
+ }
+
+ public int executePost(String serviceEndpoint, String postBody) throws ClientProtocolException, ConnectException {
+ DefaultHttpClient httpClient= new DefaultHttpClient();
+ try {
+ HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
+ + serviceEndpoint, postBody);
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode != 200) {
+ String resultString = getHttpResponseString(response);
+ if(StringUtils.isNotBlank(resultString)) {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ if(exception != null) {
+ System.out.println(exception);
+ }
+ }
+ }
+ return responseCode;
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
+ public Object executeList(String serviceEndpoint, Class _class, String entityName) throws CommandException{
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ HttpResponse response = null;
+
+ try {
+ response = restClient.doGet(httpClient, restClient.getBaseURL() + serviceEndpoint);
+ int responseCode = response.getStatusLine().getStatusCode();
+ String resultString = getHttpResponseString(response);
+
+ if (resultString == null) {
+ return null;
+ }
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if (responseCode != 200) {
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return null;
+ }
+
+ return gson.fromJson(resultString, _class);
+ } catch (Exception e) {
+ handleException(String.format("Error in listing %s", entityName), e);
+ return null;
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
+ public int executePut(String serviceEndpoint, String postBody) throws IOException {
+ DefaultHttpClient httpClient= new DefaultHttpClient();
+ try {
+ HttpResponse response = restClient.doPut(httpClient, restClient.getBaseURL()
+ + serviceEndpoint, postBody);
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode != 200) {
+ String resultString = getHttpResponseString(response);
+ if(StringUtils.isNotBlank(resultString)) {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ if(exception != null) {
+ System.out.println(exception);
+ }
+ }
+ }
+ return responseCode;
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
+ public int executeDelete(String serviceEndpoint, String identifier) throws IOException {
+ DefaultHttpClient httpClient= new DefaultHttpClient();
+ try {
+ HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL() + serviceEndpoint.replace("{id}", identifier));
+
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode != 200) {
+ String resultString = getHttpResponseString(response);
+ if(StringUtils.isNotBlank(resultString)) {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ if(exception != null) {
+ System.out.println(exception);
+ }
+ }
+ }
+ return responseCode;
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
public void sync(String alias) throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/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 2ecd891..216d124 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
@@ -40,37 +40,7 @@ import org.apache.commons.lang3.text.StrTokenizer;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
-import org.apache.stratos.cli.commands.ActivateTenantCommand;
-import org.apache.stratos.cli.commands.AddTenantCommand;
-import org.apache.stratos.cli.commands.AddUserCommand;
-import org.apache.stratos.cli.commands.AutoscalePolicyCommand;
-import org.apache.stratos.cli.commands.AutoscalingPolicyDeploymentCommand;
-import org.apache.stratos.cli.commands.CartridgeDeploymentCommand;
-import org.apache.stratos.cli.commands.DeactivateTenantCommand;
-import org.apache.stratos.cli.commands.DeleteUserCommand;
-import org.apache.stratos.cli.commands.DeployServiceDeploymentCommand;
-import org.apache.stratos.cli.commands.DeploymentPolicyCommand;
-import org.apache.stratos.cli.commands.DeploymentPolicyDeploymentCommand;
-import org.apache.stratos.cli.commands.DescribeAutoScalingPolicyCommand;
-import org.apache.stratos.cli.commands.DescribeCartridgeCommand;
-import org.apache.stratos.cli.commands.DescribeDeploymentPolicyCommand;
-import org.apache.stratos.cli.commands.DescribePartitionCommand;
-import org.apache.stratos.cli.commands.ExitCommand;
-import org.apache.stratos.cli.commands.HelpCommand;
-import org.apache.stratos.cli.commands.ListAllTenants;
-import org.apache.stratos.cli.commands.ListAllUsers;
-import org.apache.stratos.cli.commands.ListCartridgesCommand;
-import org.apache.stratos.cli.commands.ListDeployServiceCommand;
-import org.apache.stratos.cli.commands.ListMemberCommand;
-import org.apache.stratos.cli.commands.ListSubscribedCartridgesCommand;
-import org.apache.stratos.cli.commands.PartitionCommand;
-import org.apache.stratos.cli.commands.PartitionDeploymentCommand;
-import org.apache.stratos.cli.commands.SubscribeCommand;
-import org.apache.stratos.cli.commands.SubscribedCartridgeInfoCommand;
-import org.apache.stratos.cli.commands.SyncCommand;
-import org.apache.stratos.cli.commands.UndeployCartridgeDefinitionCommand;
-import org.apache.stratos.cli.commands.UndeployServiceDefinitionCommand;
-import org.apache.stratos.cli.commands.UnsubscribeCommand;
+import org.apache.stratos.cli.commands.*;
import org.apache.stratos.cli.completer.CommandCompleter;
import org.apache.stratos.cli.exception.CommandException;
import org.apache.stratos.cli.utils.CliConstants;
@@ -138,7 +108,6 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new AddTenantCommand();
commands.put(command.getName(), command);
- //Adding User Operations
command = new AddUserCommand();
commands.put(command.getName(), command);
@@ -148,9 +117,6 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new ListAllUsers();
commands.put(command.getName(), command);
- //command = new DeleteTenantCommand();
- //commands.put(command.getName(), command);
-
command = new ListAllTenants();
commands.put(command.getName(), command);
@@ -214,17 +180,20 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
command = new SubscribedCartridgeInfoCommand();
commands.put(command.getName(), command);
- //command = new AddDomainMappingCommand();
- //commands.put(command.getName(), command);
-
- //command = new RemoveDomainMappingCommand();
- //commands.put(command.getName(), command);
-
command = new SyncCommand();
commands.put(command.getName(), command);
-
- //command = new PoliciesCommand();
- //commands.put(command.getName(), command);
+
+ command = new DeployKubernetesGroupCommand();
+ commands.put(command.getName(), command);
+
+ command = new DeployKubernetesHostCommand();
+ commands.put(command.getName(), command);
+
+ command = new UndeployKubernetesGroupCommand();
+ commands.put(command.getName(), command);
+
+ command = new UndeployKubernetesHostCommand();
+ commands.put(command.getName(), command);
if (logger.isDebugEnabled()) {
logger.debug("Created {} commands for the application. {}", commands.size(), commands.keySet());
@@ -424,7 +393,6 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon
try {
success = RestCommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin);
- //success = CommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin);
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Error when trying to login", e);
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/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
new file mode 100644
index 0000000..7b0ad24
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java
@@ -0,0 +1,108 @@
+/**
+ * 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.CommandLineUtils;
+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");
+ 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.BAD_ARGS_CODE;
+ }
+
+ 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.BAD_ARGS_CODE;
+ }
+ String resourceFileContent = CommandLineUtils.readResource(resourcePath);
+ RestCommandLineService.getInstance().deployKubernetesGroup(resourceFileContent);
+ return CliConstants.SUCCESSFUL_CODE;
+ } else {
+ System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ } catch (ParseException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error parsing arguments", e);
+ }
+ System.out.println(e.getMessage());
+ return CliConstants.BAD_ARGS_CODE;
+ } catch (IOException e) {
+ System.out.println("Invalid resource path");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/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
new file mode 100644
index 0000000..2886e52
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java
@@ -0,0 +1,108 @@
+/**
+ * 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.CommandLineUtils;
+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 option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true,
+ "Kubernetes host resource path");
+ options.addOption(option);
+ }
+
+ @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.BAD_ARGS_CODE;
+ }
+
+ 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.BAD_ARGS_CODE;
+ }
+ String resourceFileContent = CommandLineUtils.readResource(resourcePath);
+ RestCommandLineService.getInstance().deployKubernetesHost(resourceFileContent);
+ return CliConstants.SUCCESSFUL_CODE;
+ } else {
+ System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ } catch (ParseException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error parsing arguments", e);
+ }
+ System.out.println(e.getMessage());
+ return CliConstants.BAD_ARGS_CODE;
+ } catch (IOException e) {
+ System.out.println("Invalid resource path");
+ return CliConstants.BAD_ARGS_CODE;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
new file mode 100644
index 0000000..ffa8be2
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java
@@ -0,0 +1,78 @@
+/**
+ * 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.IOException;
+
+/**
+ * Un-deploy kubernetes group command.
+ */
+public class UndeployKubernetesGroupCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(UndeployKubernetesGroupCommand.class);
+
+ public UndeployKubernetesGroupCommand() {
+ }
+
+ @Override
+ public String getName() {
+ return "undeploy-kubernetes-group";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Undeploy kubernetes group";
+ }
+
+ @Override
+ public String getArgumentSyntax() {
+ return "[group-id]";
+ }
+
+ @Override
+ public Options getOptions() {
+ return null;
+ }
+
+ @Override
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing command: ", getName());
+ }
+
+ if ((args == null) || (args.length <= 0)) {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.BAD_ARGS_CODE;
+ }
+
+ String groupId = args[0];
+ RestCommandLineService.getInstance().undeployKubernetesGroup(groupId);
+ return CliConstants.SUCCESSFUL_CODE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
new file mode 100644
index 0000000..6ddda4f
--- /dev/null
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java
@@ -0,0 +1,76 @@
+/**
+ * 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;
+
+/**
+ * Un-deploy kubernetes host command.
+ */
+public class UndeployKubernetesHostCommand implements Command<StratosCommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(UndeployKubernetesHostCommand.class);
+
+ public UndeployKubernetesHostCommand() {
+ }
+
+ @Override
+ public String getName() {
+ return "undeploy-kubernetes-host";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Undeploy kubernetes host";
+ }
+
+ @Override
+ public String getArgumentSyntax() {
+ return "[host-id]";
+ }
+
+ @Override
+ public Options getOptions() {
+ return null;
+ }
+
+ @Override
+ public int execute(StratosCommandContext context, String[] args) throws CommandException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing command: ", getName());
+ }
+
+ if ((args == null) || (args.length <= 0)) {
+ context.getStratosApplication().printUsage(getName());
+ return CliConstants.BAD_ARGS_CODE;
+ }
+
+ String hostId = args[0];
+ RestCommandLineService.getInstance().undeployKubernetesHost(hostId);
+ return CliConstants.SUCCESSFUL_CODE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0f41d013/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
index 91e2251..77a0636 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CommandLineUtils.java
@@ -18,6 +18,9 @@
*/
package org.apache.stratos.cli.utils;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
import java.text.MessageFormat;
import java.util.ResourceBundle;
@@ -91,4 +94,21 @@ public class CommandLineUtils {
}
return message;
}
+
+ public static String readResource(String fileName) throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader(fileName));
+ try {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ sb.append("\n");
+ line = br.readLine();
+ }
+ return sb.toString();
+ } finally {
+ br.close();
+ }
+ }
}