You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ma...@apache.org on 2014/02/17 08:04:29 UTC
git commit: Handle exception in CLI
Repository: incubator-stratos
Updated Branches:
refs/heads/master 3779ee91b -> 2ebe599c0
Handle exception in CLI
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/2ebe599c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/2ebe599c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/2ebe599c
Branch: refs/heads/master
Commit: 2ebe599c034819d0ee324f1a2336d15962d6001b
Parents: 3779ee9
Author: Manula Thantriwatte <ma...@apache.org>
Authored: Mon Feb 17 12:33:59 2014 +0530
Committer: Manula Thantriwatte <ma...@apache.org>
Committed: Mon Feb 17 12:33:59 2014 +0530
----------------------------------------------------------------------
.../stratos/cli/RestCommandLineService.java | 460 +++++++++----------
1 file changed, 229 insertions(+), 231 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2ebe599c/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 b693f16..04a2fb0 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
@@ -441,6 +441,7 @@ public class RestCommandLineService {
String responseCode = "" + response.getStatusLine().getStatusCode();
String resultString = getHttpResponseString(response);
+
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
@@ -457,6 +458,7 @@ public class RestCommandLineService {
System.out.println("Cartridge is null");
return;
}
+
// Get LB IP s
Map<String, Set<String>> lbIpMap = getLbIpList(cartridge, httpClient);
final Set<String> lbPrivateIpSet = lbIpMap.get("private");
@@ -492,7 +494,6 @@ public class RestCommandLineService {
+ cartridge.getPublicIp());
}
}
- //CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
System.out.println();
} catch (Exception e) {
handleException("Exception in listing subscribe cartridges", e);
@@ -519,10 +520,20 @@ public class RestCommandLineService {
// Invoke cluster/{clusterId}
for (String clusterId : lbClusterIdSet) {
HttpResponse responseCluster = restClientService.doGet(httpClient, restClientService.getUrl() + listClusterRestEndpoint
- +"clusterId/"+ clusterId,
- restClientService.getUsername(), restClientService.getPassword());
+ +"clusterId/"+ clusterId, restClientService.getUsername(), restClientService.getPassword());
+
+ String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
String resultStringCluster = getHttpResponseString(responseCluster);
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ ExceptionMapper exception = gson.fromJson(resultStringCluster, ExceptionMapper.class);
+ System.out.println(exception);
+ return null;
+ }
+
Cluster cluster = getClusterObjectFromString(resultStringCluster);
if (cluster == null) {
@@ -569,7 +580,6 @@ public class RestCommandLineService {
return;
}
-
System.out.println("\nList of members in the [cluster]: " + alias);
for (Member member : members) {
System.out.println("\n\tServiceName : "+member.getServiceName());
@@ -584,16 +594,27 @@ public class RestCommandLineService {
System.out.println("\tMemberFloatingIp : "+member.getMemberPublicIp());
System.out.println("\t-----------------------");
}
- //CommandLineUtils.printTable(members, memberMapper, headers.toArray(new String[headers.size()]));
+
System.out.println("==================================================");
System.out.println("List of LB members for the [cluster]: " + alias );
// Invoke cluster/{clusterId}
for (Member m : members) {
HttpResponse responseCluster = restClientService.doGet(httpClient, restClientService.getUrl() + listClusterRestEndpoint
- +"clusterId/"+ m.getLbClusterId(),
- restClientService.getUsername(), restClientService.getPassword());
- String resultStringCluster = getHttpResponseString(responseCluster);
+ +"clusterId/"+ m.getLbClusterId(), restClientService.getUsername(), restClientService.getPassword());
+
+ String responseCode = "" + responseCluster.getStatusLine().getStatusCode();
+ String resultStringCluster = getHttpResponseString(responseCluster);
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ ExceptionMapper exception = gson.fromJson(resultStringCluster, ExceptionMapper.class);
+ System.out.println(exception);
+ break;
+ }
+
printLBs(resultStringCluster);
}
@@ -622,20 +643,19 @@ public class RestCommandLineService {
Cluster cluster = getClusterObjectFromString(getHttpResponseString(response));
- if (cluster == null) {
- System.out.println("No existing subscriptions found for alias " + alias);
- return null;
- }
+ if (cluster == null) {
+ System.out.println("No existing subscriptions found for alias " + alias);
+ return null;
+ }
- Member[] members = new Member[cluster.getMember().size()];
- members = cluster.getMember().toArray(members);
+ Member[] members = new Member[cluster.getMember().size()];
+ members = cluster.getMember().toArray(members);
- return members;
+ return members;
} catch (Exception e) {
handleException("Exception in get member", e);
return null;
}
-
}
private Cluster getClusterObjectFromString(String resultString) {
@@ -684,9 +704,6 @@ public class RestCommandLineService {
System.out.println("\tMemberFloatingIp : "+member.getMemberPublicIp());
System.out.println("\t-----------------------");
}
-
- //CommandLineUtils.printTable(members, memberMapper, headers.toArray(new String[headers.size()]));
-
}
// This method does the cartridge subscription
@@ -722,11 +739,11 @@ public class RestCommandLineService {
completeJsonSubscribeString, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operation. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while subscribing cartridge");
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -775,11 +792,11 @@ public class RestCommandLineService {
completeJsonSubscribeString, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operation. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while subscribing cartridge");
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -806,17 +823,14 @@ public class RestCommandLineService {
if (repoURL != null) {
System.out.println("GIT Repository URL: " + repoURL);
}
-
- //Cartridge cart = stub.getCartridgeInfo(alias);
- //System.out.format("Your application is being published here. %s%n", getAccessURLs(cart));
}
+
if (subcriptionConnectInfo != null) {
hostnames += ", " + subcriptionConnectInfo.getHostname();
hostnamesLabel = "host names";
- //Cartridge cart = stub.getCartridgeInfo(alias);
- //System.out.format("Your data application is being published here. %s%n", getAccessURLs(cart));
}
+
if (externalRepoURL != null) {
String takeTimeMsg = "(this might take few minutes... depending on repo size)\n";
System.out.println(takeTimeMsg);
@@ -854,15 +868,9 @@ public class RestCommandLineService {
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operation. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)){
+ if (responseCode.equals(CliConstants.RESPONSE_OK)){
System.out.println("Tenant added successfully");
return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while creating tenant");
- return;
} else {
String resultString = getHttpResponseString(response);
ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
@@ -885,14 +893,18 @@ public class RestCommandLineService {
+ addTenantEndPoint + "/" + tenantDomain, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if (responseCode.equals(CliConstants.RESPONSE_OK)) {
System.out.println("You have succesfully delete " + tenantDomain + " tenant");
return;
} else {
- System.out.println("Error occured while deleting " + tenantDomain + " tenant");
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return;
}
} catch (Exception e) {
@@ -910,14 +922,18 @@ public class RestCommandLineService {
+ deactivateTenantRestEndPoint + "/" + tenantDomain, "", restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if (responseCode.equals(CliConstants.RESPONSE_OK)) {
System.out.println("You have succesfully deactivate " + tenantDomain + " tenant");
return;
} else {
- System.out.println("Error occured while deactivating " + tenantDomain + " tenant");
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return;
}
} catch (Exception e) {
@@ -935,14 +951,18 @@ public class RestCommandLineService {
+ activateTenantRestEndPoint + "/" + tenantDomain, "", restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if (responseCode.equals(CliConstants.RESPONSE_OK)) {
System.out.println("You have succesfully activate " + tenantDomain + " tenant");
return;
} else {
- System.out.println("Error occured while activating " + tenantDomain + " tenant");
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return;
}
} catch (Exception e) {
@@ -961,16 +981,19 @@ public class RestCommandLineService {
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if (responseCode.equals(CliConstants.RESPONSE_OK)) {
System.out.println("You have successfully unsubscribed " + alias + " cartridge");
return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while unsubscribe " + alias + " cartridge");
- return;
+ } else {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return;
}
+
} catch ( Exception e) {
handleException("Exception in un-subscribing cartridge", e);
} finally {
@@ -987,16 +1010,19 @@ public class RestCommandLineService {
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+ 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 if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while deploying cartridge definition");
+ } else {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
+
} catch (Exception e) {
handleException("Exception in deploy cartridge definition", e);
} finally {
@@ -1012,14 +1038,18 @@ public class RestCommandLineService {
+ cartridgeDeploymentEndPoint + "/" + id, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+
+ 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 {
- System.out.println("Error occured while undeploy " + id + " cartridge");
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return;
}
} catch (Exception e) {
@@ -1037,16 +1067,17 @@ public class RestCommandLineService {
partitionDefinition, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
+ String resultString = getHttpResponseString(response);
- if (responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("You have successfully deployed the partition");
- return;
- }
- else if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
+ 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 if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while deploying partition");
+ } else {
+ System.out.println("You have successfully deployed the partition");
return;
}
@@ -1066,15 +1097,16 @@ public class RestCommandLineService {
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 if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while deploying autoscaling policy");
+ } else {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1093,14 +1125,17 @@ public class RestCommandLineService {
deployService, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+
+ 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 if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while deploying the multi-tenant service cluster");
+ } else {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1119,14 +1154,18 @@ public class RestCommandLineService {
+ deployServiceEndPoint + "/" + id, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+
+ 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 {
- System.out.println("Error occured while undeploy multi-tenant service cluster");
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
+ return;
}
} catch (Exception e) {
@@ -1144,11 +1183,14 @@ public class RestCommandLineService {
restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing deploy services");
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1159,8 +1201,6 @@ public class RestCommandLineService {
return;
}
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
ServiceDefinitionList definitionList = gson.fromJson(resultString, ServiceDefinitionList.class);
if (definitionList == null) {
@@ -1222,15 +1262,16 @@ public class RestCommandLineService {
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 if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while deploying deployment policy");
+ } else {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1249,23 +1290,22 @@ public class RestCommandLineService {
restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing partitions");
+ String resultString = 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;
}
- String resultString = getHttpResponseString(response);
-
if (resultString == null) {
System.out.println("Response content is empty");
return;
}
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
PartitionList partitionList = gson.fromJson(resultString, PartitionList.class);
if (partitionList == null) {
@@ -1313,11 +1353,14 @@ public class RestCommandLineService {
restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing autoscase policies");
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1327,8 +1370,7 @@ public class RestCommandLineService {
System.out.println("Response content is empty");
return;
}
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
+
AutoscalePolicyList policyList = gson.fromJson(resultString, AutoscalePolicyList.class);
if (policyList == null) {
@@ -1374,11 +1416,14 @@ public class RestCommandLineService {
restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing deployment policies");
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1388,14 +1433,13 @@ public class RestCommandLineService {
return;
}
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
DeploymentPolicyList policyList = gson.fromJson(resultString, DeploymentPolicyList.class);
if (policyList == null) {
System.out.println("Deployment policy list is empty");
return;
}
+
RowMapper<DeploymentPolicy> partitionMapper = new RowMapper<DeploymentPolicy>() {
public String[] getData(DeploymentPolicy policy) {
@@ -1432,15 +1476,17 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
- + listDeploymentPolicyRestEndPoint,
- restClientService.getUsername(), restClientService.getPassword());
+ + listDeploymentPolicyRestEndPoint, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing deployment policies");
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1450,14 +1496,13 @@ public class RestCommandLineService {
return;
}
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
DeploymentPolicyList deploymentPolicyList = gson.fromJson(resultString, DeploymentPolicyList.class);
if (deploymentPolicyList == null) {
System.out.println("Deployment policy list is empty");
return;
}
+
for (DeploymentPolicy policy : deploymentPolicyList.getDeploymentPolicy()) {
if(policy.getId().equals(id)) {
System.out.println("The Deployment policy is: \n");
@@ -1467,23 +1512,6 @@ public class RestCommandLineService {
}
System.out.println("No matching Deployment policy found");
-
- /*RowMapper<DeploymentPolicy> partitionMapper = new RowMapper<DeploymentPolicy>() {
-
- public String[] getData(DeploymentPolicy policy) {
- String[] data = new String[1];
- data[0] = policy.getId();
- return data;
- }
- };
-
- DeploymentPolicy[] deploymentPolicies = new DeploymentPolicy[1];
- deploymentPolicies[0] = deploymentPolicy;
-
- System.out.println("The Deployment policy is: \n");
- System.out.println(resultString);*/
- //CommandLineUtils.printTable(deploymentPolicies, partitionMapper, "ID");
-
} catch (Exception e) {
handleException("Exception in listing deployment polices", e);
} finally {
@@ -1496,32 +1524,27 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
- + listParitionRestEndPoint,
- restClientService.getUsername(), restClientService.getPassword());
+ + listParitionRestEndPoint, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing deployment policies");
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
+
String resultString = getHttpResponseString(response);
if (resultString == null) {
System.out.println("Response content is empty");
return;
}
-
- if (resultString == null) {
- System.out.println("Response content is empty");
- return;
- }
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
- PartitionList partitionList = gson.fromJson(resultString, PartitionList.class);
+ PartitionList partitionList = gson.fromJson(resultString, PartitionList.class);
for (Partition partition : partitionList.getPartition()) {
if(partition.getId().equals(id)) {
@@ -1531,30 +1554,6 @@ public class RestCommandLineService {
}
}
System.out.println("No matching partition found...");
-
-
- /*GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
- Partition partition = gson.fromJson(resultString, Partition.class);
-
- if (partition == null) {
- System.out.println("Deployment policy list is empty");
- return;
- }
- RowMapper<Partition> partitionMapper = new RowMapper<Partition>() {
-
- public String[] getData(Partition policy) {
- String[] data = new String[1];
- data[0] = policy.getId();
- return data;
- }
- };
-
- System.out.println("The Partition is:");
- System.out.println(resultString);
- System.out.println(resultString); */
- //CommandLineUtils.printTable(deploymentPolicies, partitionMapper, "ID");
-
} catch (Exception e) {
handleException("Exception in listing deployment polices", e);
} finally {
@@ -1567,15 +1566,18 @@ public class RestCommandLineService {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = restClientService.doGet(httpClient, restClientService.getUrl()
- + listAutoscalePolicyRestEndPoint,
- restClientService.getUsername(), restClientService.getPassword());
+ + listAutoscalePolicyRestEndPoint, restClientService.getUsername(), restClientService.getPassword());
String responseCode = "" + response.getStatusLine().getStatusCode();
- if (responseCode.equals("" + CliConstants.RESPONSE_AUTHORIZATION_FAIL)) {
- System.out.println("Invalid operations. Authorization failed");
- return;
- } else if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
- System.out.println("Error occured while listing deployment policies");
+
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+
+ if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+ String resultString = getHttpResponseString(response);
+ ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+ System.out.println(exception);
return;
}
@@ -1585,14 +1587,13 @@ public class RestCommandLineService {
return;
}
- GsonBuilder gsonBuilder = new GsonBuilder();
- Gson gson = gsonBuilder.create();
AutoscalePolicyList policyList = gson.fromJson(resultString, AutoscalePolicyList.class);
if (policyList == null) {
System.out.println("Autoscale policy list is empty");
return;
}
+
for(AutoscalePolicy policy : policyList.getAutoscalePolicy()) {
if(policy.getId().equalsIgnoreCase(id)) {
System.out.println("Autoscale policy is:");
@@ -1602,20 +1603,6 @@ public class RestCommandLineService {
}
System.out.println("No matching Autoscale Policy found...");
-
- /*RowMapper<AutoscalePolicy> partitionMapper = new RowMapper<AutoscalePolicy>() {
-
- public String[] getData(AutoscalePolicy policy) {
- String[] data = new String[1];
- data[0] = policy.getId();
- return data;
- }
- };
-
- System.out.println("The Autoscaling Policy is: \n");
- System.out.println(resultString);*/
- //CommandLineUtils.printTable(deploymentPolicies, partitionMapper, "ID");
-
} catch (Exception e) {
handleException("Exception in listing deployment polices", e);
} finally {
@@ -1627,7 +1614,6 @@ public class RestCommandLineService {
private class DeploymentPolicyList {
private ArrayList<DeploymentPolicy> deploymentPolicy;
-
public ArrayList<DeploymentPolicy> getDeploymentPolicy() {
return deploymentPolicy;
}
@@ -1713,10 +1699,12 @@ public class RestCommandLineService {
private String getAccessURLs(Cartridge cartridge) {
PortMapping[] portMappings = cartridge.getPortMappings();
StringBuilder urlBuilder = new StringBuilder();
- for (PortMapping portMapping : portMappings) {
+
+ for (PortMapping portMapping : portMappings) {
String url = portMapping.getProtocol()+"://"+ cartridge.getHostName() + ":" + portMapping.getProxyPort() + "/";
urlBuilder.append(url).append(",");
}
+
return urlBuilder.toString();
}
@@ -1727,9 +1715,11 @@ public class RestCommandLineService {
String output;
String result = "";
+
while ((output = reader.readLine()) != null) {
result += output;
}
+
return result;
} catch (SocketException e) {
System.out.println("Connection problem");
@@ -1748,10 +1738,13 @@ public class RestCommandLineService {
if (logger.isDebugEnabled()) {
logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
}
+
String message = CommandLineUtils.getMessage(key, args);
+
if (logger.isErrorEnabled()) {
logger.error(message);
}
+
System.out.println(message);
throw new CommandException(message, e);
}
@@ -1782,19 +1775,24 @@ public class RestCommandLineService {
public class ErrorWrapper {
private String errorCode;
private String errorMessage;
- public String getErrorCode() {
+
+ public String getErrorCode() {
return errorCode;
}
- public void setErrorCode(String errorCode) {
+
+ public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
- public String getErrorMessage() {
+
+ public String getErrorMessage() {
return errorMessage;
}
- public void setErrorMessage(String errorMessage) {
+
+ public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
- @Override
+
+ @Override
public String toString() {
return "Exception [errorCode=" + errorCode
+ ", errorMessage=" + errorMessage + "]";