Fixed issues found when removing a non existing cartridge

Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/04bf4cbb
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/04bf4cbb
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/04bf4cbb

Branch: refs/heads/master
Commit: 04bf4cbb7ed750c5f252b1bc75ef93c23d158ede
Parents: 2ca933c
Author: Dinithi <[email protected]>
Authored: Wed May 20 19:24:53 2015 +0530
Committer: Dinithi <[email protected]>
Committed: Wed May 20 19:24:53 2015 +0530

----------------------------------------------------------------------
 .../apache/stratos/rest/endpoint/api/StratosApiV41.java | 12 ++++++++----
 .../stratos/rest/endpoint/api/StratosApiV41Utils.java   | 11 ++++++-----
 2 files changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/04bf4cbb/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
index 7b50e40..bb6585f 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java
@@ -426,10 +426,14 @@ public class StratosApiV41 extends AbstractApi {
     @AuthorizationAction("/permission/protected/manage/removeCartridge")
     public Response removeCartridge(
             @PathParam("cartridgeType") String cartridgeType) throws 
RestAPIException {
-        StratosApiV41Utils.removeCartridge(cartridgeType);
-        return Response.ok().entity(new 
ResponseMessageBean(ResponseMessageBean.SUCCESS,
-                String.format("Cartridge deleted successfully: 
[cartridge-type] %s", cartridgeType))).build();
-
+        try {
+            StratosApiV41Utils.removeCartridge(cartridgeType);
+            return Response.ok().entity(new 
ResponseMessageBean(ResponseMessageBean.SUCCESS,
+                    String.format("Cartridge deleted successfully: 
[cartridge-type] %s", cartridgeType))).build();
+        } catch (Exception e) {
+            return Response.status(Response.Status.BAD_REQUEST).entity(new 
ResponseMessageBean(
+                    ResponseMessageBean.ERROR, e.getMessage())).build();
+        }
     }
 
     // API methods for cartridge groups

http://git-wip-us.apache.org/repos/asf/stratos/blob/04bf4cbb/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index 9fd3413..8ca2ff0 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -25,7 +25,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.stub.*;
 import org.apache.stratos.autoscaler.stub.deployment.policy.ApplicationPolicy;
-import org.apache.stratos.autoscaler.stub.exception.UnremovablePolicyException;
 import org.apache.stratos.autoscaler.stub.pojo.ApplicationContext;
 import org.apache.stratos.autoscaler.stub.pojo.ServiceGroup;
 import org.apache.stratos.cloud.controller.stub.*;
@@ -252,10 +251,12 @@ public class StratosApiV41Utils {
             if (log.isInfoEnabled()) {
                 log.info(String.format("Successfully removed cartridge: 
[cartridge-type] %s ", cartridgeType));
             }
-        } catch (Exception e) {
-            String msg = "Could not remove cartridge " + 
e.getLocalizedMessage();
-            log.error(msg, e);
-            throw new RestAPIException(e.getMessage(), e);
+        } catch (RemoteException e) {
+            throw new RestAPIException(e.getMessage());
+        } catch (CloudControllerServiceInvalidCartridgeTypeExceptionException 
e) {
+            throw new 
RestAPIException(e.getFaultMessage().getInvalidCartridgeTypeException().getMessage());
+        } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
+            throw new 
RestAPIException(e.getFaultMessage().getCartridgeNotFoundException().getMessage());
         }
     }
 

Reply via email to