You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/02/17 09:55:42 UTC

[2/4] git commit: timeout before performing forceful shutdown

timeout before performing forceful shutdown


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

Branch: refs/heads/master
Commit: 9754664a261f2968dcdc4cf1e18a3d414643e8ae
Parents: b0da7e0
Author: Nirmal Fernando <ni...@apache.org>
Authored: Mon Feb 17 14:24:29 2014 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Mon Feb 17 14:24:29 2014 +0530

----------------------------------------------------------------------
 .../impl/CloudControllerServiceImpl.java        | 43 ++++++++++++++++----
 .../cloud/controller/pojo/ClusterContext.java   | 16 +++++---
 2 files changed, 46 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9754664a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
index eeaebf7..f999e47 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
@@ -907,8 +907,18 @@ public class CloudControllerServiceImpl implements CloudControllerService {
         property = props.getProperty(Constants.DEVICE_NAME);
         String deviceName = property != null ? property : null;
         
-	    dataHolder.addClusterContext(new ClusterContext(clusterId, cartridgeType, payload, 
-	    		hostName, isLb, isVolumeRequired, shouldDeleteVolume, volumeSize, deviceName));
+        property = props.getProperty(Constants.GRACEFUL_SHUTDOWN_TIMEOUT);
+        long timeout = property != null ? Long.parseLong(property) : 30000;
+        
+	    ClusterContext ctxt = new ClusterContext(clusterId, cartridgeType, payload, 
+	    		hostName, isLb);
+	    ctxt.setVolumeRequired(isVolumeRequired);
+	    ctxt.setShouldDeleteVolume(shouldDeleteVolume);
+	    ctxt.setDeviceName(deviceName);
+	    ctxt.setVolumeSize(volumeSize);
+	    ctxt.setTimeoutInMillis(timeout);
+	    
+		dataHolder.addClusterContext(ctxt);
 	    TopologyBuilder.handleClusterCreated(registrant, isLb);
 	    
 	    persist();
@@ -961,16 +971,33 @@ public class CloudControllerServiceImpl implements CloudControllerService {
             Runnable r = new Runnable() {
                  public void run() {
                      ClusterContext ctxt = dataHolder.getClusterContext(clusterId_);
+                     if(ctxt == null) {
+                    	 String msg = "Unregistration of service cluster failed. Cluster not found: " + clusterId_;
+                    	 log.error(msg);
+                     }
                      Collection<Member> members = TopologyManager.getTopology().
                              getService(ctxt.getCartridgeType()).getCluster(clusterId_).getMembers();
-                     while(members.size() > 0) {
-                        //waiting until all the members got removed from the Topology
+                     long endTime = System.currentTimeMillis() + ctxt.getTimeoutInMillis() * members.size();
+                     
+                     while(members.size() > 0 && System.currentTimeMillis()< endTime) {
+                        //waiting until all the members got removed from the Topology/ timed out
                         CloudControllerUtil.sleep(1000);
                      }
-                    if(ctxt == null) {
-                        String msg = "Unregistration of service cluster failed. Cluster not found: " + clusterId_;
-                        log.error(msg);
-                    }
+                     
+                     // if there're still alive members
+                     if(members.size() > 0) {
+                    	 //forcefully terminate them
+                    	 for (Member member : members) {
+							
+                    		 try {
+								terminateInstance(member.getMemberId());
+							} catch (Exception e) {
+								// we are not gonna stop the execution due to errors.
+								log.warn("Instance termination failed of member [id] "+member.getMemberId(), e);
+							}
+						}
+                     }
+                     
                      log.info("Unregistration of service cluster: " + clusterId_);
                      if(ctxt.shouldDeleteVolume()) {
                     	 Cartridge cartridge = dataHolder.getCartridge(ctxt.getCartridgeType());

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9754664a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
index 7ec4dd3..96a2a1d 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
@@ -42,18 +42,16 @@ public class ClusterContext implements Serializable{
     private String deviceName;
     // optional volume id
     private String volumeId;
+    // timeout in milliseconds - this would be the per member time that CC waits before forcefully terminate instances on an unregistration.
+    private long timeoutInMillis;
 
     public ClusterContext(String clusterId, String cartridgeType, String payload, String hostName, 
-    		boolean isLbCluster, boolean isVolumeRequired, boolean shouldDeleteVolume, int volumeSize, String deviceName) {
+    		boolean isLbCluster) {
         this.clusterId = clusterId;
         this.cartridgeType = cartridgeType;
         this.payload = payload;
         this.setHostName(hostName);
         this.isLbCluster = isLbCluster;
-        this.isVolumeRequired = isVolumeRequired;
-        this.shouldDeleteVolume = shouldDeleteVolume;
-        this.volumeSize = volumeSize;
-        this.deviceName = deviceName;
     }
     
     public String getClusterId() {
@@ -131,4 +129,12 @@ public class ClusterContext implements Serializable{
 		this.deviceName = deviceName;
 	}
 
+	public long getTimeoutInMillis() {
+		return timeoutInMillis;
+	}
+
+	public void setTimeoutInMillis(long timeoutInMillis) {
+		this.timeoutInMillis = timeoutInMillis;
+	}
+
 }