Repository: stratos
Updated Branches:
  refs/heads/master ed90b71b8 -> 9035a5ee6


more validation on application policy and network partition algorithms


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

Branch: refs/heads/master
Commit: 9035a5ee6527ef1fa9f1b41f5b4f401116cc66a3
Parents: ed90b71
Author: R-Rajkumar <[email protected]>
Authored: Sat Mar 7 01:18:54 2015 +0530
Committer: R-Rajkumar <[email protected]>
Committed: Sat Mar 7 01:18:54 2015 +0530

----------------------------------------------------------------------
 .../OneAfterAnotherAlgorithm.java               | 56 ++++++++++++++++++++
 .../monitor/component/ApplicationMonitor.java   | 38 +++++++++++++
 .../autoscaler/registry/RegistryManager.java    |  2 +-
 .../stratos/autoscaler/util/AutoscalerUtil.java | 20 +++++++
 4 files changed, 115 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/9035a5ee/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/networkpartition/OneAfterAnotherAlgorithm.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/networkpartition/OneAfterAnotherAlgorithm.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/networkpartition/OneAfterAnotherAlgorithm.java
index e97b132..e75f709 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/networkpartition/OneAfterAnotherAlgorithm.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/networkpartition/OneAfterAnotherAlgorithm.java
@@ -21,35 +21,91 @@ package 
org.apache.stratos.autoscaler.algorithms.networkpartition;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.algorithms.NetworkPartitionAlgorithm;
 import org.apache.stratos.autoscaler.pojo.policy.deployment.ApplicationPolicy;
 
 public class OneAfterAnotherAlgorithm implements NetworkPartitionAlgorithm{
+       
+       private static final Log log = 
LogFactory.getLog(NetworkPartitionAlgorithm.class);
 
        @Override
        public List<String> 
getNextNetworkPartitions(NetworkPartitionAlgorithmContext 
networkPartitionAlgorithmContext) {
                
                if (networkPartitionAlgorithmContext == null) {
+                       if (log.isWarnEnabled()) {
+                               String msg = "Network partition algorithm 
context is null";
+                               log.warn(msg);
+                       }
+                       return null;
+               }
+               
+               String applicationId = 
networkPartitionAlgorithmContext.getApplicationId();
+               if (applicationId == null) {
+                       if (log.isWarnEnabled()) {
+                               String msg = "Application id is null in etwork 
partition algorithm context";
+                               log.warn(msg);
+                       }
                        return null;
                }
                
                ApplicationPolicy applicationPolicy = 
networkPartitionAlgorithmContext.getApplicationPolicy();
                if (applicationPolicy == null) {
+                       if (log.isWarnEnabled()) {
+                               String msg = String.format("No application 
policy found in network partition algorithm context [application-id] %s", 
applicationId);
+                               log.warn(msg);
+                       }
                        return null;
                }
                
                String[] networkPartitions = 
applicationPolicy.getNetworkPartitions();
+               String applicatioinPolicyId = applicationPolicy.getId();
                if (networkPartitions == null || networkPartitions.length == 0) 
{
+                       if (log.isWarnEnabled()) {
+                               String msg = String.format("Network partitions 
found in application policy [application-id] %s [application-policy-id] %s", 
+                                               applicationId, 
applicatioinPolicyId);
+                               log.warn(msg);
+                       }
                        return null;
                }
                
                int totalNetworkPartitions = networkPartitions.length;
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("%s network partitions found 
in application policy [application-id] %s [application-policy-id] %s", 
+                                       totalNetworkPartitions, applicationId, 
applicatioinPolicyId);
+                       log.debug(msg);
+               }
+               
                int currentPartitionIndex = 
networkPartitionAlgorithmContext.getCurrentNetworkPartitionIndex().intValue();
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("Current network partition 
index is %s [application-id] %s [application-policy-d]", 
+                                       currentPartitionIndex, applicationId, 
applicatioinPolicyId);
+                       log.debug(msg);
+               }
+               
                if (currentPartitionIndex >= totalNetworkPartitions) {
+                       if (log.isDebugEnabled()) {
+                               String msg = 
String.format("currentPartitionIndex >= totalNetworkPartitions, hence no more 
network partitions are available "
+                                               + "[application-id] %s 
[application-policy-d]", currentPartitionIndex, applicationId, 
applicatioinPolicyId);
+                               log.debug(msg);
+                       }
                        return null;
                }
                
                int selectedIndex = 
networkPartitionAlgorithmContext.getCurrentNetworkPartitionIndex().incrementAndGet();
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("Selected network partition 
index is %s (starting from 1,2,3...) [application-id] %s 
[application-policy-d]", 
+                                       selectedIndex, applicationId, 
applicatioinPolicyId);
+                       log.debug(msg);
+               }
+               
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("Selected network partition 
is %s [application-id] %s [application-policy-d]", 
+                                       networkPartitions[selectedIndex-1], 
applicationId, applicatioinPolicyId);
+                       log.debug(msg);
+               }
+               
                List<String> nextNetworkPartitions = new ArrayList<String>();
                nextNetworkPartitions.add(networkPartitions[selectedIndex-1]);
                

http://git-wip-us.apache.org/repos/asf/stratos/blob/9035a5ee/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
index 4b27f48..1f0c853 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
@@ -329,7 +329,18 @@ public class ApplicationMonitor extends 
ParentComponentMonitor {
                }
         
         String networkPartitionAlgorithmName = 
applicationPolicy.getAlgorithm();
+        if (log.isDebugEnabled()) {
+                       String msg = String.format("Network partition algorithm 
is %s [application-id] %s", networkPartitionAlgorithmName, appId);
+                       log.debug(msg);
+               }
+        
         NetworkPartitionAlgorithm algorithm = 
getNetworkPartitionAlgorithm(networkPartitionAlgorithmName);
+        if (algorithm == null) {
+                       String msg = String.format("Coudln't create network 
partition algorithm [application-id] %s", appId);
+                       log.error(msg);
+                       throw new RuntimeException(msg);
+               }
+        
         List<String> nextNetworkPartitions = 
algorithm.getNextNetworkPartitions(algorithmContext);
         if (nextNetworkPartitions == null || nextNetworkPartitions.isEmpty()) {
                        String msg = String.format("No network partitions 
available for application bursting [application-id] %s", appId);
@@ -419,7 +430,18 @@ public class ApplicationMonitor extends 
ParentComponentMonitor {
                }
         
         String networkPartitionAlgorithmName = 
applicationPolicy.getAlgorithm();
+        if (log.isDebugEnabled()) {
+                       String msg = String.format("Network partition algorithm 
is %s [application-id] %s", networkPartitionAlgorithmName, appId);
+                       log.debug(msg);
+               }
+        
         NetworkPartitionAlgorithm algorithm = 
getNetworkPartitionAlgorithm(networkPartitionAlgorithmName);
+        if (algorithm == null) {
+                       String msg = String.format("Coudln't create network 
partition algorithm [application-id] %s", appId);
+                       log.error(msg);
+                       throw new RuntimeException(msg);
+               }
+        
         List<String> nextNetworkPartitions = 
algorithm.getNextNetworkPartitions(algorithmContext);
         if (nextNetworkPartitions == null || nextNetworkPartitions.isEmpty()) {
                        String msg = String.format("No network partitions 
available for application bursting [application-id] %s", appId);
@@ -489,11 +511,27 @@ public class ApplicationMonitor extends 
ParentComponentMonitor {
                }
        
        if 
(algorithmName.equals(StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID))
 {
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("Network partition algorithm 
is set to %s in applicatioin policy", 
+                                       
StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID);
+                       log.debug(msg);
+                       }
                        return new OneAfterAnotherAlgorithm();
                } else if 
(algorithmName.equals(StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID))
 {
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("Network partition algorithm 
is set to %s in applicatioin policy", 
+                                       
StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID);
+                       log.debug(msg);
+                       }
                        return new AllAtOnceAlgorithm();
                }
        
+               if (log.isDebugEnabled()) {
+                       String msg = String.format("Invalid network partition 
algorithm %s found in applicatioin policy", 
+                               
StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID);
+                       log.debug(msg);
+               }
+       
        return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/9035a5ee/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
index 3f770cb..b60fe2c 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
@@ -431,7 +431,7 @@ public class RegistryManager {
                 if (serializedObj != null) {
                     try {
                         Object dataObj = 
Deserializer.deserializeFromByteArray((byte[]) serializedObj);
-                        if (dataObj instanceof ApplicationPolicy) {
+                        if (dataObj instanceof 
NetworkPartitionAlgorithmContext) {
                                algorithmContext = 
(NetworkPartitionAlgorithmContext) dataObj;
                             if (log.isDebugEnabled()) {
                                 log.debug(String.format("Network partition 
algorithm context read from registry %s", algorithmContext.toString()));

http://git-wip-us.apache.org/repos/asf/stratos/blob/9035a5ee/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 59cce01..73916f7 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
@@ -58,6 +58,7 @@ import 
org.apache.stratos.cloud.controller.stub.domain.NetworkPartitionRef;
 import org.apache.stratos.common.Properties;
 import org.apache.stratos.common.Property;
 import org.apache.stratos.common.client.CloudControllerServiceClient;
+import org.apache.stratos.common.constants.StratosConstants;
 import org.apache.stratos.messaging.domain.application.Application;
 import org.apache.stratos.messaging.domain.application.Applications;
 import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
@@ -597,6 +598,25 @@ public class AutoscalerUtil {
                        throw new InvalidApplicationPolicyException(msg);
                }
        
+       // 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 partition algorithm is null or empty";
+                       log.error(msg);
+                       throw new InvalidApplicationPolicyException(msg);
+               }
+       
+       // 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 -> Invalid network partition algorithm. "
+                                       + "It should be either %s or %s, but 
found %s", 
+                                       
StratosConstants.NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID, 
+                                       
StratosConstants.NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID, algorithm);
+                       log.error(msg);
+                       throw new InvalidApplicationPolicyException(msg);
+               }
+       
        // application policy should contain at least one network partition 
reference
        String[] networkPartitionIds = applicationPolicy.getNetworkPartitions();
                if (null == networkPartitionIds || networkPartitionIds.length 
== 0) {

Reply via email to