You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2015/05/20 19:40:38 UTC

[4/4] stratos git commit: Fixed issues found when removing a non existing cartridge

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/54106d53
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/54106d53
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/54106d53

Branch: refs/heads/master
Commit: 54106d5382f198be5d08757e3839d8a24cd6beb5
Parents: 7ee7ecf
Author: Dinithi <di...@wso2.com>
Authored: Wed May 20 19:24:53 2015 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Wed May 20 23:10:30 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/54106d53/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 647d8d2..b4dbb45 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/stratos/cartridges/manage")
     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/54106d53/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());
         }
     }