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/11/21 12:06:44 UTC

[3/3] stratos git commit: adding instance id generation and isolating the dynamic data from monitors

adding instance id generation and isolating the dynamic data from monitors


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

Branch: refs/heads/master
Commit: 081116de0ada9a88e537a427c2dfb48322b9d04c
Parents: ee57e31
Author: reka <rt...@gmail.com>
Authored: Fri Nov 21 16:00:57 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Fri Nov 21 16:36:29 2014 +0530

----------------------------------------------------------------------
 .../applications/topic/ApplicationBuilder.java  | 74 ++++++++++++++++++--
 .../AutoscalerTopologyEventReceiver.java        |  4 +-
 .../stratos/autoscaler/monitor/Monitor.java     | 10 +--
 .../monitor/MonitorStatusEventBuilder.java      |  8 +--
 .../monitor/ParentComponentMonitor.java         | 68 ++++++++++++++----
 .../monitor/application/ApplicationMonitor.java | 73 +++++--------------
 .../application/ApplicationMonitorFactory.java  | 38 ++++++----
 .../monitor/events/ApplicationStatusEvent.java  |  4 +-
 .../monitor/events/ClusterStatusEvent.java      |  4 +-
 .../monitor/events/GroupStatusEvent.java        |  4 +-
 .../monitor/events/GroupTerminateAllEvent.java  | 29 --------
 .../autoscaler/monitor/events/MonitorEvent.java |  5 +-
 .../monitor/events/MonitorScalingEvent.java     |  4 +-
 .../monitor/events/MonitorStartAllEvent.java    | 28 --------
 .../monitor/events/MonitorStatusEvent.java      |  4 +-
 .../events/MonitorTerminateAllEvent.java        | 29 --------
 .../autoscaler/monitor/group/GroupMonitor.java  | 55 ++++++++++-----
 17 files changed, 228 insertions(+), 213 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
index de45f62..d45a62f 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
@@ -74,6 +74,35 @@ public class ApplicationBuilder {
         ApplicationsEventPublisher.sendApplicationCreatedEvent(application);
     }
 
+    public static void handleApplicationInstanceCreatedEvent(String appId, String instanceId) {
+        if (log.isDebugEnabled()) {
+            log.debug("Handling application activation event: [application-id] " + appId);
+        }
+
+        Applications applications = ApplicationHolder.getApplications();
+        Application application = applications.getApplication(appId);
+        //update the status of the Group
+        if (application == null) {
+            log.warn(String.format("Application does not exist: [application-id] %s",
+                    appId));
+            return;
+        }
+
+        ApplicationStatus status = ApplicationStatus.Active;
+
+        //TODO create new instanceConext***************
+        if (application.isStateTransitionValid(status)) {
+            //setting the status, persist and publish
+            application.setStatus(status);
+            updateApplicationMonitor(appId, status);
+            ApplicationHolder.persistApplication(application);
+            ApplicationsEventPublisher.sendApplicationActivatedEvent(appId);
+        } else {
+            log.warn(String.format("Application state transition is not valid: [application-id] %s " +
+                    " [current-status] %s [status-requested] %s", appId, application.getStatus(), status));
+        }
+    }
+
     public static void handleApplicationActivatedEvent(String appId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling application activation event: [application-id] " + appId);
@@ -317,6 +346,43 @@ public class ApplicationBuilder {
         }
     }
 
+    public static void handleGroupInstanceCreatedEvent(String appId, String groupId, String instanceId) {
+        if (log.isDebugEnabled()) {
+            log.debug("Handling Group creation for the [group]: " + groupId +
+                    " in the [application] " + appId);
+        }
+
+        Applications applications = ApplicationHolder.getApplications();
+        Application application = applications.getApplication(appId);
+        //update the status of the Group
+        if (application == null) {
+            log.warn(String.format("Application %s does not exist",
+                    appId));
+            return;
+        }
+
+        Group group = application.getGroupRecursively(groupId);
+        if (group == null) {
+            log.warn(String.format("Group %s does not exist",
+                    groupId));
+            return;
+        }
+
+        GroupStatus status = GroupStatus.Created;
+        group.getInstanceContexts(instanceId);
+        if (group.isStateTransitionValid(status)) {
+            //setting the status, persist and publish
+            group.setStatus(status);
+            updateGroupMonitor(appId, groupId, status);
+            ApplicationHolder.persistApplication(application);
+            ApplicationsEventPublisher.sendGroupCreatedEvent(appId, groupId);
+        } else {
+            log.warn("Group state transition is not valid: [group-id] " + groupId + " [current-state] " + group.getStatus()
+                    + "[requested-state] " + status);
+        }
+    }
+
+
     public static void handleGroupInActivateEvent(String appId, String groupId) {
         if (log.isDebugEnabled()) {
             log.debug("Handling group in-active event: [group]: " + groupId +
@@ -412,9 +478,7 @@ public class ApplicationBuilder {
         //Updating the Application Monitor
         ApplicationMonitor applicationMonitor = AutoscalerContext.getInstance().getAppMonitor(appId);
         if (applicationMonitor != null) {
-            if(applicationMonitor.getStatus() != status) {
-                applicationMonitor.setStatus(status);
-            }
+            applicationMonitor.setStatus(status, null);
         } else {
             log.warn("Application monitor cannot be found: [application-id] " + appId);
         }
@@ -427,9 +491,7 @@ public class ApplicationBuilder {
         if (applicationMonitor != null) {
             GroupMonitor monitor = (GroupMonitor) applicationMonitor.findGroupMonitorWithId(groupId);
             if (monitor != null ) {
-                if(monitor.getStatus() != status) {
-                    monitor.setStatus(status);
-                }
+                monitor.setStatus(status, null);
             } else {
                 log.warn("Group monitor cannot be found: [group-id] " + groupId +
                         " [application-id] " + appId);

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
index 5296d75..bd36dd9 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.AutoscalerContext;
 import org.apache.stratos.autoscaler.applications.ApplicationHolder;
+import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
 import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
 import org.apache.stratos.autoscaler.event.publisher.InstanceNotificationPublisher;
 import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
@@ -204,7 +205,7 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                     return;
                 }
                 //changing the status in the monitor, will notify its parent monitor
-                monitor.setStatus(ClusterStatus.Active);
+
             }
         });
 
@@ -472,7 +473,6 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                                 appId);
                     }
                     applicationMonitor = ApplicationMonitorFactory.getApplicationMonitor(appId);
-
                     long end = System.currentTimeMillis();
                     log.info("Time taken to start app monitor: " + (end - start) / 1000);
                     success = true;

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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 30b015d..31276c1 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
@@ -31,7 +31,7 @@ public abstract class Monitor implements EventHandler {
     //has startup dependents
     protected boolean hasStartupDependents;
     //has scaling dependents
-    protected boolean isGroupScalingEnabled;
+    protected boolean hasGroupScalingDependent;
 
     /**
      * Return the id of the monitor
@@ -102,8 +102,8 @@ public abstract class Monitor implements EventHandler {
      *
      * @return startup dependencies exist or not
      */
-    public boolean isGroupScalingEnabled() {
-        return isGroupScalingEnabled;
+    public boolean isHasGroupScalingDependent() {
+        return hasGroupScalingDependent;
     }
 
     /**
@@ -120,7 +120,7 @@ public abstract class Monitor implements EventHandler {
      *
      * @param hasDependent
      */
-    public void setGroupScalingEnabled(boolean hasDependent) {
-        this.isGroupScalingEnabled = hasDependent;
+    public void setHasGroupScalingDependent(boolean hasDependent) {
+        this.hasGroupScalingDependent = hasDependent;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
index 5ee4204..08e15a7 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
@@ -32,24 +32,24 @@ public class MonitorStatusEventBuilder {
     private static final Log log = LogFactory.getLog(MonitorStatusEventBuilder.class);
 
     public static void handleClusterStatusEvent(ParentComponentMonitor parent, ClusterStatus status, String clusterId) {
-        ClusterStatusEvent clusterStatusEvent = new ClusterStatusEvent(status, clusterId);
+        ClusterStatusEvent clusterStatusEvent = new ClusterStatusEvent(status, clusterId, null);
         notifyParent(parent, clusterStatusEvent);
     }
 
     public static void handleGroupStatusEvent(ParentComponentMonitor parent, GroupStatus status, String groupId) {
-        GroupStatusEvent groupStatusEvent = new GroupStatusEvent(status, groupId);
+        GroupStatusEvent groupStatusEvent = new GroupStatusEvent(status, groupId, null);
         notifyParent(parent, groupStatusEvent);
     }
 
     public static void handleApplicationStatusEvent(ParentComponentMonitor parent, ApplicationStatus status, String appId) {
-        ApplicationStatusEvent applicationStatusEvent = new ApplicationStatusEvent(status, appId);
+        ApplicationStatusEvent applicationStatusEvent = new ApplicationStatusEvent(status, appId, null);
         notifyParent(parent, applicationStatusEvent);
     }
 
     public static void handleClusterScalingEvent(ParentComponentMonitor parent, String networkPartitionId, float factor, String appId) {
 
         //Send notifications to parent of the cluster monitor
-        MonitorScalingEvent monitorScalingEvent = new MonitorScalingEvent(appId, networkPartitionId, factor) ;
+        MonitorScalingEvent monitorScalingEvent = new MonitorScalingEvent(appId, networkPartitionId, null,factor) ;
         notifyParent(parent, monitorScalingEvent);
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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 bc33c55..93415bf 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
@@ -36,6 +36,7 @@ import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
 import org.apache.stratos.autoscaler.status.checker.StatusChecker;
 import org.apache.stratos.messaging.domain.applications.GroupStatus;
 import org.apache.stratos.messaging.domain.applications.ParentComponent;
+import org.apache.stratos.messaging.domain.applications.scaling.instance.context.InstanceContext;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
@@ -57,6 +58,8 @@ public abstract class ParentComponentMonitor extends Monitor {
     protected DependencyTree scalingDependencyTree;
     //monitors map, key=GroupAlias/clusterId and value=GroupMonitor/AbstractClusterMonitor
     protected Map<String, Monitor> aliasToActiveMonitorsMap;
+    //instances, key=instance id and value=instanceContext
+    protected Map<String, InstanceContext> instanceIdToInstanceContextMap;
     //monitors map, stopped monitors
     protected List<String> inactiveMonitorsList;
     //terminating monitors list
@@ -65,7 +68,8 @@ public abstract class ParentComponentMonitor extends Monitor {
     public ParentComponentMonitor(ParentComponent component) throws DependencyBuilderException {
         aliasToActiveMonitorsMap = new HashMap<String, Monitor>();
         inactiveMonitorsList = new ArrayList<String>();
-        setTerminatingMonitorsList(new ArrayList<String>());
+        terminatingMonitorsList = new ArrayList<String>();
+        setInstanceIdToInstanceContextMap(new HashMap<String, InstanceContext>());
         //clusterIdToClusterMonitorsMap = new HashMap<String, AbstractClusterMonitor>();
         this.id = component.getUniqueIdentifier();
         //Building the startup dependencies for this monitor within the immediate children
@@ -78,11 +82,23 @@ public abstract class ParentComponentMonitor extends Monitor {
      * This will start the parallel dependencies at once from the top level.
      * it will get invoked when the monitor starts up only.
      */
-    public void startDependency() throws TopologyInConsistentException {
+    public void startDependency(ParentComponent component, String instanceId) throws TopologyInConsistentException {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
                 getStarAbleDependencies();
-        startDependency(applicationContexts);
+        startDependency(applicationContexts, instanceId);
+
+    }
+
+    /**
+     * This will start the parallel dependencies at once from the top level.
+     * it will get invoked when the monitor starts up only.
+     */
+    public void startDependency(ParentComponent component) throws TopologyInConsistentException {
+        //start the first dependency
+        List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
+                getStarAbleDependencies();
+        startDependency(applicationContexts, null);
 
     }
 
@@ -94,7 +110,7 @@ public abstract class ParentComponentMonitor extends Monitor {
     public boolean startDependency(String id) throws TopologyInConsistentException {
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree
                 .getStarAbleDependencies(id);
-        return startDependency(applicationContexts);
+        return startDependency(applicationContexts, null);
     }
 
     /**
@@ -106,7 +122,7 @@ public abstract class ParentComponentMonitor extends Monitor {
         //start the first dependency which went to terminated
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
                 getStarAbleDependenciesByTermination();
-        startDependency(applicationContexts);
+        startDependency(applicationContexts, null);
 
     }
 
@@ -116,7 +132,7 @@ public abstract class ParentComponentMonitor extends Monitor {
      *
      * @param applicationContexts the found applicationContexts to be started
      */
-    private boolean startDependency(List<ApplicationChildContext> applicationContexts)
+    private boolean startDependency(List<ApplicationChildContext> applicationContexts, String instanceId)
             throws TopologyInConsistentException {
         if (applicationContexts != null && applicationContexts.isEmpty()) {
             //all the groups/clusters have been started and waiting for activation
@@ -131,7 +147,14 @@ public abstract class ParentComponentMonitor extends Monitor {
             if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
                 //to avoid if it is already started
                 context.setTerminated(false);
-                startMonitor(this, context);
+                startMonitor(this, context, instanceId);
+            } else {
+                if(!this.instanceIdToInstanceContextMap.containsKey(instanceId)) {
+                    Monitor monitor = this.aliasToActiveMonitorsMap.get(context.getId());
+                    //monitor.onParentStatusEvent();
+                    //ask to start the next snapshot for the monitor
+                    //TODO notify the relevant children
+                }
             }
         }
 
@@ -139,6 +162,12 @@ public abstract class ParentComponentMonitor extends Monitor {
 
     }
 
+    protected String generateInstanceId(ParentComponent component) {
+        String instanceId = component.getUniqueIdentifier() + "_" +
+                (component.getInstanceContextCount() + 1);
+        return instanceId;
+    }
+
     /**
      * This will start the child monitors based on the active of siblings according to start up order
      *
@@ -341,10 +370,11 @@ public abstract class ParentComponentMonitor extends Monitor {
                     GroupMonitor monitor1 = (GroupMonitor) monitor;
                     ApplicationHolder.acquireReadLock();
                     try {
-                        if (monitor1.getStatus() == GroupStatus.Active) {
+                        //TODO***********
+                        /*if (monitor1.getStatus() == GroupStatus.Active) {
                             parentsActive = true;
 
-                        }
+                        }*/
                     } finally {
                         ApplicationHolder.releaseReadLock();
                     }
@@ -385,11 +415,11 @@ public abstract class ParentComponentMonitor extends Monitor {
         }
     }
 
-    protected synchronized void startMonitor(ParentComponentMonitor parent, ApplicationChildContext context) {
+    protected synchronized void startMonitor(ParentComponentMonitor parent, ApplicationChildContext context, String instanceId) {
         Thread th = null;
         if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
             th = new Thread(
-                    new MonitorAdder(parent, context, this.appId));
+                    new MonitorAdder(parent, context, this.appId, instanceId));
             if (log.isDebugEnabled()) {
                 log.debug(String
                         .format("Monitor Adder has been added: [cluster] %s ",
@@ -404,15 +434,26 @@ public abstract class ParentComponentMonitor extends Monitor {
         }
     }
 
+    public Map<String, InstanceContext> getInstanceIdToInstanceContextMap() {
+        return instanceIdToInstanceContextMap;
+    }
+
+    public void setInstanceIdToInstanceContextMap(Map<String, InstanceContext> instanceIdToInstanceContextMap) {
+        this.instanceIdToInstanceContextMap = instanceIdToInstanceContextMap;
+    }
+
     private class MonitorAdder implements Runnable {
         private ApplicationChildContext context;
         private ParentComponentMonitor parent;
         private String appId;
+        private String instanceId;
 
-        public MonitorAdder(ParentComponentMonitor parent, ApplicationChildContext context, String appId) {
+        public MonitorAdder(ParentComponentMonitor parent, ApplicationChildContext context,
+                                                            String instanceId, String appId) {
             this.parent = parent;
             this.context = context;
             this.appId = appId;
+            this.instanceId = instanceId;
         }
 
         public void run() {
@@ -430,7 +471,7 @@ public abstract class ParentComponentMonitor extends Monitor {
                             + context.getId());
                 }
                 try {
-                    monitor = ApplicationMonitorFactory.getMonitor(parent, context, appId);
+                    monitor = ApplicationMonitorFactory.getMonitor(parent, context, appId, instanceId);
                 } catch (DependencyBuilderException e) {
                     String msg = "Monitor creation failed for: " + context.getId();
                     log.warn(msg, e);
@@ -462,6 +503,7 @@ public abstract class ParentComponentMonitor extends Monitor {
                 throw new RuntimeException(msg);
             }
             aliasToActiveMonitorsMap.put(context.getId(), monitor);
+            // ApplicationBuilder.
             if (log.isInfoEnabled()) {
                 log.info(String.format("Monitor has been added successfully for: %s",
                         context.getId()));

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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 a90bc12..1ce5cdd 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.applications.topic.ApplicationBuilder;
 import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
 import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.monitor.Monitor;
@@ -31,6 +32,7 @@ import org.apache.stratos.autoscaler.status.checker.StatusChecker;
 import org.apache.stratos.messaging.domain.applications.Application;
 import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
 import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.applications.ParentComponent;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
 
@@ -41,61 +43,23 @@ import java.util.Collection;
  */
 public class ApplicationMonitor extends ParentComponentMonitor {
     private static final Log log = LogFactory.getLog(ApplicationMonitor.class);
-    //status of the monitor whether it is running/in_maintainable/terminated
-    private ApplicationStatus status;
 
     public ApplicationMonitor(Application application) throws DependencyBuilderException,
             TopologyInConsistentException {
         super(application);
         //setting the appId for the application
         this.appId = application.getUniqueIdentifier();
-        this.status = application.getStatus(null);
         //starting the first set of dependencies from its children
-        startDependency();
-
-    }
-
-    /**
-     * To find all the clusters of an application
-     *
-     * @param appId the application which contains the clusters
-     * @return all the clusters of the application
-     */
-//    public List<String> findClustersOfApplication(String appId) {
-//        List<String> clusters = new ArrayList<String>();
-//        Set<ClusterDataHolder> clusterData;
-//
-//        TopologyManager.acquireReadLockForApplication(appId);
-//        try {
-//            clusterData = TopologyManager.getTopology().getApplication(appId).getClusterDataRecursively();
-//
-//        } finally {
-//            TopologyManager.releaseReadLockForApplication(appId);
-//        }
-//
-//        if (clusterData != null) {
-//            for (ClusterDataHolder clusterDataHolder : clusterData) {
-//                clusters.add(clusterDataHolder.getClusterId());
-//            }
-//        }
-//
-//        return clusters;
-//    }
-
-    /**
-     * Find the cluster monitor by traversing recursively in the hierarchical monitors.
-     *
-     * @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(),
-                aliasToActiveMonitorsMap.values());*/
-        return null;
+        if(application.getInstanceContextCount() > 0) {
+            startDependency(application);
+        } else {
+            String instanceId = this.generateInstanceId(application);
+            startDependency(application, instanceId);
+            ApplicationBuilder.handleApplicationInstanceCreatedEvent(appId, instanceId);
 
+        }
     }
 
-
     /**
      * Find the group monitor by traversing recursively in the hierarchical monitors.
      *
@@ -137,10 +101,9 @@ public class ApplicationMonitor extends ParentComponentMonitor {
      *
      * @param status the status
      */
-    public void setStatus(ApplicationStatus status) {
-        this.status = status;
+    public void setStatus(ApplicationStatus status, String instanceId) {
         //notify the children about the state change
-        MonitorStatusEventBuilder.notifyChildren(this, new ApplicationStatusEvent(status, appId));
+        MonitorStatusEventBuilder.notifyChildren(this, new ApplicationStatusEvent(status, appId, null));
     }
 
     @Override
@@ -164,11 +127,12 @@ public class ApplicationMonitor extends ParentComponentMonitor {
                 this.terminatingMonitorsList.remove(id);
                 this.aliasToActiveMonitorsMap.remove(id);
             }
-            if (this.status == ApplicationStatus.Terminating) {
+            //TODO
+            /*if (this.status == ApplicationStatus.Terminating) {
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);
             } else {
                 onChildTerminatedEvent(id);
-            }
+            }*/
 
         } else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated) {
             //Check whether all dependent goes Terminated and then start them in parallel.
@@ -178,10 +142,11 @@ public class ApplicationMonitor extends ParentComponentMonitor {
             } else {
                 log.warn("[monitor] " + id + " cannot be found in the inActive monitors list");
             }
-            if (this.status == ApplicationStatus.Terminating || this.status == ApplicationStatus.Terminated) {
+            //TODO
+            /*if (this.status == ApplicationStatus.Terminating || this.status == ApplicationStatus.Terminated) {
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);
                 log.info("Executing the un-subscription request for the [monitor] " + id);
-            }
+            }*/
         }
     }
 
@@ -204,8 +169,4 @@ public class ApplicationMonitor extends ParentComponentMonitor {
     public void onEvent(MonitorScalingEvent scalingEvent) {
 
     }
-
-    public ApplicationStatus getStatus() {
-        return status;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
index cb8a4fa..45a6a36 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
@@ -57,15 +57,16 @@ public class ApplicationMonitorFactory {
      * @throws PolicyValidationException     throws while validating the policy associated with cluster
      * @throws PartitionValidationException  throws while validating the partition used in a cluster
      */
-    public static Monitor getMonitor(ParentComponentMonitor parentMonitor, ApplicationChildContext context, String appId)
+    public static Monitor getMonitor(ParentComponentMonitor parentMonitor,
+                                     ApplicationChildContext context, String appId, String instanceId)
             throws TopologyInConsistentException,
             DependencyBuilderException, PolicyValidationException, PartitionValidationException {
     	
         Monitor monitor;
         if (context instanceof GroupChildContext) {
-            monitor = getGroupMonitor(parentMonitor, context, appId);
+            monitor = getGroupMonitor(parentMonitor, context, appId, instanceId);
         } else if (context instanceof ClusterChildContext) {
-            monitor = getClusterMonitor(parentMonitor, (ClusterChildContext) context, appId);
+            monitor = getClusterMonitor(parentMonitor, (ClusterChildContext) context, appId, instanceId);
             if (monitor != null) {
             	((AbstractClusterMonitor)monitor).startScheduler();
             	AutoscalerContext.getInstance().addClusterMonitor((AbstractClusterMonitor)monitor);
@@ -86,7 +87,8 @@ public class ApplicationMonitorFactory {
      * @throws DependencyBuilderException    throws while building dependency for app monitor
      * @throws TopologyInConsistentException throws while traversing thr topology
      */
-    public static Monitor getGroupMonitor(ParentComponentMonitor parentMonitor, ApplicationChildContext context, String appId)
+    public static Monitor getGroupMonitor(ParentComponentMonitor parentMonitor,
+                                          ApplicationChildContext context, String appId, String instanceId)
             throws DependencyBuilderException,
             TopologyInConsistentException {
         GroupMonitor groupMonitor;
@@ -95,7 +97,7 @@ public class ApplicationMonitorFactory {
         try {
             Group group = ApplicationHolder.getApplications().
                     getApplication(appId).getGroupRecursively(context.getId());
-            groupMonitor = new GroupMonitor(group, appId);
+            groupMonitor = new GroupMonitor(group, appId, instanceId);
             groupMonitor.setAppId(appId);
             if (parentMonitor != null) {
                 groupMonitor.setParent(parentMonitor);
@@ -105,13 +107,22 @@ public class ApplicationMonitorFactory {
                 } else {
                     groupMonitor.setHasStartupDependents(false);
                 }
-                //TODO make sure when it is async
 
-                if (group.getStatus(null) != groupMonitor.getStatus()) {
+                if(group.isGroupScalingEnabled()) {
+                    groupMonitor.setGroupScalingEnabled(true);
+                } else if(parentMonitor instanceof GroupMonitor) {
+                    if(((GroupMonitor)parentMonitor).isGroupScalingEnabled() ||
+                            parentMonitor.isHasGroupScalingDependent()) {
+                        groupMonitor.setHasGroupScalingDependent(true);
+                    }
+                }
+                //TODO*********** make it sync with the topology
+
+                /*if (group.getStatus() != groupMonitor.getStatus()) {
                     //updating the status, if the group is not in created state when creating group Monitor
                     //so that groupMonitor will notify the parent (useful when restarting stratos)
-                    groupMonitor.setStatus(group.getStatus(null));
-                }
+                    groupMonitor.setStatus(group.getStatus());
+                }*/
             }
 
         } finally {
@@ -165,7 +176,8 @@ public class ApplicationMonitorFactory {
      * @throws org.apache.stratos.autoscaler.exception.PartitionValidationException
      */
     public static AbstractClusterMonitor getClusterMonitor(ParentComponentMonitor parentMonitor,
-                                                     ClusterChildContext context, String appId)
+                                                            ClusterChildContext context,
+                                                            String appId, String instanceId)
             throws PolicyValidationException,
             PartitionValidationException,
             TopologyInConsistentException {
@@ -204,10 +216,10 @@ public class ApplicationMonitorFactory {
             }
 
             //setting the scaling dependent behaviour of the cluster monitor
-            if(parentMonitor.isGroupScalingEnabled() || (context.isGroupScalingEnabled())) {
-                clusterMonitor.setGroupScalingEnabled(true);
+            if(parentMonitor.isHasGroupScalingDependent() || (context.isGroupScalingEnabled())) {
+                clusterMonitor.setHasGroupScalingDependent(true);
             } else {
-                clusterMonitor.setGroupScalingEnabled(false);
+                clusterMonitor.setHasGroupScalingDependent(false);
             }
             //setting the status of the cluster, if it doesn't match with Topology cluster status.
             if (cluster.getStatus() != clusterMonitor.getStatus()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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
index 83c764d..566c9c2 100644
--- 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
@@ -27,8 +27,8 @@ public class ApplicationStatusEvent extends MonitorStatusEvent {
 
     private ApplicationStatus status;
 
-    public ApplicationStatusEvent(ApplicationStatus status, String id) {
-        super(id);
+    public ApplicationStatusEvent(ApplicationStatus status, String id, String instanceId) {
+        super(id, instanceId);
         this.status = status;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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
index 58c59ba..1eca48a 100644
--- 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
@@ -27,8 +27,8 @@ public class ClusterStatusEvent extends MonitorStatusEvent {
 
     private ClusterStatus status;
 
-    public ClusterStatusEvent(ClusterStatus status, String id) {
-        super(id);
+    public ClusterStatusEvent(ClusterStatus status, String id, String instanceId) {
+        super(id , instanceId);
         this.status = status;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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
index 7f21761..50c297b 100644
--- 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
@@ -26,8 +26,8 @@ import org.apache.stratos.messaging.domain.applications.GroupStatus;
 public class GroupStatusEvent extends MonitorStatusEvent {
     private GroupStatus status;
 
-    public GroupStatusEvent(GroupStatus status, String id) {
-        super(id);
+    public GroupStatusEvent(GroupStatus status, String id, String instanceId) {
+        super(id, instanceId);
         this.status = status;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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
deleted file mode 100644
index 0fdf9e3..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupTerminateAllEvent.java
+++ /dev/null
@@ -1,29 +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 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/081116de/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
index 47229a1..c4aff32 100644
--- 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
@@ -21,8 +21,11 @@ package org.apache.stratos.autoscaler.monitor.events;
 public abstract class MonitorEvent {
     protected String id;
 
-    public MonitorEvent(String id) {
+    protected String instanceId;
+
+    public MonitorEvent(String id , String instanceId) {
         this.id = id;
+        this.instanceId = instanceId;
     }
 
     public String getId(){

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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
index 53b076b..504d7c2 100644
--- 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
@@ -26,8 +26,8 @@ public class MonitorScalingEvent extends MonitorEvent {
     private float factor;
     private String networkPartitionId;
 
-    public  MonitorScalingEvent(String id, String networkPartitionId, float factor) {
-        super(id);
+    public  MonitorScalingEvent(String id, String networkPartitionId, String instanceId, float factor) {
+        super(id, instanceId);
         this.factor = factor;
         this.networkPartitionId = networkPartitionId;
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
deleted file mode 100644
index 21f83ec..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
+++ /dev/null
@@ -1,28 +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 start the child monitors
- */
-public class MonitorStartAllEvent extends MonitorEvent {
-    public MonitorStartAllEvent(String id) {
-        super(id);
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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 7d2f480..f4ba558 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
@@ -25,8 +25,8 @@ import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
  */
 public abstract class MonitorStatusEvent extends MonitorEvent {
 
-    public MonitorStatusEvent(String id) {
-        super(id);
+    public MonitorStatusEvent(String id, String instanceId) {
+        super(id , instanceId);
     }
 
     public String getId() {

http://git-wip-us.apache.org/repos/asf/stratos/blob/081116de/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
deleted file mode 100644
index 86efc7e..0000000
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorTerminateAllEvent.java
+++ /dev/null
@@ -1,29 +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 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/081116de/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 d6d293e..c5a5d4d 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
@@ -36,17 +36,21 @@ import org.apache.stratos.autoscaler.status.checker.StatusChecker;
 import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
 import org.apache.stratos.messaging.domain.applications.Group;
 import org.apache.stratos.messaging.domain.applications.GroupStatus;
+import org.apache.stratos.messaging.domain.applications.ParentComponent;
+import org.apache.stratos.messaging.domain.applications.scaling.instance.context.InstanceContext;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
 
+import java.util.Map;
+
 /**
  * This is GroupMonitor to monitor the group which consists of
  * groups and clusters
  */
 public class GroupMonitor extends ParentComponentMonitor implements EventHandler {
     private static final Log log = LogFactory.getLog(GroupMonitor.class);
-    //status of the monitor whether it is running/in_maintainable/terminated
-    private GroupStatus status;
+    //whether groupScaling enabled or not
+    private boolean groupScalingEnabled;
 
     /**
      * Constructor of GroupMonitor
@@ -55,12 +59,21 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
      * @throws DependencyBuilderException    throws when couldn't build the Topology
      * @throws TopologyInConsistentException throws when topology is inconsistent
      */
-    public GroupMonitor(Group group, String appId) throws DependencyBuilderException,
+    public GroupMonitor(Group group, String appId, String instanceId) throws DependencyBuilderException,
             TopologyInConsistentException {
         super(group);
         this.appId = appId;
-        this.status = group.getStatus(null);
-        startDependency();
+        if(group.getInstanceContextCount() > 0) {
+            this.startDependency(group);
+        } else {
+            String instanceId1 = instanceId;
+            if (group.isGroupScalingEnabled()) {
+                instanceId1 = this.generateInstanceId(group);
+            }
+            this.startDependency(group, instanceId1);
+            ApplicationBuilder.handleGroupInstanceCreatedEvent(appId, group.getUniqueIdentifier(), instanceId1);
+
+        }
     }
 
     /**
@@ -68,10 +81,10 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
      *
      * @param status status of the group
      */
-    public void setStatus(GroupStatus status) {
+    public void setStatus(GroupStatus status, String instanceId) {
 
         //if(this.status != status) {
-        this.status = status;
+        //this.status = status;
         //notifying the parent
         if (status == GroupStatus.Inactive && !this.hasStartupDependents) {
             log.info("[Group] " + this.id + "is not notifying the parent, " +
@@ -79,10 +92,10 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
         } else {
             // notify parent
             log.info("[Group] " + this.id + "is notifying the [parent] " + this.parent.getId());
-            MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, this.status, this.id);
+            MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, status, this.id);
         }
         //notify the children about the state change
-        MonitorStatusEventBuilder.notifyChildren(this, new GroupStatusEvent(status, getId()));
+        MonitorStatusEventBuilder.notifyChildren(this, new GroupStatusEvent(status, getId(), null));
     }
 
     @Override
@@ -106,11 +119,12 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
                 }
             }
             //If cluster monitor, need to terminate the existing one
-            if (this.status == GroupStatus.Terminating) {
+            //TODO block
+            /*if (this.status == GroupStatus.Terminating) {
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);
             } else {
                 onChildTerminatedEvent(id);
-            }
+            }*/
 
         } else if (status1 == ClusterStatus.Terminating || status1 == GroupStatus.Terminating) {
             //mark the child monitor as inActive in the map
@@ -124,19 +138,23 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
             } else {
                 log.warn("[monitor] " + id + " cannot be found in the inActive monitors list");
             }
-            if (this.status == GroupStatus.Terminating || this.status == GroupStatus.Terminated) {
+            //TODO block
+            /*if (this.status == GroupStatus.Terminating || this.status == GroupStatus.Terminated) {
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, this.appId);
                 log.info("Executing the un-subscription request for the [monitor] " + id);
-            }
+            }*/
         }
     }
 
     @Override
     public void onParentStatusEvent(MonitorStatusEvent statusEvent) {
         // send the ClusterTerminating event
-        if (statusEvent.getStatus() == GroupStatus.Terminating || statusEvent.getStatus() ==
-                ApplicationStatus.Terminating) {
+        if (statusEvent.getStatus() == GroupStatus.Terminating ||
+                statusEvent.getStatus() == ApplicationStatus.Terminating) {
             ApplicationBuilder.handleGroupTerminatingEvent(appId, id);
+        } if(statusEvent.getStatus() == ClusterStatus.Created ||
+                                            statusEvent.getStatus() == GroupStatus.Created) {
+            ApplicationBuilder.handleGroupInstanceCreatedEvent(this.appId, this.id,null );
         }
     }
 
@@ -173,8 +191,11 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler
 
     }
 
-    public GroupStatus getStatus() {
-        return status;
+    public boolean isGroupScalingEnabled() {
+        return groupScalingEnabled;
     }
 
+    public void setGroupScalingEnabled(boolean groupScalingEnabled) {
+        this.groupScalingEnabled = groupScalingEnabled;
+    }
 }