You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2014/10/13 14:34:48 UTC

git commit: fixing parallel monitors activation issue

Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 904245219 -> 961e58483


fixing parallel monitors activation issue


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

Branch: refs/heads/4.0.0-grouping
Commit: 961e584834c027fbd99f5626a4b399a3fdaea558
Parents: 9042452
Author: reka <rt...@gmail.com>
Authored: Mon Oct 13 18:04:36 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Mon Oct 13 18:04:36 2014 +0530

----------------------------------------------------------------------
 .../status/checker/StatusChecker.java           | 61 ++++++++++----------
 1 file changed, 31 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/961e5848/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
index 16c294a..ee04fff 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
@@ -24,6 +24,7 @@ import org.apache.stratos.autoscaler.AutoscalerContext;
 import org.apache.stratos.autoscaler.NetworkPartitionContext;
 import org.apache.stratos.autoscaler.PartitionContext;
 import org.apache.stratos.autoscaler.grouping.topic.StatusEventPublisher;
+import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
 import org.apache.stratos.messaging.domain.topology.*;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
@@ -48,40 +49,38 @@ public class StatusChecker {
     }
 
     /**
-     *
-     * @param clusterId1
+     * Calculating whether the cluster has all min instances as active and send the
+     * ClusterActivatedEvent.
+     * @param clusterId id of the cluster
      */
-    public void onMemberStatusChange(String clusterId1) {
-        final String clusterId = clusterId1;
-        Runnable exCluster = new Runnable() {
-            public void run() {
-                ClusterMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId);
-                boolean clusterActive = false;
-                for (NetworkPartitionContext networkPartitionContext : monitor.getNetworkPartitionCtxts().values()) {
-                    //minimum check per partition
-                    for (PartitionContext partitionContext : networkPartitionContext.getPartitionCtxts().values()) {
-                        if (partitionContext.getMinimumMemberCount() == partitionContext.getActiveMemberCount()) {
-                            clusterActive = true;
-                        } else if (partitionContext.getActiveMemberCount() > partitionContext.getMinimumMemberCount()) {
-                            log.info("cluster already activated...");
-                            clusterActive = true;
-                        } else {
-                            clusterActive = false;
-                        }
-                    }
-                }
-                // if active then notify upper layer
-                if (clusterActive) {
-                    //send event to cluster status topic
-                    StatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
-                            monitor.getServiceId(), monitor.getClusterId());
+    public void onMemberStatusChange(String clusterId) {
+        ClusterMonitor monitor = AutoscalerContext.getInstance().getMonitor(clusterId);
+        boolean clusterActive = clusterActive(monitor);
+        // if active then notify upper layer
+        if (clusterActive) {
+            //send event to cluster status topic
+            StatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
+                    monitor.getServiceId(), monitor.getClusterId());
+        }
+    }
 
+    private boolean clusterActive(AbstractClusterMonitor monitor) {
+        boolean clusterActive = false;
+        for (NetworkPartitionContext networkPartitionContext : monitor.getNetworkPartitionCtxts().values()) {
+            //minimum check per partition
+            for (PartitionContext partitionContext : networkPartitionContext.getPartitionCtxts().values()) {
+                if (partitionContext.getMinimumMemberCount() == partitionContext.getActiveMemberCount()) {
+                    clusterActive = true;
+                } else if (partitionContext.getActiveMemberCount() > partitionContext.getMinimumMemberCount()) {
+                    log.info("cluster already activated...");
+                    clusterActive = true;
+                } else {
+                    clusterActive = false;
+                    return clusterActive;
                 }
-
             }
-        };
-        Thread clusterThread = new Thread(exCluster);
-        clusterThread.start();
+        }
+        return clusterActive;
     }
 
     /**
@@ -267,6 +266,7 @@ public class StatusChecker {
                 groupActiveStatus = true;
             } else {
                 groupActiveStatus = false;
+                break;
             }
         }
         return groupActiveStatus;
@@ -282,6 +282,7 @@ public class StatusChecker {
                 clusterActiveStatus = true;
             } else {
                 clusterActiveStatus = false;
+                break;
             }
         }
         return clusterActiveStatus;