Updated Branches: refs/heads/master ac17f0c3b -> afe62c5c9
Support undeploy multi-tenant service cluster command in CLI Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/afe62c5c Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/afe62c5c Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/afe62c5c Branch: refs/heads/master Commit: afe62c5c9e0ae230d36a6124676e7972440b50e3 Parents: ac17f0c Author: Manula Thantriwatte <[email protected]> Authored: Wed Feb 12 11:56:38 2014 +0530 Committer: Manula Thantriwatte <[email protected]> Committed: Wed Feb 12 11:56:38 2014 +0530 ---------------------------------------------------------------------- .../apache/stratos/cli/GenericRestClient.java | 2 +- .../java/org/apache/stratos/cli/RestClient.java | 31 ++++++++++++++++++-- .../stratos/cli/RestCommandLineService.java | 27 ++++++++--------- .../apache/stratos/cli/StratosApplication.java | 5 ++-- 4 files changed, 44 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/afe62c5c/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 54e7442..f59aa26 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 @@ -56,7 +56,7 @@ public interface GenericRestClient { */ public HttpResponse doGet(DefaultHttpClient httpClient, String resourcePath, String userName, String passWord); - public void doDelete(); + public HttpResponse doDelete(DefaultHttpClient httpClient, String resourcePath, String userName, String passWord); public void doPut(); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/afe62c5c/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 f28fc70..6a6228d 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 @@ -21,10 +21,11 @@ package org.apache.stratos.cli; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.ConnectException; +import java.net.*; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.HttpConnectionParams; @@ -139,8 +140,32 @@ public class RestClient implements GenericRestClient{ } } - public void doDelete() { - //To change body of implemented methods use File | Settings | File Templates. + public HttpResponse doDelete(DefaultHttpClient httpClient, String resourcePath, String userName, String passWord) { + try { + HttpDelete httpDelete = new HttpDelete(resourcePath); + httpDelete.addHeader("Content-Type", "application/json"); + + String userPass = userName + ":" + passWord; + String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8")); + httpDelete.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(httpDelete); + + return response; + + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } } public void doPut() { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/afe62c5c/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 b902b0a..9b78895 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 @@ -940,7 +940,7 @@ public class RestCommandLineService { } } - // This method helps to deploy service + // This method helps to deploy multi-tenant service cluster public void deployService (String deployService) throws CommandException{ DefaultHttpClient httpClient= new DefaultHttpClient(); try { @@ -951,42 +951,41 @@ public class RestCommandLineService { if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) { System.out.println("Invalid operations. Authorization failed"); return; - } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) { - System.out.println("Error occured while deploying service"); + } else if (responseCode.equals(CliConstants.RESPONSE_NO_CONTENT)) { + System.out.println("You have succesfully deploy the multi-tenant service cluster"); return; - } else { - System.out.println("You have successfully deployed the service"); + } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) { + System.out.println("Error occured while deploying the multi-tenant service cluster"); return; } } catch (Exception e) { - handleException("Exception in deploying autoscale police", e); + handleException("Exception in deploying multi-tenant service cluster", e); } finally { httpClient.getConnectionManager().shutdown(); } } - // This method helps to undeploy multitenant service cluster + // This method helps to undeploy multi-tenant service cluster public void undeployService(String id) throws CommandException{ DefaultHttpClient httpClient = new DefaultHttpClient(); try { - HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() - + deployServiceEndPoint + "/" + id, - restClientService.getUsername(), restClientService.getPassword()); + HttpResponse response = restClientService.doDelete(httpClient, restClientService.getUrl() + + deployServiceEndPoint + "/" + id, restClientService.getUsername(), restClientService.getPassword()); String responseCode = "" + response.getStatusLine().getStatusCode(); if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) { System.out.println("Invalid operations. Authorization failed"); return; - } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) { - System.out.println("Error occured while undeploying multitenant service cluster"); + } else if (responseCode.equals(CliConstants.RESPONSE_NO_CONTENT)) { + System.out.println("You have succesfully undeploy multi-tenant service cluster"); return; } else { - System.out.println("You have successfully undeploy multitenant service cluster"); + System.out.println("Error occured while undeploy multi-tenant service cluster"); } } catch (Exception e) { - handleException("Exception in listing deployment polices", e); + handleException("Exception in undeploying multi-tenant service cluster", e); } finally { httpClient.getConnectionManager().shutdown(); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/afe62c5c/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 a04d58b..ac0d31d 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 @@ -114,9 +114,8 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeployServiceDeploymentCommand(); commands.put(command.getName(), command); - // Need to implement delete request - //command = new UndeployServiceDefinitionCommand(); - //commands.put(command.getName(), command); + command = new UndeployServiceDefinitionCommand(); + commands.put(command.getName(), command); command = new DeploymentPolicyDeploymentCommand(); commands.put(command.getName(), command);
