Repository: incubator-stratos
Updated Branches:
  refs/heads/master a44262aef -> c271ce8e8


throwing a RestAPI Exception from subcribe operation


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

Branch: refs/heads/master
Commit: 4a64af57ba150fe26b5953eeded42fe64db25e48
Parents: 3fd8064
Author: Isuru <[email protected]>
Authored: Mon Feb 17 18:08:08 2014 +0530
Committer: Isuru <[email protected]>
Committed: Mon Feb 17 18:08:08 2014 +0530

----------------------------------------------------------------------
 .../rest/endpoint/services/ServiceUtils.java    | 26 ++++++++++++++------
 .../rest/endpoint/services/StratosAdmin.java    | 16 +++++-------
 2 files changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4a64af57/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index cedf8c9..c9c821a 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -219,16 +219,16 @@ public class ServiceUtils {
         return stratosAdminResponse;
     }
 
-    private static CloudControllerServiceClient 
getCloudControllerServiceClient () {
+    private static CloudControllerServiceClient 
getCloudControllerServiceClient () throws RestAPIException {
 
         try {
             return CloudControllerServiceClient.getServiceClient();
 
         } catch (AxisFault axisFault) {
-            String errorMsg = "Error in getting CloudControllerServiceClient 
instance";
+            String errorMsg = "Error in getting CloudControllerServiceClient 
instance to connect to the Cloud Controller";
             log.error(errorMsg, axisFault);
+            throw new RestAPIException(errorMsg);
         }
-        return null;
     }
 
     public static Partition[] getAvailablePartitions () throws 
RestAPIException {
@@ -308,16 +308,16 @@ public class ServiceUtils {
         return PojoConverter.populatePartitionPojo(partition);
     }
 
-    private static AutoscalerServiceClient getAutoscalerServiceClient () {
+    private static AutoscalerServiceClient getAutoscalerServiceClient () 
throws RestAPIException {
 
         try {
             return AutoscalerServiceClient.getServiceClient();
 
         } catch (AxisFault axisFault) {
-            String errorMsg = "Error in getting AutoscalerServiceClient 
instance";
+            String errorMsg = "Error in getting AutoscalerServiceClient 
instance to connect to the Autoscaler";
             log.error(errorMsg, axisFault);
+            throw new RestAPIException(errorMsg);
         }
-        return null;
     }
 
     public static AutoscalePolicy[] getAutoScalePolicies () throws 
RestAPIException {
@@ -804,12 +804,22 @@ public class ServiceUtils {
         return true;
     }
 
+    static SubscriptionInfo subscribeToCartridge (CartridgeInfoBean 
cartridgeInfoBean, ConfigurationContext configurationContext, String 
tenantUsername,
+                                                  String tenantDomain) throws 
RestAPIException {
+
+        try {
+            return subscribe(cartridgeInfoBean, configurationContext, 
tenantUsername, tenantDomain);
+
+        } catch (Exception e) {
+            throw new RestAPIException(e.getMessage());
+        }
+    }
 
-    static SubscriptionInfo subscribe(CartridgeInfoBean cartridgeInfoBean, 
ConfigurationContext configurationContext, String tenantUsername, String 
tenantDomain)
+    private static SubscriptionInfo subscribe (CartridgeInfoBean 
cartridgeInfoBean, ConfigurationContext configurationContext, String 
tenantUsername, String tenantDomain)
                                        throws ADCException, PolicyException, 
UnregisteredCartridgeException,
             InvalidCartridgeAliasException, DuplicateCartridgeAliasException, 
RepositoryRequiredException,
             AlreadySubscribedException, 
RepositoryCredentialsRequiredException, InvalidRepositoryException,
-            RepositoryTransportException {
+            RepositoryTransportException, RestAPIException {
         // LB cartridges won't go thru this method.
 
         //TODO: this is a temp fix. proper fix is to move this logic to 
CartridgeSubscriptionManager

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4a64af57/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
index 41e31fc..a9cfb53 100644
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
@@ -356,16 +356,12 @@ public class StratosAdmin extends AbstractAdmin {
     @Produces("application/json")
     @Consumes("application/json")
     @AuthorizationAction("/permission/protected/manage/monitor/tenants")
-    public SubscriptionInfo subscribe(CartridgeInfoBean cartridgeInfoBean) {
-        try {
-            return ServiceUtils.subscribe(cartridgeInfoBean,
-                    getConfigContext(),
-                    getUsername(),
-                    getTenantDomain());
-        } catch (Exception exception) {
-            log.error(exception);
-            return null;
-        }
+    public SubscriptionInfo subscribe(CartridgeInfoBean cartridgeInfoBean) 
throws RestAPIException {
+
+        return ServiceUtils.subscribeToCartridge(cartridgeInfoBean,
+                getConfigContext(),
+                getUsername(),
+                getTenantDomain());
     }
 
     @GET

Reply via email to