stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [35/50] [abbrv] git commit: initial parent to child status notification
Date Thu, 30 Oct 2014 04:13:59 GMT
initial parent to child status notification


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

Branch: refs/heads/docker-grouping-merge
Commit: ff315c990eb33532bcd28eecba32d2b86256991c
Parents: 3b51d5c
Author: Isuru Haththotuwa <isuruh@apache.org>
Authored: Wed Oct 29 15:13:47 2014 +0530
Committer: Isuru Haththotuwa <isuruh@apache.org>
Committed: Wed Oct 29 15:16:22 2014 +0530

----------------------------------------------------------------------
 .../AutoscalerTopologyEventReceiver.java        |  2 +-
 .../monitor/AbstractClusterMonitor.java         |  2 +-
 .../autoscaler/monitor/EventHandler.java        | 11 ++++--
 .../monitor/MonitorStatusEventBuilder.java      |  8 +++--
 .../monitor/ParentComponentMonitor.java         | 35 ++++++++++++++++++++
 .../monitor/application/ApplicationMonitor.java |  9 ++---
 .../monitor/cluster/ClusterMonitor.java         |  7 +++-
 .../autoscaler/monitor/group/GroupMonitor.java  |  9 +++--
 8 files changed, 67 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/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 ac8b6c9..8c2d1a1 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
@@ -470,7 +470,7 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
 
 //        topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener() {
 //            @Override
-//            protected void onEvent(Event event) {
+//            protected void onChildEvent(Event event) {
 //
 //                log.info("[ApplicationRemovedEvent] Received: " + event.getClass());
 //

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
index 1461b6e..1eda837 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
@@ -248,7 +248,7 @@ abstract public class AbstractClusterMonitor extends Monitor implements
Runnable
     }
 
     @Override
-    public void onEvent(MonitorStatusEvent statusEvent) {
+    public void onChildEvent(MonitorStatusEvent statusEvent) {
 
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java
index e4eb816..06c722c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java
@@ -27,11 +27,18 @@ import org.apache.stratos.autoscaler.monitor.events.MonitorTerminateAllEvent;
  */
 public interface EventHandler {
     /**
-     * Triggered when an event is received.
+     * Triggered when an event is received from a child.
      *
      * @param statusEvent
      */
-    public abstract void onEvent(MonitorStatusEvent statusEvent);
+    public abstract void onChildEvent(MonitorStatusEvent statusEvent);
+
+    /**
+     * Triggered when an event is received from the parent.
+     *
+     * @param statusEvent
+     */
+    public abstract void onParentEvent(MonitorStatusEvent statusEvent);
 
     /**
      * Triggered when termination decision is made.

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
index fcb0f06..30187ea 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
@@ -50,8 +50,12 @@ public class MonitorStatusEventBuilder {
     }
 
     private static void notifyParent(ParentComponentMonitor parent, MonitorStatusEvent statusEvent)
{
-        parent.onEvent(statusEvent);
+        parent.onChildEvent(statusEvent);
     }
 
-
+    public static void notifyChildren (ParentComponentMonitor parent, MonitorStatusEvent
statusEvent) {
+        for (Monitor activeChildMonitor : parent.getAliasToActiveMonitorsMap().values())
{
+            activeChildMonitor.onParentEvent(statusEvent);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/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 bd50f42..7ad0a43 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
@@ -30,6 +30,8 @@ import org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationCont
 import org.apache.stratos.autoscaler.grouping.topic.StatusEventPublisher;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.status.checker.StatusChecker;
+import org.apache.stratos.messaging.domain.topology.ApplicationStatus;
+import org.apache.stratos.messaging.domain.topology.GroupStatus;
 import org.apache.stratos.messaging.domain.topology.ParentComponent;
 
 import java.util.HashMap;
@@ -111,6 +113,39 @@ public abstract class ParentComponentMonitor extends Monitor {
         }
     }
 
+    @Override
+    public void onParentEvent(MonitorStatusEvent statusEvent) {
+
+        if (statusEvent.getStatus() == GroupStatus.Terminating || statusEvent.getStatus()
==
+                ApplicationStatus.Terminating) {
+
+            // parent monitor is in Terminating state. send Terminating event for all monitors
+            for (Monitor childMonitor : this.getAliasToActiveMonitorsMap().values()) {
+                if (childMonitor.hasActiveMonitors()) {
+                    // this is a Group Monitor, send Group Terminating
+                    StatusEventPublisher.sendGroupTerminatingEvent(appId, childMonitor.getId());
+                    markMonitorAsInactive(childMonitor.getId());
+                } else {
+                    // this is a Cluster Monitor, send Cluster Terminating
+                    StatusEventPublisher.sendClusterTerminatingEvent(appId,
+                            ((AbstractClusterMonitor) childMonitor).getServiceId(),
+                            ((AbstractClusterMonitor) childMonitor).getClusterId());
+                    markMonitorAsInactive(((AbstractClusterMonitor) childMonitor).getClusterId());
+                }
+
+            }
+        }
+    }
+
+    // move to inactive monitors list to use in the Terminated event
+    private synchronized void markMonitorAsInactive (String monitorKey) {
+
+        if (!this.aliasToInActiveMonitorsMap.containsKey(monitorKey)) {
+            this.aliasToInActiveMonitorsMap.put(monitorKey,
+                    this.aliasToActiveMonitorsMap.remove(monitorKey));
+        }
+    }
+
     protected void onChildInActiveEvent(String idOfEvent) {
         List<ApplicationContext> terminationList;
         Monitor monitor;

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/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 77def36..337a5c5 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
@@ -27,6 +27,7 @@ import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 import org.apache.stratos.autoscaler.monitor.MonitorStatusEventBuilder;
 import org.apache.stratos.autoscaler.monitor.ParentComponentMonitor;
+import org.apache.stratos.autoscaler.monitor.events.ApplicationStatusEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorScalingEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorTerminateAllEvent;
@@ -143,14 +144,14 @@ public class ApplicationMonitor extends ParentComponentMonitor {
     public void setStatus(ApplicationStatus status) {
         log.info(String.format("[ApplicationMonitor] %s " +
                 "state changes from %s to %s", id, this.status, status));
-        //if(this.status != status) {
-            this.status = status;
 
-        //}
+       this.status = status;
+       //notify the children about the state change
+       MonitorStatusEventBuilder.notifyChildren(this.parent, new ApplicationStatusEvent(status,
appId));
     }
 
     @Override
-    public void onEvent(MonitorStatusEvent statusEvent) {
+    public void onChildEvent(MonitorStatusEvent statusEvent) {
         monitor(statusEvent);
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/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 b47fb15..b9f6cbf 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
@@ -275,7 +275,12 @@ public class ClusterMonitor extends AbstractClusterMonitor {
     }
 
     @Override
-    public void onEvent(MonitorStatusEvent statusEvent) {
+    public void onChildEvent(MonitorStatusEvent statusEvent) {
 
     }
+
+    @Override
+    public void onParentEvent(MonitorStatusEvent statusEvent) {
+        // doesn't have to do anything since this is not a Parent Monitor
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/ff315c99/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 e6f8495..2fe5ae7 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
@@ -25,9 +25,7 @@ import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.monitor.EventHandler;
 import org.apache.stratos.autoscaler.monitor.MonitorStatusEventBuilder;
 import org.apache.stratos.autoscaler.monitor.ParentComponentMonitor;
-import org.apache.stratos.autoscaler.monitor.events.MonitorScalingEvent;
-import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
-import org.apache.stratos.autoscaler.monitor.events.MonitorTerminateAllEvent;
+import org.apache.stratos.autoscaler.monitor.events.*;
 import org.apache.stratos.autoscaler.status.checker.StatusChecker;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.Group;
@@ -59,7 +57,7 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
     }
 
     @Override
-    public void onEvent(MonitorStatusEvent statusEvent) {
+    public void onChildEvent(MonitorStatusEvent statusEvent) {
         monitor(statusEvent);
     }
 
@@ -150,6 +148,7 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
                 MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, this.status,
this.id);
             }
         //}
-
+        //notify the children about the state change
+        MonitorStatusEventBuilder.notifyChildren(this.parent, new GroupStatusEvent(status,
getId()));
     }
 }


Mime
View raw message