Updated Branches: refs/heads/master 73b229594 -> 9c77676a5
CLI operation to deactivate tenant Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/9c77676a Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/9c77676a Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/9c77676a Branch: refs/heads/master Commit: 9c77676a5e8166e8887d073f2051c5e6dd15cd4b Parents: 73b2295 Author: Manula Thantriwatte <[email protected]> Authored: Wed Feb 12 17:05:45 2014 +0530 Committer: Manula Thantriwatte <[email protected]> Committed: Wed Feb 12 17:05:45 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 30 ++++++++- .../apache/stratos/cli/StratosApplication.java | 3 + .../cli/commands/DeactivateTenantCommand.java | 70 ++++++++++++++++++++ .../apache/stratos/cli/utils/CliConstants.java | 4 ++ 4 files changed, 105 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9c77676a/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 e5a4069..d3bee8e 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 @@ -78,7 +78,8 @@ public class RestCommandLineService { private final String listAutoscalePolicyRestEndPoint = "/stratos/admin/policy/autoscale"; private final String listDeploymentPolicyRestEndPoint = "/stratos/admin/policy/deployment"; private final String deployServiceEndPoint = "/stratos/admin/service/definition"; - private final String listDeployServices = "/stratos/admin/service"; + private final String listDeployServicesRestEndPoint = "/stratos/admin/service"; + private final String deactivateTenantRestEndPoint = "/stratos/admin/tenant/deactivate"; private static class SingletonHolder { private final static RestCommandLineService INSTANCE = new RestCommandLineService(); @@ -862,6 +863,31 @@ public class RestCommandLineService { } } + // This method helps to deactivate the created tenant + public void deactivateTenant(String tenantDomain) throws CommandException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpResponse response = restClientService.doPost(httpClient, restClientService.getUrl() + + deactivateTenantRestEndPoint + "/" + tenantDomain, "", 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_NO_CONTENT)) { + System.out.println("You have succesfully deactivate " + tenantDomain + " tenant"); + return; + } else { + System.out.println("Error occured while deactivating " + tenantDomain + " tenant"); + } + + } catch (Exception e) { + handleException("Exception in deactivating " + tenantDomain + " tenant", e); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } + // This method helps to unsubscribe cartridges public void unsubscribe(String alias) throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); @@ -1043,7 +1069,7 @@ public class RestCommandLineService { public void listDeployServices() throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); try { - HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() + listDeployServices, + HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() + listDeployServicesRestEndPoint, restClientService.getUsername(), restClientService.getPassword()); String responseCode = "" + response.getStatusLine().getStatusCode(); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9c77676a/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 9829bde..c3cb723 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 @@ -105,6 +105,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeleteTenantCommand(); commands.put(command.getName(), command); + command = new DeactivateTenantCommand(); + commands.put(command.getName(), command); + command = new CartridgeDeploymentCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9c77676a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java new file mode 100644 index 0000000..3ede8d2 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeactivateTenantCommand.java @@ -0,0 +1,70 @@ +/** + * 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 DeactivateTenantCommand implements Command<StratosCommandContext> { + private static final Logger logger = LoggerFactory.getLogger(DeactivateTenantCommand.class); + + @Override + public String getName() { + return CliConstants.DEACTIVATE_TENANT; + } + + @Override + public String getDescription() { + return "Deactivate Tenant"; + } + + @Override + public String getArgumentSyntax() { + return "[Tenant Domain]"; + } + + @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 == 1) { + String id = args[0]; + if (logger.isDebugEnabled()) { + logger.debug("Getting deactivate tenant info {}", id); + } + RestCommandLineService.getInstance().deactivateTenant(id); + return CliConstants.SUCCESSFUL_CODE; + } else { + context.getStratosApplication().printUsage(getName()); + return CliConstants.BAD_ARGS_CODE; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9c77676a/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 b442c52..07e0265 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 @@ -163,6 +163,10 @@ public class CliConstants { * Delete tenant */ public static final String DELETE_TENANT = "delete-tenant"; + /** + * Deactivate tenant + */ + public static final String DEACTIVATE_TENANT = "deactivate-tenant"; /** * Describe the deployment policy */
