You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2014/10/21 06:45:59 UTC

[2/2] git commit: adding support for in_active status changes in monitor

adding support for in_active status changes in monitor


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

Branch: refs/heads/4.0.0-grouping
Commit: 6e723749f4ece9a680a85f864587be757f597e94
Parents: 2978649
Author: reka <rt...@gmail.com>
Authored: Tue Oct 21 10:12:37 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Tue Oct 21 10:15:36 2014 +0530

----------------------------------------------------------------------
 .../grouping/dependency/DependencyTree.java     |  19 ++++
 .../grouping/topic/StatusEventPublisher.java    |  12 +-
 .../AutoscalerTopologyEventReceiver.java        |  20 +++-
 .../monitor/AbstractClusterMonitor.java         |  13 +++
 .../autoscaler/monitor/EventHandler.java        |  16 +++
 .../stratos/autoscaler/monitor/Monitor.java     |  10 ++
 .../monitor/ParentComponentMonitor.java         |   4 +-
 .../monitor/application/ApplicationMonitor.java |  12 ++
 .../monitor/events/GroupTerminateAllEvent.java  |  29 +++++
 .../autoscaler/monitor/events/MonitorEvent.java |  31 +++++
 .../monitor/events/MonitorScalingEvent.java     |  30 +++++
 .../monitor/events/MonitorStatusEvent.java      |   5 +-
 .../events/MonitorTerminateAllEvent.java        |  29 +++++
 .../autoscaler/monitor/group/GroupMonitor.java  |  82 +++++++++-----
 .../status/checker/StatusChecker.java           | 113 ++++++++++++++-----
 15 files changed, 357 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
index e4f214e..642a40a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
@@ -104,6 +104,25 @@ public class DependencyTree {
         return null;
     }
 
+    public ApplicationContext findParentContextWithId(String id) {
+        return findParentContextWithId(null, id, this.applicationContextList);
+    }
+
+
+    private ApplicationContext findParentContextWithId(ApplicationContext parent, String id,
+                                                       List<ApplicationContext> contexts) {
+        for (ApplicationContext context : contexts) {
+            //TODO check for the status
+            if (context.getId().equals(id)) {
+                return parent;
+            }
+        }
+        //if not found in the top level search recursively
+        for (ApplicationContext context : this.applicationContextList) {
+            return findParentContextWithId(context, id, context.getApplicationContextList());
+        }
+        return null;
+    }
     /**
      * Getting the next start able dependencies upon the activate event
      * received for a group/cluster which is part of this tree.

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 4867b9c..abc03df 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
@@ -6,7 +6,13 @@ import org.apache.stratos.messaging.broker.publish.EventPublisher;
 import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.application.status.*;
-import org.apache.stratos.messaging.event.topology.ClusterCreatedEvent;
+import org.apache.stratos.messaging.event.application.status.ApplicationActivatedEvent;
+import org.apache.stratos.messaging.event.application.status.ApplicationInactivatedEvent;
+import org.apache.stratos.messaging.event.application.status.ClusterActivatedEvent;
+import org.apache.stratos.messaging.event.application.status.ClusterMaintenanceModeEvent;
+import org.apache.stratos.messaging.event.application.status.GroupActivatedEvent;
+import org.apache.stratos.messaging.event.topology.*;
+import org.apache.stratos.messaging.event.topology.GroupInActivateEvent;
 import org.apache.stratos.messaging.util.Constants;
 
 /**
@@ -95,9 +101,9 @@ public class StatusEventPublisher {
                     " [group]: " + groupId);
         }
 
-        /*GroupActivatedEvent groupActivatedEvent = new GroupActivatedEvent(appId, groupId);
+        GroupInActivateEvent groupInActivateEvent = new GroupInActivateEvent(appId, groupId);
 
-        publishEvent(groupActivatedEvent);*/
+        publishEvent(groupInActivateEvent);
     }
 
     public static void sendApplicationActivatedEvent(String appId) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 6cb186e..c5095e3 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
@@ -141,7 +141,6 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
         topologyEventReceiver.addEventListener(new ClusterActivatedEventListener() {
             @Override
             protected void onEvent(Event event) {
-
                 log.info("[ClusterActivatedEvent] Received: " + event.getClass());
 
                 ClusterActivatedEvent clusterActivatedEvent = (ClusterActivatedEvent) event;
@@ -158,6 +157,25 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
             }
         });
 
+        topologyEventReceiver.addEventListener(new ClusterCreatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+
+                log.info("[ClusterActivatedEvent] Received: " + event.getClass());
+
+                ClusterCreatedEvent clusterCreatedEvent = (ClusterCreatedEvent) event;
+                String clusterId = clusterCreatedEvent.getClusterId();
+                AbstractClusterMonitor clusterMonitor =
+                        (AbstractClusterMonitor) AutoscalerContext.getInstance().getMonitor(clusterId);
+
+                //changing the status in the monitor, will notify its parent monitor
+                clusterMonitor.setStatus(ClusterStatus.Created);
+
+                //starting the status checker to decide on the status of it's parent
+                //StatusChecker.getInstance().onClusterStatusChange(clusterId, appId);
+            }
+        });
+
         topologyEventReceiver.addEventListener(new ClusterInActivateEventListener() {
             @Override
             protected void onEvent(Event event) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 487e8be..3e630fa 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
@@ -23,7 +23,9 @@ 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.MonitorScalingEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.MonitorTerminateAllEvent;
 import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
 import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
 import org.apache.stratos.autoscaler.util.AutoScalerConstants;
@@ -258,4 +260,15 @@ abstract public class AbstractClusterMonitor extends Monitor implements Runnable
     public void onEvent(MonitorStatusEvent statusEvent) {
 
     }
+
+    @Override
+    public void onEvent(MonitorTerminateAllEvent terminateAllEvent) {
+
+    }
+
+    @Override
+    public void onEvent(MonitorScalingEvent scalingEvent) {
+
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 b1ba90f..e4eb816 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
@@ -18,7 +18,9 @@
  */
 package org.apache.stratos.autoscaler.monitor;
 
+import org.apache.stratos.autoscaler.monitor.events.MonitorScalingEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.MonitorTerminateAllEvent;
 
 /**
  * Event Handler to notify the observer/to receive notification
@@ -30,4 +32,18 @@ public interface EventHandler {
      * @param statusEvent
      */
     public abstract void onEvent(MonitorStatusEvent statusEvent);
+
+    /**
+     * Triggered when termination decision is made.
+     *
+     * @param terminateAllEvent
+     */
+    public abstract void onEvent(MonitorTerminateAllEvent terminateAllEvent);
+
+    /**
+     * Triggered when scaling decision is made.
+     *
+     * @param scalingEvent
+     */
+    public abstract void onEvent(MonitorScalingEvent scalingEvent);
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 a0f1d98..3276c47 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
@@ -35,6 +35,8 @@ public abstract class Monitor implements EventHandler {
     //monitors map, stopped monitors
     protected Map<String, Monitor> aliasToInActiveMonitorsMap;
 
+    protected boolean killChildren;
+
     public String getId() {
         return id;
     }
@@ -67,4 +69,12 @@ public abstract class Monitor implements EventHandler {
     public void setParent(ParentComponentMonitor parent) {
         this.parent = parent;
     }
+
+    public boolean hasMonitors() {
+        boolean hasMonitor = false;
+        if(this.aliasToActiveMonitorsMap != null ) {
+            hasMonitor = true;
+        }
+        return hasMonitor;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 08f2376..9948976 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
@@ -42,11 +42,11 @@ public abstract class ParentComponentMonitor extends Monitor {
     private static final Log log = LogFactory.getLog(ParentComponentMonitor.class);
 
     //id of the monitor, it can be alias or the id
-    protected String id;
+    //protected String id;
     //The monitors dependency tree with all the startable/killable dependencies
     protected DependencyTree dependencyTree;
     //Application id of this particular monitor
-    protected String appId;
+    //protected String appId;
 
     public ParentComponentMonitor(ParentComponent component) throws DependencyBuilderException {
         aliasToActiveMonitorsMap = new HashMap<String, Monitor>();

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 c3c7459..3e80570 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
@@ -26,7 +26,9 @@ import org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationCont
 import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 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.status.checker.StatusChecker;
 import org.apache.stratos.messaging.domain.topology.Application;
 import org.apache.stratos.messaging.domain.topology.ApplicationStatus;
@@ -162,6 +164,16 @@ public class ApplicationMonitor extends ParentComponentMonitor {
     }
 
     @Override
+    public void onEvent(MonitorTerminateAllEvent terminateAllEvent) {
+
+    }
+
+    @Override
+    public void onEvent(MonitorScalingEvent scalingEvent) {
+
+    }
+
+    @Override
     protected void monitor(MonitorStatusEvent statusEvent) {
         /*ApplicationContext context = this.dependencyTree.
                 findApplicationContextWithId(statusEvent.getId());

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupTerminateAllEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupTerminateAllEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupTerminateAllEvent.java
new file mode 100644
index 0000000..0fdf9e3
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupTerminateAllEvent.java
@@ -0,0 +1,29 @@
+/*
+ * 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 handle the termination of all groups/clusters of a group.
+ */
+public class GroupTerminateAllEvent extends MonitorTerminateAllEvent {
+
+    public GroupTerminateAllEvent(String id) {
+        super(id);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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
new file mode 100644
index 0000000..a733a0e
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.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;
+
+/**
+ * Created by reka on 10/20/14.
+ */
+public abstract class MonitorEvent {
+    protected String id;
+
+    public MonitorEvent(String id) {
+        this.id = id;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorScalingEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorScalingEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorScalingEvent.java
new file mode 100644
index 0000000..ce7b311
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorScalingEvent.java
@@ -0,0 +1,30 @@
+/*
+ * 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 is to handle scaling of the monitors
+ */
+public abstract class MonitorScalingEvent extends MonitorEvent {
+
+    public  MonitorScalingEvent(String id) {
+        super(id);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 d4af749..7d2f480 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
@@ -23,11 +23,10 @@ import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
 /**
  * Monitor Status Event
  */
-public abstract class MonitorStatusEvent {
-    protected String id;
+public abstract class MonitorStatusEvent extends MonitorEvent {
 
     public MonitorStatusEvent(String id) {
-        this.setId(id);
+        super(id);
     }
 
     public String getId() {

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorTerminateAllEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorTerminateAllEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorTerminateAllEvent.java
new file mode 100644
index 0000000..86efc7e
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorTerminateAllEvent.java
@@ -0,0 +1,29 @@
+/*
+ * 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 be used to terminate all the instances of the cluster/group.
+ */
+public class MonitorTerminateAllEvent extends MonitorEvent {
+
+    public MonitorTerminateAllEvent(String id) {
+        super(id);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 5129e34..54c37e9 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
@@ -23,10 +23,11 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
 import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
-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.grouping.topic.StatusEventPublisher;
+import org.apache.stratos.autoscaler.monitor.*;
+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.status.checker.StatusChecker;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.Group;
@@ -66,6 +67,16 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
     }
 
     @Override
+    public void onEvent(MonitorTerminateAllEvent terminateAllEvent) {
+
+    }
+
+    @Override
+    public void onEvent(MonitorScalingEvent scalingEvent) {
+
+    }
+
+    @Override
     protected void monitor(MonitorStatusEvent statusEvent) {
         String id = statusEvent.getId();
         LifeCycleState status1 = statusEvent.getStatus();
@@ -96,53 +107,66 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
                 //TODO check whether dependent in_active. Then kill c1.
                 //evaluate termination behavior and take action based on that.
 
-                List<ApplicationContext> terminationList = new ArrayList<ApplicationContext>();
+                List<ApplicationContext> terminationList;
+                Monitor monitor;
                 terminationList = this.dependencyTree.getTerminationDependencies(id);
+                //Temporarily move the group/cluster to inactive list
+                this.aliasToInActiveMonitorsMap.put(id, this.aliasToActiveMonitorsMap.remove(id));
 
                 if (terminationList != null) {
                     //Move to in_active monitors list
-                    this.aliasToInActiveMonitorsMap.put(id, this.aliasToActiveMonitorsMap.remove(id));
                     boolean allInActive = false;
                     //check whether all the children are in_active state
                     for (ApplicationContext terminationContext : terminationList) {
                         //Check for whether all dependent are in_active
                         if (this.aliasToInActiveMonitorsMap.containsKey(terminationContext.getId())) {
-                            allInActive = true;
+                            monitor = this.aliasToInActiveMonitorsMap.
+                                    get(terminationContext.getId());
+                            //start to kill it
+                            monitor.onEvent(new MonitorTerminateAllEvent(terminationContext.getId()));
+
                         } else {
-                            allInActive = false;
+                            monitor = this.aliasToActiveMonitorsMap.
+                                                            get(terminationContext.getId());
+                            if(monitor.hasMonitors()) {
+                                //it is a group
+                                StatusEventPublisher.sendGroupInActivateEvent(this.appId, terminationContext.getId());
+                            } else {
+                                StatusEventPublisher.sendClusterInActivateEvent(this.appId,
+                                        ((AbstractClusterMonitor)monitor).getServiceId(), terminationContext.getId());
+
+                            }
+
                         }
                     }
 
                     if (allInActive) {
                         //Then kill-all of each termination dependents and get a lock for CM
-                        //if start order then can kill only the first one, rest of them will get killed based on created event of first one.
+                        //if start order then can kill only the first one,
+                        // rest of them will get killed based on created event of first one.
                     }
-                }
-
+                } else {
+                    //find any other immediate dependent which is in_active/created state
+                    ApplicationContext context1 = this.dependencyTree.findParentContextWithId(id);
+                    if(context1 != null) {
+                        if(this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
+                            monitor = this.aliasToInActiveMonitorsMap.get(id);
+                            //killall
+                            monitor.onEvent(new MonitorTerminateAllEvent(id));
 
+                        } else {
+                            monitor = this.aliasToActiveMonitorsMap.get(context1.getId());
+                        }
+                    } else {
+                        //Independent monitor
+                    }
 
+                }
 
 
+                //To update the status of the Group
+                StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);
 
-                /*if(terminationList != null && !terminationList.isEmpty()) {
-                    for(ApplicationContext context1 : terminationList) {
-                        if(context1 instanceof ClusterContext) {
-                            AbstractClusterMonitor monitor = this.clusterIdToClusterMonitorsMap.
-                                    get(context1.getId());
-                            //Whether life cycle change to Created
-                            if(monitor.getStatus() == Status.Created) {
-                                canTerminate = true;
-                            } else {
-                                //TODO sending group in_active event to dependent cluster/group
-                                StatusEventPublisher.sendGroupActivatedEvent(this.appId, this.id);
-                                //not all dependent clusters are in created state.
-                                canTerminate = false;
-                            }
-                        }
-                    }
-                    if(canTerminate) {
-                       //
-                    }*/
             } else if (status1 == ClusterStatus.Created || status1 == GroupStatus.Created) {
                 //TODO get dependents
                 List<ApplicationContext> dependents = this.dependencyTree.getTerminationDependencies(id);

http://git-wip-us.apache.org/repos/asf/stratos/blob/6e723749/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 f8d1601..de6f261 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
@@ -125,7 +125,7 @@ public class StatusChecker {
         if (clusterInActive) {
             //TODO evaluate life cycle
             //send cluster In-Active event to cluster status topic
-            StatusEventPublisher.sendGroupInActivateEvent(appId, monitor.getParent().getId());
+            StatusEventPublisher.sendClusterInActivateEvent(appId, monitor.getServiceId(), clusterId);
 
         } else {
             boolean clusterActive = clusterActive(monitor);
@@ -230,8 +230,8 @@ public class StatusChecker {
     private boolean updateChildStatus(String appId, String id, Map<String, Group> groups,
                                       Map<String, ClusterDataHolder> clusterData, ParentComponent parent) {
         boolean groupActive = false;
-        boolean clustersActive;
-        boolean groupsActive;
+        ClusterStatus clustersActive;
+        GroupStatus groupsActive;
         boolean childFound = false;
         boolean clusterFound = false;
 
@@ -243,41 +243,71 @@ public class StatusChecker {
         log.info("cluster found: " + clusterFound);
         if (clusterFound || groups.containsKey(id)) {
             childFound = true;
-            if (!clusterData.isEmpty() && !groups.isEmpty()) {
+            /*if (!clusterData.isEmpty() && !groups.isEmpty()) {
                 if (log.isDebugEnabled()) {
                     log.debug("group active found: " + clusterFound);
                 }
-                clustersActive = getClusterStatus(clusterData);
-                groupsActive = getGroupStatus(groups);
+
                 if (log.isDebugEnabled()) {
                     log.debug("Active cluster" + clustersActive + " and group: " + groupActive);
                 }
-                groupActive = clustersActive && groupsActive;
+                groupActive = clustersActive == ClusterStatus.Active && groupsActive == GroupStatus.Active;
             } else if (!groups.isEmpty()) {
                 groupsActive = getGroupStatus(groups);
                 if (log.isDebugEnabled()) {
                     log.info("group active found: " + clusterFound);
                 }
-                groupActive = groupsActive;
+                groupActive = groupsActive == GroupStatus.Active;
             } else if (!clusterData.isEmpty()) {
                 clustersActive = getClusterStatus(clusterData);
                 if (log.isDebugEnabled()) {
                     log.debug("Active cluster" + clustersActive + " and group: " + groupActive);
                 }
-                groupActive = clustersActive;
+                groupActive = clustersActive == ClusterStatus.Active;
+            } */
+
+            clustersActive = getClusterStatus(clusterData);
+            groupsActive = getGroupStatus(groups);
+
+            if (groupsActive == null && clustersActive == ClusterStatus.Active ||
+                    clustersActive == null && groupsActive == GroupStatus.Active ||
+                    groupsActive == GroupStatus.Active && clustersActive == ClusterStatus.Active) {
+                //send activation event
+                if (parent instanceof Application) {
+                    //send application activated event
+                    log.info("sending app activate found: " + appId);
+                    StatusEventPublisher.sendApplicationActivatedEvent(appId);
+                } else if (parent instanceof Group) {
+                    //send activation to the parent
+                    log.info("sending group activate found: " + parent.getUniqueIdentifier());
+                    StatusEventPublisher.sendGroupActivatedEvent(appId, parent.getUniqueIdentifier());
+                }
+            } else if (groupsActive == null && clustersActive == ClusterStatus.Inactive ||
+                    clustersActive == null && groupsActive == GroupStatus.Inactive ||
+                    groupsActive == GroupStatus.Inactive && clustersActive == ClusterStatus.Inactive) {
+                    //send the in activation event
+                if (parent instanceof Application) {
+                    //send application activated event
+                    log.info("sending app in-active found: " + appId);
+                    StatusEventPublisher.sendApplicationInActivatedEvent(appId);
+                } else if (parent instanceof Group) {
+                    //send activation to the parent
+                    log.info("sending group in-active found: " + parent.getUniqueIdentifier());
+                    StatusEventPublisher.sendGroupInActivateEvent(appId, parent.getUniqueIdentifier());
+                }
+            } else if (groupsActive == null && clustersActive == ClusterStatus.Terminating ||
+                    clustersActive == null && groupsActive == GroupStatus.Terminating ||
+                    groupsActive == GroupStatus.Terminating && clustersActive == ClusterStatus.Terminating) {
+                    //send the terminating event
+            } else if (groupsActive == null && clustersActive == ClusterStatus.Terminated ||
+                    clustersActive == null && groupsActive == GroupStatus.Terminated ||
+                    groupsActive == GroupStatus.Terminated && clustersActive == ClusterStatus.Terminated) {
+                    //send the terminated event
             } else {
                 log.warn("Clusters/groups not found in this [component] " + appId);
             }
-            //send the activation event
-            if (parent instanceof Application && groupActive) {
-                //send application activated event
-                log.info("sending app activate found: " + appId);
-                StatusEventPublisher.sendApplicationActivatedEvent(appId);
-            } else if (parent instanceof Group && groupActive) {
-                //send activation to the parent
-                log.info("sending group activate found: " + parent.getUniqueIdentifier());
-                StatusEventPublisher.sendGroupActivatedEvent(appId, parent.getUniqueIdentifier());
-            }
+
+
             return childFound;
         } else {
             log.warn("There is no child found in the [group/cluster] " + id + " found in the " +
@@ -286,33 +316,56 @@ public class StatusChecker {
         return childFound;
     }
 
-    private boolean getGroupStatus(Map<String, Group> groups) {
+    private GroupStatus getGroupStatus(Map<String, Group> groups) {
         boolean groupActiveStatus = false;
+        GroupStatus status = null;
+
         for (Group group : groups.values()) {
-            if (group.getTempStatus() == Status.Activated) {
+            /*if (group.getTempStatus() == Status.Activated) {
                 groupActiveStatus = true;
             } else {
                 groupActiveStatus = false;
                 break;
+            }*/
+
+            if (group.getStatus() == GroupStatus.Active) {
+                status = GroupStatus.Active;
+            } else if(group.getStatus() == GroupStatus.Inactive){
+                status = GroupStatus.Inactive;
+                break;
+            } else if(group.getStatus() == GroupStatus.Created) {
+                status = GroupStatus.Created;
+            } else if(group.getStatus() == GroupStatus.Terminating) {
+                status = GroupStatus.Terminating;
+                break;
+            } else if(group.getStatus() == GroupStatus.Terminated) {
+                status = GroupStatus.Terminated;
             }
         }
-        return groupActiveStatus;
+        return status;
 
     }
 
-    private boolean getClusterStatus(Map<String, ClusterDataHolder> clusterData) {
-        boolean clusterActiveStatus = false;
+    private ClusterStatus getClusterStatus(Map<String, ClusterDataHolder> clusterData) {
+        ClusterStatus status = null;
         for (Map.Entry<String, ClusterDataHolder> clusterDataHolderEntry : clusterData.entrySet()) {
             Service service = TopologyManager.getTopology().getService(clusterDataHolderEntry.getValue().getServiceType());
-            if (service.getCluster(clusterDataHolderEntry.getValue().getClusterId()).
-                    getStatus() == ClusterStatus.Active) {
-                clusterActiveStatus = true;
-            } else {
-                clusterActiveStatus = false;
+            Cluster cluster = service.getCluster(clusterDataHolderEntry.getValue().getClusterId());
+            if (cluster.getStatus() == ClusterStatus.Active) {
+                status = ClusterStatus.Active;
+            } else if(cluster.getStatus() == ClusterStatus.Inactive){
+                status = ClusterStatus.Inactive;
+                break;
+            } else if(cluster.getStatus() == ClusterStatus.Created) {
+                status = ClusterStatus.Created;
+            } else if(cluster.getStatus() == ClusterStatus.Terminating) {
+                status = ClusterStatus.Terminating;
                 break;
+            } else if(cluster.getStatus() == ClusterStatus.Terminated) {
+                status = ClusterStatus.Terminated;
             }
         }
-        return clusterActiveStatus;
+        return status;
     }
 
     private static class Holder {