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/14 18:02:07 UTC

[1/3] stratos git commit: fixing terminate-dependent handling issue

Repository: stratos
Updated Branches:
  refs/heads/4.1.0-test 11215791f -> 03bd88799


fixing terminate-dependent handling issue


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

Branch: refs/heads/4.1.0-test
Commit: 12c125de71a67fb1fc2538a9b4010f1791461fde
Parents: 1121579
Author: reka <rt...@gmail.com>
Authored: Sun Dec 14 09:50:26 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Sun Dec 14 22:30:45 2014 +0530

----------------------------------------------------------------------
 .../component/ParentComponentMonitor.java       | 192 ++++++++++---------
 .../processor/group/GroupStatusProcessor.java   |   9 +
 2 files changed, 110 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/12c125de/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 d85ba90..2cb1632 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
@@ -59,11 +59,11 @@ import java.util.concurrent.ExecutorService;
  * control them according to the dependencies respectively.
  */
 public abstract class ParentComponentMonitor extends Monitor {
-	private static final Log log = LogFactory.getLog(ParentComponentMonitor.class);
+    private static final Log log = LogFactory.getLog(ParentComponentMonitor.class);
     private static final String IDENTIFIER = "Auto-Scaler";
     private static final int THREAD_POOL_SIZE = 10;
 
-	//The monitors dependency tree with all the start-able/kill-able dependencies
+    //The monitors dependency tree with all the start-able/kill-able dependencies
     protected DependencyTree startupDependencyTree;
     //The monitors dependency tree with all the scaling dependencies
     protected Set<ScalingDependentList> scalingDependencies;
@@ -75,8 +75,8 @@ public abstract class ParentComponentMonitor extends Monitor {
     protected Map<String, List<String>> inactiveInstancesMap;
     //terminating map, key=alias, value instanceIds
     protected Map<String, List<String>> terminatingInstancesMap;
-	//Executor service to maintain the thread pool
-	private ExecutorService executorService;
+    //Executor service to maintain the thread pool
+    private ExecutorService executorService;
 
     public ParentComponentMonitor(ParentComponent component) throws DependencyBuilderException {
         aliasToActiveMonitorsMap = new ConcurrentHashMap<String, Monitor>();
@@ -181,11 +181,18 @@ public abstract class ParentComponentMonitor extends Monitor {
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
                 getStarAbleDependenciesByTermination(this, instanceId);
         for (ApplicationChildContext context : applicationContexts) {
-            if (context instanceof GroupChildContext) {
-                GroupMonitor groupMonitor = (GroupMonitor) this.aliasToActiveMonitorsMap.
-                                                        get(context.getId());
-            } else if(context instanceof ClusterChildContext) {
-
+            if (log.isDebugEnabled()) {
+                log.debug("Dependency check for the Group " + context.getId() + " started");
+            }
+            //FIXME whether to start new monitor or throw exception
+            if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
+                String msg = "Required Monitor cannot be fount in the hierarchy";
+                throw new MonitorNotFoundException(msg);
+            } else {
+                //starting a new instance of the child
+                Monitor monitor = aliasToActiveMonitorsMap.get(context.getId());
+                //Creating the new instance
+                monitor.createInstanceOnDemand(instanceId);
             }
         }
 
@@ -296,8 +303,8 @@ public abstract class ParentComponentMonitor extends Monitor {
         terminationList = this.startupDependencyTree.getTerminationDependencies(childId);
         //Need to notify the parent about the status  change from Active-->Inactive
         // TODO to make app also inaction if (this.parent != null) {
-                ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().
-                        process(id, appId, instanceId);
+        ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().
+                process(id, appId, instanceId);
 
         //TODO checking whether terminating them in reverse order,
         // TODO if so can handle it in the parent event.
@@ -372,7 +379,7 @@ public abstract class ParentComponentMonitor extends Monitor {
         terminationList = this.startupDependencyTree.getTerminationDependencies(eventId);
         //Make sure that all the dependents have been terminated properly to start the recovery
         if (terminationList != null) {
-            allDependentTerminated = allDependentTerminated(terminationList);
+            allDependentTerminated = allDependentTerminated(terminationList, instanceId);
         }
         log.info("Calculating the dependencies to be started upon the termination of the " +
                 "group/cluster " + eventId + " for [instance] " + instanceId);
@@ -413,17 +420,20 @@ public abstract class ParentComponentMonitor extends Monitor {
 
     }
 
-    private boolean allDependentTerminated(List<ApplicationChildContext> terminationList) {
+    private boolean allDependentTerminated(List<ApplicationChildContext> terminationList, String instanceId) {
         boolean allDependentTerminated = false;
         for (ApplicationChildContext context1 : terminationList) {
-            if (this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
-                log.warn("Dependent [monitor] " + context1.getId() + " not in the correct state");
-                allDependentTerminated = false;
-                return allDependentTerminated;
-            } else if (this.inactiveInstancesMap.containsKey(context1.getId())) {
-                log.info("Waiting for the [dependent] " + context1.getId() + " to be terminated...");
+            if (this.inactiveInstancesMap.containsKey(context1.getId()) &&
+                    this.inactiveInstancesMap.get(context1.getId()).contains(instanceId)
+                    || this.terminatingInstancesMap.containsKey(context1.getId()) &&
+                    this.terminatingInstancesMap.get(context1.getId()).contains(instanceId)) {
+                log.info("Waiting for the [dependent] " + context1.getId() + " [instance] " +
+                        instanceId + "to be terminated...");
                 allDependentTerminated = false;
                 return allDependentTerminated;
+            } else if (this.aliasToActiveMonitorsMap.get(context1.getId()).getInstance(instanceId) != null) {
+                log.info("[Dependent] " + context1.getId() + "[Instance] " + instanceId +
+                        "has not been started to terminate yet. Hence waiting....");
             } else {
                 allDependentTerminated = true;
             }
@@ -437,16 +447,16 @@ public abstract class ParentComponentMonitor extends Monitor {
         boolean parentsTerminated = false;
         for (ApplicationChildContext context1 : parentContexts) {
             if (this.inactiveInstancesMap.containsKey(context1.getId()) &&
-                    this.inactiveInstancesMap.get(context1.getId()).contains(instanceId)) {
+                    this.inactiveInstancesMap.get(context1.getId()).contains(instanceId)
+                    || this.terminatingInstancesMap.containsKey(context1.getId()) &&
+                    this.terminatingInstancesMap.get(context1.getId()).contains(instanceId)) {
                 log.info("Waiting for the [Parent Monitor] " + context1.getId()
                         + " to be terminated");
                 parentsTerminated = false;
                 return parentsTerminated;
-            } else if (this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
-                if (parentsTerminated) {
-                    log.warn("Found the Dependent [monitor] " + context1.getId()
-                            + " in the active list wrong state");
-                }
+            } else if (this.aliasToActiveMonitorsMap.get(context1.getId()).getInstance(instanceId) != null) {
+                log.info("[Dependent Parent] " + context1.getId() + "[Instance] " + instanceId +
+                        "has not been started to terminate yet. Hence waiting....");
             } else {
                 log.info("[Parent Monitor] " + context1.getId()
                         + " has already been terminated");
@@ -553,13 +563,13 @@ public abstract class ParentComponentMonitor extends Monitor {
     protected synchronized void startMonitor(ParentComponentMonitor parent,
                                              ApplicationChildContext context, List<String> instanceId) {
 
-	    if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
-		    pendingMonitorsList.add(context.getId());
-		    executorService.submit(new MonitorAdder(parent, context, this.appId, instanceId));
-		    if (log.isDebugEnabled()) {
-			    log.debug(String.format("Monitor Adder has been added: [cluster] %s ",context.getId()));
-		    }
-	    }
+        if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
+            pendingMonitorsList.add(context.getId());
+            executorService.submit(new MonitorAdder(parent, context, this.appId, instanceId));
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Monitor Adder has been added: [cluster] %s ", context.getId()));
+            }
+        }
 
     }
 
@@ -634,76 +644,76 @@ public abstract class ParentComponentMonitor extends Monitor {
         return autoscaleAlgorithm;
     }
 
-private class MonitorAdder implements Runnable {
-    private ApplicationChildContext context;
-    private ParentComponentMonitor parent;
-    private String appId;
-    private List<String> instanceId;
-
-    public MonitorAdder(ParentComponentMonitor parent, ApplicationChildContext context,
-                        String appId, List<String> instanceId) {
-        this.parent = parent;
-        this.context = context;
-        this.appId = appId;
-        this.instanceId = instanceId;
+    public Set<ScalingDependentList> getScalingDependencies() {
+        return scalingDependencies;
     }
 
-    public void run() {
-        Monitor monitor = null;
-        int retries = 5;
-        boolean success = false;
-        while (!success && retries != 0) {
+    private class MonitorAdder implements Runnable {
+        private ApplicationChildContext context;
+        private ParentComponentMonitor parent;
+        private String appId;
+        private List<String> instanceId;
+
+        public MonitorAdder(ParentComponentMonitor parent, ApplicationChildContext context,
+                            String appId, List<String> instanceId) {
+            this.parent = parent;
+            this.context = context;
+            this.appId = appId;
+            this.instanceId = instanceId;
+        }
+
+        public void run() {
+            Monitor monitor = null;
+            int retries = 5;
+            boolean success = false;
+            while (!success && retries != 0) {
                 /*//TODO remove thread.sleep, exectutor service
                 try {
                     Thread.sleep(5000);
                 } catch (InterruptedException e1) {
                 }*/
 
-            if (log.isInfoEnabled()) {
-                log.info("Monitor is going to be started for [group/cluster] "
-                        + context.getId());
-            }
-            try {
-                monitor = MonitorFactory.getMonitor(parent, context, appId, instanceId);
-            } catch (DependencyBuilderException e) {
-                String msg = "Monitor creation failed for: " + context.getId();
-                log.warn(msg, e);
-                retries--;
-            } catch (TopologyInConsistentException e) {
-                String msg = "Monitor creation failed for: " + context.getId();
-                log.warn(msg, e);
-                retries--;
-            } catch (PolicyValidationException e) {
-                String msg = "Monitor creation failed for: " + context.getId();
-                log.warn(msg, e);
-                retries--;
-            } catch (PartitionValidationException e) {
-                String msg = "Monitor creation failed for: " + context.getId();
-                log.warn(msg, e);
-                retries--;
+                if (log.isInfoEnabled()) {
+                    log.info("Monitor is going to be started for [group/cluster] "
+                            + context.getId());
+                }
+                try {
+                    monitor = MonitorFactory.getMonitor(parent, context, appId, instanceId);
+                } catch (DependencyBuilderException e) {
+                    String msg = "Monitor creation failed for: " + context.getId();
+                    log.warn(msg, e);
+                    retries--;
+                } catch (TopologyInConsistentException e) {
+                    String msg = "Monitor creation failed for: " + context.getId();
+                    log.warn(msg, e);
+                    retries--;
+                } catch (PolicyValidationException e) {
+                    String msg = "Monitor creation failed for: " + context.getId();
+                    log.warn(msg, e);
+                    retries--;
+                } catch (PartitionValidationException e) {
+                    String msg = "Monitor creation failed for: " + context.getId();
+                    log.warn(msg, e);
+                    retries--;
+                }
+                success = true;
             }
-            success = true;
-        }
 
-        if (monitor == null) {
-            String msg = "Monitor creation failed, even after retrying for 5 times, "
-                    + "for : " + context.getId();
-            log.error(msg);
-            //TODO parent.notify();
-            throw new RuntimeException(msg);
-        }
+            if (monitor == null) {
+                String msg = "Monitor creation failed, even after retrying for 5 times, "
+                        + "for : " + context.getId();
+                log.error(msg);
+                //TODO parent.notify();
+                throw new RuntimeException(msg);
+            }
 
-        aliasToActiveMonitorsMap.put(context.getId(), monitor);
-        pendingMonitorsList.remove(context.getId());
-        // ApplicationBuilder.
-        if (log.isInfoEnabled()) {
-            log.info(String.format("Monitor has been added successfully for: %s",
-                    context.getId()));
+            aliasToActiveMonitorsMap.put(context.getId(), monitor);
+            pendingMonitorsList.remove(context.getId());
+            // ApplicationBuilder.
+            if (log.isInfoEnabled()) {
+                log.info(String.format("Monitor has been added successfully for: %s",
+                        context.getId()));
+            }
         }
     }
 }
-
-	public Set<ScalingDependentList> getScalingDependencies() {
-		return scalingDependencies;
-	}
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/12c125de/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
index ff2072b..057b57c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
@@ -18,6 +18,8 @@
  */
 package org.apache.stratos.autoscaler.status.processor.group;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.status.processor.StatusProcessor;
 import org.apache.stratos.messaging.domain.applications.ClusterDataHolder;
 import org.apache.stratos.messaging.domain.applications.Group;
@@ -37,6 +39,8 @@ import java.util.Map;
  * This will be used to process the group status
  */
 public abstract class GroupStatusProcessor extends StatusProcessor {
+    private static final Log log = LogFactory.getLog(GroupStatusProcessor.class);
+
 
     /**
      * Message processing and delegating logic.
@@ -111,10 +115,15 @@ public abstract class GroupStatusProcessor extends StatusProcessor {
                 Cluster cluster = service.getCluster(clusterId);
                 ClusterInstance context = cluster.getInstanceContexts(instanceId);
                 if (context != null) {
+                    if(log.isInfoEnabled()) {
+                        log.info("Checking the status of cluster " + clusterId + " instance status is: " +
+                                context.getStatus().toString());
+                    }
                     if(context.getStatus() == status) {
                         clusterStat = true;
                     } else {
                         clusterStat = false;
+                        return clusterStat;
                     }
                 } else {
                     //Checking whether non-existent context is for a terminated state change


[2/3] stratos git commit: removing policy id from the log

Posted by re...@apache.org.
removing policy id from the log


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

Branch: refs/heads/4.1.0-test
Commit: 3ac4f824283622597b595e0f7f49c4cdad6557f7
Parents: 12c125d
Author: reka <rt...@gmail.com>
Authored: Sun Dec 14 09:51:14 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Sun Dec 14 22:31:50 2014 +0530

----------------------------------------------------------------------
 .../org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3ac4f824/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index a213d90..32ff63d 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -999,8 +999,8 @@ public class StratosApiV41Utils {
             throws RestAPIException {
 
         if (log.isInfoEnabled()) {
-            log.info(String.format("Starting to deploy application: [application-id] %s [deployment-policy-id] %s",
-                    deploymentPolicyBean.getApplicationPolicy().getApplicationId(), deploymentPolicyBean.getId()));
+            log.info(String.format("Starting to deploy application: [application-id] %s",
+                    deploymentPolicyBean.getApplicationPolicy().getApplicationId()));
         }
 
         AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();


[3/3] stratos git commit: supporting start depdency by creating new instance

Posted by re...@apache.org.
supporting start depdency by creating new instance


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

Branch: refs/heads/4.1.0-test
Commit: 03bd88799624c75303770183ebe74cf0b7e270f9
Parents: 3ac4f82
Author: reka <rt...@gmail.com>
Authored: Sun Dec 14 22:22:56 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Sun Dec 14 22:31:51 2014 +0530

----------------------------------------------------------------------
 .../component/ParentComponentMonitor.java       | 63 +++++---------------
 1 file changed, 16 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/03bd8879/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 2cb1632..43dc916 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
@@ -28,8 +28,6 @@ import org.apache.stratos.autoscaler.applications.ApplicationHolder;
 import org.apache.stratos.autoscaler.applications.dependency.DependencyBuilder;
 import org.apache.stratos.autoscaler.applications.dependency.DependencyTree;
 import org.apache.stratos.autoscaler.applications.dependency.context.ApplicationChildContext;
-import org.apache.stratos.autoscaler.applications.dependency.context.ClusterChildContext;
-import org.apache.stratos.autoscaler.applications.dependency.context.GroupChildContext;
 import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
 import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
 import org.apache.stratos.autoscaler.exception.application.DependencyBuilderException;
@@ -46,11 +44,13 @@ import org.apache.stratos.messaging.domain.applications.GroupStatus;
 import org.apache.stratos.messaging.domain.applications.ParentComponent;
 import org.apache.stratos.messaging.domain.applications.ScalingDependentList;
 import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.instance.Instance;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 
@@ -119,35 +119,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 boolean startDependencyByInstanceCreation(String childId, String instanceId) throws
-            MonitorNotFoundException {
-        //start the first dependency
-        List<ApplicationChildContext> applicationContexts =
-                this.startupDependencyTree.getStarAbleDependencies(childId);
-        return 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) {
-        //start the first dependency
-        List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
-                getStartAbleDependencies();
-        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
@@ -157,23 +128,16 @@ public abstract class ParentComponentMonitor extends Monitor {
                 .getStarAbleDependencies(id);
         List<String> instanceIds = new ArrayList<String>();
         instanceIds.add(instanceId);
-        boolean startup = startDependency(applicationContexts, instanceIds);
-        return startup;
-    }
-
-    public boolean startAllChildrenDependency(ParentComponent component, String instanceId)
-            throws TopologyInConsistentException {
-        /*List<ApplicationChildContext> applicationContexts = this.startupDependencyTree
-                .findAllChildrenOfAppContext(id);*/
-        return false;//startDependency(applicationContexts, instanceId);
+        return startDependency(applicationContexts, instanceIds);
     }
 
     /**
      * 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
+     * it will get invoked when starting a child instance on termination of a sub tree
+     *
+     * @param instanceId instance id of the instance
      */
-
     public void startDependencyOnTermination(String instanceId) throws TopologyInConsistentException,
             MonitorNotFoundException, PolicyValidationException, PartitionValidationException {
 
@@ -219,6 +183,13 @@ public abstract class ParentComponentMonitor extends Monitor {
             if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
                 //to avoid if it is already started
                 startMonitor(this, context, instanceIds);
+            } else {
+                //starting a new instance of the child
+                Monitor monitor = aliasToActiveMonitorsMap.get(context.getId());
+                //Creating the new instance
+                for (String instanceId : instanceIds) {
+                    monitor.createInstanceOnDemand(instanceId);
+                }
             }
         }
 
@@ -275,11 +246,9 @@ public abstract class ParentComponentMonitor extends Monitor {
             removeInstanceFromFromInactiveMap(childId, instanceId);
             removeInstanceFromFromTerminatingMap(childId, instanceId);
 
-            boolean startDep;
+            boolean startDep = false;
             if (!aliasToActiveMonitorsMap.containsKey(childId) || !pendingMonitorsList.contains(childId)) {
                 startDep = startDependency(childId, instanceId);
-            } else {
-                startDep = startDependencyByInstanceCreation(childId, instanceId);
             }
 
             //Checking whether all the monitors got created