Github user swgkg commented on a diff in the pull request: https://github.com/apache/stratos/pull/198#discussion_r23768119 --- Diff: components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java --- @@ -1130,4 +1134,57 @@ private void printError(String message, Throwable e) { // Log error log.error(message, e); } + + // This method helps to add network partition definitions + public void addNetworkPartition(String networkPartitionDefinition) throws CommandException { + restClient.deployEntity(ENDPOINT_DEPLOY_NETWORK_PARTITION, networkPartitionDefinition, "network partition"); + } + + // This method helps to remove network partitions + public void removeNetworkPartition (String id) { + restClient.deleteEntity(ENDPOINT_REMOVE_NETWORK_PARTITION.replace("{networkPartitionId}", id), id, + "network-partition"); + } + + /** + * List network partitions + * @throws CommandException + */ + public void listNetworkPartitions() throws CommandException { + try { + Type listType = new TypeToken<ArrayList<NetworkPartitionBean>>() { + }.getType(); + List<NetworkPartitionBean> networkPartitionsList = (List<NetworkPartitionBean>) restClient.listEntity(ENDPOINT_LIST_NETWORK_PARTITIONS, + listType, "network-partitions"); + + if ((networkPartitionsList == null) || (networkPartitionsList.size() == 0)) { + System.out.println("No network partitions found"); + return; + } + + RowMapper<NetworkPartitionBean> networkPartitionMapper = new RowMapper<NetworkPartitionBean>() { + public String[] getData(NetworkPartitionBean partition) { + String[] data = new String[3]; + data[0] = partition.getId(); + data[1] = (partition.getKubernetesClusterId() != null) ? partition.getKubernetesClusterId() : ""; + data[2] = String.valueOf(partition.getPartitions().size());; + return data; + } + }; + + NetworkPartitionBean[] partitions = new NetworkPartitionBean[networkPartitionsList.size()]; + partitions = networkPartitionsList.toArray(partitions); + + System.out.println("Network partitions found:"); + CliUtils.printTable(partitions, networkPartitionMapper, "PartitionId", "Kubernetes Cluster Id", "Partitions"); + } catch (Exception e) { + String message = "Error in listing network partitions" + e; --- End diff -- We don't need to append exception to the message. We can have our own message. Thanks
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---