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/12/09 09:36:23 UTC

[3/8] stratos git commit: fixing startup of VM upon termination

fixing startup of VM upon termination


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

Branch: refs/heads/4.1.0-test
Commit: b9a7fa22de88c647133648e83336c1297fe5e412
Parents: 215565f
Author: reka <rt...@gmail.com>
Authored: Mon Dec 8 23:47:06 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Tue Dec 9 14:02:49 2014 +0530

----------------------------------------------------------------------
 .../applications/dependency/DependencyTree.java | 21 ++++--
 .../autoscaler/monitor/MonitorFactory.java      | 55 ++-------------
 .../monitor/cluster/AbstractClusterMonitor.java |  2 +-
 .../monitor/cluster/VMClusterMonitor.java       | 74 ++++++++++++++++++++
 .../monitor/component/GroupMonitor.java         | 59 ++++++++--------
 .../component/ParentComponentMonitor.java       | 55 ++++++---------
 6 files changed, 149 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/b9a7fa22/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
index 1f86ca4..1e8b69e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java
@@ -21,6 +21,8 @@ package org.apache.stratos.autoscaler.applications.dependency;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.applications.dependency.context.ApplicationChildContext;
+import org.apache.stratos.autoscaler.monitor.Monitor;
+import org.apache.stratos.autoscaler.monitor.component.ParentComponentMonitor;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -163,26 +165,33 @@ public class DependencyTree {
      *
      * @return list of dependencies
      */
-    public List<ApplicationChildContext> getStarAbleDependencies() {
+    public List<ApplicationChildContext> getStartAbleDependencies() {
         //returning the top level as the monitor is in initializing state
         return this.primaryApplicationContextList;
     }
 
-    public List<ApplicationChildContext> getStarAbleDependenciesByTermination() {
+    public List<ApplicationChildContext> getStarAbleDependenciesByTermination(
+                                                                    ParentComponentMonitor monitor,
+                                                                    String instanceId) {
         //Breadth First search over the graph to find out which level has the terminated contexts
-        return traverseGraphByLevel(this.primaryApplicationContextList);
+
+        return traverseGraphByLevel(this.primaryApplicationContextList, monitor, instanceId);
     }
 
 
-    private List<ApplicationChildContext> traverseGraphByLevel(List<ApplicationChildContext> contexts) {
+    private List<ApplicationChildContext> traverseGraphByLevel(List<ApplicationChildContext> contexts,
+                                                               ParentComponentMonitor parentMonitor,
+                                                               String instanceId) {
         for(ApplicationChildContext context : contexts) {
-            if(context.isTerminated()) {
+            Monitor monitor = parentMonitor.getMonitor(context.getId());
+            if(monitor.getInstance(instanceId) == null ||
+                    monitor.getInstancesByParentInstanceId(instanceId).isEmpty()) {
                 return contexts;
             }
         }
 
         for(ApplicationChildContext context : contexts) {
-            return traverseGraphByLevel(context.getApplicationChildContextList());
+            return traverseGraphByLevel(context.getApplicationChildContextList(), parentMonitor, instanceId);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/b9a7fa22/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
index a80e50c..5ee986b 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
@@ -34,6 +34,7 @@ import org.apache.stratos.autoscaler.exception.partition.PartitionValidationExce
 import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
 import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitorFactory;
+import org.apache.stratos.autoscaler.monitor.cluster.VMClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
 import org.apache.stratos.autoscaler.monitor.component.GroupMonitor;
 import org.apache.stratos.autoscaler.monitor.component.ParentComponentMonitor;
@@ -88,11 +89,7 @@ public class MonitorFactory {
         return monitor;
     }
 
-    private static void createClusterInstance(String serviceType, String clusterId, String alias,
-                                              String instanceId, String partitionId, String networkPartitionId) {
-        CloudControllerClient.getInstance().createClusterInstance(serviceType, clusterId, alias,
-                instanceId, partitionId, networkPartitionId);
-    }
+
 
     /**
      * This will create the GroupMonitor based on given groupId by going thr Topology
@@ -271,51 +268,11 @@ public class MonitorFactory {
             } else {
                 clusterMonitor.setHasGroupScalingDependent(false);
             }
+            //Creating the instance of the cluster
+            ((VMClusterMonitor)clusterMonitor).createClusterInstance(parentInstanceIds, cluster);
+            //add it to autoscaler context
+            AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
 
-            for (String parentInstanceId : parentInstanceIds) {
-                Instance parentMonitorInstance = parentMonitor.getInstance(parentInstanceId);
-                String partitionId = null;
-                if (parentMonitorInstance instanceof GroupInstance) {
-                    partitionId = parentMonitorInstance.getPartitionId();
-                }
-                if (parentMonitorInstance != null) {
-                    ClusterInstance clusterInstance = cluster.getInstanceContexts(parentInstanceId);
-                    if (clusterInstance != null) {
-                        // Cluster instance is already there. No need to create one.
-                        VMClusterContext clusterContext;
-                        clusterContext =
-                                ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(), cluster);
-                        clusterMonitor.setClusterContext(clusterContext);
-                        // create VMClusterContext and then add all the instanceContexts
-                        clusterContext.addInstanceContext(parentInstanceId, cluster);
-                        if (clusterMonitor.getInstance(clusterInstance.getInstanceId()) == null) {
-                            clusterMonitor.addInstance(clusterInstance);
-                        }
-                        // Checking the current status of the cluster instance
-                        boolean stateChanged =
-                                ServiceReferenceHolder.getInstance().getClusterStatusProcessorChain()
-                                        .process("", clusterId, clusterInstance.getInstanceId());
-                        if (!stateChanged && clusterInstance.getStatus() != ClusterStatus.Created) {
-                            clusterMonitor.notifyParentMonitor(clusterInstance.getStatus(),
-                                    clusterInstance.getInstanceId());
-
-                            if (clusterMonitor.hasMonitoringStarted().compareAndSet(false, true)) {
-                                clusterMonitor.startScheduler();
-                                log.info("Monitoring task for Cluster Monitor with cluster id " +
-                                        clusterId + " started successfully");
-                            }
-                        }
-                    } else {
-                        createClusterInstance(cluster.getServiceName(), clusterId, null, parentInstanceId, partitionId,
-                                parentMonitorInstance.getNetworkPartitionId());
-                    }
-
-                } else {
-
-                }
-                AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
-
-            }
 
             return clusterMonitor;
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/b9a7fa22/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
index 277948f..91e5c4a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java
@@ -68,7 +68,7 @@ public abstract class AbstractClusterMonitor extends Monitor implements Runnable
     protected AutoscalerRuleEvaluator autoscalerRuleEvaluator;
     protected String serviceType;
     private AtomicBoolean monitoringStarted;
-    private String clusterId;
+    protected String clusterId;
     private Cluster cluster;
     private int monitoringIntervalMilliseconds;
     private boolean isDestroyed;

http://git-wip-us.apache.org/repos/asf/stratos/blob/b9a7fa22/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
index ef8491a..a43f89e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
@@ -22,6 +22,8 @@ import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.client.CloudControllerClient;
+import org.apache.stratos.autoscaler.context.AutoscalerContext;
+import org.apache.stratos.autoscaler.context.cluster.ClusterContextFactory;
 import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext;
 import org.apache.stratos.autoscaler.context.cluster.VMClusterContext;
 import org.apache.stratos.autoscaler.context.member.MemberStatsContext;
@@ -30,6 +32,8 @@ import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetwo
 import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
 import org.apache.stratos.autoscaler.exception.InvalidArgumentException;
 import org.apache.stratos.autoscaler.exception.cartridge.TerminationException;
+import org.apache.stratos.autoscaler.exception.partition.PartitionValidationException;
+import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
 import org.apache.stratos.autoscaler.monitor.events.MonitorScalingEvent;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.monitor.events.builder.MonitorStatusEventBuilder;
@@ -48,6 +52,8 @@ import org.apache.stratos.common.constants.StratosConstants;
 import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
 import org.apache.stratos.messaging.domain.applications.GroupStatus;
 import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.domain.instance.Instance;
 import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.Member;
@@ -1051,4 +1057,72 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
     }
 
 
+    public void createClusterInstance(List<String> parentInstanceIds, Cluster cluster)
+            throws PolicyValidationException, PartitionValidationException {
+        for (String parentInstanceId : parentInstanceIds) {
+            createInstance(parentInstanceId, cluster);
+        }
+
+    }
+
+    public void createClusterInstanceOnScaleUp(String instanceId)
+            throws PolicyValidationException, PartitionValidationException {
+        Cluster cluster = TopologyManager.getTopology().getService(this.serviceType).
+                getCluster(this.clusterId);
+        createInstance(instanceId, cluster);
+
+    }
+
+    private static void createClusterInstance(String serviceType, String clusterId, String alias,
+                                              String instanceId, String partitionId, String networkPartitionId) {
+        CloudControllerClient.getInstance().createClusterInstance(serviceType, clusterId, alias,
+                instanceId, partitionId, networkPartitionId);
+    }
+
+    private void createInstance(String parentInstanceId, Cluster cluster)
+            throws PolicyValidationException, PartitionValidationException {
+        Instance parentMonitorInstance = this.parent.getInstance(parentInstanceId);
+        String partitionId = null;
+        if (parentMonitorInstance instanceof GroupInstance) {
+            partitionId = parentMonitorInstance.getPartitionId();
+        }
+        if (parentMonitorInstance != null) {
+            ClusterInstance clusterInstance = cluster.getInstanceContexts(parentInstanceId);
+            if (clusterInstance != null) {
+                // Cluster instance is already there. No need to create one.
+                VMClusterContext clusterContext;
+                clusterContext =
+                        ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(), cluster);
+                this.setClusterContext(clusterContext);
+                // create VMClusterContext and then add all the instanceContexts
+                clusterContext.addInstanceContext(parentInstanceId, cluster);
+                if (this.getInstance(clusterInstance.getInstanceId()) == null) {
+                    this.addInstance(clusterInstance);
+                }
+                // Checking the current status of the cluster instance
+                boolean stateChanged =
+                        ServiceReferenceHolder.getInstance().getClusterStatusProcessorChain()
+                                .process("", cluster.getClusterId(), clusterInstance.getInstanceId());
+                if (!stateChanged && clusterInstance.getStatus() != ClusterStatus.Created) {
+                    this.notifyParentMonitor(clusterInstance.getStatus(),
+                            clusterInstance.getInstanceId());
+
+                    if (this.hasMonitoringStarted().compareAndSet(false, true)) {
+                        this.startScheduler();
+                        log.info("Monitoring task for Cluster Monitor with cluster id " +
+                                cluster.getClusterId() + " started successfully");
+                    }
+                }
+            } else {
+                createClusterInstance(cluster.getServiceName(), cluster.getClusterId(), null, parentInstanceId, partitionId,
+                        parentMonitorInstance.getNetworkPartitionId());
+            }
+
+        } else {
+
+        }
+
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/b9a7fa22/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
index ac271ba..8d3f42d 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
@@ -46,7 +46,6 @@ import org.apache.stratos.messaging.domain.applications.Application;
 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.instance.ClusterInstance;
 import org.apache.stratos.messaging.domain.instance.GroupInstance;
 import org.apache.stratos.messaging.domain.instance.Instance;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
@@ -177,7 +176,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
 
         } else if (status1 == ClusterStatus.Inactive || status1 == GroupStatus.Inactive) {
             //handling restart of stratos
-            if(!this.aliasToActiveMonitorsMap.get(id).hasStartupDependents()) {
+            if (!this.aliasToActiveMonitorsMap.get(id).hasStartupDependents()) {
                 onChildActivatedEvent(id, instanceId);
             } else {
                 this.markMonitorAsInactive(instanceId);
@@ -238,7 +237,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
             Application application = ApplicationHolder.getApplications().getApplication(this.appId);
             Group group = application.getGroupRecursively(statusEvent.getId());
             //starting a new instance of this monitor
-            createInstanceAndStartDependencyOnScaleup(group, statusEvent.getInstanceId());
+            createInstanceAndStartDependencyOnScaleup(statusEvent.getInstanceId());
         }
     }
 
@@ -347,7 +346,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                 groupLevelNetworkPartitionContext = new GroupLevelNetworkPartitionContext(
                         networkPartitionId);
             }
-            if(log.isInfoEnabled()) {
+            if (log.isInfoEnabled()) {
                 log.info("[Network partition] " + networkPartitionId + "has been added for the " +
                         "[Group] " + this.id);
             }
@@ -383,7 +382,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                     networkPartitionContext.getPartitionCtxt(parentPartitionId) != null) {
                 partitionContext = new GroupLevelPartitionContext(0);
                 networkPartitionContext.addPartitionContext((GroupLevelPartitionContext) partitionContext);
-                if(log.isInfoEnabled()) {
+                if (log.isInfoEnabled()) {
                     log.info("[Partition] " + parentPartitionId + "has been added for the " +
                             "[Group] " + this.id);
                 }
@@ -402,7 +401,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                     childPartitionContexts.add((GroupLevelPartitionContext) partitionContext);
                     networkPartitionContext.addPartitionContext(
                             (GroupLevelPartitionContext) partitionContext);
-                    if(log.isInfoEnabled()) {
+                    if (log.isInfoEnabled()) {
                         log.info("[Partition] " + childLevelPartition.getPartitionId() +
                                 "has been added for the [Group] " + this.id);
                     }
@@ -441,7 +440,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
         groupInstanceContext.addPartitionContext((GroupLevelPartitionContext) partitionContext);
         groupLevelNetworkPartitionContext.addInstanceContext(groupInstanceContext);
 
-        if(log.isInfoEnabled()) {
+        if (log.isInfoEnabled()) {
             log.info("Group [Instance context] " + instanceId +
                     " has been added to [Group] " + this.id);
         }
@@ -486,7 +485,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
 
             //Have to check whether group has generated its own instances
             List<Instance> existingGroupInstances = group.getInstanceContextsWithParentId(parentInstanceId);
-            for(Instance instance : existingGroupInstances) {
+            for (Instance instance : existingGroupInstances) {
                 initialStartup = false;
                 partitionContext = groupLevelNetworkPartitionContext.
                         getPartitionContextById(instance.getPartitionId());
@@ -501,7 +500,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
              * If the group instances have been partially created or not created,
              * then create everything
              */
-            if(existingGroupInstances.size() <= groupMin) {
+            if (existingGroupInstances.size() <= groupMin) {
                 for (int i = 0; i < groupMin - existingGroupInstances.size(); i++) {
                     // Get partitionContext to create instance in
                     List<GroupLevelPartitionContext> partitionContexts = groupLevelNetworkPartitionContext.
@@ -510,7 +509,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                             new GroupLevelPartitionContext[partitionContexts.size()];
                     if (parentPartitionId == null) {
                         AutoscaleAlgorithm algorithm = this.getAutoscaleAlgorithm(
-                                        groupLevelNetworkPartitionContext.getPartitionAlgorithm());
+                                groupLevelNetworkPartitionContext.getPartitionAlgorithm());
                         partitionContext = algorithm.getNextScaleUpPartitionContext(
                                 (partitionContexts.toArray(groupLevelPartitionContexts)));
                     } else {
@@ -526,7 +525,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
             }
 
         }
-        if(log.isInfoEnabled()) {
+        if (log.isInfoEnabled()) {
             log.info("Starting the dependencies for the [Group] " + group.getUniqueIdentifier());
         }
         startDependency(group, instanceIdsToStart);
@@ -534,20 +533,22 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
     }
 
 
-
     /**
      * This will start the group instance based on the given parent instanceId
      * A new monitor is not created in this case
      *
-     * @param group
      * @param parentInstanceId
      * @throws org.apache.stratos.autoscaler.exception.application.MonitorNotFoundException
      */
-    public void createInstanceAndStartDependencyOnScaleup(Group group, String parentInstanceId)
+    public void createInstanceAndStartDependencyOnScaleup(String parentInstanceId)
             throws MonitorNotFoundException {
         // Get parent instance context
         Instance parentInstanceContext = getParentInstanceContext(parentInstanceId);
 
+        //TODO to get lock
+        Group group = ApplicationHolder.getApplications().
+                getApplication(this.appId).getGroupRecursively(this.id);
+
         // Get existing or create new GroupLevelNetworkPartitionContext
         GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext =
                 getGroupLevelNetworkPartitionContext(group.getUniqueIdentifier(),
@@ -559,7 +560,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
         PartitionContext partitionContext;
         String parentPartitionId = parentInstanceContext.getPartitionId();
         int groupMax = group.getGroupMaxInstances();
-        if(group.getInstanceContextCount() < groupMax) {
+        if (group.getInstanceContextCount() < groupMax) {
             // Get partitionContext to create instance in
             if (parentPartitionId == null) {
                 AutoscaleAlgorithm algorithm = this.getAutoscaleAlgorithm(
@@ -571,7 +572,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
                 partitionContext = groupLevelNetworkPartitionContext.
                         getPartitionContextById(parentPartitionId);
             }
-            if(partitionContext != null) {
+            if (partitionContext != null) {
                 groupInstanceId = createGroupInstanceAndAddToMonitor(group, parentInstanceContext,
                         partitionContext,
                         groupLevelNetworkPartitionContext,
@@ -598,8 +599,8 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
      * @param networkPartitionId
      * @return
      */
-    private GroupInstance createGroupInstance(Group group,  String networkPartitionId,
-                                              String parentInstanceId, String partitionId ) {
+    private GroupInstance createGroupInstance(Group group, String networkPartitionId,
+                                              String parentInstanceId, String partitionId) {
         String instanceId = parentInstanceId;
         int minGroupInstances = group.getGroupMinInstances();
         int maxGroupInstances = group.getGroupMaxInstances();
@@ -631,31 +632,31 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
     }
 
     public boolean verifyGroupStatus(String instanceId, GroupStatus requiredStatus) {
-        if(this.instanceIdToInstanceMap.containsKey(instanceId)) {
-            if(((GroupInstance)this.instanceIdToInstanceMap.get(instanceId)).getStatus() == requiredStatus) {
+        if (this.instanceIdToInstanceMap.containsKey(instanceId)) {
+            if (((GroupInstance) this.instanceIdToInstanceMap.get(instanceId)).getStatus() == requiredStatus) {
                 return true;
             }
         } else {
             List<GroupInstance> instances = new ArrayList<GroupInstance>();
             String networkPartitionId = null;
             int noOfInstancesOfRequiredStatus = 0;
-            for(Instance instance : this.instanceIdToInstanceMap.values()) {
-                GroupInstance groupInstance = (GroupInstance)instance;
-                if(groupInstance.getParentId().equals(instanceId)) {
+            for (Instance instance : this.instanceIdToInstanceMap.values()) {
+                GroupInstance groupInstance = (GroupInstance) instance;
+                if (groupInstance.getParentId().equals(instanceId)) {
                     instances.add(groupInstance);
                     networkPartitionId = groupInstance.getNetworkPartitionId();
-                    if(groupInstance.getStatus() == requiredStatus) {
-                        noOfInstancesOfRequiredStatus ++;
+                    if (groupInstance.getStatus() == requiredStatus) {
+                        noOfInstancesOfRequiredStatus++;
                     }
                 }
             }
-            if(!instances.isEmpty()) {
+            if (!instances.isEmpty()) {
                 int minInstances = this.networkPartitionCtxts.get(networkPartitionId).
-                                                getMinInstanceCount();
-                if(noOfInstancesOfRequiredStatus >= minInstances) {
+                        getMinInstanceCount();
+                if (noOfInstancesOfRequiredStatus >= minInstances) {
                     return true;
                 } else {
-                    if(requiredStatus == GroupStatus.Inactive && noOfInstancesOfRequiredStatus >= 1) {
+                    if (requiredStatus == GroupStatus.Inactive && noOfInstancesOfRequiredStatus >= 1) {
                         return true;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/b9a7fa22/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
index 0e9e267..61fbf11 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
@@ -40,6 +40,7 @@ import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 import org.apache.stratos.autoscaler.monitor.MonitorFactory;
 import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.cluster.VMClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.events.builder.MonitorStatusEventBuilder;
 import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
 import org.apache.stratos.messaging.domain.applications.Group;
@@ -92,7 +93,7 @@ public abstract class ParentComponentMonitor extends Monitor {
     public void startDependency(ParentComponent component, List<String> instanceIds) {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
-                getStarAbleDependencies(); //TODO t
+                getStartAbleDependencies();
         startDependency(applicationContexts, instanceIds);
 
     }
@@ -105,7 +106,7 @@ public abstract class ParentComponentMonitor extends Monitor {
             MonitorNotFoundException {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
-                getStarAbleDependencies();
+                getStartAbleDependencies();
         startDependency(applicationContexts, instanceId);
 
     }
@@ -123,23 +124,6 @@ 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(ParentComponent component) {
-        //start the first dependency
-        List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
-                getStarAbleDependencies();
-        Collection<Instance> contexts = component.getInstanceIdToInstanceContextMap().values();
-        //traversing through all the Instance context and start them
-        List<String> instanceIds = new ArrayList<String>();
-        for (Instance context : contexts) {
-            instanceIds.add(context.getInstanceId());
-        }
-        startDependency(applicationContexts, instanceIds);
-    }
-
-    /**
      * This will get invoked based on the activation event of its one of the child
      *
      * @param id alias/clusterId of which receive the activated event
@@ -153,28 +137,25 @@ public abstract class ParentComponentMonitor extends Monitor {
         return startup;
     }
 
-    public boolean startAllChildrenDependency(ParentComponent component, String instanceId)
-            throws TopologyInConsistentException {
-        /*List<ApplicationChildContext> applicationContexts = this.startupDependencyTree
-                .findAllChildrenOfAppContext(id);*/
-        return false;//startDependency(applicationContexts, instanceId);
-    }
-
     /**
      * This will start the parallel dependencies at once from the top level
      * by traversing to find the terminated dependencies.
      * it will get invoked when start a child monitor on termination of a sub tree
      */
-    public void startDependencyOnTermination() throws TopologyInConsistentException {
+    public void startDependencyOnTermination(String instanceId) throws TopologyInConsistentException,
+            MonitorNotFoundException, PolicyValidationException, PartitionValidationException {
         //start the first dependency which went to terminated
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
-                getStarAbleDependenciesByTermination();
+                getStarAbleDependenciesByTermination(this, instanceId);
         for(ApplicationChildContext context : applicationContexts) {
             if(context instanceof GroupChildContext) {
                 GroupMonitor groupMonitor = (GroupMonitor) this.aliasToActiveMonitorsMap.
                                                         get(context.getId());
+                groupMonitor.createInstanceAndStartDependencyOnScaleup(instanceId);
             } else if(context instanceof ClusterChildContext) {
-
+                VMClusterMonitor clusterMonitor = (VMClusterMonitor) this.
+                                                    aliasToActiveMonitorsMap.get(context.getId());
+                clusterMonitor.createClusterInstanceOnScaleUp(instanceId);
             }
         }
 
@@ -203,9 +184,7 @@ public abstract class ParentComponentMonitor extends Monitor {
                 startMonitor(this, context, instanceIds);
             }
         }
-
         return true;
-
     }
 
     /**
@@ -389,10 +368,18 @@ public abstract class ParentComponentMonitor extends Monitor {
                 (parentContexts.isEmpty() || parentsTerminated || allParentsActive)) {
             //Find the non existent monitor by traversing dependency tree
             try {
-                this.startDependencyOnTermination();
+                this.startDependencyOnTermination(instanceId);
             } catch (TopologyInConsistentException e) {
                 //TODO revert the siblings and notify parent, change a flag for reverting/un-subscription
                 log.error("Error while starting the monitor upon termination" + e);
+            } catch (MonitorNotFoundException e) {
+                //TODO revert the siblings and notify parent, change a flag for reverting/un-subscription
+                log.error("Error while starting the monitor by relevant monitor not found" + e);
+            } catch (PartitionValidationException e) {
+                log.error("Error while starting the monitor upon termination by partition validation failed" + e);
+            } catch (PolicyValidationException e) {
+                log.error("Error while starting the monitor upon termination by policy validation failed" + e);
+
             }
         } else {
             ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().
@@ -531,6 +518,10 @@ public abstract class ParentComponentMonitor extends Monitor {
         return aliasToActiveMonitorsMap;
     }
 
+    public Monitor getMonitor(String monitorId) {
+        return this.aliasToActiveMonitorsMap.get(monitorId);
+    }
+
     public void setAliasToActiveMonitorsMap(Map<String, Monitor> aliasToActiveMonitorsMap) {
         this.aliasToActiveMonitorsMap = aliasToActiveMonitorsMap;
     }