Updated Branches:
  refs/heads/master 819373a9f -> b797ef7a5

Error handle 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/3fdc53cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/3fdc53cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/3fdc53cf

Branch: refs/heads/master
Commit: 3fdc53cfc813cc52ce427a2e496d83b172ccf596
Parents: 214bf85
Author: Manula Thantriwatte <[email protected]>
Authored: Tue Dec 17 18:51:15 2013 +0530
Committer: Manula Thantriwatte <[email protected]>
Committed: Tue Dec 17 18:51:15 2013 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     | 78 +++++++++++++++++---
 .../apache/stratos/cli/utils/CliConstants.java  |  1 +
 2 files changed, 67 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/3fdc53cf/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 5a517f1..175ffe7 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
@@ -172,8 +172,13 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doGet(restClientService.getUrl() + 
listAvailableCartridgesRestEndpoint,
                     restClientService.getUsername(), 
restClientService.getPassword());
 
-            String resultString = getHttpResponseString(response);
+            String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in list available cartridges");
+                return;
+            }
 
+            String resultString = getHttpResponseString(response);
             if (resultString == null) {
                 return;
             }
@@ -257,6 +262,12 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doGet(restClientService.getUrl() + 
listSubscribedCartridgesRestEndpoint,
                     restClientService.getUsername(), 
restClientService.getPassword());
 
+            String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in list subscribe cartridges");
+                return;
+            }
+
             String resultString = getHttpResponseString(response);
 
             GsonBuilder gsonBuilder = new GsonBuilder();
@@ -351,9 +362,13 @@ public class RestCommandLineService {
                 HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + 
subscribCartridgeRestEndpoint,
                         completeJsonSubscribeString, 
restClientService.getUsername(), restClientService.getPassword());
 
-                String subscription = getHttpResponseString(response);
-
                 String responseCode = "" + 
response.getStatusLine().getStatusCode();
+                if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                    System.out.println("Error occur in subscribe cartridge");
+                    return;
+                }
+
+                String subscription = getHttpResponseString(response);
 
                 if (subscription == null) {
                     System.out.println("Error");
@@ -401,9 +416,13 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + 
subscribCartridgeRestEndpoint,
                     completeJsonSubscribeString, 
restClientService.getUsername(), restClientService.getPassword());
 
-            String subscriptionOutput = getHttpResponseString(response);
             String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in subscribe cartridge");
+                return;
+            }
 
+            String subscriptionOutput = getHttpResponseString(response);
 
             if (subscriptionOutput == null) {
                 System.out.println("Error");
@@ -478,8 +497,11 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + addTenantEndPoint,
                     completeJsonString, restClientService.getUsername(), 
restClientService.getPassword());
 
-            String result = getHttpResponseString(response);
             String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in create tenant");
+                return;
+            }
 
             if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) 
{
                 System.out.println("Invalid operation. Authorization failed");
@@ -516,8 +538,11 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + 
cartridgeDeploymentEndPoint,
                     cartridgeDefinition, restClientService.getUsername(), 
restClientService.getPassword());
 
-            String result = getHttpResponseString(response);
             String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in deploy cartridge 
definition");
+                return;
+            }
 
             if (responseCode.equals(CliConstants.RESPONSE_AUTHORIZATION_FAIL)) 
{
                 System.out.println("Invalid operations. Authorization failed");
@@ -536,8 +561,13 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + 
partitionDeploymentEndPoint,
                     partitionDefinition, restClientService.getUsername(), 
restClientService.getPassword());
 
-            String result = getHttpResponseString(response);
             String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in deploy partition");
+                return;
+            }
+
+            String result = getHttpResponseString(response);
 
             if (result.equals("true")) {
                 System.out.println("You have successfully deployed the 
partition");
@@ -564,8 +594,13 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + 
autoscalingPolicyDeploymentEndPoint,
                     autoScalingPolicy, restClientService.getUsername(), 
restClientService.getPassword());
 
-            String result = getHttpResponseString(response);
             String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in deploy autoscaling policy");
+                return;
+            }
+
+            String result = getHttpResponseString(response);
 
             if (result.equals("true")) {
                 System.out.println("You have successfully deployed the 
autoscaling policy");
@@ -592,8 +627,14 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doPost(restClientService.getUrl() + 
deploymentPolicyDeploymentEndPoint,
                     deploymentPolicy, restClientService.getUsername(), 
restClientService.getPassword());
 
-            String result = getHttpResponseString(response);
+
             String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in deploy deployment policy");
+                return;
+            }
+
+            String result = getHttpResponseString(response);
 
             if (result.equals("true")) {
                 System.out.println("You have successfully deployed the 
deployment policy");
@@ -620,9 +661,16 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doGet(restClientService.getUrl() + listParitionRestEndPoint,
                     restClientService.getUsername(), 
restClientService.getPassword());
 
+            String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in list partitions");
+                return;
+            }
+
             String resultString = getHttpResponseString(response);
 
             if (resultString == null) {
+                System.out.println("Response content is empty");
                 return;
             }
 
@@ -631,7 +679,7 @@ public class RestCommandLineService {
             PartitionList partitionList = gson.fromJson(resultString, 
PartitionList.class);
 
             if (partitionList == null) {
-                System.out.println("Partition list is null");
+                System.out.println("Partition list is empty");
                 return;
             }
 
@@ -665,10 +713,16 @@ public class RestCommandLineService {
             HttpResponse response = 
restClientService.doGet(restClientService.getUrl() + 
listAutoscalePolicyRestEndPoint,
                     restClientService.getUsername(), 
restClientService.getPassword());
 
-            System.out.println(response.getStatusLine().getStatusCode());
+            String responseCode = "" + 
response.getStatusLine().getStatusCode();
+            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
+                System.out.println("Error occur in list autoscase policies");
+                return;
+            }
+
             String resultString = getHttpResponseString(response);
 
             if (resultString == null) {
+                System.out.println("Response content is empty");
                 return;
             }
 
@@ -677,7 +731,7 @@ public class RestCommandLineService {
             AutoscalePolicyList policyList = gson.fromJson(resultString, 
AutoscalePolicyList.class);
 
             if (policyList == null) {
-                System.out.println("Autoscale policy list is null");
+                System.out.println("Autoscale policy list is empty");
                 return;
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/3fdc53cf/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
 
b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
index 047bb50..382a82b 100644
--- 
a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
+++ 
b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/utils/CliConstants.java
@@ -192,4 +192,5 @@ public class CliConstants {
     public static final String RESPONSE_AUTHORIZATION_FAIL = "403";
     public static final String RESPONSE_NO_CONTENT = "204";
     public static final String RESPONSE_OK = "200";
+    public static final String RESPONSE_BAD_REQUEST = "400";
 }

Reply via email to