You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/10/11 17:42:32 UTC
[1/2] git commit: Refactoring CLI commands with new generic
implementation
Repository: stratos
Updated Branches:
refs/heads/master 2c3e1526d -> c13d21c59
Refactoring CLI commands with new generic implementation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c3aa855a
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c3aa855a
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c3aa855a
Branch: refs/heads/master
Commit: c3aa855a60557291bcf75e706535fd0c6d7e0686
Parents: 70d646b
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat Oct 11 21:12:08 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat Oct 11 21:12:08 2014 +0530
----------------------------------------------------------------------
.../java/org/apache/stratos/cli/RestClient.java | 6 +-
.../stratos/cli/RestCommandLineService.java | 719 +++++--------------
.../cli/commands/ActivateTenantCommand.java | 2 +-
.../DescribeDeploymentPolicyCommand.java | 2 +-
.../commands/ListAutoscalePolicyCommand.java | 2 +-
.../cli/commands/ListDeployServiceCommand.java | 2 +-
.../stratos/cli/commands/SyncCommand.java | 6 +-
.../stratos/cli/exception/ErrorWrapper.java | 4 +-
8 files changed, 194 insertions(+), 549 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
index af2cb6f..93c0e74 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestClient.java
@@ -250,8 +250,7 @@ public class RestClient implements GenericRestClient {
private int executePost(String serviceEndpoint, String postBody) throws IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = doPost(httpClient, getBaseURL()
- + serviceEndpoint, postBody);
+ HttpResponse response = doPost(httpClient, getBaseURL()+ serviceEndpoint, postBody);
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode < 200 || responseCode >= 300) {
@@ -288,8 +287,7 @@ public class RestClient implements GenericRestClient {
private int executePut(String serviceEndpoint, String postBody) throws IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = doPut(httpClient, getBaseURL()
- + serviceEndpoint, postBody);
+ HttpResponse response = doPut(httpClient, getBaseURL() + serviceEndpoint, postBody);
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode < 200 || responseCode >= 300) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/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 e35e318..21856fa 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
@@ -75,44 +75,49 @@ public class RestCommandLineService {
private RestClient restClient;
// REST endpoints
- private final String initializeCookieEndpoint = "/stratos/admin/cookie";
- private final String listAvailableCartridgesRestEndpoint = "/stratos/admin/cartridge/available/list";
- private final String listSubscribedCartridgesRestEndpoint = "/stratos/admin/cartridge/list/subscribed";
- private final String listSubscribedCartridgeInfoRestEndpoint = "/stratos/admin/cartridge/info/";
- private final String listClusterRestEndpoint = "/stratos/admin/cluster/";
- private final String subscribCartridgeRestEndpoint = "/stratos/admin/cartridge/subscribe";
- private final String addTenantEndPoint = "/stratos/admin/tenant";
- private final String addUserEndPoint = "/stratos/admin/user";
- private final String unsubscribeTenantEndPoint = "/stratos/admin/cartridge/unsubscribe";
- private final String cartridgeDeploymentEndPoint = "/stratos/admin/cartridge/definition";
- private final String syncEndPoint = "/stratos/admin/cartridge/sync";
- private final String partitionDeploymentEndPoint = "/stratos/admin/policy/deployment/partition";
- private final String autoscalingPolicyDeploymentEndPoint = "/stratos/admin/policy/autoscale";
- private final String deploymentPolicyDeploymentEndPoint = "/stratos/admin/policy/deployment";
- private final String listParitionRestEndPoint = "/stratos/admin/partition";
- private final String listAutoscalePolicyRestEndPoint = "/stratos/admin/policy/autoscale";
- private final String listDeploymentPolicyRestEndPoint = "/stratos/admin/policy/deployment";
- private final String deployServiceEndPoint = "/stratos/admin/service/definition";
- private final String listDeployServicesRestEndPoint = "/stratos/admin/service";
- private final String deactivateTenantRestEndPoint = "/stratos/admin/tenant/deactivate";
- private final String activateTenantRestEndPoint = "/stratos/admin/tenant/activate";
- private final String listAllTenantRestEndPoint = "/stratos/admin/tenant/list";
- private final String listAllUserRestEndPoint = "/stratos/admin/user/list";
- private final String getListAvailableCartridgeInfoRestEndPoint = "/stratos/admin/cartridge/available/info";
-
- private final String deployKubernetesGroup = "/stratos/admin/kubernetes/deploy/group";
- 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 getKubernetesGroup = "/stratos/admin/kubernetes/group/{id}";
- private final String getKubernetesHost = "/stratos/admin/kubernetes/hosts/{id}";
- private final String getKubernetesMaster = "/stratos/admin/kubernetes/master/{id}";
+ private final String INIT_COOKIE_ENDPOINT = "/stratos/admin/cookie";
+
+ private final String SUBSCRIBE_CARTRIDGE_ENDPOINT = "/stratos/admin/cartridge/subscribe";
+ private final String ADD_TENANT_ENDPOINT = "/stratos/admin/tenant";
+ private final String ADD_USER_ENDPOINT = "/stratos/admin/user";
+
+ private final String UNSUBSCRIBE_CARTRIDGE_OF_TENANT_ENDPOINT = "/stratos/admin/cartridge/unsubscribe";
+ private final String SYNCHRONIZE_ARTIFACTS_ENDPOINT = "/stratos/admin/cartridge/sync";
+
+ private final String DEPLOY_CARTRIDGE_ENDPOINT = "/stratos/admin/cartridge/definition";
+ private final String DEPLOY_PARTITION_ENDPOINT = "/stratos/admin/policy/deployment/partition";
+ private final String DEPLOY_AUTOSCALING_POLICY_ENDPOINT = "/stratos/admin/policy/autoscale";
+ private final String DEPLOY_DEPLOYMENT_POLICY_ENDPOINT = "/stratos/admin/policy/deployment";
+ private final String DEPLOY_SERVICE_ENDPOINT = "/stratos/admin/service/definition";
+ private final String DEPLOY_KUBERNETES_GROUP_ENDPOINT = "/stratos/admin/kubernetes/deploy/group";
+ private final String DEPLOY_KUBERNETES_HOST_ENDPOINT = "/stratos/admin/kubernetes/deploy/host";
+
+ private final String LIST_PARTITION_ENDPOINT = "/stratos/admin/partition";
+ private final String LIST_AUTOSCALING_POLICY_ENDPOINT = "/stratos/admin/policy/autoscale";
+ private final String LIST_DEPLOYMENT_POLICY_ENDPOINT = "/stratos/admin/policy/deployment";
+ private final String LIST_CARTRIDGES_ENDPOINT = "/stratos/admin/cartridge/available/list";
+ private final String LIST_CARTRIDGE_SUBSCRIPTIONS_ENDPOINT = "/stratos/admin/cartridge/list/subscribed";
+ private final String LIST_SERVICE_ENDPOINT = "/stratos/admin/service";
+ private final String LIST_TENANT_ENDPOINT = "/stratos/admin/tenant/list";
+ private final String LIST_USERS_ENDPOINT = "/stratos/admin/user/list";
+ private final String LIST_KUBERNETES_GROUP_ENDPOINT = "/stratos/admin/kubernetes/group";
+ private final String LIST_KUBERNETES_HOSTS_ENDPOINT = "/stratos/admin/kubernetes/hosts/{groupId}";
+
+ private final String GET_CARTRIDGE_ENDPOINT = "/stratos/admin/cartridge/available/info";
+ private final String GET_CARTRIDGE_OF_TENANT_ENDPOINT = "/stratos/admin/cartridge/info/";
+ private final String GET_CLUSTER_OF_TENANT_ENDPOINT = "/stratos/admin/cluster/";
+ private final String GET_KUBERNETES_GROUP_ENDPOINT = "/stratos/admin/kubernetes/group/{id}";
+ private final String GET_KUBERNETES_MASTER_ENDPOINT = "/stratos/admin/kubernetes/master/{id}";
+ private final String GET_KUBERNETES_HOST_ENDPOINT = "/stratos/admin/kubernetes/hosts/{id}";
+
+ private final String DEACTIVATE_TENANT_ENDPOINT = "/stratos/admin/tenant/deactivate";
+ private final String ACTIVATE_TENANT_ENDPOINT = "/stratos/admin/tenant/activate";
+
+ private final String UNDEPLOY_KUBERNETES_GROUP_ENDPOINT = "/stratos/admin/kubernetes/group/{id}";
+ private final String UNDEPLOY_KUBERNETES_HOST_ENDPOINT = "/stratos/admin/kubernetes/host/{id}";
+
+ private final String UPDATE_KUBERNETES_MASTER_ENDPOINT = "/stratos/admin/kubernetes/update/master";
+ private final String UPDATE_KUBERNETES_HOST_ENDPOINT = "/stratos/admin/kubernetes/update/host";
private static class SingletonHolder {
private final static RestCommandLineService INSTANCE = new RestCommandLineService();
@@ -122,6 +127,11 @@ public class RestCommandLineService {
return SingletonHolder.INSTANCE;
}
+ public Gson getGson() {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ return gsonBuilder.create();
+ }
+
// Loing method. This will authenticate the user
public boolean login(String serverURL, String username, String password, boolean validateLogin) throws Exception {
try {
@@ -170,7 +180,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
if (validateLogin) {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + initializeCookieEndpoint);
+ HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + INIT_COOKIE_ENDPOINT);
if (response != null) {
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -204,7 +214,6 @@ public class RestCommandLineService {
authenticator.setPassword(password);
authenticator.setPreemptiveAuthentication(true);
- RestClient restClient;
ConfigurationContext configurationContext = null;
try {
configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
@@ -218,14 +227,7 @@ public class RestCommandLineService {
transportOutDescription.getSender().init(configurationContext, transportOutDescription);
}
- restClient = new RestClient(serverURL, username, password);
- //restClient = new ApplicationManagementServiceStub(configurationContext, serverURL + "/services/ApplicationManagementService");
- //ServiceClient client = stub._getServiceClient();
- //Options option = client.getOptions();
- //option.setManageSession(true);
- //option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
- //option.setTimeOutInMilliSeconds(300000);
- this.restClient = restClient;
+ this.restClient = new RestClient(serverURL, username, password);
}
public Cartridge listCartridge(String cartridgeType) throws CommandException{
@@ -233,7 +235,7 @@ public class RestCommandLineService {
HttpResponse response;
try {
- String endpoint = restClient.getBaseURL() + getListAvailableCartridgeInfoRestEndPoint + "/" + cartridgeType;
+ String endpoint = restClient.getBaseURL() + GET_CARTRIDGE_ENDPOINT + "/" + cartridgeType;
response = restClient.doGet(httpClient, endpoint);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -268,7 +270,7 @@ public class RestCommandLineService {
HttpResponse response = null;
try {
- response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
+ response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -310,7 +312,7 @@ public class RestCommandLineService {
public void listAvailableCartridges() throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
+ HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -418,7 +420,7 @@ public class RestCommandLineService {
public void describeAvailableCartridges(String type) throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
+ HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -461,7 +463,7 @@ public class RestCommandLineService {
public void listSubscribedCartridges(final boolean full) throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listSubscribedCartridgesRestEndpoint);
+ HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGE_SUBSCRIPTIONS_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -556,7 +558,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listSubscribedCartridgeInfoRestEndpoint + alias);
+ + GET_CARTRIDGE_OF_TENANT_ENDPOINT + alias);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -640,7 +642,7 @@ public class RestCommandLineService {
// Invoke cluster/{clusterId}
for (String clusterId : lbClusterIdSet) {
HttpResponse responseCluster = restClient.doGet(httpClient, restClient.getBaseURL()
- + listClusterRestEndpoint + "lb");
+ + GET_CLUSTER_OF_TENANT_ENDPOINT + "lb");
String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
String resultStringCluster = CliUtils.getHttpResponseString(responseCluster);
@@ -720,7 +722,7 @@ public class RestCommandLineService {
// Invoke cluster/{clusterId}
for (Member m : members) {
- HttpResponse responseCluster = restClient.doGet(httpClient, restClient.getBaseURL() + listClusterRestEndpoint
+ HttpResponse responseCluster = restClient.doGet(httpClient, restClient.getBaseURL() + GET_CLUSTER_OF_TENANT_ENDPOINT
+"clusterId/"+ m.getLbClusterId());
String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
@@ -748,7 +750,7 @@ public class RestCommandLineService {
private Member[] getMembers(String cartridgeType, String alias, DefaultHttpClient httpClient) throws Exception{
try {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listClusterRestEndpoint + cartridgeType + "/" + alias);
+ + GET_CLUSTER_OF_TENANT_ENDPOINT + cartridgeType + "/" + alias);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -836,7 +838,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listDeployServicesRestEndPoint + "/" + cartridgeType);
+ + LIST_SERVICE_ENDPOINT + "/" + cartridgeType);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -877,7 +879,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listDeployServicesRestEndPoint + "/" + cartridgeType);
+ + LIST_SERVICE_ENDPOINT + "/" + cartridgeType);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -949,7 +951,7 @@ public class RestCommandLineService {
String jsonSubscribeString = gson.toJson(cartridgeInfoBean, CartridgeInfoBean.class);
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + subscribCartridgeRestEndpoint,
+ HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + SUBSCRIBE_CARTRIDGE_ENDPOINT,
jsonSubscribeString);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1008,19 +1010,19 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + subscribCartridgeRestEndpoint,
+ HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + SUBSCRIBE_CARTRIDGE_ENDPOINT,
subscriptionJson);
String responseCode = "" + response.getStatusLine().getStatusCode();
if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CommandLineUtils.getHttpResponseString(response);
+ String resultString = CliUtils.getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
return;
}
- String subscriptionOutput = CommandLineUtils.getHttpResponseString(response);
+ String subscriptionOutput = CliUtils.getHttpResponseString(response);
if (subscriptionOutput == null) {
System.out.println("Error in response");
@@ -1074,7 +1076,7 @@ public class RestCommandLineService {
String jsonString = gson.toJson(tenantInfo, TenantInfoBean.class);
HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + addTenantEndPoint, jsonString);
+ + ADD_TENANT_ENDPOINT, jsonString);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1114,7 +1116,7 @@ public class RestCommandLineService {
String jsonString = gson.toJson(userInfoBean, UserInfoBean.class);
HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + addUserEndPoint, jsonString);
+ + ADD_USER_ENDPOINT, jsonString);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1139,7 +1141,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL()
- + addTenantEndPoint + "/" + tenantDomain);
+ + ADD_TENANT_ENDPOINT + "/" + tenantDomain);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1167,7 +1169,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL()
- + addUserEndPoint + "/" + userName);
+ + ADD_USER_ENDPOINT + "/" + userName);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1195,7 +1197,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + deactivateTenantRestEndPoint + "/" + tenantDomain, "");
+ + DEACTIVATE_TENANT_ENDPOINT + "/" + tenantDomain, "");
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1223,7 +1225,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + activateTenantRestEndPoint + "/" + tenantDomain, "");
+ + ACTIVATE_TENANT_ENDPOINT + "/" + tenantDomain, "");
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1231,7 +1233,7 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
if (responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("You have succesfully activate " + tenantDomain + " tenant");
+ System.out.println("You have succesfully activated tenant: " + tenantDomain);
return;
} else {
String resultString = CliUtils.getHttpResponseString(response);
@@ -1240,7 +1242,7 @@ public class RestCommandLineService {
}
} catch (Exception e) {
- handleException("Exception in activating " + tenantDomain + " tenant", e);
+ handleException("Error in activating tenant: " + tenantDomain, e);
} finally {
httpClient.getConnectionManager().shutdown();
}
@@ -1251,7 +1253,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listAllTenantRestEndPoint);
+ + LIST_TENANT_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -1319,7 +1321,7 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listAllUserRestEndPoint);
+ + LIST_USERS_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
@@ -1383,7 +1385,7 @@ public class RestCommandLineService {
public void unsubscribe(String alias) throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + unsubscribeTenantEndPoint, alias);
+ HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + UNSUBSCRIBE_CARTRIDGE_OF_TENANT_ENDPOINT, alias);
String responseCode = "" + response.getStatusLine().getStatusCode();
@@ -1408,205 +1410,45 @@ public class RestCommandLineService {
// This method helps to deploy cartridge definitions
public void deployCartridgeDefinition (String cartridgeDefinition) throws CommandException{
- DefaultHttpClient httpClient = new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + cartridgeDeploymentEndPoint,
- cartridgeDefinition);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
-
- if (responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("You have successfully deployed the cartridge");
- return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- }
-
- } catch (Exception e) {
- handleException("Exception in deploy cartridge definition", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ restClient.deployEntity(DEPLOY_CARTRIDGE_ENDPOINT, cartridgeDefinition, "cartridge");
}
// This method helps to undeploy cartridge definitions
public void undeployCartrigdeDefinition (String id) throws CommandException{
- DefaultHttpClient httpClient = new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL()
- + cartridgeDeploymentEndPoint + "/" + id);
-
- 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 undeploy " + id + " cartridge");
- return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- }
-
- } catch (Exception e) {
- handleException("Exception in undeploying " + id + " cartridge", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ restClient.undeployEntity(DEPLOY_CARTRIDGE_ENDPOINT, "cartridge", id);
}
// This method helps to deploy partitions
public void deployPartition (String partitionDefinition) throws CommandException{
- DefaultHttpClient httpClient = new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + partitionDeploymentEndPoint, partitionDefinition);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CliUtils.getHttpResponseString(response);
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
-
- if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- return;
- } else {
- System.out.println("You have successfully deployed the partition");
- return;
- }
-
- } catch (Exception e) {
- handleException("Exception in deploying partitions", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ restClient.deployEntity(DEPLOY_PARTITION_ENDPOINT, partitionDefinition, "partition");
}
// This method helps to deploy autoscalling polices
public void deployAutoscalingPolicy (String autoScalingPolicy) throws CommandException{
- DefaultHttpClient httpClient= new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + autoscalingPolicyDeploymentEndPoint, autoScalingPolicy);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
-
- if (responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("You have successfully deployed the autoscaling policy");
- return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- }
-
- } catch (Exception e) {
- handleException("Exception in deploying autoscale police", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ restClient.deployEntity(DEPLOY_AUTOSCALING_POLICY_ENDPOINT, autoScalingPolicy, "autoscaling policy");
}
// This method helps to deploy multi-tenant service cluster
- public void deployService (String deployService) throws CommandException{
- DefaultHttpClient httpClient= new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + deployServiceEndPoint, deployService);
-
- 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 deploy the multi-tenant service cluster");
- return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- }
-
- } catch (Exception e) {
- handleException("Exception in deploying multi-tenant service cluster", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ public void deployService (String serviceDefinition) throws CommandException{
+ restClient.deployEntity(DEPLOY_SERVICE_ENDPOINT, serviceDefinition, "service");
}
// This method helps to undeploy multi-tenant service cluster
- public void undeployService(String id) throws CommandException{
- DefaultHttpClient httpClient = new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doDelete(httpClient, restClient.getBaseURL()
- + deployServiceEndPoint + "/" + id);
-
- 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 undeploy multi-tenant service cluster");
- return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- }
-
- } catch (Exception e) {
- handleException("Exception in undeploying multi-tenant service cluster", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ public void undeployService(String id) throws CommandException {
+ restClient.undeployEntity(DEPLOY_SERVICE_ENDPOINT, "service", id);
}
- // This method list deploy services
- public void listDeployServices() throws CommandException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ public void listServices() throws CommandException {
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listDeployServicesRestEndPoint);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
+ ServiceDefinitionList list = (ServiceDefinitionList) restClient.listEntity(LIST_SERVICE_ENDPOINT,
+ ServiceDefinitionList.class, "service");
- if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
+ if((list == null) || (list.getServiceDefinition() == null) || (list.getServiceDefinition().size() == 0)) {
+ System.out.println("No services found");
return;
}
- String resultString = CliUtils.getHttpResponseString(response);
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- ServiceDefinitionList definitionList = gson.fromJson(resultString, ServiceDefinitionList.class);
- if (definitionList == null) {
- System.out.println("Deploy service list is empty");
- return;
- }
-
- RowMapper<ServiceDefinitionBean> deployServiceMapper = new RowMapper<ServiceDefinitionBean>() {
+ RowMapper<ServiceDefinitionBean> rowMapper = new RowMapper<ServiceDefinitionBean>() {
public String[] getData(ServiceDefinitionBean definition) {
String[] data = new String[6];
@@ -1620,89 +1462,36 @@ public class RestCommandLineService {
}
};
- ServiceDefinitionBean[] definitionArry = new ServiceDefinitionBean[definitionList.getServiceDefinition().size()];
- definitionArry = definitionList.getServiceDefinition().toArray(definitionArry);
+ ServiceDefinitionBean[] array = new ServiceDefinitionBean[list.getServiceDefinition().size()];
+ array = list.getServiceDefinition().toArray(array);
- if (definitionArry.length == 0) {
- if (logger.isDebugEnabled()) {
- logger.debug("No deploy services are found");
- }
- System.out.println("There are no deploy services available");
- return;
- }
-
- System.out.println("Available Deploy Services :");
- CliUtils.printTable(definitionArry, deployServiceMapper, "Cartridge Type", "Deployment Policy Name",
+ System.out.println("Services available:");
+ CliUtils.printTable(array, rowMapper, "Cartridge Type", "Deployment Policy Name",
"Autoscaling Policy Name", "Cluster Domain", "Tenant Range", "Accessibility");
- System.out.println();
-
} catch (Exception e) {
- handleException("Exception in listing deploy services", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in listing services";
+ System.out.println(message);
+ logger.error(message, e);
}
}
// This method helps to deploy deployment polices
public void deployDeploymentPolicy (String deploymentPolicy) throws CommandException{
- DefaultHttpClient httpClient = new DefaultHttpClient();
- try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
- + deploymentPolicyDeploymentEndPoint, deploymentPolicy);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
-
- if (responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("You have successfully deployed the deployment policy");
- return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- }
-
- } catch (Exception e) {
- handleException("Exception in deploying deployment policy", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
+ restClient.deployEntity(DEPLOY_DEPLOYMENT_POLICY_ENDPOINT, deploymentPolicy, "deployment policy");
}
// This method list available partitons
public void listPartitions() throws CommandException{
- DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listParitionRestEndPoint);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
- String resultString = CliUtils.getHttpResponseString(response);
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
-
- if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- return;
- }
-
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- PartitionList partitionList = gson.fromJson(resultString, PartitionList.class);
+ PartitionList list = (PartitionList) restClient.listEntity(LIST_PARTITION_ENDPOINT,
+ PartitionList.class, "partitions");
- if (partitionList == null) {
- System.out.println("Partition list is empty");
+ if ((list == null) || (list.getPartition() == null) || (list.getPartition().size() == 0)) {
+ System.out.println("No partitions found");
return;
}
- RowMapper<Partition> partitionMapper = new RowMapper<Partition>() {
+ RowMapper<Partition> rowMapper = new RowMapper<Partition>() {
public String[] getData(Partition partition) {
String[] data = new String[3];
@@ -1713,64 +1502,31 @@ public class RestCommandLineService {
}
};
- Partition[] partitions = new Partition[partitionList.getPartition().size()];
- partitions = partitionList.getPartition().toArray(partitions);
+ Partition[] partitions = new Partition[list.getPartition().size()];
+ partitions = list.getPartition().toArray(partitions);
- if (partitions.length == 0) {
- String message = "Cannot find any deployed Partition. "
- + "Please deploy a Partition using [" + CliConstants.PARTITION_DEPLOYMENT + "] command.";
- if (logger.isDebugEnabled()) {
- logger.debug(message);
- }
- System.out.println(message);
- return;
- }
-
- System.out.println("Available Partitions:" );
- CliUtils.printTable(partitions, partitionMapper, "ID", "Provider", "Accessibilty");
+ System.out.println("Available partitions:" );
+ CliUtils.printTable(partitions, rowMapper, "ID", "Provider", "Accessibility");
System.out.println();
} catch (Exception e) {
- handleException("Exception in listing partitions", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in listing partitions";
+ System.out.println(message);
+ logger.error(message, e);
}
}
- // This method list autoscale policies
- public void listAutoscalePolicies() throws CommandException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ public void listAutoscalingPolicies() throws CommandException {
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listAutoscalePolicyRestEndPoint);
-
- 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;
- }
-
- String resultString = CliUtils.getHttpResponseString(response);
-
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- AutoscalePolicyList policyList = gson.fromJson(resultString, AutoscalePolicyList.class);
+ AutoscalePolicyList list = (AutoscalePolicyList) restClient.listEntity(LIST_AUTOSCALING_POLICY_ENDPOINT,
+ AutoscalePolicyList.class, "autoscaling policies");
- if (policyList == null) {
- System.out.println("Autoscale policy list is empty");
+ if ((list == null) || (list.getAutoscalePolicy() == null) || (list.getAutoscalePolicy().size() == 0)) {
+ System.out.println("No autoscaling policies found");
return;
}
- RowMapper<AutoscalePolicy> partitionMapper = new RowMapper<AutoscalePolicy>() {
+ RowMapper<AutoscalePolicy> rowMapper = new RowMapper<AutoscalePolicy>() {
public String[] getData(AutoscalePolicy policy) {
String[] data = new String[2];
@@ -1780,62 +1536,29 @@ public class RestCommandLineService {
}
};
- AutoscalePolicy[] policyArry = new AutoscalePolicy[policyList.getAutoscalePolicy().size()];
- policyArry = policyList.getAutoscalePolicy().toArray(policyArry);
-
- if (policyArry.length == 0) {
- String message = "Cannot find any deployed auto-scaling policy. "
- + "Please deploy a policy using [" + CliConstants.AUTOSCALING_POLICY_DEPLOYMENT + "] command.";
- if (logger.isDebugEnabled()) {
- logger.debug(message);
- }
- System.out.println(message);
- return;
- }
-
- System.out.println("Available Auto-scaling Policies:");
- CliUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
+ AutoscalePolicy[] array = new AutoscalePolicy[list.getAutoscalePolicy().size()];
+ array = list.getAutoscalePolicy().toArray(array);
+ System.out.println("Available autoscaling policies:");
+ CliUtils.printTable(array, rowMapper, "ID", "Accessibility");
} catch (Exception e) {
- handleException("Exception in listing autoscale policies", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in listing autoscaling policies";
+ System.out.println(message);
+ logger.error(message, e);
}
}
- // This method list deployment policies
public void listDeploymentPolicies() throws CommandException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listDeploymentPolicyRestEndPoint);
-
- 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;
- }
-
- String resultString = CliUtils.getHttpResponseString(response);
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- DeploymentPolicyList policyList = gson.fromJson(resultString, DeploymentPolicyList.class);
+ DeploymentPolicyList list = (DeploymentPolicyList)restClient.listEntity(LIST_DEPLOYMENT_POLICY_ENDPOINT,
+ DeploymentPolicyList.class, "deployment policies");
- if (policyList == null) {
- System.out.println("Deployment policy list is empty");
+ if ((list == null) || (list.getDeploymentPolicy() == null) || (list.getDeploymentPolicy().size() == 0)) {
+ System.out.println("No deployment policies found");
return;
}
- RowMapper<DeploymentPolicy> partitionMapper = new RowMapper<DeploymentPolicy>() {
+ RowMapper<DeploymentPolicy> rowMapper = new RowMapper<DeploymentPolicy>() {
public String[] getData(DeploymentPolicy policy) {
String[] data = new String[2];
@@ -1845,176 +1568,101 @@ public class RestCommandLineService {
}
};
- DeploymentPolicy[] policyArry = new DeploymentPolicy[policyList.getDeploymentPolicy().size()];
- policyArry = policyList.getDeploymentPolicy().toArray(policyArry);
+ DeploymentPolicy[] array = new DeploymentPolicy[list.getDeploymentPolicy().size()];
+ array = list.getDeploymentPolicy().toArray(array);
- if (policyArry.length == 0) {
- String message = "Cannot find any deployed deployment policy. "
- + "Please deploy a policy using [" + CliConstants.DEPLOYMENT_POLICY_DEPLOYMENT + "] command.";
- if (logger.isDebugEnabled()) {
- logger.debug(message);
- }
- System.out.println(message);
- return;
- }
-
- System.out.println("Available Deployment Policies:");
- CliUtils.printTable(policyArry, partitionMapper, "ID", "Accessibility");
+ System.out.println("Available deployment policies:");
+ CliUtils.printTable(array, rowMapper, "ID", "Accessibility");
System.out.println();
-
} catch (Exception e) {
- handleException("Exception in listing deployment polices", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in listing deployment policies";
+ System.out.println(message);
+ logger.error(message, e);
}
}
- // This method list deployment policies
- public void describeDeploymentPolicies(String id) throws CommandException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
+ public void describeDeploymentPolicy(String id) throws CommandException {
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listDeploymentPolicyRestEndPoint);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
+ DeploymentPolicyList list = (DeploymentPolicyList)restClient.listEntity(LIST_DEPLOYMENT_POLICY_ENDPOINT,
+ DeploymentPolicyList.class, "deployment policies");
- 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);
+ if ((list == null) || (list.getDeploymentPolicy() == null) || (list.getDeploymentPolicy().size() == 0)) {
+ System.out.println("Deployment policy not found: " + id);
return;
}
- String resultString = CliUtils.getHttpResponseString(response);
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- DeploymentPolicyList deploymentPolicyList = gson.fromJson(resultString, DeploymentPolicyList.class);
-
- if (deploymentPolicyList == null) {
- System.out.println("Deployment policy list is empty");
- return;
- }
-
- for (DeploymentPolicy policy : deploymentPolicyList.getDeploymentPolicy()) {
+ for (DeploymentPolicy policy : list.getDeploymentPolicy()) {
if(policy.getId().equals(id)) {
- System.out.println("The Deployment policy is: \n");
- System.out.println(gson.toJson(policy));
+ System.out.println("Deployment policy: " + id);
+ System.out.println(getGson().toJson(policy));
return;
}
}
-
- System.out.println("No matching Deployment policy found");
+ System.out.println("Deployment policy not found: " + id);
} catch (Exception e) {
- handleException("Exception in listing deployment polices", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in describing deployment policy: " + id;
+ System.out.println(message);
+ logger.error(message, e);
}
}
- // This method list deployment policies
public void describePartition(String id) throws CommandException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listParitionRestEndPoint);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
+ PartitionList list = (PartitionList) restClient.listEntity(LIST_PARTITION_ENDPOINT,
+ PartitionList.class, "partitions");
- if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- return;
- }
-
- String resultString = CliUtils.getHttpResponseString(response);
- if (resultString == null) {
- System.out.println("Response content is empty");
+ if ((list == null) || (list.getPartition() == null) || (list.getPartition().size() == 0)) {
+ System.out.println("Partition not found: " + id);
return;
}
- PartitionList partitionList = gson.fromJson(resultString, PartitionList.class);
-
- for (Partition partition : partitionList.getPartition()) {
+ for (Partition partition : list.getPartition()) {
if(partition.getId().equals(id)) {
- System.out.println("The Partition is:");
- System.out.println(gson.toJson(partition));
+ System.out.println("Partition: " + id);
+ System.out.println(getGson().toJson(partition));
return;
}
}
- System.out.println("Cannot find a matching Partition for [id] "+id);
+ System.out.println("Partition not found: " + id);
} catch (Exception e) {
- handleException("Exception in listing deployment polices", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in describing partition: " + id;
+ System.out.println(message);
+ logger.error(message, e);
}
}
- // This method describe about auto scaling policies
public void describeAutoScalingPolicy(String id) throws CommandException {
- DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL()
- + listAutoscalePolicyRestEndPoint);
-
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
+ AutoscalePolicyList list = (AutoscalePolicyList) restClient.listEntity(LIST_AUTOSCALING_POLICY_ENDPOINT,
+ AutoscalePolicyList.class, "autoscaling policies");
- if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
- return;
- }
-
- String resultString = CliUtils.getHttpResponseString(response);
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- AutoscalePolicyList policyList = gson.fromJson(resultString, AutoscalePolicyList.class);
-
- if (policyList == null) {
- System.out.println("Autoscale policy list is empty");
+ if ((list == null) || (list.getAutoscalePolicy() == null) || (list.getAutoscalePolicy().size() == 0)) {
+ System.out.println("Autoscaling policy not found: " + id);
return;
}
- for(AutoscalePolicy policy : policyList.getAutoscalePolicy()) {
+ for(AutoscalePolicy policy : list.getAutoscalePolicy()) {
if(policy.getId().equalsIgnoreCase(id)) {
- System.out.println("Autoscale policy is:");
- System.out.println(gson.toJson(policy));
+ System.out.println("Autoscaling policy: " + id);
+ System.out.println(getGson().toJson(policy));
return;
}
}
- System.out.println("No matching Autoscale Policy found...");
-
+ System.out.println("Autoscaling policy not found: " + id);
} catch (Exception e) {
- handleException("Exception in listing deployment polices", e);
- } finally {
- httpClient.getConnectionManager().shutdown();
+ String message = "Error in describing autoscaling policy: " + id;
+ System.out.println(message);
+ logger.error(message, e);
}
}
public void deployKubernetesGroup(String entityBody) {
- restClient.deployEntity(deployKubernetesGroup, entityBody, "kubernetes group");
+ restClient.deployEntity(DEPLOY_KUBERNETES_GROUP_ENDPOINT, entityBody, "kubernetes group");
}
public void listKubernetesGroups() {
try {
- KubernetesGroupList list = (KubernetesGroupList) restClient.listEntity(listKubernetesGroup, KubernetesGroupList.class, "kubernetes group");
+ KubernetesGroupList list = (KubernetesGroupList) restClient.listEntity(LIST_KUBERNETES_GROUP_ENDPOINT, 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) {
@@ -2041,16 +1689,16 @@ public class RestCommandLineService {
}
public void undeployKubernetesGroup(String groupId) {
- restClient.undeployEntity(undeployKubernetesGroup, "kubernetes group", groupId);
+ restClient.undeployEntity(UNDEPLOY_KUBERNETES_GROUP_ENDPOINT, "kubernetes group", groupId);
}
public void deployKubernetesHost(String entityBody) {
- restClient.deployEntity(deployKubernetesHost, entityBody, "kubernetes host");
+ restClient.deployEntity(DEPLOY_KUBERNETES_HOST_ENDPOINT, entityBody, "kubernetes host");
}
public void listKubernetesHosts(String groupId) {
try {
- KubernetesHostList list = (KubernetesHostList) restClient.listEntity(listKubernetesHost.replace("{groupId}", groupId),
+ KubernetesHostList list = (KubernetesHostList) restClient.listEntity(LIST_KUBERNETES_HOSTS_ENDPOINT.replace("{groupId}", groupId),
KubernetesHostList.class, "kubernetes host");
if((list != null) && (list.getKubernetesHost() != null) && (list.getKubernetesHost().size() > 0)) {
RowMapper<KubernetesHost> partitionMapper = new RowMapper<KubernetesHost>() {
@@ -2079,26 +1727,26 @@ public class RestCommandLineService {
}
public void undeployKubernetesHost(String hostId) {
- restClient.undeployEntity(undeployKubernetesHost, "kubernetes host", hostId);
+ restClient.undeployEntity(UNDEPLOY_KUBERNETES_HOST_ENDPOINT, "kubernetes host", hostId);
}
public void updateKubernetesMaster(String entityBody) {
- restClient.updateEntity(updateKubernetesMaster, entityBody, "kubernetes master");
+ restClient.updateEntity(UPDATE_KUBERNETES_MASTER_ENDPOINT, entityBody, "kubernetes master");
}
public void updateKubernetesHost(String entityBody) {
- restClient.updateEntity(updateKubernetesHost, entityBody, "kubernetes host");
+ restClient.updateEntity(UPDATE_KUBERNETES_HOST_ENDPOINT, entityBody, "kubernetes host");
}
- public void sync(String alias) throws CommandException {
+ public void synchronizeArtifacts(String cartridgeAlias) throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + syncEndPoint, alias);
+ HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL() + SYNCHRONIZE_ARTIFACTS_ENDPOINT, cartridgeAlias);
String responseCode = "" + response.getStatusLine().getStatusCode();
if (responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.format("Synchronizing repository for alias: %s%n", alias);
+ System.out.println(String.format("Synchronizing artifacts for cartridge subscription alias: %s", cartridgeAlias));
return;
} else {
GsonBuilder gsonBuilder = new GsonBuilder();
@@ -2107,9 +1755,10 @@ public class RestCommandLineService {
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
System.out.println(exception);
}
-
} catch (Exception e) {
- handleException("Exception when synchronizing repository for alias: " + alias, e);
+ String message = "Error in synchronizing artifacts for cartridge subscription alias: " + cartridgeAlias;
+ System.out.println(message);
+ logger.error(message, e);
} finally {
httpClient.getConnectionManager().shutdown();
}
@@ -2294,7 +1943,7 @@ public class RestCommandLineService {
public boolean isMultiTenant(String type) throws CommandException {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
- HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + listAvailableCartridgesRestEndpoint);
+ HttpResponse response = restClient.doGet(httpClient, restClient.getBaseURL() + LIST_CARTRIDGES_ENDPOINT);
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = CliUtils.getHttpResponseString(response);
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/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 35fa624..4f4ca3b 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
@@ -42,7 +42,7 @@ public class ActivateTenantCommand implements Command<StratosCommandContext> {
@Override
public String getArgumentSyntax() {
- return "[Tenant Domain]";
+ return "[tenant-domain]";
}
@Override
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
index fe44e26..3fe22ef 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/DescribeDeploymentPolicyCommand.java
@@ -60,7 +60,7 @@ public class DescribeDeploymentPolicyCommand implements Command<StratosCommandCo
if (logger.isDebugEnabled()) {
logger.debug("Getting Deployment policy info {}", id);
}
- RestCommandLineService.getInstance().describeDeploymentPolicies(id);
+ RestCommandLineService.getInstance().describeDeploymentPolicy(id);
return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
index 779b8bd..a7e439e 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListAutoscalePolicyCommand.java
@@ -52,7 +52,7 @@ public class ListAutoscalePolicyCommand implements Command<StratosCommandContext
}
if (args == null || args.length == 0) {
//CommandLineService.getInstance().listAvailableCartridges();
- RestCommandLineService.getInstance().listAutoscalePolicies();
+ RestCommandLineService.getInstance().listAutoscalingPolicies();
return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
index 127e0a5..a45ac02 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/ListDeployServiceCommand.java
@@ -51,7 +51,7 @@ public class ListDeployServiceCommand implements Command<StratosCommandContext>
logger.debug("Executing {} command...", getName());
}
if (args == null || args.length == 0) {
- RestCommandLineService.getInstance().listDeployServices();
+ RestCommandLineService.getInstance().listServices();
return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
index ba06e8e..017bf15 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/commands/SyncCommand.java
@@ -55,12 +55,12 @@ public class SyncCommand implements Command<StratosCommandContext> {
logger.debug("Executing {} command...", getName());
}
if (args != null && args.length == 1) {
- String alias = args[0];
+ String cartridgeSubscriptionAlias = args[0];
if (logger.isDebugEnabled()) {
- logger.debug("Synchronizing repository for cartridge subscription alias {}", alias);
+ logger.debug("Synchronizing repository for cartridge subscription alias {}", cartridgeSubscriptionAlias);
}
- RestCommandLineService.getInstance().sync(alias);
+ RestCommandLineService.getInstance().synchronizeArtifacts(cartridgeSubscriptionAlias);
return CliConstants.COMMAND_SUCCESSFULL;
} else {
context.getStratosApplication().printUsage(getName());
http://git-wip-us.apache.org/repos/asf/stratos/blob/c3aa855a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/exception/ErrorWrapper.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/exception/ErrorWrapper.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/exception/ErrorWrapper.java
index 01376f3..cc71ea0 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/exception/ErrorWrapper.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/exception/ErrorWrapper.java
@@ -41,8 +41,6 @@ public class ErrorWrapper {
@Override
public String toString() {
- return "Exception [errorCode=" + errorCode
- + ", errorMessage=" + errorMessage + "]";
+ return "Error [code = " + errorCode + ", message = " + errorMessage + "]";
}
-
}
[2/2] git commit: Merge remote-tracking branch 'origin/master'
Posted by im...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c13d21c5
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c13d21c5
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c13d21c5
Branch: refs/heads/master
Commit: c13d21c5923fd89f343dca9a060f755cbd326145
Parents: c3aa855 2c3e152
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat Oct 11 21:12:25 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat Oct 11 21:12:25 2014 +0530
----------------------------------------------------------------------
.../stratos/kubernetes/client/model/Pod.java | 23 ++++++++++++++++++++
1 file changed, 23 insertions(+)
----------------------------------------------------------------------