Repository: stratos Updated Branches: refs/heads/docker-grouping-merge 5d2b33a2d -> 46edc50db
Implement list-service-group command Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/289d5e2c Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/289d5e2c Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/289d5e2c Branch: refs/heads/docker-grouping-merge Commit: 289d5e2c8db997cf471ce619a3574029a966f300 Parents: 6805c11 Author: Manula Thantriwatte <[email protected]> Authored: Fri Nov 7 05:42:50 2014 +0000 Committer: Manula Thantriwatte <[email protected]> Committed: Fri Nov 7 05:42:50 2014 +0000 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 22 +++++++ .../apache/stratos/cli/StratosApplication.java | 3 + .../definitions/DependencyDefinitions.java | 50 +++++++++++++++ .../definitions/ServiceGroupDefinition.java | 65 +++++++++++++++++++ .../grouping/definitions/ServiceGroupList.java | 41 ++++++++++++ .../definitions/StartupOrderDefinition.java | 43 +++++++++++++ .../cli/commands/ListServiceGroupCommand.java | 67 ++++++++++++++++++++ 7 files changed, 291 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/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 e52e659..9b0a3d0 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,8 @@ 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.definitions.ServiceGroupDefinition; +import org.apache.stratos.cli.beans.grouping.definitions.ServiceGroupList; import org.apache.stratos.cli.beans.kubernetes.KubernetesGroup; import org.apache.stratos.cli.beans.kubernetes.KubernetesGroupList; import org.apache.stratos.cli.beans.kubernetes.KubernetesHost; @@ -104,6 +106,7 @@ public class RestCommandLineService { private static final String ENDPOINT_LIST_USERS = "/stratos/admin/user/list"; private static final String ENDPOINT_LIST_KUBERNETES_GROUPS = "/stratos/admin/kubernetes/group"; private static final String ENDPOINT_LIST_KUBERNETES_HOSTS = "/stratos/admin/kubernetes/hosts/{groupId}"; + private static final String ENDPOINT_LIST_SERVICE_GROUP = "/stratos/admin/group/definition/{groupDefinitionName}"; private static final String ENDPOINT_GET_CARTRIDGE_OF_TENANT = "/stratos/admin/cartridge/info/{id}"; private static final String ENDPOINT_GET_CLUSTER_OF_TENANT = "/stratos/admin/cluster/"; @@ -1822,6 +1825,25 @@ public class RestCommandLineService { restClient.undeployEntity(ENDPOINT_UNDEPLOY_SERVICE_GROUP, "service group", groupDefinitionName); } + public void listServiceGroup (String groupDefinitionName) { + try { + + ServiceGroupDefinition list = (ServiceGroupDefinition) restClient.listEntity(ENDPOINT_LIST_SERVICE_GROUP.replace("{groupDefinitionName}", groupDefinitionName), + ServiceGroupDefinition.class, "serviceGroup"); + + if ((list == null) || (list.getName() == null)) { + System.out.println("null"); + System.out.println("Service group not found: " + groupDefinitionName); + return; + } + + System.out.println(getGson().toJson(list)); + } catch (Exception e) { + String message = "Error in describing service group: " + groupDefinitionName; + System.out.println(message); + log.error(message, e); + } + } // This method helps to deploy applications public void deployApplication (String entityBody) { restClient.deployEntity(ENDPOINT_DEPLOY_APPLICATION, entityBody, "application"); http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/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 9fc783b..fc7d99b 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 @@ -216,6 +216,9 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeployServiceGroupCommand(); commands.put(command.getName(), command); + command = new ListServiceGroupCommand(); + commands.put(command.getName(), command); + command = new UndeployServiceGroupCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/DependencyDefinitions.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/DependencyDefinitions.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/DependencyDefinitions.java new file mode 100644 index 0000000..4d74778 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/DependencyDefinitions.java @@ -0,0 +1,50 @@ +/* + * 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.definitions; + +import java.util.List; + +public class DependencyDefinitions { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private List<String> startupOrders; + + private String terminationBehaviour; + + public String getTerminationBehaviour() { + return terminationBehaviour; + } + + public void setTerminationBehaviour(String terminationBehaviour) { + this.terminationBehaviour = terminationBehaviour; + } + + public List<String> getStartupOrders() { + return startupOrders; + } + + public void setStartupOrders(List<String> startupOrders) { + this.startupOrders = startupOrders; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupDefinition.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupDefinition.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupDefinition.java new file mode 100644 index 0000000..d3af12f --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupDefinition.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.beans.grouping.definitions; + +import java.util.List; + +public class ServiceGroupDefinition { + + private String name; + + private List<String> subGroups; + + private List<String> cartridges; + + private DependencyDefinitions dependencies; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List<String> getSubGroups() { + return subGroups; + } + + public void setSubGroups(List<String> subGroups) { + this.subGroups = subGroups; + } + + public List<String> getCartridges() { + return cartridges; + } + + public void setCartridges(List<String> cartridges) { + this.cartridges = cartridges; + } + + public DependencyDefinitions getDependencies() { + return dependencies; + } + + public void setDependencies(DependencyDefinitions dependencies) { + this.dependencies = dependencies; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupList.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupList.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupList.java new file mode 100644 index 0000000..25949c8 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/ServiceGroupList.java @@ -0,0 +1,41 @@ +/** + * 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.definitions; + +import java.util.ArrayList; + +/** + * Service group list. + */ +public class ServiceGroupList { + private ArrayList<ServiceGroupDefinition> serviceGroup; + + public ArrayList<ServiceGroupDefinition> getServiceGroup() { + return serviceGroup; + } + + public void setServiceGroup(ArrayList<ServiceGroupDefinition> serviceGroup) { + this.serviceGroup = serviceGroup; + } + + ServiceGroupList () { + serviceGroup = new ArrayList<ServiceGroupDefinition>(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/StartupOrderDefinition.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/StartupOrderDefinition.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/StartupOrderDefinition.java new file mode 100644 index 0000000..8e437e1 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/grouping/definitions/StartupOrderDefinition.java @@ -0,0 +1,43 @@ +/* + * 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.definitions; + +public class StartupOrderDefinition { + + private String start; + + private String after; + + public String getStart() { + return start; + } + + public void setStart(String start) { + this.start = start; + } + + public String getAfter() { + return after; + } + + public void setAfter(String after) { + this.after = after; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/289d5e2c/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServiceGroupCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServiceGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServiceGroupCommand.java new file mode 100644 index 0000000..4af8bd1 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServiceGroupCommand.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 ListServiceGroupCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(ListServiceGroupCommand.class); + + public ListServiceGroupCommand() { + } + + public String getName() { + return "list-service-group"; + } + + public String getDescription() { + return "List service groups"; + } + + public String getArgumentSyntax() { + return "[group-definition-name]"; + } + + 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 groupId = args[0]; + RestCommandLineService.getInstance().listServiceGroup(groupId); + return CliConstants.COMMAND_SUCCESSFULL; + } + } + + public Options getOptions() { + return null; + } +}
