Updated Branches: refs/heads/master c2aeea20d -> ea65ed7fb
STRATOS-438 - List Deploy Service Command for 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/a95feeea Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/a95feeea Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/a95feeea Branch: refs/heads/master Commit: a95feeea4acd37d3d44e736667316ebc2b8e4043 Parents: 3bea806 Author: Manula Thantriwatte <[email protected]> Authored: Wed Feb 12 16:30:05 2014 +0530 Committer: Manula Thantriwatte <[email protected]> Committed: Wed Feb 12 16:30:05 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 95 ++++++++++++++++++++ .../apache/stratos/cli/StratosApplication.java | 3 + .../beans/cartridge/ServiceDefinitionBean.java | 86 ++++++++++++++++++ .../cli/commands/ListDeployServiceCommand.java | 65 ++++++++++++++ .../apache/stratos/cli/utils/CliConstants.java | 5 ++ 5 files changed, 254 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95feeea/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 2e91aa1..10d46fe 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 @@ -37,6 +37,7 @@ import org.apache.stratos.cli.beans.autoscaler.policy.deployment.DeploymentPolic import org.apache.stratos.cli.beans.cartridge.Cartridge; import org.apache.stratos.cli.beans.cartridge.CartridgeInfoBean; import org.apache.stratos.cli.beans.cartridge.PortMapping; +import org.apache.stratos.cli.beans.cartridge.ServiceDefinitionBean; import org.apache.stratos.cli.beans.topology.Cluster; import org.apache.stratos.cli.beans.topology.Member; import org.apache.stratos.cli.exception.CommandException; @@ -77,6 +78,7 @@ 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 static class SingletonHolder { private final static RestCommandLineService INSTANCE = new RestCommandLineService(); @@ -1037,6 +1039,83 @@ public class RestCommandLineService { } } + // This method list deploy services + public void listDeployServices() throws CommandException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl() + listDeployServices, + 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 listing deploy services"); + return; + } + + String resultString = getHttpResponseString(response); + + if (resultString == null) { + System.out.println("Response content is empty"); + return; + } + + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + ServiceDefinitionList definitionList = gson.fromJson(resultString, ServiceDefinitionList.class); + + if (definitionList == null) { + System.out.println("Deploy service list is empty"); + return; + } + + RowMapper<ServiceDefinitionBean> deployServiceMapper = new RowMapper<ServiceDefinitionBean>() { + + public String[] getData(ServiceDefinitionBean definition) { + String[] data = new String[7]; + data[0] = definition.getServiceName(); + data[1] = definition.getCartridgeType(); + data[2] = definition.getDeploymentPolicyName(); + data[3] = definition.getAutoscalingPolicyName(); + data[4] = definition.getClusterDomain(); + data[5] = definition.getClusterSubDomain(); + data[6] = definition.getTenantRange(); + return data; + } + }; + + ServiceDefinitionBean[] definitionArry = new ServiceDefinitionBean[definitionList.getServiceDefinition().size()]; + definitionArry = definitionList.getServiceDefinition().toArray(definitionArry); + + if (definitionArry.length == 0) { + if (logger.isDebugEnabled()) { + logger.debug("No deploy services are found"); + } + System.out.println("There are no deploy services available"); + return; + } + + List<String> headers = new ArrayList<String>(); + headers.add("Service Name"); + headers.add("Cartridge Type"); + headers.add("Deployment Policy Name"); + headers.add("Autoscaling Policy Name"); + headers.add("Cluster Domain"); + headers.add("Cluster Sub Domain"); + headers.add("Tenant Range"); + + System.out.println("Available Deploy Services :"); + CommandLineUtils.printTable(definitionArry, deployServiceMapper, headers.toArray(new String[headers.size()])); + + } catch (Exception e) { + handleException("Exception in listing deploy services", e); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } + // This method helps to deploy deployment polices public void deployDeploymentPolicy (String deploymentPolicy) throws CommandException{ DefaultHttpClient httpClient = new DefaultHttpClient(); @@ -1484,6 +1563,22 @@ public class RestCommandLineService { } } + private class ServiceDefinitionList { + private ArrayList<ServiceDefinitionBean> serviceDefinition; + + public ArrayList<ServiceDefinitionBean> getServiceDefinition() { + return serviceDefinition; + } + + public void setServiceDefinition(ArrayList<ServiceDefinitionBean> serviceDefinition) { + this.serviceDefinition = serviceDefinition; + } + + ServiceDefinitionList() { + serviceDefinition = new ArrayList<ServiceDefinitionBean>(); + } + } + // This class convert JSON string to PartitionLIst object private class PartitionList { private ArrayList<Partition> partition; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95feeea/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 97f8da5..9829bde 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 @@ -120,6 +120,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new UndeployServiceDefinitionCommand(); commands.put(command.getName(), command); + command = new ListDeployServiceCommand(); + commands.put(command.getName(), command); + command = new UndeployCartridgeDefinitionCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95feeea/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/ServiceDefinitionBean.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/ServiceDefinitionBean.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/ServiceDefinitionBean.java new file mode 100644 index 0000000..52048d2 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/cartridge/ServiceDefinitionBean.java @@ -0,0 +1,86 @@ +/* + * 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.beans.cartridge; + +public class ServiceDefinitionBean { + private String serviceName; + private String cartridgeType; + private String deploymentPolicyName; + private String autoscalingPolicyName; + private String clusterDomain; + private String clusterSubDomain; + private String tenantRange; + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getCartridgeType() { + return cartridgeType; + } + + public void setCartridgeType(String cartridgeType) { + this.cartridgeType = cartridgeType; + } + + public String getDeploymentPolicyName() { + return deploymentPolicyName; + } + + public void setDeploymentPolicyName(String deploymentPolicyName) { + this.deploymentPolicyName = deploymentPolicyName; + } + + public String getAutoscalingPolicyName() { + return autoscalingPolicyName; + } + + public void setAutoscalingPolicyName(String autoscalingPolicyName) { + this.autoscalingPolicyName = autoscalingPolicyName; + } + + public String getClusterDomain() { + return clusterDomain; + } + + public void setClusterDomain(String clusterDomain) { + this.clusterDomain = clusterDomain; + } + + public String getClusterSubDomain() { + return clusterSubDomain; + } + + public void setClusterSubDomain(String clusterSubDomain) { + this.clusterSubDomain = clusterSubDomain; + } + + public String getTenantRange() { + return tenantRange; + } + + public void setTenantRange(String tenantRange) { + this.tenantRange = tenantRange; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95feeea/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java new file mode 100644 index 0000000..7580c56 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java @@ -0,0 +1,65 @@ +/** + * 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 ListDeployServiceCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(ListDeployServiceCommand.class); + + public ListDeployServiceCommand() { + } + + public String getName() { + return CliConstants.LIST_DEPLOY_SERVICE; + } + + public String getDescription() { + return "List available deploy services"; + } + + public String getArgumentSyntax() { + return null; + } + + public int execute(StratosCommandContext context, String[] args) throws CommandException { + if (logger.isDebugEnabled()) { + logger.debug("Executing {} command...", getName()); + } + if (args == null || args.length == 0) { + RestCommandLineService.getInstance().listDeployServices(); + return CliConstants.SUCCESSFUL_CODE; + } else { + context.getStratosApplication().printUsage(getName()); + return CliConstants.BAD_ARGS_CODE; + } + } + + public Options getOptions() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95feeea/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 ee0cf0f..b442c52 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 @@ -75,6 +75,11 @@ public class CliConstants { public static final String LIST_AUTOSCALE_POLICY = "list-autoscale-policies"; /** + * List the available deploy services + */ + public static final String LIST_DEPLOY_SERVICE= "list-deploy-services"; + + /** * Add tenant */ public static final String ADD_TENANT = "create-tenant";
