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

[32/50] [abbrv] git commit: moving force termination to a separate thread

moving force termination to a separate thread


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

Branch: refs/heads/docker-grouping-merge
Commit: d474b13671ccdfc4fdff31d15795dc71f5ad62f9
Parents: 1b7064d
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Wed Oct 29 11:51:16 2014 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Wed Oct 29 11:51:27 2014 +0530

----------------------------------------------------------------------
 .../AutoscalerTopologyEventReceiver.java        | 14 ++---
 .../monitor/cluster/ClusterMonitor.java         | 57 ++++++++++++++++----
 2 files changed, 55 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/d474b136/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
index 7b411b8..608100a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -389,12 +389,14 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                                 } else {
                                     // if not active, forcefully terminate
                                     clusterMonitor.setStatus(ClusterStatus.Terminating);
-                                    try {
-                                        CloudControllerClient.getInstance().terminateAllInstances(clusterData.getClusterId());
-                                    } catch (TerminationException e) {
-                                        log.error("Unable to terminate instances for [ cluster id ] " +
-                                                clusterData.getClusterId(), e);
-                                    }
+                                    clusterMonitor.terminateAllMembers();
+//                                    try {
+//                                        // TODO: introduce a task to do this cleanup
+//                                        CloudControllerClient.getInstance().terminateAllInstances(clusterData.getClusterId());
+//                                    } catch (TerminationException e) {
+//                                        log.error("Unable to terminate instances for [ cluster id ] " +
+//                                                clusterData.getClusterId(), e);
+//                                    }
                                 }
                             } else {
                                 log.warn("No Cluster Monitor found for cluster id " + clusterData.getClusterId());

http://git-wip-us.apache.org/repos/asf/stratos/blob/d474b136/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
index d67b4f4..69dac23 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
@@ -22,7 +22,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.NetworkPartitionContext;
 import org.apache.stratos.autoscaler.PartitionContext;
+import org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.exception.TerminationException;
 import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
@@ -101,17 +103,52 @@ public class ClusterMonitor extends AbstractClusterMonitor {
     @Override
     public void terminateAllMembers() {
 
-        for (NetworkPartitionContext networkPartitionContext : networkPartitionCtxts.values()) {
-            for (PartitionContext partitionContext : networkPartitionContext.getPartitionCtxts().values()) {
-                //if (log.isDebugEnabled()) {
-                log.info("Starting to terminate all members in Network Partition [ " +
-                        networkPartitionContext.getId() + " ], Partition [ " +
-                        partitionContext.getPartitionId() + " ]");
-                // }
-
-                terminateAllFactHandle = AutoscalerRuleEvaluator.evaluateTerminateAll
-                        (terminateAllKnowledgeSession, terminateAllFactHandle, partitionContext);
+        Thread memberTerminator = new Thread(new Runnable(){
+            public void run(){
+
+                for (NetworkPartitionContext networkPartitionContext : networkPartitionCtxts.values()) {
+                    for (PartitionContext partitionContext : networkPartitionContext.getPartitionCtxts().values()) {
+                        //if (log.isDebugEnabled()) {
+                        log.info("Starting to terminate all members in Network Partition [ " +
+                                networkPartitionContext.getId() + " ], Partition [ " +
+                                partitionContext.getPartitionId() + " ]");
+                        // }
+                        // need to terminate active, pending and obsolete members
+
+                        // active members
+                        for (MemberContext activeMemberCtxt : partitionContext.getActiveMembers()) {
+                            log.info("Terminating active member [member id] " + activeMemberCtxt.getMemberId());
+                            terminateMember(activeMemberCtxt.getMemberId());
+                        }
+
+                        // pending members
+                        for  (MemberContext pendingMemberCtxt : partitionContext.getPendingMembers()) {
+                            log.info("Terminating pending member [member id] " + pendingMemberCtxt.getMemberId());
+                            terminateMember(pendingMemberCtxt.getMemberId());
+                        }
+
+                        // obsolete members
+                        for (String obsoleteMemberId : partitionContext.getObsoletedMembers()) {
+                            log.info("Terminating obsolete member [member id] " + obsoleteMemberId);
+                            terminateMember(obsoleteMemberId);
+                        }
+
+//                terminateAllFactHandle = AutoscalerRuleEvaluator.evaluateTerminateAll
+//                        (terminateAllKnowledgeSession, terminateAllFactHandle, partitionContext);
+                    }
+                }
             }
+        }, "Member Terminator - [cluster id] " + this.clusterId);
+
+        memberTerminator.start();
+    }
+
+    private static void terminateMember (String memberId) {
+        try {
+            CloudControllerClient.getInstance().terminate(memberId);
+
+        } catch (TerminationException e) {
+            log.error("Unable to terminate member [member id ] " + memberId, e);
         }
     }