Add describe-application command in CLI
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/60a87aff Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/60a87aff Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/60a87aff Branch: refs/heads/master Commit: 60a87aff2109f68de079e9f90b309d3f314b2329 Parents: d8d29b4 Author: Manula Thantriwatte <[email protected]> Authored: Sat Nov 8 07:43:40 2014 +0000 Committer: Manula Thantriwatte <[email protected]> Committed: Sat Nov 8 07:43:40 2014 +0000 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 22 ++++ .../apache/stratos/cli/StratosApplication.java | 3 + .../grouping/applications/ApplicationBean.java | 34 +++++ .../grouping/applications/Applications.java | 70 ++++++++++ .../beans/grouping/applications/Clusters.java | 81 ++++++++++++ .../cli/beans/grouping/applications/Groups.java | 82 ++++++++++++ .../cli/beans/grouping/applications/Member.java | 130 +++++++++++++++++++ .../beans/grouping/applications/Property.java | 46 +++++++ .../beans/grouping/applications/SubGroups.java | 70 ++++++++++ .../commands/DescribeApplicationCommand.java | 67 ++++++++++ 10 files changed, 605 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/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 bc92157..3d3dcfb 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 @@ -50,6 +50,7 @@ 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.grouping.applications.ApplicationBean; import org.apache.stratos.cli.beans.grouping.serviceGroups.ServiceGroupList; import org.apache.stratos.cli.beans.kubernetes.KubernetesGroup; import org.apache.stratos.cli.beans.kubernetes.KubernetesGroupList; @@ -107,6 +108,7 @@ public class RestCommandLineService { private static final String ENDPOINT_LIST_KUBERNETES_GROUPS = API_CONTEXT + "/kubernetes/group"; private static final String ENDPOINT_LIST_KUBERNETES_HOSTS = API_CONTEXT + "/kubernetes/hosts/{groupId}"; private static final String ENDPOINT_LIST_SERVICE_GROUP = API_CONTEXT + "/group/definition/{groupDefinitionName}"; + private static final String ENDPOINT_LIST_APPLICATION = API_CONTEXT + "/application/{appId}"; private static final String ENDPOINT_GET_CARTRIDGE_OF_TENANT = API_CONTEXT + "/cartridge/info/{id}"; private static final String ENDPOINT_GET_CLUSTER_OF_TENANT = API_CONTEXT + "/cluster/"; @@ -1852,4 +1854,24 @@ public class RestCommandLineService { public void undeployApplication(String id) throws CommandException { restClient.undeployEntity(ENDPOINT_UNDEPLOY_APPLICATION, "application", id); } + + // This method helps to describe applications + public void describeApplication (String applicationID) { + try { + ApplicationBean list = (ApplicationBean) restClient.listEntity(ENDPOINT_LIST_APPLICATION.replace("{appId}", applicationID), + ApplicationBean.class, "applications"); + + if ((list == null) || (list.getApplications() == null)) { + System.out.println("Application not found: " + applicationID); + return; + } + + System.out.println("Application : " + applicationID); + System.out.println(getGson().toJson(list.getApplications())); + } catch (Exception e) { + String message = "Error in describing application: " + applicationID; + System.out.println(message); + log.error(message, e); + } + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/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 dedd6c6..35ad657 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 @@ -228,6 +228,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new UndeployApplicationCommand(); commands.put(command.getName(), command); + command = new DescribeApplicationCommand(); + commands.put(command.getName(), command); + if (logger.isDebugEnabled()) { logger.debug("Created {} commands for the application. {}", commands.size(), commands.keySet()); } http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/ApplicationBean.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/ApplicationBean.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/ApplicationBean.java new file mode 100644 index 0000000..de4365c --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/ApplicationBean.java @@ -0,0 +1,34 @@ +/** + * 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.grouping.applications; + +public class ApplicationBean +{ + private Applications applications; + + public Applications getApplications () + { + return applications; + } + + public void setApplications (Applications applications) + { + this.applications = applications; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Applications.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Applications.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Applications.java new file mode 100644 index 0000000..44ad23c --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Applications.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.beans.grouping.applications; + +public class Applications +{ + private String id; + + private String tenantAdminUsername; + + private String tenantDomain; + + private Groups groups; + + public String getId () + { + return id; + } + + public void setId (String id) + { + this.id = id; + } + + public String getTenantAdminUsername () + { + return tenantAdminUsername; + } + + public void setTenantAdminUsername (String tenantAdminUsername) + { + this.tenantAdminUsername = tenantAdminUsername; + } + + public String getTenantDomain () + { + return tenantDomain; + } + + public void setTenantDomain (String tenantDomain) + { + this.tenantDomain = tenantDomain; + } + + public Groups getGroups () + { + return groups; + } + + public void setGroups (Groups groups) + { + this.groups = groups; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Clusters.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Clusters.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Clusters.java new file mode 100644 index 0000000..3cc7761 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Clusters.java @@ -0,0 +1,81 @@ +/** + * 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.grouping.applications; + +public class Clusters { + private Member[] member; + + private String isLbCluster; + + private String[] hostNames; + + private String tenantRange; + + private String clusterId; + + private String serviceName; + + public Member[] getMember() { + return member; + } + + public void setMember(Member[] member) { + this.member = member; + } + + public String getIsLbCluster() { + return isLbCluster; + } + + public void setIsLbCluster(String isLbCluster) { + this.isLbCluster = isLbCluster; + } + + public String[] getHostNames() { + return hostNames; + } + + public void setHostNames(String[] hostNames) { + this.hostNames = hostNames; + } + + public String getTenantRange() { + return tenantRange; + } + + public void setTenantRange(String tenantRange) { + this.tenantRange = tenantRange; + } + + public String getClusterId() { + return clusterId; + } + + public void setClusterId(String clusterId) { + this.clusterId = clusterId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Groups.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Groups.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Groups.java new file mode 100644 index 0000000..e82cf05 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Groups.java @@ -0,0 +1,82 @@ +/** + * 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.grouping.applications; + +public class Groups +{ + private String deploymentPolicy; + + private Clusters clusters; + + private String alias; + + private String autoScalingPolicy; + + private SubGroups[] subGroups; + + public String getDeploymentPolicy () + { + return deploymentPolicy; + } + + public void setDeploymentPolicy (String deploymentPolicy) + { + this.deploymentPolicy = deploymentPolicy; + } + + public Clusters getClusters () + { + return clusters; + } + + public void setClusters (Clusters clusters) + { + this.clusters = clusters; + } + + public String getAlias () + { + return alias; + } + + public void setAlias (String alias) + { + this.alias = alias; + } + + public String getAutoScalingPolicy () + { + return autoScalingPolicy; + } + + public void setAutoScalingPolicy (String autoScalingPolicy) + { + this.autoScalingPolicy = autoScalingPolicy; + } + + public SubGroups[] getSubGroups () + { + return subGroups; + } + + public void setSubGroups (SubGroups[] subGroups) + { + this.subGroups = subGroups; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Member.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Member.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Member.java new file mode 100644 index 0000000..0cbb087 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Member.java @@ -0,0 +1,130 @@ +/** + * 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.grouping.applications; + +public class Member +{ + private String networkPartitionId; + + private String memberPublicIp; + + private String status; + + private Property[] property; + + private String memberId; + + private String partitionId; + + private String clusterId; + + private String memberIp; + + private String serviceName; + + public String getNetworkPartitionId () + { + return networkPartitionId; + } + + public void setNetworkPartitionId (String networkPartitionId) + { + this.networkPartitionId = networkPartitionId; + } + + public String getMemberPublicIp () + { + return memberPublicIp; + } + + public void setMemberPublicIp (String memberPublicIp) + { + this.memberPublicIp = memberPublicIp; + } + + public String getStatus () + { + return status; + } + + public void setStatus (String status) + { + this.status = status; + } + + public Property[] getProperty () + { + return property; + } + + public void setProperty (Property[] property) + { + this.property = property; + } + + public String getMemberId () + { + return memberId; + } + + public void setMemberId (String memberId) + { + this.memberId = memberId; + } + + public String getPartitionId () + { + return partitionId; + } + + public void setPartitionId (String partitionId) + { + this.partitionId = partitionId; + } + + public String getClusterId () + { + return clusterId; + } + + public void setClusterId (String clusterId) + { + this.clusterId = clusterId; + } + + public String getMemberIp () + { + return memberIp; + } + + public void setMemberIp (String memberIp) + { + this.memberIp = memberIp; + } + + public String getServiceName () + { + return serviceName; + } + + public void setServiceName (String serviceName) + { + this.serviceName = serviceName; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Property.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Property.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Property.java new file mode 100644 index 0000000..cd7dda3 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/Property.java @@ -0,0 +1,46 @@ +/** + * 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.grouping.applications; + +public class Property +{ + private String name; + + private String value; + + public String getName () + { + return name; + } + + public void setName (String name) + { + this.name = name; + } + + public String getValue () + { + return value; + } + + public void setValue (String value) + { + this.value = value; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/SubGroups.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/SubGroups.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/SubGroups.java new file mode 100644 index 0000000..a1a85f9 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/applications/SubGroups.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.beans.grouping.applications; + +public class SubGroups +{ + private String deploymentPolicy; + + private Clusters clusters; + + private String alias; + + private String autoScalingPolicy; + + public String getDeploymentPolicy () + { + return deploymentPolicy; + } + + public void setDeploymentPolicy (String deploymentPolicy) + { + this.deploymentPolicy = deploymentPolicy; + } + + public Clusters getClusters () + { + return clusters; + } + + public void setClusters (Clusters clusters) + { + this.clusters = clusters; + } + + public String getAlias () + { + return alias; + } + + public void setAlias (String alias) + { + this.alias = alias; + } + + public String getAutoScalingPolicy () + { + return autoScalingPolicy; + } + + public void setAutoScalingPolicy (String autoScalingPolicy) + { + this.autoScalingPolicy = autoScalingPolicy; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/60a87aff/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeApplicationCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeApplicationCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeApplicationCommand.java new file mode 100644 index 0000000..dbac1e8 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeApplicationCommand.java @@ -0,0 +1,67 @@ +/** + * 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 DescribeApplicationCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(DescribeApplicationCommand.class); + + public DescribeApplicationCommand() { + } + + public String getName() { + return "describe-application"; + } + + public String getDescription() { + return "Describe application"; + } + + public String getArgumentSyntax() { + return "[application-id]"; + } + + 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.COMMAND_FAILED; + } else { + String applicationId = args[0]; + RestCommandLineService.getInstance().describeApplication(applicationId); + return CliConstants.COMMAND_SUCCESSFULL; + } + } + + public Options getOptions() { + return null; + } +}
