Repository: stratos Updated Branches: refs/heads/master 0f41d0137 -> ef816f063
Adding kubernetes group and host list commands to cli Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/ef816f06 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/ef816f06 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/ef816f06 Branch: refs/heads/master Commit: ef816f0630ac876d48cd4e63790d790c7b7b6931 Parents: 0f41d01 Author: Imesh Gunaratne <[email protected]> Authored: Fri Oct 10 23:17:56 2014 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Fri Oct 10 23:17:56 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 68 +++++++++++++++++++- .../apache/stratos/cli/StratosApplication.java | 6 ++ .../cli/beans/kubernetes/KubernetesGroup.java | 44 +++++++++++++ .../beans/kubernetes/KubernetesGroupList.java | 37 +++++++++++ .../cli/beans/kubernetes/KubernetesHost.java | 53 +++++++++++++++ .../beans/kubernetes/KubernetesHostList.java | 37 +++++++++++ .../commands/ListKubernetesGroupsCommand.java | 66 +++++++++++++++++++ .../commands/ListKubernetesHostsCommand.java | 67 +++++++++++++++++++ 8 files changed, 375 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/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 04eabc1..631510f 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 @@ -56,6 +56,10 @@ 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.kubernetes.KubernetesGroup; +import org.apache.stratos.cli.beans.kubernetes.KubernetesGroupList; +import org.apache.stratos.cli.beans.kubernetes.KubernetesHost; +import org.apache.stratos.cli.beans.kubernetes.KubernetesHostList; import org.apache.stratos.cli.beans.topology.Cluster; import org.apache.stratos.cli.beans.topology.Member; import org.apache.stratos.cli.exception.CommandException; @@ -101,12 +105,15 @@ public class RestCommandLineService { private final String getListAvailableCartridgeInfoRestEndPoint = "/stratos/admin/cartridge/available/info"; private final String deployKubernetesGroup = "/stratos/admin/kubernetes/deploy/group"; - private final String deployKubernetesHost = "/stratos/admin/kubernetes/deploy/host"; + private final String listKubernetesGroup = "/stratos/admin/kubernetes/group"; private final String undeployKubernetesGroup = "/stratos/admin/kubernetes/group/{id}"; + + private final String deployKubernetesHost = "/stratos/admin/kubernetes/deploy/host"; + private final String listKubernetesHost = "/stratos/admin/kubernetes/hosts/{groupId}"; private final String undeployKubernetesHost = "/stratos/admin/kubernetes/host/{id}"; + private final String updateKubernetesMaster = "/stratos/admin/kubernetes/update/master"; private final String updateKubernetesHost = "/stratos/admin/kubernetes/update/host"; - private final String listKubernetesGroup = "/stratos/admin/kubernetes/group"; private final String getKubernetesGroup = "/stratos/admin/kubernetes/group/{id}"; private final String getKubernetesHost = "/stratos/admin/kubernetes/hosts/{id}"; private final String getKubernetesMaster = "/stratos/admin/kubernetes/master/{id}"; @@ -1953,6 +1960,33 @@ public class RestCommandLineService { deployEntity(deployKubernetesGroup, entityBody, "kubernetes group"); } + public void listKubernetesGroups() { + try { + KubernetesGroupList list = (KubernetesGroupList) executeList(listKubernetesGroup, KubernetesGroupList.class, "kubernetes group"); + if((list != null) && (list.getKubernetesGroup() != null) && (list.getKubernetesGroup().size() > 0)) { + RowMapper<KubernetesGroup> partitionMapper = new RowMapper<KubernetesGroup>() { + public String[] getData(KubernetesGroup kubernetesGroup) { + String[] data = new String[2]; + data[0] = kubernetesGroup.getGroupId(); + data[1] = kubernetesGroup.getDescription(); + return data; + } + }; + + KubernetesGroup[] array = new KubernetesGroup[list.getKubernetesGroup().size()]; + array = list.getKubernetesGroup().toArray(array); + System.out.println("Available kubernetes groups:" ); + CommandLineUtils.printTable(array, partitionMapper, "Group ID", "Description"); + } else { + String message = "No kubernetes groups found."; + System.out.println(message); + return; + } + } catch (Exception e) { + logger.error("Error in listing kubernetes groups"); + } + } + public void undeployKubernetesGroup(String groupId) { undeployEntity(undeployKubernetesGroup, "kubernetes group", groupId); } @@ -1961,6 +1995,35 @@ public class RestCommandLineService { deployEntity(deployKubernetesHost, entityBody, "kubernetes host"); } + public void listKubernetesHosts(String groupId) { + try { + KubernetesHostList list = (KubernetesHostList) executeList(listKubernetesHost.replace("{groupId}", groupId), + KubernetesHostList.class, "kubernetes host"); + if((list != null) && (list.getKubernetesHost() != null) && (list.getKubernetesHost().size() > 0)) { + RowMapper<KubernetesHost> partitionMapper = new RowMapper<KubernetesHost>() { + public String[] getData(KubernetesHost kubernetesHost) { + String[] data = new String[3]; + data[0] = kubernetesHost.getHostId(); + data[1] = kubernetesHost.getHostname(); + data[2] = kubernetesHost.getHostIpAddress(); + return data; + } + }; + + KubernetesHost[] array = new KubernetesHost[list.getKubernetesHost().size()]; + array = list.getKubernetesHost().toArray(array); + System.out.println("Available kubernetes hosts:" ); + CommandLineUtils.printTable(array, partitionMapper, "Host ID", "Hostname", "IP Address"); + } else { + String message = "No kubernetes hosts found."; + System.out.println(message); + return; + } + } catch (Exception e) { + logger.error("Error in listing kubernetes hosts"); + } + } + public void undeployKubernetesHost(String hostId) { undeployEntity(undeployKubernetesHost, "kubernetes host", hostId); } @@ -2066,7 +2129,6 @@ public class RestCommandLineService { System.out.println(exception); return null; } - return gson.fromJson(resultString, _class); } catch (Exception e) { handleException(String.format("Error in listing %s", entityName), e); http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/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 216d124..b76edcb 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 @@ -186,6 +186,12 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeployKubernetesGroupCommand(); commands.put(command.getName(), command); + command = new ListKubernetesGroupsCommand(); + commands.put(command.getName(), command); + + command = new ListKubernetesHostsCommand(); + commands.put(command.getName(), command); + command = new DeployKubernetesHostCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroup.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroup.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroup.java new file mode 100644 index 0000000..2eda746 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroup.java @@ -0,0 +1,44 @@ +/** + * 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.kubernetes; + +/** + * Kubernetes group. + */ +public class KubernetesGroup { + private String groupId; + private String description; + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroupList.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroupList.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroupList.java new file mode 100644 index 0000000..4ca23b5 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesGroupList.java @@ -0,0 +1,37 @@ +/** + * 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.kubernetes; + +import java.util.ArrayList; + +/** + * Kubernetes group list. + */ +public class KubernetesGroupList { + private ArrayList<KubernetesGroup> kubernetesGroup; + + public ArrayList<KubernetesGroup> getKubernetesGroup() { + return kubernetesGroup; + } + + public void setKubernetesGroup(ArrayList<KubernetesGroup> kubernetesGroup) { + this.kubernetesGroup = kubernetesGroup; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHost.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHost.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHost.java new file mode 100644 index 0000000..06e7311 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHost.java @@ -0,0 +1,53 @@ +/** + * 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.kubernetes; + +/** + * Kubernetes host. + */ +public class KubernetesHost { + private String hostId; + private String hostname; + private String hostIpAddress; + + public String getHostId() { + return hostId; + } + + public void setHostId(String hostId) { + this.hostId = hostId; + } + + public String getHostname() { + return hostname; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + public String getHostIpAddress() { + return hostIpAddress; + } + + public void setHostIpAddress(String hostIpAddress) { + this.hostIpAddress = hostIpAddress; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHostList.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHostList.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHostList.java new file mode 100644 index 0000000..029b21d --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/beans/kubernetes/KubernetesHostList.java @@ -0,0 +1,37 @@ +/** + * 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.kubernetes; + +import java.util.ArrayList; + +/** + * Kubernetes group list. + */ +public class KubernetesHostList { + private ArrayList<KubernetesHost> kubernetesHost; + + public ArrayList<KubernetesHost> getKubernetesHost() { + return kubernetesHost; + } + + public void setKubernetesHost(ArrayList<KubernetesHost> kubernetesHost) { + this.kubernetesHost = kubernetesHost; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/ef816f06/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java new file mode 100644 index 0000000..146df48 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesGroupsCommand.java @@ -0,0 +1,66 @@ +/** + * 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 ListKubernetesGroupsCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(ListKubernetesGroupsCommand.class); + + public ListKubernetesGroupsCommand() { + } + + public String getName() { + return "list-kubernetes-groups"; + } + + public String getDescription() { + return "List kubernetes groups"; + } + + 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().listKubernetesGroups(); + 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/stratos/blob/ef816f06/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.java new file mode 100644 index 0000000..43062e7 --- /dev/null +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListKubernetesHostsCommand.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 ListKubernetesHostsCommand implements Command<StratosCommandContext> { + + private static final Logger logger = LoggerFactory.getLogger(ListKubernetesHostsCommand.class); + + public ListKubernetesHostsCommand() { + } + + public String getName() { + return "list-kubernetes-hosts"; + } + + public String getDescription() { + return "List kubernetes hosts"; + } + + public String getArgumentSyntax() { + return "[group-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.BAD_ARGS_CODE; + } else { + String groupId = args[0]; + RestCommandLineService.getInstance().listKubernetesHosts(groupId); + return CliConstants.SUCCESSFUL_CODE; + } + } + + public Options getOptions() { + return null; + } +}
