Fixing issues in CLI when adding application-policy

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

Branch: refs/heads/master
Commit: ccabe5dd554fc95c751e6f99688d08b6ed6eb9a7
Parents: 70edf39
Author: anuruddhal <[email protected]>
Authored: Tue May 19 13:40:52 2015 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Tue May 19 15:32:43 2015 +0530

----------------------------------------------------------------------
 .../autoscaler/pojo/policy/PolicyManager.java   | 10 +++---
 .../stratos/autoscaler/util/AutoscalerUtil.java | 34 ++++++++++----------
 .../rest/endpoint/api/StratosApiV41.java        | 11 ++++---
 3 files changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/ccabe5dd/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
index 12e66ff..e7fc57c 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
@@ -228,14 +228,14 @@ public class PolicyManager {
         }
     }
 
-    public void removeApplicationPolicyInInformationModel(String 
applicationId) throws InvalidPolicyException {
-        if (applicationPolicyListMap.containsKey(applicationId)) {
+    public void removeApplicationPolicyInInformationModel(String 
applicationPolicyId) throws InvalidPolicyException {
+        if (applicationPolicyListMap.containsKey(applicationPolicyId)) {
             if (log.isDebugEnabled()) {
-                log.debug("Removing application policy [application-id] " + 
applicationId);
+                log.debug("Removing application policy [application-policy-id] 
" + applicationPolicyId);
             }
-            applicationPolicyListMap.remove(applicationId);
+            applicationPolicyListMap.remove(applicationPolicyId);
         } else {
-            throw new InvalidPolicyException("No such application id [" + 
applicationId + "] exists");
+            throw new InvalidPolicyException(String.format("Application policy 
not found: [application-policy-id] %s", applicationPolicyId));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/ccabe5dd/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index ce71418..fc3e6a6 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -604,14 +604,14 @@ public class AutoscalerUtil {
 
         // application policy can't be null
         if (null == applicationPolicy) {
-            String msg = "Invalid Application Policy. Cause -> Application 
Policy is null";
+            String msg = "Invalid Application Policy: Application Policy is 
null";
             log.error(msg);
             throw new InvalidApplicationPolicyException(msg);
         }
 
         // application policy id can't be null
         if (applicationPolicy.getId() == null || 
StringUtils.isBlank(applicationPolicy.getId())) {
-            String msg = "Invalid Application Policy. Cause -> Application 
policy id null or empty";
+            String msg = "Invalid Application Policy: Application policy id 
null or empty";
             log.error(msg);
             throw new InvalidApplicationPolicyException(msg);
         }
@@ -619,7 +619,7 @@ public class AutoscalerUtil {
         // network partition algorithm can't null or empty
         String algorithm = applicationPolicy.getAlgorithm();
         if (algorithm == null || StringUtils.isBlank(algorithm)) {
-            String msg = "Invalid Application Policy. Cause -> Network " +
+            String msg = "Invalid Application Policy: Network " +
                     "partition algorithm is null or empty";
             log.error(msg);
             throw new InvalidApplicationPolicyException(msg);
@@ -628,7 +628,7 @@ public class AutoscalerUtil {
         // network partition algorithm should be either one-after-another or 
all-at-once
         if 
(!algorithm.equals(StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID)
                 && 
!algorithm.equals(StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID)) 
{
-            String msg = String.format("Invalid Application Policy. Cause -> " 
+
+            String msg = String.format("Invalid Application Policy: " +
                             "Invalid network partition algorithm. "
                             + "It should be either %s or %s, but found %s",
                     
StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID,
@@ -640,8 +640,8 @@ public class AutoscalerUtil {
         // application policy should contain at least one network partition 
reference
         String[] networkPartitionIds = 
applicationPolicy.getNetworkPartitions();
         if (null == networkPartitionIds || networkPartitionIds.length == 0) {
-            String msg = "Invalid Application Policy. "
-                    + "Cause -> Application Policy is not containing any 
network partition reference";
+            String msg = "Invalid Application Policy: "
+                    + "Application Policy is not containing any network 
partition reference";
             log.error(msg);
             throw new InvalidApplicationPolicyException(msg);
         }
@@ -651,8 +651,8 @@ public class AutoscalerUtil {
 
             // network-partition-id can't be null or empty
             if (null == networkPartitionId || networkPartitionId.isEmpty()) {
-                String msg = String.format("Invalid Application Policy. "
-                        + "Cause -> Invalid network-partition-id : %s", 
networkPartitionId);
+                String msg = String.format("Invalid Application Policy: "
+                        + "Invalid network-partition-id [network-partition-id] 
%s", networkPartitionId);
                 log.error(msg);
                 throw new InvalidApplicationPolicyException(msg);
             }
@@ -660,8 +660,8 @@ public class AutoscalerUtil {
             // network partitions should be added already
             if (null == CloudControllerServiceClient.getInstance().
                     getNetworkPartition(networkPartitionId)) {
-                String msg = String.format("Network partition not found : 
[network-partition-id]  %s in " +
-                                "[application-policy-id] %s", 
networkPartitionId,applicationPolicy.getId());
+                String msg = String.format("Network partition not found: 
[network-partition-id]  %s in " +
+                        "[application-policy-id] %s", networkPartitionId, 
applicationPolicy.getId());
                 log.error(msg);
                 throw new InvalidApplicationPolicyException(msg);
             }
@@ -686,8 +686,8 @@ public class AutoscalerUtil {
                                 for (String networkPartitionId : 
networkPartitionIds) {
                                     // network-partition-id can't be null or 
empty
                                     if (null == networkPartitionId || 
networkPartitionId.isEmpty()) {
-                                        String msg = String.format("Invalid 
Application Policy. "
-                                                        + "Cause -> Invalid 
network-partition-id : %s",
+                                        String msg = String.format("Invalid 
Application Policy: "
+                                                        + "Invalid 
network-partition-id [network-partition-id] %s",
                                                 networkPartitionId);
                                         log.error(msg);
                                         throw new 
InvalidApplicationPolicyException(msg);
@@ -696,9 +696,9 @@ public class AutoscalerUtil {
                                     // network partitions should be added 
already
                                     if (null == 
CloudControllerServiceClient.getInstance().
                                             
getNetworkPartition(networkPartitionId)) {
-                                        String msg = String.format("Invalid 
Application Policy. "
-                                                + "Cause -> Network partition 
not found for " +
-                                                "network-partition-id : %s", 
networkPartitionId);
+                                        String msg = String.format("Invalid 
Application Policy: "
+                                                + "Network partition not found 
for " +
+                                                "[network-partition-id] : %s", 
networkPartitionId);
                                         log.error(msg);
                                         throw new 
InvalidApplicationPolicyException(msg);
                                     }
@@ -738,8 +738,8 @@ public class AutoscalerUtil {
             String networkPartitionId = 
applicationPolicyNetworkPartitionerence;
             // validate application policy against the given application
             if (!isAppUsingNetworkPartitionId(applicationId, 
networkPartitionId)) {
-                String msg = String.format("Invalid Application Policy. "
-                                + "Cause -> Network partition 
[network-partition-id] %s is not used in application [application-id] %s. "
+                String msg = String.format("Invalid Application Policy: "
+                                + "Network partition [network-partition-id] %s 
is not used in application [application-id] %s. "
                                 + "Hence application bursting will fail. 
Either remove %s from application policy or make all the cartridges available 
in %s",
                         networkPartitionId, applicationId, networkPartitionId, 
networkPartitionId);
                 log.error(msg);

http://git-wip-us.apache.org/repos/asf/stratos/blob/ccabe5dd/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 670e38b..9f977ee 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
@@ -825,8 +825,9 @@ public class StratosApiV41 extends AbstractApi {
                     String.format("Application policy added successfully: 
[application-policy] %s",
                             applicationPolicy.getId()))).build();
         } catch (AutoscalerServiceInvalidApplicationPolicyExceptionException 
e) {
+            String backendErrorMessage = 
e.getFaultMessage().getInvalidApplicationPolicyException().getMessage();
             return Response.status(Response.Status.BAD_REQUEST).entity(new 
ResponseMessageBean(
-                    ResponseMessageBean.ERROR, "Invalid application 
policy")).build();
+                    ResponseMessageBean.ERROR, backendErrorMessage)).build();
         } catch 
(AutoscalerServiceApplicationPolicyAlreadyExistsExceptionException e) {
             return Response.status(Response.Status.CONFLICT).entity(new 
ResponseMessageBean(
                     ResponseMessageBean.ERROR, "Application policy already 
exists")).build();
@@ -907,11 +908,12 @@ public class StratosApiV41 extends AbstractApi {
                             applicationPolicyId))).build();
         } catch (ApplicationPolicyIdIsEmptyException e) {
             return Response.status(Response.Status.BAD_REQUEST).entity(new 
ResponseMessageBean(
-                    ResponseMessageBean.ERROR, "Autoscaling policy id is 
empty"))
+                    ResponseMessageBean.ERROR, "Application policy id is 
empty"))
                     .build();
         } catch (AutoscalerServiceInvalidPolicyExceptionException e) {
+            String backendErrorMessage = 
e.getFaultMessage().getInvalidPolicyException().getMessage();
             return Response.status(Response.Status.BAD_REQUEST).entity(new 
ResponseMessageBean(
-                    ResponseMessageBean.ERROR, "Autoscaling policy is 
invalid"))
+                    ResponseMessageBean.ERROR, backendErrorMessage))
                     .build();
         }
     }
@@ -934,8 +936,9 @@ public class StratosApiV41 extends AbstractApi {
         try {
             StratosApiV41Utils.updateApplicationPolicy(applicationPolicy);
         } catch (AutoscalerServiceInvalidApplicationPolicyExceptionException 
e) {
+            String backendErrorMessage = 
e.getFaultMessage().getInvalidApplicationPolicyException().getMessage();
             return Response.status(Response.Status.BAD_REQUEST).entity(new 
ResponseMessageBean(
-                    ResponseMessageBean.ERROR, "Invalid application policy"))
+                    ResponseMessageBean.ERROR, backendErrorMessage))
                     .build();
         } catch 
(AutoscalerServiceApplicatioinPolicyNotExistsExceptionException e) {
             return Response.status(Response.Status.NOT_FOUND).entity(new 
ResponseMessageBean(

Reply via email to