Updated Branches: refs/heads/master 9c77676a5 -> 357e11b6f
Add CLI option to activate, deactivated 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/357e11b6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/357e11b6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/357e11b6 Branch: refs/heads/master Commit: 357e11b6f08f023b8ef92abd859129b376b784f9 Parents: 9c77676 Author: Manula Thantriwatte <[email protected]> Authored: Wed Feb 12 17:18:15 2014 +0530 Committer: Manula Thantriwatte <[email protected]> Committed: Wed Feb 12 17:18:15 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 26 ++++++++ .../apache/stratos/cli/StratosApplication.java | 3 + .../cli/commands/ActivateTenantCommand.java | 70 ++++++++++++++++++++ .../cli/commands/DeactivateTenantCommand.java | 2 +- .../apache/stratos/cli/utils/CliConstants.java | 4 ++ 5 files changed, 104 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/357e11b6/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 d3bee8e..ac704c1 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 @@ -80,6 +80,7 @@ public class RestCommandLineService { private final String deployServiceEndPoint = "/stratos/admin/service/definition"; private final String listDeployServicesRestEndPoint = "/stratos/admin/service"; private final String deactivateTenantRestEndPoint = "/stratos/admin/tenant/deactivate"; + private final String activateTenantRestEndPoint = "/stratos/admin/tenant/activate"; private static class SingletonHolder { private final static RestCommandLineService INSTANCE = new RestCommandLineService(); @@ -888,6 +889,31 @@ public class RestCommandLineService { } } + // This method helps to activate, deactivated tenant + public void activateTenant(String tenantDomain) throws CommandException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpResponse response = restClientService.doPost(httpClient, restClientService.getUrl() + + activateTenantRestEndPoint + "/" + 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 activate " + tenantDomain + " tenant"); + return; + } else { + System.out.println("Error occured while activating " + tenantDomain + " tenant"); + } + + } catch (Exception e) { + handleException("Exception in activating " + tenantDomain + " tenant", e); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } + // This method helps to unsubscribe cartridges public void unsubscribe(String alias) throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/357e11b6/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 c3cb723..40eb496 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 @@ -108,6 +108,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeactivateTenantCommand(); commands.put(command.getName(), command); + command = new ActivateTenantCommand(); + commands.put(command.getName(), command); + command = new CartridgeDeploymentCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/357e11b6/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java new file mode 100644 index 0000000..84acbc1 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.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 ActivateTenantCommand implements Command<StratosCommandContext> { + private static final Logger logger = LoggerFactory.getLogger(ActivateTenantCommand.class); + + @Override + public String getName() { + return CliConstants.ACTIVATE_TENANT; + } + + @Override + public String getDescription() { + return "Activate 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().activateTenant(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/357e11b6/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 index 3ede8d2..83adf1f 100644 --- 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 @@ -37,7 +37,7 @@ public class DeactivateTenantCommand implements Command<StratosCommandContext> { @Override public String getDescription() { - return "Deactivate Tenant"; + return "Deactivate tenant"; } @Override http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/357e11b6/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 07e0265..f3b84e1 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 @@ -167,6 +167,10 @@ public class CliConstants { * Deactivate tenant */ public static final String DEACTIVATE_TENANT = "deactivate-tenant"; + /** + * Activate tenant + */ + public static final String ACTIVATE_TENANT = "activate-tenant"; /** * Describe the deployment policy */
