stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject git commit: adding eventing support for monitors
Date Tue, 07 Oct 2014 12:56:30 GMT
Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 4bd661ede -> 2536b30b3


adding eventing support for monitors


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

Branch: refs/heads/4.0.0-grouping
Commit: 2536b30b3933dff9fc9f67420cae45f494e5eaf2
Parents: 4bd661e
Author: reka <rthirunavukkarasu23@gmail.com>
Authored: Tue Oct 7 18:26:12 2014 +0530
Committer: reka <rthirunavukkarasu23@gmail.com>
Committed: Tue Oct 7 18:26:12 2014 +0530

----------------------------------------------------------------------
 .../grouping/dependency/DependencyBuilder.java  |  11 +-
 .../dependency/context/ApplicationContext.java  |  15 ++
 .../AutoscalerTopologyEventReceiver.java        |   4 +-
 .../monitor/AbstractClusterMonitor.java         |  51 ++++---
 .../autoscaler/monitor/EventHandler.java        |  33 +++++
 .../stratos/autoscaler/monitor/Monitor.java     | 137 ++++++++++---------
 .../monitor/MonitorStatusEventBuilder.java      |  55 ++++++++
 .../monitor/application/ApplicationMonitor.java | 104 +++++++++++---
 .../monitor/cluster/ClusterMonitor.java         |  51 +++----
 .../events/ApplicationActivatedEvent.java       |  42 ------
 .../monitor/events/ApplicationStatusEvent.java  |  36 +++++
 .../monitor/events/ClusterActivatedEvent.java   |  54 --------
 .../events/ClusterInMaintenanceEvent.java       |  25 ----
 .../monitor/events/ClusterStatusEvent.java      |  36 +++++
 .../monitor/events/GroupActivatedEvent.java     |  48 -------
 .../monitor/events/GroupInMaintenanceEvent.java |  25 ----
 .../monitor/events/GroupStatusEvent.java        |  31 +++++
 .../autoscaler/monitor/events/MonitorEvent.java |  27 ----
 .../monitor/events/MonitorStatusEvent.java      |  27 ++--
 .../autoscaler/monitor/group/GroupMonitor.java  |  74 ++++++----
 20 files changed, 498 insertions(+), 388 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
index 6d1eee3..59b9bf8 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
@@ -54,14 +54,19 @@ public class DependencyBuilder {
      * @return the dependency tree out of the dependency orders
      */
     public DependencyTree buildDependency(ParentBehavior component) {
-        Group group = (Group) component;
-        DependencyTree dependencyTree = new DependencyTree(group.getAlias());
+        String alias = null;
+        if(component instanceof Application) {
+            alias = ((Application)component).getId();
+        } else if(component instanceof Group) {
+            alias = ((Group) component).getAlias();
+        }
+        DependencyTree dependencyTree = new DependencyTree(alias);
         DependencyOrder dependencyOrder = component.getDependencyOrder();
 
         if (dependencyOrder != null) {
             if (log.isDebugEnabled()) {
                 log.debug("Building dependency for the Application/Group " +
-                        group.getAlias());
+                        alias);
             }
 
             //Parsing the kill behaviour

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
index d9b6df8..f923bb0 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
@@ -35,10 +35,13 @@ public abstract class ApplicationContext {
 
     private Status status;
 
+    private List<Status> statusLifeCycle;
+
     protected boolean killDependent;
 
     public ApplicationContext(String id, boolean killDependent) {
         applicationContextList = new ArrayList<ApplicationContext>();
+        statusLifeCycle = new ArrayList<Status>();
         this.killDependent = killDependent;
         this.id = id;
     }
@@ -56,6 +59,10 @@ public abstract class ApplicationContext {
 
     }
 
+    public void addStatusToLIfeCycle(Status status) {
+       this.statusLifeCycle.add(status);
+    }
+
     public String getId() {
         return id;
     }
@@ -71,4 +78,12 @@ public abstract class ApplicationContext {
     public void setStatus(Status status) {
         this.status = status;
     }
+
+    public List<Status> getStatusLifeCycle() {
+        return statusLifeCycle;
+    }
+
+    public void setStatusLifeCycle(List<Status> statusLifeCycle) {
+        this.statusLifeCycle = statusLifeCycle;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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 627b648..3e1bfe2 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
@@ -582,7 +582,7 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                     }
                     applicationMonitor = AutoscalerUtil.getApplicationMonitor(application);
                     long end = System.currentTimeMillis();
-                    log.info("Time taken to start app monitor: " + (end - start)/1000);
+                    log.info("Time taken to start Napp monitor: " + (end - start)/1000);
                     success = true;
                     //TODO exception handling
                 } catch (Exception e) {
@@ -594,7 +594,7 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
 
             if (applicationMonitor == null) {
                 String msg = "Application monitor creation failed, even after retrying for 5 times, "
-                        + "for Application: " + applicationMonitor.getId();
+                        + "for Application: " + application.getId();
                 log.error(msg);
                 throw new RuntimeException(msg);
             }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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 ae47f63..d48fdb4 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
@@ -18,18 +18,14 @@
  */
 package org.apache.stratos.autoscaler.monitor;
 
-import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
-import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
-
-import java.util.Map;
-import java.util.Observable;
-import java.util.Observer;
-
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.NetworkPartitionContext;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.autoscaler.monitor.events.ClusterStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
+import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
 import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
 import org.apache.stratos.autoscaler.util.AutoScalerConstants;
 import org.apache.stratos.autoscaler.util.ConfUtil;
@@ -41,12 +37,14 @@ import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 import org.drools.runtime.StatefulKnowledgeSession;
 import org.drools.runtime.rule.FactHandle;
 
+import java.util.Map;
+
 /**
  * Is responsible for monitoring a service cluster. This runs periodically
  * and perform minimum instance check and scaling check using the underlying
  * rules engine.
  */
-abstract public class AbstractClusterMonitor extends Observable implements Observer, Runnable {
+abstract public class AbstractClusterMonitor implements EventHandler, Runnable {
 
     private static final Log log = LogFactory.getLog(AbstractClusterMonitor.class);
     // Map<NetworkpartitionId, Network Partition Context>
@@ -70,6 +68,8 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser
 
     protected Status status;
 
+    protected Monitor parent;
+
     protected AutoscalerRuleEvaluator autoscalerRuleEvaluator;
 
     // time intereval between two runs of the Monitor. Default is 90000ms.
@@ -79,7 +79,7 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser
         readConfigurations();
     }
 
-    private void readConfigurations () {
+    private void readConfigurations() {
 
         XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
         monitorInterval = conf.getInt(AutoScalerConstants.AUTOSCALER_MONITOR_INTERVAL, 90000);
@@ -97,7 +97,7 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser
     public NetworkPartitionContext getNetworkPartitionCtxt(Member member) {
         log.info("***** getNetworkPartitionCtxt " + member.getNetworkPartitionId());
         String networkPartitionId = member.getNetworkPartitionId();
-        if(networkPartitionCtxts.containsKey(networkPartitionId)) {
+        if (networkPartitionCtxts.containsKey(networkPartitionId)) {
             log.info("returnnig network partition context " + networkPartitionCtxts.get(networkPartitionId));
             return networkPartitionCtxts.get(networkPartitionId);
         }
@@ -105,10 +105,10 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser
         return null;
     }
 
-    public String getPartitionOfMember(String memberId){
-        for(Service service: TopologyManager.getTopology().getServices()){
-            for(Cluster cluster: service.getClusters()){
-                if(cluster.memberExists(memberId)){
+    public String getPartitionOfMember(String memberId) {
+        for (Service service : TopologyManager.getTopology().getServices()) {
+            for (Cluster cluster : service.getClusters()) {
+                if (cluster.memberExists(memberId)) {
                     return cluster.getMember(memberId).getPartitionId();
                 }
             }
@@ -232,11 +232,6 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser
         this.terminateDependencyFactHandle = terminateDependencyFactHandle;
     }
 
-    @Override
-    public void update(Observable observable, Object o) {
-            //get the update from parent monitor
-    }
-
     public int getMonitorInterval() {
         return monitorInterval;
     }
@@ -249,7 +244,21 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser
         log.info(String.format("[Monitor] %s is notifying the parent" +
                 "on its state change from %s to %s", clusterId, this.status, status));
         this.status = status;
-        setChanged();
-        notifyObservers(new MonitorStatusEvent(status, clusterId));
+        //notifying the parent monitor about the state change
+        MonitorStatusEventBuilder.handleClusterStatusEvent(this.parent, this.status, this.clusterId);
+
+    }
+
+    public Monitor getParent() {
+        return parent;
+    }
+
+    public void setParent(Monitor parent) {
+        this.parent = parent;
+    }
+
+    @Override
+    public void onEvent(MonitorStatusEvent statusEvent) {
+
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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
new file mode 100644
index 0000000..b1ba90f
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.autoscaler.monitor;
+
+import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
+
+/**
+ * Event Handler to notify the observer/to receive notification
+ */
+public interface EventHandler {
+    /**
+     * Triggered when an event is received.
+     *
+     * @param statusEvent
+     */
+    public abstract void onEvent(MonitorStatusEvent statusEvent);
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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 a75df54..0554406 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
@@ -30,9 +30,11 @@ import org.apache.stratos.autoscaler.grouping.dependency.context.ClusterContext;
 import org.apache.stratos.autoscaler.grouping.dependency.context.GroupContext;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.cluster.LbClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
 import org.apache.stratos.autoscaler.util.AutoscalerUtil;
 import org.apache.stratos.messaging.domain.topology.*;
+import org.apache.stratos.messaging.event.application.status.StatusEvent;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
 import java.util.*;
@@ -44,35 +46,35 @@ import java.util.concurrent.TimeUnit;
  * Monitor is to monitor it's child monitors and
  * control them according to the dependencies respectively.
  */
-public abstract class Monitor extends Observable implements Observer {
+public abstract class Monitor implements EventHandler {
     private static final Log log = LogFactory.getLog(Monitor.class);
 
+    //id of the monitor, it can be alias or the id
     protected String id;
-
+    //GroupMonitor map, key=GroupAlias and value=GroupMonitor
     protected Map<String, GroupMonitor> aliasToGroupMonitorsMap;
-
+    //AbstractMonitor map, key=clusterId and value=AbstractMonitors
     protected Map<String, AbstractClusterMonitor> clusterIdToClusterMonitorsMap;
-
-    protected Map<String, ScheduledExecutorService> clusterIdToExecutorServiceMap;
-
-    private Map<String, ScheduledExecutorService> adderIdToExecutorServiceMap;
-
+    //The monitors dependency tree with all the startable/killable dependencies
     protected DependencyTree dependencyTree;
-
+    //application/group reference from the Topology
     protected ParentBehavior component;
-
+    //status of the monitor whether it is running/in_maintainable/terminated
     protected Status status;
 
     public Monitor(ParentBehavior component) {
         aliasToGroupMonitorsMap = new HashMap<String, GroupMonitor>();
         clusterIdToClusterMonitorsMap = new HashMap<String, AbstractClusterMonitor>();
-        clusterIdToExecutorServiceMap = new HashMap<String, ScheduledExecutorService>();
-        adderIdToExecutorServiceMap = new HashMap<String, ScheduledExecutorService>();
         //preOrderTraverse = new LinkedList<String>();
         this.component = component;
         dependencyTree = DependencyBuilder.getInstance().buildDependency(component);
     }
 
+    /**
+     *
+     */
+    protected abstract void monitor(MonitorStatusEvent statusEvent);
+
 
     /**
      * This will start the parallel dependencies at once from the top level.
@@ -88,6 +90,7 @@ public abstract class Monitor extends Observable implements Observer {
 
     /**
      * This will get invoked based on the activation event of its one of the child
+     *
      * @param id alias/clusterId of which receive the activated event
      */
     public void startDependency(String id) {
@@ -95,10 +98,15 @@ public abstract class Monitor extends Observable implements Observer {
         startDependency(applicationContexts);
     }
 
+    /**
+     * To start the dependency of the given application contexts
+     *
+     * @param applicationContexts the found applicationContexts to be started
+     */
     private void startDependency(List<ApplicationContext> applicationContexts) {
-        if(applicationContexts == null) {
+        if (applicationContexts == null) {
             //all the groups/clusters have been started and waiting for activation
-            log.warn("There is no child found for the [group]: " + this.id );
+            log.warn("There is no child found for the [group]: " + this.id);
         }
         for (ApplicationContext context : applicationContexts) {
             if (log.isDebugEnabled()) {
@@ -150,10 +158,10 @@ public abstract class Monitor extends Observable implements Observer {
             }
         }
         if (adder != null) {
-            adderIdToExecutorServiceMap.put(cluster.getClusterId(), adder);
+            //adderIdToExecutorServiceMap.put(cluster.getClusterId(), adder);
             log.info(String
-                        .format("Cluster monitor thread has been started successfully: [cluster] %s ",
-                                cluster.getClusterId()));
+                    .format("Cluster monitor thread has been started successfully: [cluster] %s ",
+                            cluster.getClusterId()));
         }
     }
 
@@ -176,10 +184,10 @@ public abstract class Monitor extends Observable implements Observer {
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }*/
-            adderIdToExecutorServiceMap.put(((Group)component).getAlias(), adder);
+            //adderIdToExecutorServiceMap.put(((Group)component).getAlias(), adder);
             log.info(String
-                        .format("Group monitor thread has been started successfully: [group] %s ",
-                                dependency));
+                    .format("Group monitor thread has been started successfully: [group] %s ",
+                            dependency));
         }
     }
 
@@ -187,12 +195,36 @@ public abstract class Monitor extends Observable implements Observer {
         return status;
     }
 
-    public Map<String, ScheduledExecutorService> getAdderIdToExecutorServiceMap() {
-        return adderIdToExecutorServiceMap;
+    public Map<String, GroupMonitor> getAliasToGroupMonitorsMap() {
+        return aliasToGroupMonitorsMap;
     }
 
-    public void setAdderIdToExecutorServiceMap(Map<String, ScheduledExecutorService> adderIdToExecutorServiceMap) {
-        this.adderIdToExecutorServiceMap = adderIdToExecutorServiceMap;
+    public void setAliasToGroupMonitorsMap(Map<String, GroupMonitor> aliasToGroupMonitorsMap) {
+        this.aliasToGroupMonitorsMap = aliasToGroupMonitorsMap;
+    }
+
+    public String getId() {
+        return this.id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Map<String, AbstractClusterMonitor> getClusterIdToClusterMonitorsMap() {
+        return clusterIdToClusterMonitorsMap;
+    }
+
+    public void setClusterIdToClusterMonitorsMap(Map<String, AbstractClusterMonitor> clusterIdToClusterMonitorsMap) {
+        this.clusterIdToClusterMonitorsMap = clusterIdToClusterMonitorsMap;
+    }
+
+    public void addAbstractMonitor(AbstractClusterMonitor monitor) {
+        this.clusterIdToClusterMonitorsMap.put(monitor.getClusterId(), monitor);
+    }
+
+    public AbstractClusterMonitor getAbstractMonitor(String clusterId) {
+        return this.clusterIdToClusterMonitorsMap.get(clusterId);
     }
 
     private class ClusterMonitorAdder implements Runnable {
@@ -214,12 +246,13 @@ public abstract class Monitor extends Observable implements Observer {
                 } catch (InterruptedException e1) {
                 }*/
                 try {
-                    if(log.isDebugEnabled()) {
+                    if (log.isDebugEnabled()) {
                         log.debug("CLuster monitor is going to be started for [cluster] "
                                 + cluster.getClusterId());
                     }
                     monitor = AutoscalerUtil.getClusterMonitor(cluster);
-                    monitor.addObserver(parent);
+                    monitor.setParent(parent);
+                    //monitor.addObserver(parent);
                     success = true;
                     //TODO start the status checker
                 } catch (PolicyValidationException e) {
@@ -238,7 +271,7 @@ public abstract class Monitor extends Observable implements Observer {
             } while (!success && retries != 0);
 
 
-                    if (monitor == null) {
+            if (monitor == null) {
                 String msg = "Cluster monitor creation failed, even after retrying for 5 times, "
                         + "for cluster: " + cluster.getClusterId();
                 log.error(msg);
@@ -273,19 +306,20 @@ public abstract class Monitor extends Observable implements Observer {
             GroupMonitor monitor = null;
             int retries = 5;
             boolean success = false;
-             do {
-                 try {
-                     Thread.sleep(5000);
-                 } catch (InterruptedException e1) {
-                 }
+            do {
+                try {
+                    Thread.sleep(5000);
+                } catch (InterruptedException e1) {
+                }
 
                 try {
-                    if(log.isDebugEnabled()) {
+                    if (log.isDebugEnabled()) {
                         log.debug("Group monitor is going to be started for [group] "
                                 + dependency);
                     }
                     monitor = AutoscalerUtil.getGroupMonitor(component.getGroup(dependency));
-                    monitor.addObserver(parent);
+                    monitor.setParent(parent);
+                    //monitor.addObserver(parent);
                     success = true;
 
                 } catch (Exception e) {
@@ -306,7 +340,7 @@ public abstract class Monitor extends Observable implements Observer {
             }
 
             aliasToGroupMonitorsMap.put(dependency, monitor);
-            parent.addObserver(monitor);
+            //parent.addObserver(monitor);
 
             if (log.isInfoEnabled()) {
                 log.info(String.format("Group monitor has been added successfully: [group] %s",
@@ -366,37 +400,4 @@ public abstract class Monitor extends Observable implements Observer {
     }
 
 
-    public Map<String, GroupMonitor> getAliasToGroupMonitorsMap() {
-        return aliasToGroupMonitorsMap;
-    }
-
-    public String getId() {
-        return this.id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public void setAliasToGroupMonitorsMap(Map<String, GroupMonitor> aliasToGroupMonitorsMap) {
-        this.aliasToGroupMonitorsMap = aliasToGroupMonitorsMap;
-    }
-
-    public Map<String, AbstractClusterMonitor> getClusterIdToClusterMonitorsMap() {
-        return clusterIdToClusterMonitorsMap;
-    }
-
-    public void addAbstractMonitor(AbstractClusterMonitor monitor) {
-        this.clusterIdToClusterMonitorsMap.put(monitor.getClusterId(), monitor);
-    }
-
-    public AbstractClusterMonitor getAbstractMonitor(String clusterId) {
-        return this.clusterIdToClusterMonitorsMap.get(clusterId);
-    }
-
-    public void setClusterIdToClusterMonitorsMap(Map<String, AbstractClusterMonitor> clusterIdToClusterMonitorsMap) {
-        this.clusterIdToClusterMonitorsMap = clusterIdToClusterMonitorsMap;
-    }
-
-
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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
new file mode 100644
index 0000000..a3f9e8f
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.autoscaler.monitor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.monitor.events.ApplicationStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.ClusterStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.GroupStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
+import org.apache.stratos.messaging.domain.topology.Status;
+
+/**
+ * This will build the necessary monitor status events to be sent to the parent/child  monitor
+ */
+public class MonitorStatusEventBuilder {
+    private static final Log log = LogFactory.getLog(MonitorStatusEventBuilder.class);
+
+    public static void handleClusterStatusEvent(Monitor parent, Status status, String clusterId) {
+        ClusterStatusEvent clusterStatusEvent = new ClusterStatusEvent(status, clusterId);
+        notifyParent(parent, clusterStatusEvent);
+    }
+
+    public static void handleGroupStatusEvent(Monitor parent, Status status, String groupId) {
+        GroupStatusEvent groupStatusEvent = new GroupStatusEvent(status, groupId);
+        notifyParent(parent, groupStatusEvent);
+    }
+
+    public static void handleApplicationStatusEvent(Monitor parent, Status status, String appId) {
+        ApplicationStatusEvent applicationStatusEvent = new ApplicationStatusEvent(status, appId);
+        notifyParent(parent, applicationStatusEvent);
+    }
+
+    private static void notifyParent(Monitor parent, MonitorStatusEvent statusEvent) {
+       parent.onEvent(statusEvent);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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 30b8727..a0f0a39 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
@@ -20,6 +20,7 @@ package org.apache.stratos.autoscaler.monitor.application;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
 import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
@@ -30,7 +31,6 @@ import org.apache.stratos.messaging.domain.topology.Status;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.Observable;
 
 /**
  * ApplicationMonitor is to control the child monitors
@@ -44,10 +44,10 @@ public class ApplicationMonitor extends Monitor {
         startDependency();
     }
 
-    @Override
+    /*@Override
     public void update(Observable observable, Object event) {
-        if (event instanceof MonitorStatusEvent) {
-            MonitorStatusEvent statusEvent = (MonitorStatusEvent) event;
+        if (event instanceof MonitorStatusEvent1111) {
+            MonitorStatusEvent1111 statusEvent = (MonitorStatusEvent1111) event;
             Status childStatus = statusEvent.getStatus();
             String notifier = statusEvent.getNotifierId();
             log.info(String.format("[Monitor] %s got notified from the [child] %s" +
@@ -59,20 +59,15 @@ public class ApplicationMonitor extends Monitor {
                 startDependency(notifier);
             }
         }
-    }
+    }*/
 
 
     /**
-     * Find the group monitor by traversing recursively in the hierarchical monitors.
+     * To find all the clusters of an application
      *
-     * @param groupId the unique alias of the Group
-     * @return the found GroupMonitor
+     * @param appId the application which contains the clusters
+     * @return all the clusters of the application
      */
-    public GroupMonitor findGroupMonitorWithId(String groupId) {
-        return findGroupMonitor(groupId, aliasToGroupMonitorsMap.values());
-
-    }
-
     public List<String> findClustersOfApplication(String appId) {
         List<String> clusters = new ArrayList<String>();
         //considering only one level
@@ -84,18 +79,26 @@ public class ApplicationMonitor extends Monitor {
 
     }
 
-
     /**
      * Find the cluster monitor by traversing recursively in the hierarchical monitors.
      *
-     * @param clusterId
-     * @return
+     * @param clusterId cluster id of the monitor to be searched
+     * @return the found cluster monitor
      */
     public AbstractClusterMonitor findClusterMonitorWithId(String clusterId) {
-        return findClusterMonitor(clusterId, clusterIdToClusterMonitorsMap.values(), aliasToGroupMonitorsMap.values());
+        return findClusterMonitor(clusterId, clusterIdToClusterMonitorsMap.values(),
+                aliasToGroupMonitorsMap.values());
 
     }
 
+    /**
+     * utility method to recursively search for cluster monitors in the App monitor
+     *
+     * @param clusterId       cluster id of the monitor to be searched
+     * @param clusterMonitors cluster monitors found in the app Monitor
+     * @param groupMonitors   group monitors found in the app monitor
+     * @return the found cluster monitor
+     */
     private AbstractClusterMonitor findClusterMonitor(String clusterId,
                                                       Collection<AbstractClusterMonitor> clusterMonitors,
                                                       Collection<GroupMonitor> groupMonitors) {
@@ -115,6 +118,25 @@ public class ApplicationMonitor extends Monitor {
 
     }
 
+    /**
+     * Find the group monitor by traversing recursively in the hierarchical monitors.
+     *
+     * @param groupId the unique alias of the Group
+     * @return the found GroupMonitor
+     */
+    public GroupMonitor findGroupMonitorWithId(String groupId) {
+        return findGroupMonitor(groupId, aliasToGroupMonitorsMap.values());
+
+    }
+
+
+    /**
+     * Utility method to find the group monitor recursively within app monitor
+     *
+     * @param id       the unique alias of the Group
+     * @param monitors the group monitors found in the app monitor
+     * @return the found GroupMonitor
+     */
     private GroupMonitor findGroupMonitor(String id, Collection<GroupMonitor> monitors) {
         for (GroupMonitor monitor : monitors) {
             // check if alias is equal, if so, return
@@ -131,10 +153,23 @@ public class ApplicationMonitor extends Monitor {
     }
 
 
+    /**
+     * To find the parent monitor of a group's associate monitor
+     *
+     * @param groupId the id of the group
+     * @return the found parent monitor of the group
+     */
     public Monitor findParentMonitorOfGroup(String groupId) {
         return findParentMonitorForGroup(groupId, this);
     }
 
+    /**
+     * Find the parent monitor of the given group in the app monitor
+     *
+     * @param groupId the id of the group
+     * @param monitor the app monitor
+     * @return the found parent monitor of the group
+     */
     private Monitor findParentMonitorForGroup(String groupId, Monitor monitor) {
         //if this monitor has the group, return it as the parent
         if (monitor.getAliasToGroupMonitorsMap().containsKey(groupId)) {
@@ -152,10 +187,23 @@ public class ApplicationMonitor extends Monitor {
 
     }
 
+    /**
+     * Find the parent monitor of the given cluster in the app monitor
+     *
+     * @param clusterId the id of the cluster
+     * @return the found parent monitor of the cluster
+     */
     public Monitor findParentMonitorOfCluster(String clusterId) {
         return findParentMonitorForCluster(clusterId, this);
     }
 
+    /**
+     * Find the parent monitor of the given cluster in the app monitor
+     *
+     * @param clusterId the id of the cluster
+     * @param monitor   the app monitor
+     * @return the found parent monitor of the cluster
+     */
     private Monitor findParentMonitorForCluster(String clusterId, Monitor monitor) {
         //if this monitor has the group, return it as the parent
         if (monitor.getClusterIdToClusterMonitorsMap().containsKey(clusterId)) {
@@ -173,9 +221,31 @@ public class ApplicationMonitor extends Monitor {
 
     }
 
+    /**
+     * To set the status of the application monitor
+     *
+     * @param status the status
+     */
     public void setStatus(Status status) {
         log.info(String.format("[ApplicationMonitor] %s " +
                 "state changes from %s to %s", id, this.status, status));
         this.status = status;
     }
+
+    @Override
+    public void onEvent(MonitorStatusEvent statusEvent) {
+        this.monitor(statusEvent);
+    }
+
+    @Override
+    protected void monitor(MonitorStatusEvent statusEvent) {
+        ApplicationContext context = this.dependencyTree.
+                findApplicationContextWithId(statusEvent.getId());
+        if(context.getStatusLifeCycle().isEmpty()) {
+            startDependency(statusEvent.getId());
+        } else {
+            //TODO act based on life cyle events
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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 1189f8f..0c81334 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
@@ -24,13 +24,13 @@ import org.apache.stratos.autoscaler.NetworkPartitionContext;
 import org.apache.stratos.autoscaler.PartitionContext;
 import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
 import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
 import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
 import org.apache.stratos.cloud.controller.stub.pojo.MemberContext;
 import org.apache.stratos.cloud.controller.stub.pojo.Properties;
 import org.apache.stratos.cloud.controller.stub.pojo.Property;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.domain.topology.Status;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -77,32 +77,32 @@ public class ClusterMonitor extends AbstractClusterMonitor {
         } catch (InterruptedException ignore) {
         }*/
         //this.status = Status.Running;
-            while (!isDestroyed()) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Cluster monitor is running.. " + this.toString());
-                }
-                try {
-                    if(!ClusterStatus.In_Maintenance.equals(status)) {
-                        monitor();
-                    } else {
-                        if (log.isDebugEnabled()) {
-                            log.debug("Cluster monitor is suspended as the cluster is in " +
-                                    ClusterStatus.In_Maintenance + " mode......");
-                        }
+        while (!isDestroyed()) {
+            if (log.isDebugEnabled()) {
+                log.debug("Cluster monitor is running.. " + this.toString());
+            }
+            try {
+                if (!ClusterStatus.In_Maintenance.equals(status)) {
+                    monitor();
+                } else {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Cluster monitor is suspended as the cluster is in " +
+                                ClusterStatus.In_Maintenance + " mode......");
                     }
-                } catch (Exception e) {
-                    log.error("Cluster monitor: Monitor failed." + this.toString(), e);
-                }
-                try {
-                    Thread.sleep(monitorInterval);
-                } catch (InterruptedException ignore) {
                 }
+            } catch (Exception e) {
+                log.error("Cluster monitor: Monitor failed." + this.toString(), e);
+            }
+            try {
+                Thread.sleep(monitorInterval);
+            } catch (InterruptedException ignore) {
             }
+        }
 
 
     }
 
-    private boolean isPrimaryMember(MemberContext memberContext){
+    private boolean isPrimaryMember(MemberContext memberContext) {
         Properties props = memberContext.getProperties();
         if (log.isDebugEnabled()) {
             log.debug(" Properties [" + props + "] ");
@@ -133,14 +133,14 @@ public class ClusterMonitor extends AbstractClusterMonitor {
                 List<String> primaryMemberListInPartition = new ArrayList<String>();
                 // get active primary members in this partition context
                 for (MemberContext memberContext : partitionContext.getActiveMembers()) {
-                    if (isPrimaryMember(memberContext)){
+                    if (isPrimaryMember(memberContext)) {
                         primaryMemberListInPartition.add(memberContext.getMemberId());
                     }
                 }
 
                 // get pending primary members in this partition context
                 for (MemberContext memberContext : partitionContext.getPendingMembers()) {
-                    if (isPrimaryMember(memberContext)){
+                    if (isPrimaryMember(memberContext)) {
                         primaryMemberListInPartition.add(memberContext.getMemberId());
                     }
                 }
@@ -185,7 +185,7 @@ public class ClusterMonitor extends AbstractClusterMonitor {
             boolean loadAverageReset = networkPartitionContext.isLoadAverageReset();
 
             if (log.isDebugEnabled()) {
-                log.debug("flag of rifReset: "  + rifReset + " flag of memoryConsumptionReset" + memoryConsumptionReset
+                log.debug("flag of rifReset: " + rifReset + " flag of memoryConsumptionReset" + memoryConsumptionReset
                         + " flag of loadAverageReset" + loadAverageReset);
             }
             if (rifReset || memoryConsumptionReset || loadAverageReset) {
@@ -241,4 +241,9 @@ public class ClusterMonitor extends AbstractClusterMonitor {
     public void setHasPrimary(boolean hasPrimary) {
         this.hasPrimary = hasPrimary;
     }
+
+    @Override
+    public void onEvent(MonitorStatusEvent statusEvent) {
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java
deleted file mode 100644
index 719c94f..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.monitor.events;
-
-import org.apache.stratos.messaging.domain.topology.Status;
-
-/**
- * This will use to notify observers upon a application activation events received in Topology.
- */
-public class ApplicationActivatedEvent extends MonitorEvent {
-    private Status status;
-    private String appId;
-
-    public ApplicationActivatedEvent(Status status, String appId) {
-        this.status = status;
-        this.appId = appId;
-    }
-
-    public Status getStatus() {
-        return status;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationStatusEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationStatusEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationStatusEvent.java
new file mode 100644
index 0000000..783cc7a
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationStatusEvent.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.autoscaler.monitor.events;
+
+import org.apache.stratos.messaging.domain.topology.Status;
+
+/**
+ * This will use to notify observers upon a application activation events received in Topology.
+ */
+public class ApplicationStatusEvent extends MonitorStatusEvent {
+
+    public ApplicationStatusEvent(Status status, String id) {
+        super(status, id);
+    }
+
+    public Status getStatus() {
+        return this.status;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java
deleted file mode 100644
index 54e6407..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.monitor.events;
-
-import org.apache.stratos.messaging.domain.topology.Status;
-
-/**
- * This will use to notify observers upon a cluster activation events received in Topology.
- */
-public class ClusterActivatedEvent extends MonitorEvent {
-    private Status status;
-    private String appId;
-    private String clusterId;
-    private String serviceName;
-
-    public ClusterActivatedEvent(Status status, String appId, String clusterId, String serviceName) {
-        this.status = status;
-        this.appId = appId;
-        this.clusterId = clusterId;
-        this.serviceName = serviceName;
-    }
-
-    public Status getStatus() {
-        return status;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public String getServiceName() {
-        return serviceName;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java
deleted file mode 100644
index 14d322c..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.monitor.events;
-
-/**
- * This will use to notify observers upon a cluster maintenance events received in Topology.
- */
-public class ClusterInMaintenanceEvent extends MonitorEvent {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterStatusEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterStatusEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterStatusEvent.java
new file mode 100644
index 0000000..d05208f
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterStatusEvent.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.autoscaler.monitor.events;
+
+import org.apache.stratos.messaging.domain.topology.Status;
+
+/**
+ * This will use to notify observers upon a cluster activation events received in Topology.
+ */
+public class ClusterStatusEvent extends MonitorStatusEvent {
+
+    public ClusterStatusEvent(Status status, String id) {
+        super(status, id);
+    }
+
+    public Status getStatus() {
+        return super.getStatus();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java
deleted file mode 100644
index cd7d37d..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.monitor.events;
-
-import org.apache.stratos.messaging.domain.topology.Status;
-
-/**
- * This will use to notify observers upon a group activation events received in Topology.
- */
-public class GroupActivatedEvent extends MonitorEvent {
-    private Status status;
-    private String appId;
-    private String groupId;
-
-    public GroupActivatedEvent(Status status, String appId, String groupId) {
-        this.status = status;
-        this.appId = appId;
-        this.groupId = groupId;
-    }
-
-    public Status getStatus() {
-        return status;
-    }
-
-    public String getAppId() {
-        return appId;
-    }
-
-    public String getGroupId() {
-        return groupId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java
deleted file mode 100644
index 163e0d6..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.monitor.events;
-
-/**
- * This will use to notify observers upon a group maintenance events received in Topology.
- */
-public class GroupInMaintenanceEvent extends MonitorEvent {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupStatusEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupStatusEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupStatusEvent.java
new file mode 100644
index 0000000..aa31d73
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupStatusEvent.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.autoscaler.monitor.events;
+
+import org.apache.stratos.messaging.domain.topology.Status;
+
+/**
+ * This will use to notify observers upon a group activation events received in Topology.
+ */
+public class GroupStatusEvent extends MonitorStatusEvent {
+
+    public GroupStatusEvent(Status status, String id) {
+        super(status, id);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java
deleted file mode 100644
index 96e2ae4..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.autoscaler.monitor.events;
-
-import java.io.Serializable;
-
-/**
- * This event will be used to notify observers based on the status events received from Topology.
- */
-public abstract class MonitorEvent implements Serializable {
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java
index 61fcf95..336bd7a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java
@@ -21,22 +21,31 @@ package org.apache.stratos.autoscaler.monitor.events;
 import org.apache.stratos.messaging.domain.topology.Status;
 
 /**
- * Created by reka on 9/25/14.
+ * Monitor Status Event
  */
-public class MonitorStatusEvent extends MonitorEvent {
-    private Status status;
-    private String notifierId;
+public abstract class MonitorStatusEvent {
+    protected Status status;
+    protected String id;
 
-    public MonitorStatusEvent(Status status, String notifierId) {
-        this.status = status;
-        this.notifierId = notifierId;
+    public MonitorStatusEvent(Status status, String id) {
+        this.setStatus(status);
+        this.setId(id);
+    }
+
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
     }
 
     public Status getStatus() {
         return status;
     }
 
-    public String getNotifierId() {
-        return notifierId;
+    public void setStatus(Status status) {
+        this.status = status;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2536b30b/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 eae7ed6..735bcd6 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
@@ -21,23 +21,25 @@ package org.apache.stratos.autoscaler.monitor.group;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
-import org.apache.stratos.autoscaler.grouping.dependency.context.ClusterContext;
-import org.apache.stratos.autoscaler.grouping.dependency.context.GroupContext;
+import org.apache.stratos.autoscaler.monitor.EventHandler;
 import org.apache.stratos.autoscaler.monitor.Monitor;
+import org.apache.stratos.autoscaler.monitor.MonitorStatusEventBuilder;
+import org.apache.stratos.autoscaler.monitor.events.ClusterStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.GroupStatusEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
-import org.apache.stratos.messaging.domain.topology.*;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-
-import java.util.List;
-import java.util.Observable;
+import org.apache.stratos.messaging.domain.topology.Group;
+import org.apache.stratos.messaging.domain.topology.Status;
+import org.apache.stratos.messaging.event.application.status.StatusEvent;
 
 /**
  * This is GroupMonitor to monitor the group which consists of
  * groups and clusters
  */
-public class GroupMonitor extends Monitor {
+public class GroupMonitor extends Monitor implements EventHandler {
     private static final Log log = LogFactory.getLog(GroupMonitor.class);
 
+    private Monitor parent;
+
     public GroupMonitor(Group group) {
         super(group);
         this.id = group.getAlias();
@@ -45,30 +47,54 @@ public class GroupMonitor extends Monitor {
 
     }
 
-    @Override
+    /*@Override
     public void update(Observable observable, Object event) {
-        if (event instanceof MonitorStatusEvent) {
-            MonitorStatusEvent statusEvent = (MonitorStatusEvent) event;
-            Status childStatus = statusEvent.getStatus();
-            String notifier = statusEvent.getNotifierId();
-            log.info(String.format("[Monitor] %s got notified from the [child] %s" +
-                    "on its state change from %s to %s", id, notifier, this.status, status));
-            if (childStatus == Status.Activated) {
-                //start the next dependency
-                startDependency(notifier);
-            } else if(childStatus == Status.In_Maintenance) {
-
-            }
+        MonitorStatusEvent1111 statusEvent = (MonitorStatusEvent1111) event;
+        Status childStatus = statusEvent.getStatus();
+        String notifier = statusEvent.getNotifierId();
+        log.info(String.format("[Monitor] %s got notified from the [child] %s" +
+                "on its state change from %s to %s", id, notifier, this.status, status));
+        if (childStatus == Status.Activated) {
+            //start the next dependency
+            startDependency(notifier);
+        } else if(childStatus == Status.In_Maintenance) {
 
         }
+    }*/
 
-    }
 
     public void setStatus(Status status) {
         log.info(String.format("[Monitor] %s is notifying the parent" +
                 "on its state change from %s to %s", id, this.status, status));
         this.status = status;
-        setChanged();
-        notifyObservers(new MonitorStatusEvent(status, id));
+        //notifying the parent
+        MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, this.status, this.id);
+        //setChanged();
+        //notifyObservers(new MonitorStatusEvent1111(status, id));
+    }
+
+    @Override
+    public void onEvent(MonitorStatusEvent statusEvent) {
+        this.monitor(statusEvent);
+    }
+
+    public Monitor getParent() {
+        return parent;
+    }
+
+    public void setParent(Monitor parent) {
+        this.parent = parent;
+    }
+
+    @Override
+    protected void monitor(MonitorStatusEvent statusEvent) {
+        ApplicationContext context = this.dependencyTree.
+                                            findApplicationContextWithId(statusEvent.getId());
+        if(context.getStatusLifeCycle().isEmpty()) {
+            startDependency(statusEvent.getId());
+        } else {
+            //TODO act based on life cyle events
+        }
+
     }
 }


Mime
View raw message