Propogating rest endpoint resource refactoring to command line interface
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/6af99011 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/6af99011 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/6af99011 Branch: refs/heads/master Commit: 6af9901141c9a89c44e76803b6cbdbb68561714c Parents: 72c9d60 Author: Shiro <[email protected]> Authored: Thu Nov 27 15:07:00 2014 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Thu Nov 27 15:22:00 2014 +0530 ---------------------------------------------------------------------- .../stratos/cli/RestCommandLineService.java | 663 ++++++------------- .../apache/stratos/cli/StratosApplication.java | 12 +- .../cli/commands/ActivateTenantCommand.java | 2 +- .../commands/DeployKubernetesGroupCommand.java | 2 +- .../commands/DeployKubernetesHostCommand.java | 38 +- .../cli/commands/DeployServiceCommand.java | 139 ---- .../commands/ListKubernetesGroupsCommand.java | 2 +- .../commands/ListKubernetesHostsCommand.java | 6 +- .../cli/commands/ListServicesCommand.java | 65 -- .../cli/commands/SubscribeCartridgeCommand.java | 330 --------- .../UnDeployKubernetesGroupCommand.java | 6 +- .../commands/UndeployKubernetesHostCommand.java | 7 +- .../UndeployServiceDefinitionCommand.java | 70 -- .../cli/commands/UnsubscribeCommand.java | 132 ---- .../commands/UpdateKubernetesHostCommand.java | 41 +- .../commands/UpdateKubernetesMasterCommand.java | 28 +- .../apache/stratos/cli/utils/CliConstants.java | 9 +- 17 files changed, 293 insertions(+), 1259 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/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 1b97031..e11afe1 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 @@ -80,56 +80,55 @@ public class RestCommandLineService { private static final String API_CONTEXT = "/api/v4.1"; private static final String ENDPOINT_INIT = API_CONTEXT + "/init"; - private static final String ENDPOINT_ADD_TENANT = API_CONTEXT + "/tenant"; - private static final String ENDPOINT_ADD_USER = API_CONTEXT + "/user"; - - private static final String ENDPOINT_DEPLOY_CARTRIDGE = API_CONTEXT + "/cartridge/definition"; - private static final String ENDPOINT_DEPLOY_PARTITION = API_CONTEXT + "/policy/deployment/partition"; - private static final String ENDPOINT_DEPLOY_AUTOSCALING_POLICY = API_CONTEXT + "/policy/autoscale"; - private static final String ENDPOINT_DEPLOY_DEPLOYMENT_POLICY = API_CONTEXT + "/policy/deployment"; - private static final String ENDPOINT_DEPLOY_SERVICE = API_CONTEXT + "/service/definition"; - private static final String ENDPOINT_DEPLOY_KUBERNETES_GROUP = API_CONTEXT + "/kubernetes/deploy/group"; - private static final String ENDPOINT_DEPLOY_KUBERNETES_HOST = API_CONTEXT + "/kubernetes/deploy/host"; - private static final String ENDPOINT_DEPLOY_SERVICE_GROUP = API_CONTEXT + "/group/definition"; - private static final String ENDPOINT_DEPLOY_APPLICATION = API_CONTEXT + "/application/definition"; - - private static final String ENDPOINT_UNDEPLOY_KUBERNETES_GROUP = API_CONTEXT + "/kubernetes/group/{id}"; - private static final String ENDPOINT_UNDEPLOY_KUBERNETES_HOST = API_CONTEXT + "/kubernetes/host/{id}"; - private static final String ENDPOINT_UNDEPLOY_SERVICE_GROUP = API_CONTEXT + "/group/definition/{id}"; - private static final String ENDPOINT_UNDEPLOY_APPLICATION = API_CONTEXT + "/application/definition/{id}"; - - private static final String ENDPOINT_LIST_PARTITIONS = API_CONTEXT + "/partition"; - private static final String ENDPOINT_LIST_AUTOSCALING_POLICIES = API_CONTEXT + "/policy/autoscale"; - private static final String ENDPOINT_LIST_DEPLOYMENT_POLICIES = API_CONTEXT + "/policy/deployment"; - private static final String ENDPOINT_LIST_CARTRIDGES = API_CONTEXT + "/cartridge/available/list"; - private static final String ENDPOINT_LIST_CARTRIDGE_SUBSCRIPTIONS = API_CONTEXT + "/cartridge/list/subscribed"; - private static final String ENDPOINT_LIST_SERVICES = API_CONTEXT + "/service"; - private static final String ENDPOINT_LIST_TENANTS = API_CONTEXT + "/tenant/list"; - private static final String ENDPOINT_LIST_USERS = API_CONTEXT + "/user/list"; - 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"; - - private static final String ENDPOINT_GET_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/"; - private static final String ENDPOINT_GET_KUBERNETES_GROUP = API_CONTEXT + "/kubernetes/group/{id}"; - private static final String ENDPOINT_GET_KUBERNETES_MASTER = API_CONTEXT + "/kubernetes/master/{id}"; - private static final String ENDPOINT_GET_KUBERNETES_HOST = API_CONTEXT + "/kubernetes/hosts/{id}"; - - private static final String ENDPOINT_UPDATE_KUBERNETES_MASTER = API_CONTEXT + "/kubernetes/update/master"; - private static final String ENDPOINT_UPDATE_KUBERNETES_HOST = API_CONTEXT + "/kubernetes/update/host"; - - private static final String ENDPOINT_SUBSCRIBE_CARTRIDGE = API_CONTEXT + "/cartridge/subscribe"; - private static final String ENDPOINT_UNSUBSCRIBE_CARTRIDGE_OF_TENANT = API_CONTEXT + "/cartridge/unsubscribe"; - private static final String ENDPOINT_SYNCHRONIZE_ARTIFACTS = API_CONTEXT + "/cartridge/sync"; - private static final String ENDPOINT_ACTIVATE_TENANT = API_CONTEXT + "/tenant/activate"; - private static final String ENDPOINT_DEACTIVATE_TENANT = API_CONTEXT + "/tenant/deactivate"; - - private static final String ENDPOINT_UPDATE_SUBSCRIPTION_PROPERTIES = API_CONTEXT + "/subscriptions/{alias}/properties"; - private static final String ENDPOINT_UPDATE_DEPLOYMENT_POLICY = API_CONTEXT + "/policy/deployment"; - private static final String ENDPOINT_UPDATE_AUTOSCALING_POLICY = API_CONTEXT + "/policy/autoscale"; + private static final String ENDPOINT_ADD_TENANT = API_CONTEXT + "/tenants"; + private static final String ENDPOINT_ADD_USER = API_CONTEXT + "/users"; + + private static final String ENDPOINT_DEPLOY_CARTRIDGE = API_CONTEXT + "/cartridges"; + private static final String ENDPOINT_DEPLOY_PARTITION = API_CONTEXT + "/partitions"; + private static final String ENDPOINT_DEPLOY_AUTOSCALING_POLICY = API_CONTEXT + "/autoscalePolicies"; + private static final String ENDPOINT_DEPLOY_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies"; + private static final String ENDPOINT_DEPLOY_KUBERNETES_CLUSTER = API_CONTEXT + "/kubernetesCluster"; + private static final String ENDPOINT_DEPLOY_KUBERNETES_HOST = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/minion"; + private static final String ENDPOINT_DEPLOY_SERVICE_GROUP = API_CONTEXT + "/groups"; + private static final String ENDPOINT_DEPLOY_APPLICATION = API_CONTEXT + "/applications"; + + private static final String ENDPOINT_UNDEPLOY_KUBERNETES_CLUSTER= API_CONTEXT + "/kubernetesCluster/{id}"; + private static final String ENDPOINT_UNDEPLOY_KUBERNETES_HOST = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/hosts/{id}"; + private static final String ENDPOINT_UNDEPLOY_SERVICE_GROUP = API_CONTEXT + "/groups/{id}"; + private static final String ENDPOINT_UNDEPLOY_APPLICATION = API_CONTEXT + "/applications/{id}"; + private static final String ENDPOINT_UNDEPLOY_CARTRIDGE = API_CONTEXT + "/cartridges/{id}"; + + private static final String ENDPOINT_LIST_PARTITIONS = API_CONTEXT + "/partitions"; + private static final String ENDPOINT_LIST_AUTOSCALING_POLICIES = API_CONTEXT + "/autoscalePolicies"; + private static final String ENDPOINT_LIST_DEPLOYMENT_POLICIES = API_CONTEXT + "/deploymentPolicies"; + private static final String ENDPOINT_LIST_CARTRIDGES = API_CONTEXT + "/cartridges"; + private static final String ENDPOINT_LIST_CARTRIDGE_SUBSCRIPTIONS = API_CONTEXT + "/subscriptions/cartridges"; + private static final String ENDPOINT_LIST_TENANTS = API_CONTEXT + "/tenants"; + private static final String ENDPOINT_LIST_USERS = API_CONTEXT + "/users"; + private static final String ENDPOINT_LIST_KUBERNETES_CLUSTERS = API_CONTEXT + "/kubernetesCluster"; + private static final String ENDPOINT_LIST_KUBERNETES_HOSTS = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/hosts"; + private static final String ENDPOINT_LIST_SERVICE_GROUP = API_CONTEXT + "/groups/{groupDefinitionName}"; + private static final String ENDPOINT_LIST_APPLICATION = API_CONTEXT + "/applications"; + + private static final String ENDPOINT_GET_APPLICATION = API_CONTEXT + "/applications/{appId}"; + private static final String ENDPOINT_GET_AUTOSCALING_POLICY = API_CONTEXT + "/autoscalePolicies/{id}"; + private static final String ENDPOINT_GET_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies/{id}"; + private static final String ENDPOINT_GET_CARTRIDGE_OF_TENANT = API_CONTEXT + "/subscriptions/{id}/cartridges"; + private static final String ENDPOINT_GET_CLUSTER_OF_TENANT = API_CONTEXT + "/clusters/"; + private static final String ENDPOINT_GET_KUBERNETES_GROUP = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}"; + private static final String ENDPOINT_GET_KUBERNETES_MASTER = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/master"; + private static final String ENDPOINT_GET_KUBERNETES_HOST = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/hosts"; + + private static final String ENDPOINT_UPDATE_KUBERNETES_MASTER = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/master"; + private static final String ENDPOINT_UPDATE_KUBERNETES_HOST = API_CONTEXT + "/kubernetesCluster/{kubernetesClusterId}/minion/{minionId}"; + + private static final String ENDPOINT_SYNCHRONIZE_ARTIFACTS = API_CONTEXT + "/repo/synchronize/{subscriptionAlias}"; + private static final String ENDPOINT_ACTIVATE_TENANT = API_CONTEXT + "/tenants/activate/{tenantDomain}"; + private static final String ENDPOINT_DEACTIVATE_TENANT = API_CONTEXT + "/tenants/deactivate/{tenantDomain}"; + + private static final String ENDPOINT_UPDATE_SUBSCRIPTION_PROPERTIES = API_CONTEXT + "/subscriptions/{subscriptionAlias}/properties"; + private static final String ENDPOINT_UPDATE_DEPLOYMENT_POLICY = API_CONTEXT + "/deploymentPolicies"; + private static final String ENDPOINT_UPDATE_AUTOSCALING_POLICY = API_CONTEXT + "/autoscalePolicies"; private static class SingletonHolder { @@ -582,10 +581,10 @@ public class RestCommandLineService { System.out.println("=================================================="); System.out.println("List of LB members for the [cluster]: " + alias); - // Invoke cluster/{clusterId} + // Invoke clusters/{clusterId} for (Member m : members) { HttpResponse responseCluster = restClient.doGet(httpClient, restClient.getBaseURL() + ENDPOINT_GET_CLUSTER_OF_TENANT - + "clusterId/" + m.getLbClusterId()); + + m.getLbClusterId()); String responseCode = "" + responseCluster.getStatusLine().getStatusCode(); String resultStringCluster = CliUtils.getHttpResponseString(responseCluster); @@ -618,7 +617,7 @@ public class RestCommandLineService { private Member[] getMembers(String cartridgeType, String alias, DefaultHttpClient httpClient) throws Exception { try { HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() - + ENDPOINT_GET_CLUSTER_OF_TENANT + cartridgeType + "/" + alias); + + ENDPOINT_GET_CLUSTER_OF_TENANT + alias); String responseCode = "" + response.getStatusLine().getStatusCode(); @@ -703,234 +702,6 @@ public class RestCommandLineService { } } - private String getAsPolicyFromServiceDefinition(String cartridgeType) throws CommandException { - DefaultHttpClient httpClient = new DefaultHttpClient(); - try { - HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() - + ENDPOINT_LIST_SERVICES + "/" + cartridgeType); - - String responseCode = "" + response.getStatusLine().getStatusCode(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - - if (!responseCode.equals(CliConstants.RESPONSE_OK)) { - String resultString = CliUtils.getHttpResponseString(response); - ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class); - System.out.println(exception); - return null; - } - - String resultString = CliUtils.getHttpResponseString(response); - if (resultString == null) { - System.out.println("Response content is empty"); - return null; - } - - String serviceDefinitionString = resultString.substring(25, resultString.length() - 1); - ServiceDefinitionBean serviceDefinition = gson.fromJson(serviceDefinitionString, ServiceDefinitionBean.class); - if (serviceDefinition == null) { - System.out.println("Deploy service list is empty"); - return null; - } - - return serviceDefinition.getAutoscalingPolicyName(); - - } catch (Exception e) { - handleException("Exception in listing deploy services", e); - return null; - } finally { - httpClient.getConnectionManager().shutdown(); - } - } - - private String getDeploymentPolicyFromServiceDefinition(String cartridgeType) throws CommandException { - DefaultHttpClient httpClient = new DefaultHttpClient(); - try { - HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() - + ENDPOINT_LIST_SERVICES + "/" + cartridgeType); - - String responseCode = "" + response.getStatusLine().getStatusCode(); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - - if (!responseCode.equals(CliConstants.RESPONSE_OK)) { - String resultString = CliUtils.getHttpResponseString(response); - ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class); - System.out.println(exception); - return null; - } - - String resultString = CliUtils.getHttpResponseString(response); - if (resultString == null) { - System.out.println("Response content is empty"); - return null; - } - - String serviceDefinitionString = resultString.substring(25, resultString.length() - 1); - ServiceDefinitionBean serviceDefinition = gson.fromJson(serviceDefinitionString, ServiceDefinitionBean.class); - if (serviceDefinition == null) { - System.out.println("Deploy service list is empty"); - return null; - } - - return serviceDefinition.getDeploymentPolicyName(); - - } catch (Exception e) { - handleException("Exception in listing deploy services", e); - return null; - } finally { - httpClient.getConnectionManager().shutdown(); - } - } - - // This method does the cartridge subscription - public void subscribe(String cartridgeType, String alias, String externalRepoURL, boolean privateRepo, String username, - String password, String asPolicy, - String depPolicy, String size, boolean remoOnTermination, boolean persistanceMapping, - boolean enableCommits, String volumeId) - throws CommandException { - DefaultHttpClient httpClient = new DefaultHttpClient(); - - CartridgeInfoBean cartridgeInfoBean = new CartridgeInfoBean(); - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - - try { - Cartridge cartridge = getCartridge(cartridgeType); - if (cartridge == null) { - System.out.println("Cartridge not found: " + cartridgeType); - return; - } - - if (cartridge.isMultiTenant()) { - asPolicy = getAsPolicyFromServiceDefinition(cartridgeType); - depPolicy = getDeploymentPolicyFromServiceDefinition(cartridgeType); - } - - cartridgeInfoBean.setCartridgeType(cartridgeType); - cartridgeInfoBean.setAlias(alias); - cartridgeInfoBean.setRepoURL(externalRepoURL); - cartridgeInfoBean.setPrivateRepo(privateRepo); - cartridgeInfoBean.setRepoUsername(username); - cartridgeInfoBean.setRepoPassword(password); - cartridgeInfoBean.setAutoscalePolicy(asPolicy); - cartridgeInfoBean.setDeploymentPolicy(depPolicy); - cartridgeInfoBean.setSize(size); - cartridgeInfoBean.setRemoveOnTermination(remoOnTermination); - cartridgeInfoBean.setPersistanceRequired(persistanceMapping); - cartridgeInfoBean.setCommitsEnabled(enableCommits); - cartridgeInfoBean.setVolumeId(volumeId); - - String jsonSubscribeString = gson.toJson(cartridgeInfoBean, CartridgeInfoBean.class); - - HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + ENDPOINT_SUBSCRIBE_CARTRIDGE, - jsonSubscribeString); - - String responseCode = "" + response.getStatusLine().getStatusCode(); - - if (!responseCode.equals(CliConstants.RESPONSE_OK)) { - String resultString = CliUtils.getHttpResponseString(response); - ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class); - System.out.println(exception); - return; - } - - String subscriptionOutput = CliUtils.getHttpResponseString(response); - - if (subscriptionOutput == null) { - System.out.println("Error in response"); - return; - } - - String subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() - 1); - SubscriptionInfo subcriptionInfo = gson.fromJson(subscriptionOutputJSON, SubscriptionInfo.class); - - System.out.format("You have successfully subscribed to %s cartridge with alias %s.%n", cartridgeType, alias); - - String repoURL; - String hostnames = null; - String hostnamesLabel = null; - if (subcriptionInfo != null) { - repoURL = subcriptionInfo.getRepositoryURL(); - hostnames = subcriptionInfo.getHostname(); - hostnamesLabel = "host name"; - - if (repoURL != null) { - System.out.println("GIT Repository URL: " + repoURL); - } - } - - if (externalRepoURL != null) { - String takeTimeMsg = "(this might take few minutes... depending on repo size)\n"; - System.out.println(takeTimeMsg); - } - - System.out.format("Please map the %s \"%s\" to LB IP%n", hostnamesLabel, hostnames); - } catch (Exception e) { - handleException("Exception in subscribing to cartridge", e); - } finally { - httpClient.getConnectionManager().shutdown(); - } - } - - // This method does the cartridge subscription - public void subscribe(String subscriptionJson) - throws CommandException { - - DefaultHttpClient httpClient = new DefaultHttpClient(); - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - - try { - HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + ENDPOINT_SUBSCRIBE_CARTRIDGE, - subscriptionJson); - - String responseCode = "" + response.getStatusLine().getStatusCode(); - - if (!responseCode.equals(CliConstants.RESPONSE_OK)) { - String resultString = CliUtils.getHttpResponseString(response); - ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class); - System.out.println(exception); - return; - } - - String subscriptionOutput = CliUtils.getHttpResponseString(response); - - if (subscriptionOutput == null) { - System.out.println("Error in response"); - return; - } - - String subscriptionOutputJSON = subscriptionOutput.substring(20, subscriptionOutput.length() - 1); - SubscriptionInfo subcriptionInfo = gson.fromJson(subscriptionOutputJSON, SubscriptionInfo.class); - - System.out.format("You have successfully subscribed. "); - - String repoURL; - String hostnames = null; - String hostnamesLabel = null; - if (subcriptionInfo != null) { - repoURL = subcriptionInfo.getRepositoryURL(); - hostnames = subcriptionInfo.getHostname(); - hostnamesLabel = "host name"; - - if (repoURL != null) { - System.out.println("GIT Repository URL: " + repoURL); - } - } - - System.out.format("Please map the %s \"%s\" to LB IP%n", hostnamesLabel, hostnames); - - } catch (Exception e) { - handleException("Exception in subscribing to cartridge", e); - } finally { - httpClient.getConnectionManager().shutdown(); - } - - } - // This method helps to create the new tenant public void addTenant(String admin, String firstName, String lastaName, String password, String domain, String email) throws CommandException { @@ -1191,28 +962,6 @@ public class RestCommandLineService { } } - // This method helps to unsubscribe cartridges - public void unsubscribe(String alias) throws CommandException { - DefaultHttpClient httpClient = new DefaultHttpClient(); - try { - HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + ENDPOINT_UNSUBSCRIBE_CARTRIDGE_OF_TENANT, alias); - int responseCode = response.getStatusLine().getStatusCode(); - - if ((responseCode >= 200) || (responseCode < 300)) { - System.out.println("You have successfully unsubscribed from cartridge: " + alias); - return; - } else { - CliUtils.printError(response); - } - } catch (Exception e) { - String message = "Error in unsubscribing cartridge: " + alias; - System.out.println(message); - log.error(message, e); - } finally { - httpClient.getConnectionManager().shutdown(); - } - } - // This method helps to deploy cartridge definitions public void deployCartridgeDefinition(String cartridgeDefinition) throws CommandException { restClient.deployEntity(ENDPOINT_DEPLOY_CARTRIDGE, cartridgeDefinition, "cartridge"); @@ -1220,7 +969,7 @@ public class RestCommandLineService { // This method helps to undeploy cartridge definitions public void undeployCartrigdeDefinition(String id) throws CommandException { - restClient.undeployEntity(ENDPOINT_DEPLOY_CARTRIDGE, "cartridge", id); + restClient.undeployEntity(ENDPOINT_UNDEPLOY_CARTRIDGE, "cartridge", id); } // This method helps to deploy partitions @@ -1233,62 +982,12 @@ public class RestCommandLineService { restClient.deployEntity(ENDPOINT_DEPLOY_AUTOSCALING_POLICY, autoScalingPolicy, "autoscaling policy"); } - /** - * Update autoscaling policy - * @param autoScalingPolicy - * @throws CommandException - */ + // This method helps to update an autoscaling policy public void updateAutoscalingPolicy(String autoScalingPolicy) throws CommandException { restClient.updateEntity(ENDPOINT_UPDATE_AUTOSCALING_POLICY, autoScalingPolicy, "autoscaling policy"); } - // This method helps to deploy multi-tenant service cluster - public void deployService(String serviceDefinition) throws CommandException { - restClient.deployEntity(ENDPOINT_DEPLOY_SERVICE, serviceDefinition, "service"); - } - - // This method helps to undeploy multi-tenant service cluster - public void undeployService(String id) throws CommandException { - restClient.undeployEntity(ENDPOINT_DEPLOY_SERVICE, "service", id); - } - - public void listServices() throws CommandException { - try { - ServiceDefinitionList list = (ServiceDefinitionList) restClient.listEntity(ENDPOINT_LIST_SERVICES, - ServiceDefinitionList.class, "service"); - - if ((list == null) || (list.getServiceDefinition() == null) || (list.getServiceDefinition().size() == 0)) { - System.out.println("No services found"); - return; - } - - RowMapper<ServiceDefinitionBean> rowMapper = new RowMapper<ServiceDefinitionBean>() { - - public String[] getData(ServiceDefinitionBean definition) { - String[] data = new String[6]; - data[0] = definition.getCartridgeType(); - data[1] = definition.getDeploymentPolicyName(); - data[2] = definition.getAutoscalingPolicyName(); - data[3] = definition.getClusterDomain(); - data[4] = definition.getTenantRange(); - data[5] = definition.getIsPublic() ? "Public" : "Private"; - return data; - } - }; - - ServiceDefinitionBean[] array = new ServiceDefinitionBean[list.getServiceDefinition().size()]; - array = list.getServiceDefinition().toArray(array); - - System.out.println("Services found:"); - CliUtils.printTable(array, rowMapper, "Cartridge Type", "Deployment Policy Name", - "Autoscaling Policy Name", "Cluster Domain", "Tenant Range", "Accessibility"); - } catch (Exception e) { - String message = "Error in listing services"; - System.out.println(message); - log.error(message, e); - } - } - + // This method helps to list applications public void listApplications() throws CommandException { try { ApplicationList list = (ApplicationList) restClient.listEntity(ENDPOINT_LIST_APPLICATION, @@ -1324,16 +1023,12 @@ public class RestCommandLineService { restClient.deployEntity(ENDPOINT_DEPLOY_DEPLOYMENT_POLICY, deploymentPolicy, "deployment policy"); } - /** - * Update deployment policy - * @param deploymentPolicy - * @throws CommandException - */ + // This method helps to update a deployment policy public void updateDeploymentPolicy(String deploymentPolicy) throws CommandException { restClient.updateEntity(ENDPOINT_UPDATE_DEPLOYMENT_POLICY, deploymentPolicy, "deployment policy"); } - // This method list available partitons + // This method lists available partitions public void listPartitions() throws CommandException { try { PartitionList list = (PartitionList) restClient.listEntity(ENDPOINT_LIST_PARTITIONS, @@ -1433,27 +1128,20 @@ public class RestCommandLineService { public void describeDeploymentPolicy(String id) throws CommandException { try { - DeploymentPolicyList list = (DeploymentPolicyList) restClient.listEntity(ENDPOINT_LIST_DEPLOYMENT_POLICIES, - DeploymentPolicyList.class, "deployment policies"); - - if ((list == null) || (list.getDeploymentPolicy() == null) || (list.getDeploymentPolicy().size() == 0)) { - System.out.println("Deployment policy not found: " + id); - return; - } - - for (DeploymentPolicy policy : list.getDeploymentPolicy()) { - if (policy.getId().equals(id)) { - System.out.println("Deployment policy: " + id); - System.out.println(getGson().toJson(policy)); - return; - } - } - System.out.println("Deployment policy not found: " + id); - } catch (Exception e) { - String message = "Error in describing deployment policy: " + id; - System.out.println(message); - log.error(message, e); - } + DeploymentPolicy policy = (DeploymentPolicy) restClient.getEntity(ENDPOINT_GET_DEPLOYMENT_POLICY, DeploymentPolicy.class, id, "deployment policy"); + + if (policy == null) { + System.out.println("Deployment policy not found: " + id); + return; + } + + System.out.println("Deployment policy: " + id); + System.out.println(getGson().toJson(policy)); + } catch (Exception e) { + String message = "Error in describing deployment policy: " + id; + System.out.println(message); + log.error(message, e); + } } public void describePartition(String id) throws CommandException { @@ -1482,23 +1170,16 @@ public class RestCommandLineService { } public void describeAutoScalingPolicy(String id) throws CommandException { - try { - AutoscalePolicyList list = (AutoscalePolicyList) restClient.listEntity(ENDPOINT_LIST_AUTOSCALING_POLICIES, - AutoscalePolicyList.class, "autoscaling policies"); - - if ((list == null) || (list.getAutoscalePolicy() == null) || (list.getAutoscalePolicy().size() == 0)) { + try { + AutoscalePolicy policy = (AutoscalePolicy) restClient.getEntity(ENDPOINT_GET_AUTOSCALING_POLICY, AutoscalePolicy.class, id, "autoscaling policy"); + + if (policy == null) { System.out.println("Autoscaling policy not found: " + id); return; } - for (AutoscalePolicy policy : list.getAutoscalePolicy()) { - if (policy.getId().equalsIgnoreCase(id)) { - System.out.println("Autoscaling policy: " + id); - System.out.println(getGson().toJson(policy)); - return; - } - } - System.out.println("Autoscaling policy not found: " + id); + System.out.println("Autoscaling policy: " + id); + System.out.println(getGson().toJson(policy)); } catch (Exception e) { String message = "Error in describing autoscaling policy: " + id; System.out.println(message); @@ -1506,13 +1187,13 @@ public class RestCommandLineService { } } - public void deployKubernetesGroup(String entityBody) { - restClient.deployEntity(ENDPOINT_DEPLOY_KUBERNETES_GROUP, entityBody, "kubernetes group"); + public void deployKubernetesCluster(String entityBody) { + restClient.deployEntity(ENDPOINT_DEPLOY_KUBERNETES_CLUSTER, entityBody, "kubernetes cluster"); } - public void listKubernetesGroups() { + public void listKubernetesClusters() { try { - KubernetesGroupList list = (KubernetesGroupList) restClient.listEntity(ENDPOINT_LIST_KUBERNETES_GROUPS, KubernetesGroupList.class, "kubernetes group"); + KubernetesGroupList list = (KubernetesGroupList) restClient.listEntity(ENDPOINT_LIST_KUBERNETES_CLUSTERS, KubernetesGroupList.class, "kubernetes cluster"); if ((list != null) && (list.getKubernetesGroup() != null) && (list.getKubernetesGroup().size() > 0)) { RowMapper<KubernetesGroup> partitionMapper = new RowMapper<KubernetesGroup>() { public String[] getData(KubernetesGroup kubernetesGroup) { @@ -1538,17 +1219,40 @@ public class RestCommandLineService { } } - public void undeployKubernetesGroup(String groupId) { - restClient.undeployEntity(ENDPOINT_UNDEPLOY_KUBERNETES_GROUP, "kubernetes group", groupId); + public void undeployKubernetesCluster(String clusterId) { + restClient.undeployEntity(ENDPOINT_UNDEPLOY_KUBERNETES_CLUSTER, "kubernetes cluster", clusterId); } - public void deployKubernetesHost(String entityBody) { - restClient.deployEntity(ENDPOINT_DEPLOY_KUBERNETES_HOST, entityBody, "kubernetes host"); + public void deployKubernetesHost(String entityBody, String clusterId) throws CommandException { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpResponse response = restClient.doPut(httpClient, restClient.getBaseURL() + + ENDPOINT_DEPLOY_KUBERNETES_HOST.replace("{kubernetesClusterId}", clusterId), entityBody); + + String responseCode = "" + response.getStatusLine().getStatusCode(); + + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + + if (responseCode.equals(CliConstants.RESPONSE_OK)) { + System.out.println("You have succesfully deployed host to Kubernetes cluster: " + clusterId); + return; + } else { + String resultString = CliUtils.getHttpResponseString(response); + ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class); + System.out.println(exception); + } + + } catch (Exception e) { + handleException("Error in deploying host to Kubernetes cluster: " + clusterId, e); + } finally { + httpClient.getConnectionManager().shutdown(); + } } - public void listKubernetesHosts(String groupId) { + public void listKubernetesHosts(String clusterId) { try { - KubernetesHostList list = (KubernetesHostList) restClient.listEntity(ENDPOINT_LIST_KUBERNETES_HOSTS.replace("{groupId}", groupId), + KubernetesHostList list = (KubernetesHostList) restClient.listEntity(ENDPOINT_LIST_KUBERNETES_HOSTS.replace("{kubernetesClusterId}", clusterId), KubernetesHostList.class, "kubernetes host"); if ((list != null) && (list.getKubernetesHost() != null) && (list.getKubernetesHost().size() > 0)) { RowMapper<KubernetesHost> partitionMapper = new RowMapper<KubernetesHost>() { @@ -1576,22 +1280,24 @@ public class RestCommandLineService { } } - public void undeployKubernetesHost(String hostId) { - restClient.undeployEntity(ENDPOINT_UNDEPLOY_KUBERNETES_HOST, "kubernetes host", hostId); + public void undeployKubernetesHost(String clusterId, String hostId) { + restClient.undeployEntity(ENDPOINT_UNDEPLOY_KUBERNETES_HOST.replace("{kubernetesClusterId}", clusterId), "kubernetes host", hostId); } - public void updateKubernetesMaster(String entityBody) { - restClient.updateEntity(ENDPOINT_UPDATE_KUBERNETES_MASTER, entityBody, "kubernetes master"); + public void updateKubernetesMaster(String entityBody, String clusterId) { + System.out.println(ENDPOINT_UPDATE_KUBERNETES_MASTER.replace("{kubernetesClusterId}", clusterId)); + restClient.updateEntity(ENDPOINT_UPDATE_KUBERNETES_MASTER.replace("{kubernetesClusterId}", clusterId), entityBody, "kubernetes master"); } - public void updateKubernetesHost(String entityBody) { - restClient.updateEntity(ENDPOINT_UPDATE_KUBERNETES_HOST, entityBody, "kubernetes host"); + public void updateKubernetesHost(String entityBody, String clusterId, String hostId) { + System.out.println((ENDPOINT_UPDATE_KUBERNETES_HOST.replace("{kubernetesClusterId}", clusterId)).replace("{minionId}", hostId)); + restClient.updateEntity((ENDPOINT_UPDATE_KUBERNETES_HOST.replace("{kubernetesClusterId}", clusterId)).replace("{minionId}", hostId), entityBody, "kubernetes host"); } public void synchronizeArtifacts(String cartridgeAlias) throws CommandException { DefaultHttpClient httpClient = new DefaultHttpClient(); try { - HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + ENDPOINT_SYNCHRONIZE_ARTIFACTS, cartridgeAlias); + HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + ENDPOINT_SYNCHRONIZE_ARTIFACTS.replace("{subscriptionAlias}", cartridgeAlias), cartridgeAlias); String responseCode = "" + response.getStatusLine().getStatusCode(); @@ -1613,6 +1319,72 @@ public class RestCommandLineService { httpClient.getConnectionManager().shutdown(); } } + + // This method helps to update cartridge subscription properties + public void updateSubscritptionProperties(String alias, String subscriptionJson) { + String url = ENDPOINT_UPDATE_SUBSCRIPTION_PROPERTIES.replace("{subscriptionAlias}", alias); + restClient.updateEntity(url, subscriptionJson, "subscription alias: "+alias); + } + + // This method helps to deploy service groups + public void deployServiceGroup (String entityBody) { + restClient.deployEntity(ENDPOINT_DEPLOY_SERVICE_GROUP, entityBody, "service group"); + } + + // This method helps to undeploy service groups + public void undeployServiceGroup (String groupDefinitionName) throws CommandException { + restClient.undeployEntity(ENDPOINT_UNDEPLOY_SERVICE_GROUP, "service group", groupDefinitionName); + } + + // This method helps to describe service group definition + public void describeServiceGroup (String groupDefinitionName) { + try { + ServiceGroupBean bean = (ServiceGroupBean) restClient.listEntity(ENDPOINT_LIST_SERVICE_GROUP.replace("{groupDefinitionName}", groupDefinitionName), + ServiceGroupBean.class, "serviceGroup"); + + if ((bean == null) || (bean.getServiceGroupDefinition() == null)) { + System.out.println("Service group not found: " + groupDefinitionName); + return; + } + + System.out.println("Service Group : " + groupDefinitionName); + System.out.println(getGson().toJson(bean.getServiceGroupDefinition())); + } 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"); + } + + // This method helps to undeploy applications + public void undeployApplication(String id) throws CommandException { + restClient.undeployEntity(ENDPOINT_UNDEPLOY_APPLICATION, "applicationId", id); + } + + // This method helps to describe applications + public void describeApplication (String applicationID) { + try { + ApplicationBean bean = (ApplicationBean) restClient.listEntity(ENDPOINT_GET_APPLICATION.replace("{appId}", applicationID), + ApplicationBean.class, "applications"); + + if ((bean == null) || (bean.getApplication() == null)) { + System.out.println("Application not found: " + applicationID); + return; + } + + System.out.println("Application : " + applicationID); + System.out.println(getGson().toJson(bean.getApplication())); + } catch (Exception e) { + String message = "Error in describing application: " + applicationID; + System.out.println(message); + log.error(message, e); + } + } // This class convert JSON string to deploymentpolicylist object private class DeploymentPolicyList { @@ -1856,69 +1628,4 @@ public class RestCommandLineService { httpClient.getConnectionManager().shutdown(); } } - - public void updateSubscritptionProperties(String alias, String subscriptionJson) { - String url = ENDPOINT_UPDATE_SUBSCRIPTION_PROPERTIES.replace("{alias}", alias); - restClient.updateEntity(url, subscriptionJson, "subscription alias: "+alias); - } - - // This method helps to deploy service groups - public void deployServiceGroup (String entityBody) { - restClient.deployEntity(ENDPOINT_DEPLOY_SERVICE_GROUP, entityBody, "service group"); - } - - // This method helps to undeploy service groups - public void undeployServiceGroup (String groupDefinitionName) throws CommandException { - restClient.undeployEntity(ENDPOINT_UNDEPLOY_SERVICE_GROUP, "service group", groupDefinitionName); - } - - // This method helps to describe service group definition - public void describeServiceGroup (String groupDefinitionName) { - try { - ServiceGroupBean bean = (ServiceGroupBean) restClient.listEntity(ENDPOINT_LIST_SERVICE_GROUP.replace("{groupDefinitionName}", groupDefinitionName), - ServiceGroupBean.class, "serviceGroup"); - - if ((bean == null) || (bean.getServiceGroupDefinition() == null)) { - System.out.println("Service group not found: " + groupDefinitionName); - return; - } - - System.out.println("Service Group : " + groupDefinitionName); - System.out.println(getGson().toJson(bean.getServiceGroupDefinition())); - } 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"); - } - - // This method helps to undeploy applications - 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 bean = (ApplicationBean) restClient.listEntity(ENDPOINT_GET_APPLICATION.replace("{appId}", applicationID), - ApplicationBean.class, "applications"); - - if ((bean == null) || (bean.getApplication() == null)) { - System.out.println("Application not found: " + applicationID); - return; - } - - System.out.println("Application : " + applicationID); - System.out.println(getGson().toJson(bean.getApplication())); - } 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/6af99011/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 0423df6..eb2282d 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 @@ -129,17 +129,17 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new DeployAutoscalingPolicyCommand(); commands.put(command.getName(), command); - command = new DeployServiceCommand(); + /*command = new DeployServiceCommand(); commands.put(command.getName(), command); command = new UndeployServiceDefinitionCommand(); - commands.put(command.getName(), command); + commands.put(command.getName(), command);*/ command = new ListApplicationsCommand(); commands.put(command.getName(), command); - command = new ListServicesCommand(); - commands.put(command.getName(), command); + /*command = new ListServicesCommand(); + commands.put(command.getName(), command);*/ command = new UndeployCartridgeDefinitionCommand(); commands.put(command.getName(), command); @@ -204,11 +204,11 @@ public class StratosApplication extends CommandLineApplication<StratosCommandCon command = new UpdateSubscriptionPropertiesCommand(); commands.put(command.getName(), command); - command = new UpdateAutoscalingPolicyCommand(); + /*command = new UpdateAutoscalingPolicyCommand(); commands.put(command.getName(), command); command = new UpdateDeploymentPolicyCommand(); - commands.put(command.getName(), command); + commands.put(command.getName(), command);*/ command = new DeployServiceGroupCommand(); commands.put(command.getName(), command); http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java index 4f4ca3b..2e6bde4 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ActivateTenantCommand.java @@ -58,7 +58,7 @@ public class ActivateTenantCommand implements Command<StratosCommandContext> { if (args != null && args.length == 1) { String id = args[0]; if (logger.isDebugEnabled()) { - logger.debug("Getting deactivate tenant info {}", id); + logger.debug("Getting activate tenant info {}", id); } RestCommandLineService.getInstance().activateTenant(id); return CliConstants.COMMAND_SUCCESSFULL; http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java index d7f7912..320fe68 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesGroupCommand.java @@ -89,7 +89,7 @@ public class DeployKubernetesGroupCommand implements Command<StratosCommandConte return CliConstants.COMMAND_FAILED; } String resourceFileContent = CliUtils.readResource(resourcePath); - RestCommandLineService.getInstance().deployKubernetesGroup(resourceFileContent); + RestCommandLineService.getInstance().deployKubernetesCluster(resourceFileContent); return CliConstants.COMMAND_SUCCESSFULL; } else { System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java index a9c9f74..235929d 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployKubernetesHostCommand.java @@ -42,10 +42,14 @@ public class DeployKubernetesHostCommand implements Command<StratosCommandContex public DeployKubernetesHostCommand() { options = new Options(); - Option option = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, + Option resourcePathOption = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, "Kubernetes host resource path"); - option.setArgName("resource path"); - options.addOption(option); + resourcePathOption.setArgName("resource path"); + Option clusterIdOption = new Option(CliConstants.CLUSTER_ID_OPTION, CliConstants.CLUSTER_ID_LONG_OPTION, true, + "Kubernetes cluster id"); + clusterIdOption.setArgName("cluster id"); + options.addOption(clusterIdOption); + options.addOption(resourcePathOption); } @Override @@ -60,7 +64,7 @@ public class DeployKubernetesHostCommand implements Command<StratosCommandContex @Override public String getArgumentSyntax() { - return null; + return null; } @Override @@ -73,28 +77,40 @@ public class DeployKubernetesHostCommand implements Command<StratosCommandContex if (logger.isDebugEnabled()) { logger.debug("Executing command: ", getName()); } - + if ((args == null) || (args.length <= 0)) { context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } - + try { CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); - if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) { - String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); + + if((commandLine.hasOption(CliConstants.RESOURCE_PATH)) && (commandLine.hasOption(CliConstants.CLUSTER_ID_OPTION))) { + + // get cluster id arg value + String clusterId = commandLine.getOptionValue(CliConstants.CLUSTER_ID_OPTION); + if (clusterId == null) { + context.getStratosApplication().printUsage(getName()); + return CliConstants.COMMAND_FAILED; + } + + // get resource path arg value + String resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); if (resourcePath == null) { - System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); + context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } String resourceFileContent = CliUtils.readResource(resourcePath); - RestCommandLineService.getInstance().deployKubernetesHost(resourceFileContent); + + RestCommandLineService.getInstance().deployKubernetesHost(resourceFileContent, clusterId); return CliConstants.COMMAND_SUCCESSFULL; } else { - System.out.println("usage: " + getName() + " [-" + CliConstants.RESOURCE_PATH + " " + CliConstants.RESOURCE_PATH_LONG_OPTION + "]"); + context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } + } catch (ParseException e) { logger.error("Error parsing arguments", e); System.out.println(e.getMessage()); http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java deleted file mode 100644 index 4961bfa..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DeployServiceCommand.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * 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.*; -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; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; - -public class DeployServiceCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(DeployServiceCommand.class); - - private final Options options; - - public DeployServiceCommand(){ - options = constructOptions(); - } - - private Options constructOptions() { - final Options options = new Options(); - - Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, - "Deploy Service resource path"); - resourcePath.setArgName("resource path"); - options.addOption(resourcePath); - - return options; - } - - public String getName() { - return CliConstants.DEPLOY_SERVICE_DEPLOYMENT; - } - - public String getDescription() { - return "Add new deploy service"; - } - - 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) { - String resourcePath = null; - String deployServiceDeployment = null; - - final CommandLineParser parser = new GnuParser(); - CommandLine commandLine; - - try { - commandLine = parser.parse(options, args); - - if (logger.isDebugEnabled()) { - logger.debug("Deploy Service Deployment"); - } - - if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) { - if (logger.isTraceEnabled()) { - logger.trace("Resource path option is passed"); - } - resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); - deployServiceDeployment = readResource(resourcePath); - } - - if (resourcePath == null) { - System.out.println("usage: " + getName() + " [-p <resource path>]"); - return CliConstants.COMMAND_FAILED; - } - - RestCommandLineService.getInstance().deployService(deployServiceDeployment); - return CliConstants.COMMAND_SUCCESSFULL; - - } catch (ParseException e) { - if (logger.isErrorEnabled()) { - logger.error("Error parsing arguments", e); - } - System.out.println(e.getMessage()); - return CliConstants.COMMAND_FAILED; - } catch (IOException e) { - //e.printStackTrace(); - System.out.println("Invalid resource path"); - return CliConstants.COMMAND_FAILED; - } - } else { - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - } - - private String readResource(String fileName) throws IOException { - BufferedReader br = new BufferedReader(new FileReader(fileName)); - try { - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - - while (line != null) { - sb.append(line); - sb.append("\n"); - line = br.readLine(); - } - return sb.toString(); - } finally { - br.close(); - } - } - - public Options getOptions() { - return options; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/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 index 22a8e05..9e86d46 100644 --- 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 @@ -52,7 +52,7 @@ public class ListKubernetesGroupsCommand implements Command<StratosCommandContex logger.debug("Executing command: ", getName()); } if ((args == null) || (args.length == 0)) { - RestCommandLineService.getInstance().listKubernetesGroups(); + RestCommandLineService.getInstance().listKubernetesClusters(); return CliConstants.COMMAND_SUCCESSFULL; } else { context.getStratosApplication().printUsage(getName()); http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/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 index 1b6831e..1b500b4 100644 --- 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 @@ -44,7 +44,7 @@ public class ListKubernetesHostsCommand implements Command<StratosCommandContext } public String getArgumentSyntax() { - return "[group-id]"; + return "[cluster-id]"; } public int execute(StratosCommandContext context, String[] args) throws CommandException { @@ -55,8 +55,8 @@ public class ListKubernetesHostsCommand implements Command<StratosCommandContext context.getStratosApplication().printUsage(getName()); return CliConstants.COMMAND_FAILED; } else { - String groupId = args[0]; - RestCommandLineService.getInstance().listKubernetesHosts(groupId); + String clusterId = args[0]; + RestCommandLineService.getInstance().listKubernetesHosts(clusterId); return CliConstants.COMMAND_SUCCESSFULL; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServicesCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServicesCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServicesCommand.java deleted file mode 100644 index a14d063..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListServicesCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 ListServicesCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(ListServicesCommand.class); - - public ListServicesCommand() { - } - - 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().listServices(); - return CliConstants.COMMAND_SUCCESSFULL; - } else { - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - } - - public Options getOptions() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java deleted file mode 100644 index a790e89..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SubscribeCartridgeCommand.java +++ /dev/null @@ -1,330 +0,0 @@ -/** - * 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.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.lang3.StringUtils; -import org.apache.stratos.cli.RestCommandLineService; -import org.apache.stratos.cli.utils.CliUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.stratos.cli.Command; -import org.apache.stratos.cli.StratosCommandContext; -import org.apache.stratos.cli.exception.CommandException; -import org.apache.stratos.cli.utils.CliConstants; - -import java.io.IOException; - -@Deprecated -public class SubscribeCartridgeCommand implements Command<StratosCommandContext> { - - private static final Logger logger = LoggerFactory.getLogger(SubscribeCartridgeCommand.class); - - private final Options options; - - public SubscribeCartridgeCommand() { - options = constructOptions(); - } - - /** - * Construct Options. - * - * @return Options expected from command-line. - */ - private Options constructOptions() { - final Options options = new Options(); - - Option resourcePath = new Option(CliConstants.RESOURCE_PATH, CliConstants.RESOURCE_PATH_LONG_OPTION, true, - "Cartridge subscription resource path"); - resourcePath.setArgName("resource path"); - options.addOption(resourcePath); - - Option autoscaling = new Option(CliConstants.AUTOSCALING_POLICY_OPTION, CliConstants.AUTOSCALING_POLICY_LONG_OPTION, - true, "Auto-scaling policy"); - autoscaling.setArgName("auto-scaling-policy"); - options.addOption(autoscaling); - - Option deployment = new Option(CliConstants.DEPLOYMENT_POLICY_OPTION, CliConstants.DEPLOYMENT_POLICY_LONG_OPTION, - true, "Deployment-policy"); - deployment.setArgName("deployment-policy"); - options.addOption(deployment); - - Option removeOnTermination = new Option(CliConstants.REMOVE_ON_TERMINATION_OPTION, CliConstants.REMOVE_ON_TERMINATION_LONG_OPTION, - true, "Remove-on-termination"); - removeOnTermination.setArgName("remove-on-termination"); - options.addOption(removeOnTermination); - - Option size = new Option(CliConstants.VOLUME_SIZE_OPTION, CliConstants.VOLUME_SIZE_LONG_OPTION, true, "Volume-size"); - size.setArgName("volume-size"); - options.addOption(size); - - Option volumeId = new Option(CliConstants.VOLUME_ID_OPTION, CliConstants.VOLUME_ID_LONG_OPTION, true, "Volume-id"); - volumeId.setArgName("volume-id"); - options.addOption(volumeId); - - Option persistance = new Option(CliConstants.PERSISTANCE_VOLUME_OPTION, CliConstants.PERSISTANCE_VOLUME_LONG_OPTION, - true, "Persistance-volume"); - persistance.setArgName("persistance-volume"); - options.addOption(persistance); - - Option urlOption = new Option(CliConstants.REPO_URL_OPTION, CliConstants.REPO_URL_LONG_OPTION, true, - "GIT repository URL"); - urlOption.setArgName("url"); - options.addOption(urlOption); - - Option usernameOption = new Option(CliConstants.USERNAME_OPTION, CliConstants.USERNAME_LONG_OPTION, true, - "GIT repository username"); - usernameOption.setArgName("username"); - options.addOption(usernameOption); - - Option passwordOption = new Option(CliConstants.PASSWORD_OPTION, CliConstants.PASSWORD_LONG_OPTION, true, - "GIT repository password"); - passwordOption.setArgName("password"); - passwordOption.setOptionalArg(true); - options.addOption(passwordOption); - - Option upstreamCommitsEnabledOption = new Option(CliConstants.ENABLE_COMMITS_OPTION, CliConstants.ENABLE_COMMITS_LONG_OPTION, true, - "Enable Git commit upstream"); - upstreamCommitsEnabledOption.setArgName("enable-commits"); - upstreamCommitsEnabledOption.setOptionalArg(true); - options.addOption(upstreamCommitsEnabledOption); - - return options; - } - - public String getName() { - return CliConstants.SUBSCRIBE_ACTION; - } - - public String getDescription() { - return "Subscribe to a cartridge"; - } - - public String getArgumentSyntax() { - return "[cartridge-type] [cartridge-subscription-alias]"; - } - - public int execute(StratosCommandContext context, String[] args) throws CommandException { - if (logger.isDebugEnabled()) { - logger.debug("Executing {} command...", getName()); - } - if (args != null && args.length > 0) { - String[] remainingArgs = null; - String type = null; - String alias = null; - String policy = null; - String asPolicy = null; - String depPolicy = null; - String repoURL = null, username = "", password = ""; - String size = null; - String volumeID = null; - String resourcePath = null; - String subscriptionJson = null; - - boolean removeOnTermination = false; - boolean privateRepo = false; - boolean persistanceMapping = false; - boolean commitsEnabled = false; - boolean isMultiTenant = false; - - final CommandLineParser parser = new GnuParser(); - CommandLine commandLine; - try { - commandLine = parser.parse(options, args); - remainingArgs = commandLine.getArgs(); - if (remainingArgs != null && remainingArgs.length == 2) { - // Get type - type = remainingArgs[0]; - alias = remainingArgs[1]; - } else if (commandLine.hasOption(CliConstants.RESOURCE_PATH)) { - if (logger.isTraceEnabled()) { - logger.trace("Resource path option is passed"); - } - try { - resourcePath = commandLine.getOptionValue(CliConstants.RESOURCE_PATH); - subscriptionJson = CliUtils.readResource(resourcePath); - } catch (IOException e) { - System.out.println("Invalid resource path"); - return CliConstants.COMMAND_FAILED; - } - - if (resourcePath == null) { - System.out.println("usage: " + getName() + " [-p <resource-path>]"); - return CliConstants.COMMAND_FAILED; - } - - RestCommandLineService.getInstance().subscribe(subscriptionJson); - return CliConstants.COMMAND_FAILED; - - } else { - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - - // This will check the subscribe cartridge type is multi tenant or single tenant - isMultiTenant = RestCommandLineService.getInstance().isMultiTenant(type); - - if (logger.isDebugEnabled()) { - logger.debug("Subscribing to {} cartridge with alias {}", type, alias); - } - if (commandLine.hasOption(CliConstants.AUTOSCALING_POLICY_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Autoscaling policy option is passed"); - } - asPolicy = commandLine.getOptionValue(CliConstants.AUTOSCALING_POLICY_OPTION); - } - if (commandLine.hasOption(CliConstants.DEPLOYMENT_POLICY_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Deployment policy option is passed"); - } - depPolicy = commandLine.getOptionValue(CliConstants.DEPLOYMENT_POLICY_OPTION); - } - if (commandLine.hasOption(CliConstants.REPO_URL_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("RepoURL option is passed"); - } - repoURL = commandLine.getOptionValue(CliConstants.REPO_URL_OPTION); - } - if (commandLine.hasOption(CliConstants.VOLUME_SIZE_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Volume size option is passed"); - - } - size = commandLine.getOptionValue(CliConstants.VOLUME_SIZE_OPTION); - } - - if (commandLine.hasOption(CliConstants.VOLUME_ID_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Volume id option is passed"); - - } - volumeID = commandLine.getOptionValue(CliConstants.VOLUME_ID_OPTION); - } - - - if (commandLine.hasOption(CliConstants.REMOVE_ON_TERMINATION_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Remove on termination option is passed"); - - } - - String optionValue = commandLine.getOptionValue(CliConstants.REMOVE_ON_TERMINATION_OPTION); - if (optionValue.equals("true")) { - removeOnTermination = true; - } else if (optionValue.equals("false")) { - removeOnTermination = false; - } else { - if (logger.isTraceEnabled()) { - logger.trace("Invalid remove on termination option value"); - } - System.out.println("Invalid remove on termination option value."); - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - } - if (commandLine.hasOption(CliConstants.PERSISTANCE_VOLUME_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Persistance volume option is passed"); - - } - - String optionValue = commandLine.getOptionValue(CliConstants.PERSISTANCE_VOLUME_OPTION); - if (optionValue.equals("true")) { - persistanceMapping = true; - } else if (optionValue.equals("false")) { - persistanceMapping = false; - } else { - if (logger.isTraceEnabled()) { - logger.trace("Invalid persistance mapping option value"); - } - System.out.println("Invalid persistance mapping option value."); - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - - } - if (commandLine.hasOption(CliConstants.USERNAME_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Username option is passed"); - } - username = commandLine.getOptionValue(CliConstants.USERNAME_OPTION); - } - if (commandLine.hasOption(CliConstants.PASSWORD_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Password option is passed"); - } - password = commandLine.getOptionValue(CliConstants.PASSWORD_OPTION); - } - if (commandLine.hasOption(CliConstants.ENABLE_COMMITS_OPTION)) { - if (logger.isTraceEnabled()) { - logger.trace("Upstream git commits are enabled"); - } - commitsEnabled = true; - } - - if ( ! isMultiTenant && depPolicy == null) { - System.out.println("Deployment policy is required."); - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - - if ( ! isMultiTenant && asPolicy == null) { - System.out.println("Autoscaling policy is required."); - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - - if ((!persistanceMapping) && ((size != null) || removeOnTermination)) { - System.out.println("You have to enable persistance mapping in cartridge subscription"); - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - - if (StringUtils.isNotBlank(username) && StringUtils.isBlank(password)) { - password = context.getApplication().getInput("GIT Repository Password", '*'); - } - - RestCommandLineService.getInstance().subscribe(type, alias, repoURL, privateRepo, username, - password, asPolicy, depPolicy, size, removeOnTermination, - persistanceMapping, commitsEnabled, volumeID); - - return CliConstants.COMMAND_SUCCESSFULL; - - } catch (ParseException e) { - if (logger.isErrorEnabled()) { - logger.error("Error parsing arguments", e); - } - System.out.println(e.getMessage()); - return CliConstants.COMMAND_FAILED; - } - } else { - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - } - - public Options getOptions() { - return options; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java index 57b8ef4..d0fdf45 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UnDeployKubernetesGroupCommand.java @@ -50,7 +50,7 @@ public class UnDeployKubernetesGroupCommand implements Command<StratosCommandCon @Override public String getArgumentSyntax() { - return "[group-id]"; + return "[cluster-id]"; } @Override @@ -69,8 +69,8 @@ public class UnDeployKubernetesGroupCommand implements Command<StratosCommandCon return CliConstants.COMMAND_FAILED; } - String groupId = args[0]; - RestCommandLineService.getInstance().undeployKubernetesGroup(groupId); + String clusterId = args[0]; + RestCommandLineService.getInstance().undeployKubernetesCluster(clusterId); return CliConstants.COMMAND_SUCCESSFULL; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java index 45a0f6c..a3b072e 100644 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java +++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployKubernetesHostCommand.java @@ -50,7 +50,7 @@ public class UndeployKubernetesHostCommand implements Command<StratosCommandCont @Override public String getArgumentSyntax() { - return "[host-id]"; + return "[cluster-id] [host-id]"; } @Override @@ -69,8 +69,9 @@ public class UndeployKubernetesHostCommand implements Command<StratosCommandCont return CliConstants.COMMAND_FAILED; } - String hostId = args[0]; - RestCommandLineService.getInstance().undeployKubernetesHost(hostId); + String clusterId = args[0]; + String hostId = args[1]; + RestCommandLineService.getInstance().undeployKubernetesHost(clusterId, hostId); return CliConstants.COMMAND_SUCCESSFULL; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/6af99011/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java deleted file mode 100644 index 37e1a76..0000000 --- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/UndeployServiceDefinitionCommand.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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 UndeployServiceDefinitionCommand implements Command<StratosCommandContext> { - private static final Logger logger = LoggerFactory.getLogger(UndeployServiceDefinitionCommand.class); - - @Override - public String getName() { - return CliConstants.UNDEPLOY_SERVICE; - } - - @Override - public String getDescription() { - return "Undeploy Multitenant Service"; - } - - @Override - public String getArgumentSyntax() { - return "[Service Type]"; - } - - @Override - public Options getOptions() { - return null; - } - - @Override - public int execute(StratosCommandContext context, String[] args) throws CommandException { - if (logger.isDebugEnabled()) { - logger.debug("Executing {} command...", getName()); - } - if (args != null && args.length == 1) { - String id = args[0]; - if (logger.isDebugEnabled()) { - logger.debug("Getting undeploy miltitenant service info {}", id); - } - RestCommandLineService.getInstance().undeployService(id); - return CliConstants.COMMAND_SUCCESSFULL; - } else { - context.getStratosApplication().printUsage(getName()); - return CliConstants.COMMAND_FAILED; - } - } -}
