Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x 3a6d92d9e -> 7811f123c


Fixing the issue of deployment policy name not being available in the 
application cluster context


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

Branch: refs/heads/stratos-4.1.x
Commit: 7811f123c58bb9c980403670c0b4f02df2c87a2d
Parents: 3a6d92d
Author: Imesh Gunaratne <[email protected]>
Authored: Wed Oct 14 11:46:53 2015 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Wed Oct 14 11:47:17 2015 +0530

----------------------------------------------------------------------
 .../applications/topic/ApplicationBuilder.java  | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/7811f123/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
index f8bb29b..165c4f8 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
@@ -18,6 +18,7 @@
  */
 package org.apache.stratos.autoscaler.applications.topic;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.applications.ApplicationHolder;
@@ -35,6 +36,7 @@ import 
org.apache.stratos.autoscaler.pojo.policy.PolicyManager;
 import org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy;
 import org.apache.stratos.autoscaler.registry.RegistryManager;
 import org.apache.stratos.autoscaler.util.AutoscalerConstants;
+import org.apache.stratos.autoscaler.util.AutoscalerUtil;
 import org.apache.stratos.common.Property;
 import org.apache.stratos.common.partition.NetworkPartitionRef;
 import org.apache.stratos.messaging.domain.application.*;
@@ -83,11 +85,24 @@ public class ApplicationBuilder {
         ApplicationHolder.persistApplication(application);
         // Add network partition ids to application cluster contexts to be 
used by cloud controller
         for(ApplicationClusterContext appClusterContext : appClusterContexts) {
-            DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().
-                    
getDeploymentPolicy(appClusterContext.getDeploymentPolicyName());
+            String deploymentPolicyName = 
appClusterContext.getDeploymentPolicyName();
+            if(StringUtils.isEmpty(deploymentPolicyName)) {
+                // Deployment policy name is not defined in each application 
cluster context
+                // therefore it needs to be find using the below util method
+                deploymentPolicyName = 
AutoscalerUtil.getDeploymentPolicyIdByAlias(application.getUniqueIdentifier(),
+                        
AutoscalerUtil.getAliasFromClusterId(appClusterContext.getClusterId()));
+            }
+            if(StringUtils.isEmpty(deploymentPolicyName)) {
+                throw new AutoScalerException(String.format("Deployment policy 
name not found: [application] %s " +
+                                "[cluster] %s", 
application.getUniqueIdentifier(),
+                        appClusterContext.getClusterId()));
+            }
+
+            DeploymentPolicy deploymentPolicy = 
PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyName);
             if(deploymentPolicy == null) {
                 throw new AutoScalerException(String.format("Deployment policy 
not found: [application] %s " +
-                        "[deployment-policy] %s", 
application.getUniqueIdentifier(),
+                        "[cluster] %s [deployment-policy] %s", 
application.getUniqueIdentifier(),
+                        appClusterContext.getClusterId(),
                         appClusterContext.getDeploymentPolicyName()));
             }
             StringBuilder stringBuilder = new StringBuilder();

Reply via email to