stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [18/50] [abbrv] git commit: fixing issues while terminatnig the child and adding life cycle check for group events
Date Thu, 30 Oct 2014 04:13:42 GMT
fixing issues while terminatnig the child and adding life cycle check for group events


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

Branch: refs/heads/docker-grouping-merge
Commit: 7b4e326440287071d6271f9583caa2c1d947fe26
Parents: 5efc025
Author: reka <rthirunavukkarasu23@gmail.com>
Authored: Tue Oct 28 10:00:21 2014 +0530
Committer: reka <rthirunavukkarasu23@gmail.com>
Committed: Tue Oct 28 10:00:50 2014 +0530

----------------------------------------------------------------------
 .../grouping/topic/StatusEventPublisher.java    | 82 +++++++++++++++++---
 .../AutoscalerTopologyEventReceiver.java        | 12 ++-
 .../stratos/autoscaler/monitor/Monitor.java     |  9 ++-
 .../monitor/ParentComponentMonitor.java         | 11 ++-
 .../monitor/application/ApplicationMonitor.java |  3 +-
 .../monitor/cluster/ClusterMonitor.java         |  6 +-
 .../autoscaler/monitor/group/GroupMonitor.java  |  3 +-
 .../status/checker/StatusChecker.java           | 27 +++++--
 8 files changed, 118 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
index ee75f74..fece506 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
@@ -4,7 +4,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.messaging.broker.publish.EventPublisher;
 import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
-import org.apache.stratos.messaging.domain.topology.ClusterDataHolder;
+import org.apache.stratos.messaging.domain.topology.*;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.application.status.*;
 import org.apache.stratos.messaging.event.application.status.AppStatusApplicationActivatedEvent;
@@ -14,6 +14,7 @@ import org.apache.stratos.messaging.event.application.status.AppStatusApplicatio
 import org.apache.stratos.messaging.event.application.status.AppStatusClusterActivatedEvent;
 import org.apache.stratos.messaging.event.application.status.AppStatusClusterInactivateEvent;
 import org.apache.stratos.messaging.event.application.status.AppStatusGroupActivatedEvent;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 import org.apache.stratos.messaging.util.Constants;
 
 import java.util.Set;
@@ -83,9 +84,25 @@ public class StatusEventPublisher {
                     " [group]: " + groupId);
         }
 
-        AppStatusGroupActivatedEvent groupActivatedEvent = new AppStatusGroupActivatedEvent(appId,
groupId);
+        try {
+            TopologyManager.acquireReadLockForApplication(appId);
+            Application application = TopologyManager.getTopology().getApplication(appId);
+            if(application != null) {
+                Group group = application.getGroupRecursively(groupId);
+                if(group.getStatus().getNextStates().contains(GroupStatus.Active)) {
+                    AppStatusGroupActivatedEvent groupActivatedEvent =
+                            new AppStatusGroupActivatedEvent(appId, groupId);
+
+                    publishEvent(groupActivatedEvent);
+                } else {
+                    log.warn("Active is not in the possible state list of [group] " + groupId);
+                }
+            }
+        } finally {
+            TopologyManager.releaseReadLockForApplication(appId);
+        }
+
 
-        publishEvent(groupActivatedEvent);
     }
 
     public static void sendGroupInActivateEvent(String appId, String groupId) {
@@ -94,11 +111,25 @@ public class StatusEventPublisher {
             log.info("Publishing Group in-activate event for [application]: " + appId +
                     " [group]: " + groupId);
         }
+        try {
+            TopologyManager.acquireReadLockForApplication(appId);
+            Application application = TopologyManager.getTopology().getApplication(appId);
+            if(application != null) {
+                Group group = application.getGroupRecursively(groupId);
+                if(group.getStatus().getNextStates().contains(GroupStatus.Inactive)) {
+                    AppStatusGroupInactivateEvent appStatusGroupInactivateEvent= new
+                            AppStatusGroupInactivateEvent(appId, groupId);
+
+                    publishEvent(appStatusGroupInactivateEvent);
+                } else {
+                    log.warn("InActive is not in the possible state list of [group] " + groupId);
+                }
+            }
+        } finally {
+            TopologyManager.releaseReadLockForApplication(appId);
+        }
 
-        AppStatusGroupInactivateEvent appStatusGroupInactivateEvent= new
-                AppStatusGroupInactivateEvent(appId, groupId);
 
-        publishEvent(appStatusGroupInactivateEvent);
     }
 
     public static void sendGroupTerminatingEvent(String appId, String groupId) {
@@ -107,9 +138,22 @@ public class StatusEventPublisher {
             log.info("Publishing Group terminating event for [application]: " + appId +
                     " [group]: " + groupId);
         }
-
-        AppStatusGroupTerminatingEvent groupInTerminatingEvent = new AppStatusGroupTerminatingEvent(appId,
groupId);
-        publishEvent(groupInTerminatingEvent);
+        try {
+            TopologyManager.acquireReadLockForApplication(appId);
+            Application application = TopologyManager.getTopology().getApplication(appId);
+            if(application != null) {
+                Group group = application.getGroupRecursively(groupId);
+                if(group.getStatus().getNextStates().contains(GroupStatus.Terminating)) {
+                    AppStatusGroupTerminatingEvent groupInTerminatingEvent =
+                            new AppStatusGroupTerminatingEvent(appId, groupId);
+                    publishEvent(groupInTerminatingEvent);
+                } else {
+                    log.warn("Terminating is not in the possible state list of [group] "
+ groupId);
+                }
+            }
+        } finally {
+            TopologyManager.releaseReadLockForApplication(appId);
+        }
     }
 
     public static void sendGroupTerminatedEvent(String appId, String groupId) {
@@ -119,8 +163,24 @@ public class StatusEventPublisher {
                     " [group]: " + groupId);
         }
 
-        AppStatusGroupTerminatedEvent groupInTerminatedEvent = new AppStatusGroupTerminatedEvent(appId,
groupId);
-        publishEvent(groupInTerminatedEvent);
+        try {
+            TopologyManager.acquireReadLockForApplication(appId);
+            Application application = TopologyManager.getTopology().getApplication(appId);
+            if(application != null) {
+                Group group = application.getGroupRecursively(groupId);
+                if(group.getStatus().getNextStates().contains(GroupStatus.Terminated)) {
+                    AppStatusGroupTerminatedEvent groupInTerminatedEvent =
+                            new AppStatusGroupTerminatedEvent(appId, groupId);
+                    publishEvent(groupInTerminatedEvent);
+                } else {
+                    log.warn("Terminated is not in the possible state list of [group] " +
groupId);
+                }
+            }
+        } finally {
+            TopologyManager.releaseReadLockForApplication(appId);
+        }
+
+
     }
 
     public static void sendApplicationActivatedEvent(String appId) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/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 89fe51f..9109d50 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
@@ -210,7 +210,13 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                         (AbstractClusterMonitor) AutoscalerContext.getInstance().getMonitor(clusterId);
 
                 //changing the status in the monitor, will notify its parent monitor
-                clusterMonitor.setStatus(ClusterStatus.Terminating);
+                if (clusterMonitor != null) {
+                    clusterMonitor.setDestroyed(true);
+                    clusterMonitor.terminateAllMembers();
+                    clusterMonitor.setStatus(ClusterStatus.Terminating);
+                } else {
+                    log.warn("No Cluster Monitor found for cluster id " + clusterId);
+                }
 
                 //starting the status checker to decide on the status of it's parent
                 //StatusChecker.getInstance().onClusterStatusChange(clusterId, appId);
@@ -251,7 +257,9 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                 GroupMonitor monitor = (GroupMonitor) appMonitor.findGroupMonitorWithId(groupId);
 
                 //changing the status in the monitor, will notify its parent monitor
-                monitor.setStatus(GroupStatus.Active);
+                if(monitor != null) {
+                    monitor.setStatus(GroupStatus.Active);
+                }
 
             }
         });

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
index 2088351..9ef7d73 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
@@ -75,13 +75,14 @@ public abstract class Monitor implements EventHandler {
 
     public boolean hasActiveMonitors() {
         boolean hasMonitor = false;
-        if(this.aliasToActiveMonitorsMap != null && !this.aliasToActiveMonitorsMap.isEmpty())
{
+        if ((this.aliasToActiveMonitorsMap != null && !this.aliasToActiveMonitorsMap.isEmpty())
||
+                (this.aliasToInActiveMonitorsMap != null && !this.aliasToInActiveMonitorsMap.isEmpty()))
{
             hasMonitor = true;
         }
         return hasMonitor;
     }
 
-    public boolean hasMonitors () {
+    public boolean hasMonitors() {
 
         return this.aliasToActiveMonitorsMap != null || this.aliasToInActiveMonitorsMap !=
null;
     }
@@ -96,8 +97,8 @@ public abstract class Monitor implements EventHandler {
 
     public boolean hasInDependentChild() {
         boolean hasInDepChild = false;
-        for(Monitor monitor : this.aliasToActiveMonitorsMap.values()) {
-            if(!monitor.isDependent()) {
+        for (Monitor monitor : this.aliasToActiveMonitorsMap.values()) {
+            if (!monitor.isDependent()) {
                 hasInDepChild = true;
                 break;
             }

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
index 9f3417d..6aa76b6 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
@@ -116,7 +116,7 @@ public abstract class ParentComponentMonitor extends Monitor {
         List<ApplicationContext> terminationList;
         Monitor monitor;
         //Temporarily move the group/cluster to inactive list
-        this.aliasToInActiveMonitorsMap.put(idOfEvent, this.aliasToActiveMonitorsMap.remove(idOfEvent));
+        //this.aliasToInActiveMonitorsMap.put(idOfEvent, this.aliasToActiveMonitorsMap.remove(idOfEvent));
 
         if(this.hasDependent) {
             //need to notify the parent
@@ -171,18 +171,20 @@ public abstract class ParentComponentMonitor extends Monitor {
         context.setTerminated(true);
 
         terminationList = this.dependencyTree.getTerminationDependencies(idOfEvent);
+
+
         /**
          * Make sure that all the dependents have been terminated properly to start the recovery
          */
         if (terminationList != null) {
             for (ApplicationContext context1 : terminationList) {
-                if (this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
+                if (!this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
                     allDependentTerminated = false;
                 } else if (this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
                     log.warn("Dependent [monitor] " + context1.getId() + " not in the correct
state");
                     allDependentTerminated = false;
                 } else {
-                    allDependentTerminated = true;
+                    log.info("Waiting for the [dependent] " + context1.getId() + " to be
terminated...");
                 }
             }
         }
@@ -213,11 +215,12 @@ public abstract class ParentComponentMonitor extends Monitor {
             //Find the non existent monitor by traversing dependency tree
 
             try {
-                this.startDependency();
+                this.startDependencyOnTermination();
             } catch (TopologyInConsistentException e) {
                 e.printStackTrace();
             }
         } else {
+            StatusChecker.getInstance().onChildStatusChange(idOfEvent, this.id, this.appId);
             log.info("Waiting for the dependent of [monitor] " + idOfEvent
                     + " to be terminated");
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
index 45530c5..66044ef 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
@@ -179,8 +179,7 @@ public class ApplicationMonitor extends ParentComponentMonitor {
         } else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated)
{
             //Check whether all dependent goes Terminated and then start them in parallel.
             this.aliasToInActiveMonitorsMap.remove(id);
-            if (this.status != ApplicationStatus.Terminating && !this.aliasToInActiveMonitorsMap.isEmpty()
&&
-                    !this.aliasToActiveMonitorsMap.isEmpty()) {
+            if (this.status != ApplicationStatus.Terminating) {
                 onChildTerminatedEvent(id);
             } else {
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/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 557fedb..a089fc6 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
@@ -72,12 +72,12 @@ public class ClusterMonitor extends AbstractClusterMonitor {
     @Override
     public void run() {
         while (!isDestroyed()) {
-            if (log.isDebugEnabled()) {
-                log.debug("Cluster monitor is running.. " + this.toString());
-            }
             try {
                 if ((this.status.getCode() <= ClusterStatus.Active.getCode()) ||
                         (this.status == ClusterStatus.Inactive && !hasDependent))
{
+                    if (log.isDebugEnabled()) {
+                        log.debug("Cluster monitor is running.. " + this.toString());
+                    }
                     monitor();
                 } else {
                     if (log.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
index 3123782..dff0bba 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
@@ -94,8 +94,7 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
         } else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated)
{
             //Check whether all dependent goes Terminated and then start them in parallel.
             this.aliasToInActiveMonitorsMap.remove(id);
-            if (this.status != GroupStatus.Terminating && !this.aliasToInActiveMonitorsMap.isEmpty()
&&
-                    !this.aliasToActiveMonitorsMap.isEmpty()) {
+            if (this.status != GroupStatus.Terminating) {
                 onChildTerminatedEvent(id);
             } else {
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);

http://git-wip-us.apache.org/repos/asf/stratos/blob/7b4e3264/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 7b3e0ac..acf6d71 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
@@ -289,8 +289,8 @@ public class StatusChecker {
                     //send the in activation event
                     if (parent instanceof Application) {
                         //send application activated event
-                        log.info("sending app in-active : " + appId);
-                    StatusEventPublisher.sendApplicationInactivatedEvent(appId);
+                        log.warn("Application can't be in in-active : " + appId);
+                    //StatusEventPublisher.sendApplicationInactivatedEvent(appId);
                 } else if (parent instanceof Group) {
                     //send activation to the parent
                     log.info("sending group in-active: " + parent.getUniqueIdentifier());
@@ -301,9 +301,22 @@ public class StatusChecker {
                     groupStatus == GroupStatus.Terminated && clusterStatus == ClusterStatus.Terminated)
{
                     //send the terminated event
                 if (parent instanceof Application) {
-                    //send application activated event
-                    log.info("sending app terminated: " + appId);
-                    StatusEventPublisher.sendApplicationTerminatedEvent(appId, parent.getClusterDataRecursively());
+                    //validating the life cycle
+                    try {
+                        TopologyManager.acquireReadLockForApplication(appId);
+                        Application application = TopologyManager.getTopology().getApplication(appId);
+                        if(application.getStatus().equals(ApplicationStatus.Terminating))
{
+                            log.info("sending app terminated: " + appId);
+                            StatusEventPublisher.sendApplicationTerminatedEvent(appId, parent.getClusterDataRecursively());
+                        } else {
+                            log.info("[Application] " + appId + " is in the [status] " +
+                                    application.getStatus().toString() + ". Hence not sending
terminated event");
+                        }
+
+                    } finally {
+                        TopologyManager.releaseReadLockForApplication(appId);
+                    }
+
                     //StatusEventPublisher.sendApp(appId);
                 } else if (parent instanceof Group) {
                     //send activation to the parent
@@ -316,8 +329,8 @@ public class StatusChecker {
                 //send the terminated event
                 if (parent instanceof Application) {
                     //send application activated event
-                    log.info("sending app terminating: " + appId);
-                    StatusEventPublisher.sendApplicationTerminatingEvent(appId);
+                    log.warn("Application can't be in terminating: " + appId);
+                    //StatusEventPublisher.sendApplicationTerminatingEvent(appId);
                     //StatusEventPublisher.sendApp(appId);
                 } else if (parent instanceof Group) {
                     //send activation to the parent


Mime
View raw message