You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/02/20 08:19:35 UTC

[2/2] stratos git commit: Refining application deployment logic: changing dependency reference identifier to alias, adding informative logs, removing unnecessary code, renaming methods

Refining application deployment logic: changing dependency reference identifier to alias, adding informative logs, removing unnecessary code, renaming methods


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

Branch: refs/heads/master
Commit: 4bb8188f773ecfb7892aee6a08109503f91df544
Parents: 33e09f2
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri Feb 20 12:45:32 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri Feb 20 12:49:28 2015 +0530

----------------------------------------------------------------------
 .../dependency/DependencyBuilder.java           |  35 ++-
 .../context/ApplicationChildContextFactory.java |  53 ++---
 .../dependency/context/GroupChildContext.java   |   1 +
 .../parser/DefaultApplicationParser.java        |  68 +++---
 .../applications/parser/ParserUtils.java        |  19 +-
 .../applications/payload/BasicPayloadData.java  |   4 +-
 .../autoscaler/context/AutoscalerContext.java   |  24 +--
 .../context/cluster/ClusterContext.java         |   3 +-
 .../AutoscalerTopologyEventReceiver.java        |   5 +-
 .../stratos/autoscaler/monitor/Monitor.java     |   9 +
 .../autoscaler/monitor/MonitorFactory.java      |  71 +++----
 .../monitor/cluster/ClusterMonitor.java         | 212 ++++++++++---------
 .../monitor/component/ApplicationMonitor.java   |  54 ++---
 .../monitor/component/GroupMonitor.java         |   5 +
 .../component/ParentComponentMonitor.java       | 175 +++++++--------
 .../services/impl/AutoscalerServiceImpl.java    |   3 +-
 .../stratos/autoscaler/util/AutoscalerUtil.java | 114 +++-------
 .../domain/application/ParentComponent.java     |  15 +-
 18 files changed, 403 insertions(+), 467 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
index 9ba005c..e753888 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java
@@ -52,18 +52,21 @@ public class DependencyBuilder {
      * @param component it will give the necessary information to build the tree
      * @return the dependency tree out of the dependency orders
      */
-    public DependencyTree buildDependency(ParentComponent component) throws DependencyBuilderException{
+    public DependencyTree buildDependency(String applicationId, ParentComponent component)
+            throws DependencyBuilderException{
 
         String identifier = component.getUniqueIdentifier();
         DependencyTree dependencyTree = new DependencyTree(identifier);
         DependencyOrder dependencyOrder = component.getDependencyOrder();
 
         if (dependencyOrder != null) {
-            log.info("Building dependency for the Application/Group " + identifier);
+            log.info(String.format("Building dependency tree: [application-id] %s [component] %s ",
+                    applicationId, identifier));
 
-            //Parsing the kill behaviour
-            String terminationBehaviour = dependencyOrder.getTerminationBehaviour();
+            log.info(String.format("Setting termination behaviour: [application-id] %s [component] %s ",
+                    applicationId, identifier));
 
+            String terminationBehaviour = dependencyOrder.getTerminationBehaviour();
             if (AutoscalerConstants.TERMINATE_NONE.equals(terminationBehaviour)) {
                 dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_NONE);
             } else if (AutoscalerConstants.TERMINATE_ALL.equals(terminationBehaviour)) {
@@ -72,23 +75,21 @@ public class DependencyBuilder {
                 dependencyTree.setTerminationBehavior(DependencyTree.TerminationBehavior.TERMINATE_DEPENDENT);
             }
 
-            log.info("Setting the [terminationBehaviour] " + terminationBehaviour + " to the " +
-                    "[dependency-tree] " + dependencyTree.getId());
-
-
-            //Parsing the start up order
             Set<StartupOrder> startupOrders = dependencyOrder.getStartupOrders();
-            ApplicationChildContext foundContext;
             ApplicationChildContext parentContext;
 
             if (startupOrders != null) {
+                log.info(String.format("Processing startup orders: [application-id] %s [component] %s",
+                        applicationId, identifier));
+
                 for (StartupOrder startupOrder : startupOrders) {
                     parentContext = null;
                     for (String startupOrderComponent : startupOrder.getStartupOrderComponentList()) {
 
                         if (startupOrderComponent != null) {
                             ApplicationChildContext applicationChildContext = ApplicationChildContextFactory.
-                                    createApplicationChildContext(startupOrderComponent, component, dependencyTree);
+                                    createApplicationChildContext(applicationId, startupOrderComponent,
+                                            component, dependencyTree);
                             String applicationChildContextId = applicationChildContext.getId();
 
                             ApplicationChildContext existingApplicationChildContext =
@@ -119,12 +120,11 @@ public class DependencyBuilder {
                                     }
                                 } else {
                                     ApplicationChildContext existingParentContext =
-                                            dependencyTree.findParentContextWithId(
-                                                    applicationChildContext.getId());
-                                    if(existingParentContext != null && existingParentContext.getId().
-                                            equals(parentContext.getId())) {
+                                            dependencyTree.findParentContextWithId(applicationChildContext.getId());
+                                    if((existingParentContext != null) &&
+                                            (existingParentContext.getId().equals(parentContext.getId()))) {
                                         if(log.isDebugEnabled()) {
-                                            log.debug("Found an existing parent Context. " +
+                                            log.debug("Found an existing parent context. " +
                                                     "Hence skipping it and parsing the next value.");
                                         }
                                         parentContext = existingApplicationChildContext;
@@ -229,7 +229,4 @@ public class DependencyBuilder {
     public static String getClusterFromStartupOrder(String startupOrder) {
         return startupOrder.substring(AutoscalerConstants.CARTRIDGE.length() + 1);
     }
-
-
-
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContextFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContextFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContextFactory.java
index 3db10c3..fc631b9 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContextFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContextFactory.java
@@ -34,53 +34,30 @@ public class ApplicationChildContextFactory {
     /**
      * Will create and return GroupChildContext/ClusterChildContext based on the type in start order/scaling order
      *
-     * @param order      reference of group/cluster in the start/scaling order
+     * @param startUpOrder      reference of group/cluster in the start/scaling order
      * @param component       The component which used to build the dependency
      * @param tree kill dependent behaviour of this component
      * @return Context
      */
-    public static ApplicationChildContext createApplicationChildContext(String order,
+    public static ApplicationChildContext createApplicationChildContext(String applicationId, String startUpOrder,
                                                                         ParentComponent component,
                                                                         DependencyTree tree) {
-        String id;
-        ApplicationChildContext applicationContext = null;
-        boolean hasDependents = tree.isTerminateDependent() || tree.isTerminateAll();
-        if (order.trim().startsWith(AutoscalerConstants.GROUP + ".")) {
-            //getting the group alias
-            id = getGroupFromStartupOrder(order);
-            applicationContext = createGroupChildContext(id, hasDependents);
-        } else if (order.trim().startsWith(AutoscalerConstants.CARTRIDGE + ".")) {
-            //getting the cartridge type
-            id = getClusterFromStartupOrder(order);
-            //getting the cluster-id from cluster alias
-            ClusterDataHolder clusterDataHolder = (ClusterDataHolder) component.getClusterDataForType().get(id);
-            applicationContext = createClusterChildContext(clusterDataHolder, hasDependents);
 
+        boolean hasDependents = tree.isTerminateDependent() || tree.isTerminateAll();
+        if (startUpOrder.trim().startsWith(AutoscalerConstants.GROUP + ".")) {
+            // Find group alias
+            String groupAlias = startUpOrder.substring(AutoscalerConstants.GROUP.length() + 1);
+            return createGroupChildContext(groupAlias, hasDependents);
+        } else if (startUpOrder.trim().startsWith(AutoscalerConstants.CARTRIDGE + ".")) {
+            // Find cartridge alias
+            String cartridgeAlias = startUpOrder.substring(AutoscalerConstants.CARTRIDGE.length() + 1);
+            // Find cluster-id from cluster alias
+            ClusterDataHolder clusterDataHolder = component.getClusterDataHolderRecursivelyByAlias(cartridgeAlias);
+            return createClusterChildContext(clusterDataHolder, hasDependents);
         } else {
-            log.warn("[Startup Order]: " + order + " contains unknown reference");
+            throw new RuntimeException(String.format("Startup order contains an unknown reference: " +
+                            "[application-id] %s [startup-order] %s", applicationId, startUpOrder));
         }
-        return applicationContext;
-
-    }
-
-    /**
-     * Utility method to get the group alias from the startup order Eg: group.mygroup
-     *
-     * @param startupOrder startup order
-     * @return group alias
-     */
-    public static String getGroupFromStartupOrder(String startupOrder) {
-        return startupOrder.substring(AutoscalerConstants.GROUP.length() + 1);
-    }
-
-    /**
-     * Utility method to get the cluster alias from startup order Eg: cartridge.myphp
-     *
-     * @param startupOrder startup order
-     * @return cluster alias
-     */
-    public static String getClusterFromStartupOrder(String startupOrder) {
-        return startupOrder.substring(AutoscalerConstants.CARTRIDGE.length() + 1);
     }
 
 	/**

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/GroupChildContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/GroupChildContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/GroupChildContext.java
index d681d00..b844144 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/GroupChildContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/GroupChildContext.java
@@ -19,6 +19,7 @@
 package org.apache.stratos.autoscaler.applications.dependency.context;
 
 public class GroupChildContext extends ApplicationChildContext {
+
     public GroupChildContext(String id, boolean killDependent) {
         super(id ,killDependent);
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
index 9e88fdc..b54b79e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
@@ -57,8 +57,8 @@ import java.util.*;
 public class DefaultApplicationParser implements ApplicationParser {
 
     private static final String METADATA_APPENDER = "-";
-    private static final String ALIAS = "alias";
-    private static final String CARTRIDGE_TYPE = "type";
+    public static final String ALIAS = "alias";
+    public static final String CARTRIDGE_TYPE = "type";
     private static Log log = LogFactory.getLog(DefaultApplicationParser.class);
 
     private List<ApplicationClusterContext> applicationClusterContexts;
@@ -293,15 +293,16 @@ public class DefaultApplicationParser implements ApplicationParser {
             }
 
             // Set application cluster data
-            if (components.getCartridgeContexts() != null) {
-                List<CartridgeContext> cartridgeContextList = Arrays.asList(components.getCartridgeContexts());
+            CartridgeContext[] cartridgeContexts = components.getCartridgeContexts();
+            if (cartridgeContexts != null) {
+                List<CartridgeContext> cartridgeContextList = Arrays.asList(cartridgeContexts);
                 Set<StartupOrder> startupOrders = application.getDependencyOrder().getStartupOrders();
                 Map<String, Map<String, ClusterDataHolder>> clusterDataMap;
 
                 clusterDataMap = parseLeafLevelSubscriptions(applicationContext.getApplicationId(),
                         applicationContext.getTenantId(), application.getKey(), null, cartridgeContextList, startupOrders);
-                application.setClusterData(clusterDataMap.get("alias"));
-                application.setClusterDataForType(clusterDataMap.get("type"));
+                application.setClusterData(clusterDataMap.get(ALIAS));
+                application.setClusterDataForType(clusterDataMap.get(CARTRIDGE_TYPE));
             }
 
             // Set groups
@@ -349,10 +350,12 @@ public class DefaultApplicationParser implements ApplicationParser {
             SubscribableInfoContext subscribableInfoContext = cartridgeContext.getSubscribableInfoContext();
             String subscriptionAlias = subscribableInfoContext.getAlias();
 
-
-            // check if a cartridgeInfo with relevant type is already deployed. else, can't continue
             CartridgeInfo cartridgeInfo = getCartridge(cartridgeType);
+            if(cartridgeInfo == null) {
+                throw new RuntimeException("Cartridge not found: " + cartridgeType);
+            }
 
+            // Add metadata keys defined in cartridges as export metadata keys
 		    for (String str : cartridgeInfo.getMetadataKeys()) {
 			    if(!StringUtils.isBlank(str)) {
 				    exportMetadataKeys.add(cartridgeContext.getSubscribableInfoContext()
@@ -360,15 +363,8 @@ public class DefaultApplicationParser implements ApplicationParser {
 			    }
 		    }
 
-
-            if (cartridgeInfo == null) {
-                handleError("No deployed Cartridge found with type [ " + cartridgeType +
-                        " ] for Composite Application");
-            }
-
             // get hostname and cluster id
             ClusterInformation clusterInfo;
-            assert cartridgeInfo != null;
             if (cartridgeInfo.getMultiTenant()) {
                 clusterInfo = new MTClusterInformation();
             } else {
@@ -382,27 +378,30 @@ public class DefaultApplicationParser implements ApplicationParser {
                 repoUrl = subscribableInfoContext.getArtifactRepositoryContext().getRepoUrl();
             }
 
-           //Get dependency cluster id
+           // Find import metadata keys
             if (dependencyOrder != null) {
                 for (StartupOrder startupOrder : dependencyOrder) {
                     for (String startupOrderComponent : startupOrder.getStartupOrderComponentList()) {
 
 	                    String[] arrStartUp= startupOrderComponent.split("\\.");
 	                    if(arrStartUp[0].equals("cartridge")) {
-		                    String dependencType = arrStartUp[1];
-		                    CartridgeInfo dependencyCartridge = getCartridge(dependencType);
-
-		                    ClusterDataHolder dataHolder = clusterDataMapByType.get(dependencType);
+		                    String cartridgeAlias = arrStartUp[1];
+                            String dependentCartridgeType = findCartridgeTypeFromAlias(cartridgeContextList, cartridgeAlias);
+		                    if(StringUtils.isBlank(dependentCartridgeType)) {
+                                throw new RuntimeException(String.format("Could not find dependent cartridge for " +
+                                        "cartridge alias: [application] %s [cartridge-alias] %s", appId, cartridgeAlias));
+                            }
+                            CartridgeInfo dependencyCartridge = getCartridge(dependentCartridgeType);
+		                    ClusterDataHolder dataHolder = clusterDataMapByType.get(dependentCartridgeType);
 
 		                    if (dataHolder != null) {
 			                    if (!dataHolder.getClusterId().equals(clusterId)) {
 				                    dependencyClusterIDs.add(dataHolder.getClusterId());
 				                    for (String str : dependencyCartridge.getMetadataKeys()) {
 					                    if (!StringUtils.isBlank(str)) {
-						                    importMetadataKeys
-								                    .add(dataHolder.getClusterId().split("\\.")[0] +
-								                         METADATA_APPENDER +
-								                         str);
+						                    importMetadataKeys.add(dataHolder.getClusterId().split("\\.")[0] +
+                                                    METADATA_APPENDER +
+                                                    str);
 					                    }
 				                    }
 				                    if (!dataHolder.getClusterId().equals(clusterId)) {
@@ -444,12 +443,27 @@ public class DefaultApplicationParser implements ApplicationParser {
 
 
         }
-        completeDataHolder.put("type", clusterDataMapByType);
-        completeDataHolder.put("alias", clusterDataMap);
+        completeDataHolder.put(CARTRIDGE_TYPE, clusterDataMapByType);
+        completeDataHolder.put(ALIAS, clusterDataMap);
         return completeDataHolder;
     }
 
-	private void createClusterDataMap(List<CartridgeContext> cartridgeContextList,
+    /**
+     * Find alias of a cartridge by cartridge type
+     * @param cartridgeContextList
+     * @param alias
+     * @return
+     */
+    private String findCartridgeTypeFromAlias(List<CartridgeContext> cartridgeContextList, String alias) {
+        for(CartridgeContext cartridgeContext : cartridgeContextList) {
+            if(alias.equals(cartridgeContext.getSubscribableInfoContext().getAlias())) {
+                return cartridgeContext.getType();
+            }
+        }
+        return null;
+    }
+
+    private void createClusterDataMap(List<CartridgeContext> cartridgeContextList,
 	                                  Map<String, ClusterDataHolder> clusterDataMap,
 	                                  Map<String, ClusterDataHolder> clusterDataMapByType)
 			throws ApplicationDefinitionException {

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java
index b943ed5..788e08f 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java
@@ -47,16 +47,14 @@ public class ParserUtils {
     private static StartupOrder getStartupOrder (String commaSeparatedStartupOrder) throws ApplicationDefinitionException{
 
         List<String> startupOrders = new ArrayList<String>();
-
         for (String startupOrder : Arrays.asList(commaSeparatedStartupOrder.split(","))) {
             startupOrder = startupOrder.trim();
             if (!startupOrder.startsWith("cartridge.") && !startupOrder.startsWith("group.")) {
-                throw new ApplicationDefinitionException("Incorrect Startup Order specified, should start with 'cartridge.' or 'group.'");
+                throw new ApplicationDefinitionException("Incorrect startup order specified, " +
+                        "should start with 'cartridge.' or 'group.'");
             }
-
             startupOrders.add(startupOrder);
         }
-
         return new StartupOrder(startupOrders);
     }
 
@@ -124,31 +122,26 @@ public class ParserUtils {
     public static Set<ScalingDependentList> convertScalingDependentList(String[] scalingDependentListArr) throws ApplicationDefinitionException {
 
         Set<ScalingDependentList> scalingDependentLists = new HashSet<ScalingDependentList>();
-
         if (scalingDependentListArr == null) {
             return scalingDependentLists;
         }
-
         for (String commaSeparatedScalingDependentList : scalingDependentListArr) {
             scalingDependentLists.add(getScalingDependentList(commaSeparatedScalingDependentList));
         }
-
         return scalingDependentLists;
     }
 
     private static ScalingDependentList getScalingDependentList (String commaSeparatedScalingDependentList) throws ApplicationDefinitionException{
 
         List<String> scalingDependentLists = new ArrayList<String>();
-
         for (String scalingDependentList : Arrays.asList(commaSeparatedScalingDependentList.split(","))) {
             scalingDependentList = scalingDependentList.trim();
             if (!scalingDependentList.startsWith("cartridge.") && !scalingDependentList.startsWith("group.")) {
-                throw new ApplicationDefinitionException("Incorrect Scaling Dependent List specified, should start with 'cartridge.' or 'group.'");
+                throw new ApplicationDefinitionException("Incorrect scaling dependent List specified, " +
+                        "should start with 'cartridge.' or 'group.'");
             }
-
             scalingDependentLists.add(scalingDependentList);
         }
-
         return new ScalingDependentList(scalingDependentLists);
     }
 
@@ -156,18 +149,14 @@ public class ParserUtils {
             throws ApplicationDefinitionException {
 
         Set<ScalingDependentList> scalingDependentLists = new HashSet<ScalingDependentList>();
-
         if (scalingDependentListArr == null) {
             return scalingDependentLists;
         }
-
-
         for (String commaSeparatedScalingDependentList : scalingDependentListArr) {
             // convertScalingDependentList all scaling dependents to aliases-based
             List<String> components = Arrays.asList(commaSeparatedScalingDependentList.split(","));
             scalingDependentLists.add(getScalingDependentList(components, groupContext));
         }
-
         return scalingDependentLists;
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
index 7c38802..9ae3280 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java
@@ -339,7 +339,9 @@ public class BasicPayloadData implements Serializable {
 				dependencyClusterIDsPayload.append("|");
 			}
 		}
-		log.debug("Dependency Cluster IDs:  " + dependencyClusterIDsPayload);
+        if(StringUtils.isNotBlank(dependencyClusterIDsPayload.toString())) {
+            log.debug("Dependency cluster ids: " + dependencyClusterIDsPayload);
+        }
 		return dependencyClusterIDsPayload.toString();
 	}
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java
index 5524c2b..97aa5e1 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java
@@ -20,17 +20,17 @@
  */
 package org.apache.stratos.autoscaler.context;
 
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext;
-import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
 import org.apache.stratos.autoscaler.registry.RegistryManager;
 import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
 import org.apache.stratos.common.clustering.DistributedObjectProvider;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 
 /**
  * It holds all cluster monitors which are active in stratos.
@@ -137,26 +137,18 @@ public class AutoscalerContext {
         return pendingApplicationMonitors;
     }
 
-    public void setPendingApplicationMonitors(List<String> pendingApplicationMonitors) {
-        this.pendingApplicationMonitors = pendingApplicationMonitors;
-    }
-
-    public void addPendingMonitor(String appId) {
+    public void addApplicationPendingMonitor(String appId) {
         this.pendingApplicationMonitors.add(appId);
     }
 
-    public void removeFromPendingMonitors(String appId) {
+    public void removeApplicationPendingMonitor(String appId) {
         this.pendingApplicationMonitors.remove(appId);
     }
 
-    public boolean containsPendingMonitor(String appId) {
+    public boolean containsApplicationPendingMonitor(String appId) {
         return this.pendingApplicationMonitors.contains(appId);
     }
 
-    public boolean monitorExists(String appId) {
-        return this.applicationMonitors.containsKey(appId);
-    }
-
     public void addApplicationContext(ApplicationContext applicationContext) {
         applicationContextMap.put(applicationContext.getApplicationId(), applicationContext);
         RegistryManager.getInstance().persistApplicationContext(applicationContext);

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
index 941a8ea..2d12879 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterContext.java
@@ -174,7 +174,8 @@ public class ClusterContext extends AbstractClusterContext {
             throws PolicyValidationException, PartitionValidationException {
 
         if (childPolicy == null) {
-            String msg = String.format("Child policy is not specified for the [instance alias] %s",clusterInstance.getAlias());
+            String msg = String.format("Child policy is not specified [alias] %s",
+                    clusterInstance.getAlias());
             log.error(msg);
             throw new PolicyValidationException(msg);
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/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 a1d3c60..4ec7d73 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
@@ -27,11 +27,8 @@ import org.apache.stratos.autoscaler.context.cluster.ClusterContextFactory;
 import org.apache.stratos.autoscaler.context.cluster.ClusterContext;
 import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
 import org.apache.stratos.autoscaler.event.publisher.InstanceNotificationPublisher;
-import org.apache.stratos.autoscaler.exception.application.DependencyBuilderException;
-import org.apache.stratos.autoscaler.exception.application.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.exception.partition.PartitionValidationException;
 import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
-import org.apache.stratos.autoscaler.monitor.MonitorFactory;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
 import org.apache.stratos.autoscaler.monitor.events.ClusterStatusEvent;
@@ -138,7 +135,7 @@ public class AutoscalerTopologyEventReceiver {
                         ApplicationHolder.acquireReadLock();
                         //start the application monitor if the policy exists
                         DeploymentPolicy policy = PolicyManager.getInstance().getDeploymentPolicyByApplication(appId);
-                        if (policy != null && !AutoscalerContext.getInstance().containsPendingMonitor(appId)) {
+                        if (policy != null && !AutoscalerContext.getInstance().containsApplicationPendingMonitor(appId)) {
                             AutoscalerUtil.getInstance().startApplicationMonitor(appId);
                         }
                     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/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 5154b2b..0930547 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
@@ -30,6 +30,9 @@ import java.util.Map;
  * Abstract class for the monitoring functionality in autoscaler.
  */
 public abstract class Monitor implements EventHandler {
+
+    public enum MonitorType { Application, Group, Cluster }
+
     //Id of the monitor, cluster=clusterId, group=group-alias, application=app-alias
     protected String id;
     //The parent app which this monitor relates to
@@ -59,6 +62,12 @@ public abstract class Monitor implements EventHandler {
     }
 
     /**
+     * Return the type of the monitor.
+     * @return
+     */
+    public abstract MonitorType getMonitorType();
+
+    /**
      * Set the id of the monitor
      *
      * @param id

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/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 80f13f4..1dca0bd 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
@@ -97,12 +97,18 @@ public class MonitorFactory {
             throws DependencyBuilderException,
             TopologyInConsistentException {
         GroupMonitor groupMonitor;
-        boolean initialStartup = false;
+        Application application = ApplicationHolder.getApplications().getApplication(appId);
+        if(application == null) {
+            throw new RuntimeException("Application not found: [application-id] " + appId);
+        }
+
         try {
             //acquiring read lock to create the monitor
             ApplicationHolder.acquireReadLock();
-            Group group = ApplicationHolder.getApplications().
-                    getApplication(appId).getGroupRecursively(context.getId());
+            Group group = application.getGroupRecursively(context.getId());
+            if(group == null) {
+                throw new RuntimeException("Group not found: [group-alias] " + context.getId());
+            }
 
             boolean hasScalingDependents = false;
             if (parentMonitor.getScalingDependencies() != null) {
@@ -130,9 +136,9 @@ public class MonitorFactory {
             ApplicationHolder.releaseReadLock();
         }
 
-        Group group = ApplicationHolder.getApplications().
-                getApplication(appId).getGroupRecursively(context.getId());
-        //Starting the minimum dependencies
+        Group group = application.getGroupRecursively(context.getId());
+
+        // Starting the minimum dependencies
         groupMonitor.createInstanceAndStartDependencyAtStartup(group, instanceIds);
 
         /**
@@ -171,18 +177,14 @@ public class MonitorFactory {
             //acquiring read lock to start the monitor
             ApplicationHolder.acquireReadLock();
             application = ApplicationHolder.getApplications().getApplication(applicationId);
-            if (application != null) {
-                applicationMonitor = new ApplicationMonitor(application);
-
-                if(null != applicationMonitor){
-                    applicationMonitor.setHasStartupDependents(false);
-                    //starting the scheduler of the application monitor
-                    applicationMonitor.startScheduler();
-                }
-            } else {
-                String msg = "Application not found in the topology: [application-id] " + applicationId;
-                throw new TopologyInConsistentException(msg);
+            if (application == null) {
+                throw new RuntimeException("Application not found in the topology: [application-id] " + applicationId);
             }
+
+            applicationMonitor = new ApplicationMonitor(application);
+            applicationMonitor.setHasStartupDependents(false);
+            // Starting the scheduler of the application monitor
+            applicationMonitor.startScheduler();
         } finally {
             ApplicationHolder.releaseReadLock();
         }
@@ -228,18 +230,17 @@ public class MonitorFactory {
         TopologyManager.acquireReadLockForCluster(serviceName, clusterId);
         try {
             Topology topology = TopologyManager.getTopology();
-            if (topology.serviceExists(serviceName)) {
-                Service service = topology.getService(serviceName);
-                if (service.clusterExists(clusterId)) {
-                    cluster = service.getCluster(clusterId);
-                } else {
-                    String msg = "[Cluster] " + clusterId + " cannot be found in the " +
-                            "Topology for [service] " + serviceName;
-                    throw new TopologyInConsistentException(msg);
-                }
-            } else {
-                String msg = "[Service] " + serviceName + " cannot be found in the Topology";
-                throw new TopologyInConsistentException(msg);
+            Service service = topology.getService(serviceName);
+            if(service == null) {
+                String msg = String.format("Service not found in topology: [service] %s", serviceName);
+                throw new RuntimeException(msg);
+            }
+
+            cluster = service.getCluster(clusterId);
+            if(cluster == null) {
+                String msg = String.format("Cluster not found in topology: [service] %s [cluster] %s",
+                        serviceName, clusterId);
+                throw new RuntimeException(msg);
             }
 
             boolean hasScalingDependents = false;
@@ -253,7 +254,6 @@ public class MonitorFactory {
 
             boolean groupScalingEnabledSubtree = false;
             if (parentMonitor instanceof GroupMonitor) {
-
                 GroupMonitor groupMonitor = (GroupMonitor) parentMonitor;
                 groupScalingEnabledSubtree = findIfChildIsInGroupScalingEnabledSubTree(groupMonitor);
             }
@@ -262,16 +262,16 @@ public class MonitorFactory {
 
             Properties props = cluster.getProperties();
             if (props != null) {
-                // set hasPrimary property
+                // Set hasPrimary property
                 // hasPrimary is true if there are primary members available in that cluster
                 clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(IS_PRIMARY)));
             }
 
-            //Setting the parent of the cluster monitor
+            // Setting the parent of the cluster monitor
             clusterMonitor.setParent(parentMonitor);
             clusterMonitor.setId(clusterId);
 
-            //setting the startup dependent behaviour of the cluster monitor
+            // Setting the startup dependent behaviour of the cluster monitor
             if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() &&
                     context.hasChild())) {
                 clusterMonitor.setHasStartupDependents(true);
@@ -279,9 +279,8 @@ public class MonitorFactory {
                 clusterMonitor.setHasStartupDependents(false);
             }
 
-            //Creating the instance of the cluster
-            ((ClusterMonitor) clusterMonitor).createClusterInstances(parentInstanceIds, cluster);
-            //add it to autoscaler context
+            // Creating the instance of the cluster
+            clusterMonitor.createClusterInstances(parentInstanceIds, cluster);
             AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
             log.info("ClusterMonitor created: " + clusterMonitor.toString());
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
index f214ab4..318125c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
@@ -72,6 +72,7 @@ import org.drools.runtime.rule.FactHandle;
 
 import java.util.*;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -146,6 +147,11 @@ public class ClusterMonitor extends Monitor implements Runnable {
         this.hasScalingDependents = hasScalingDependents;
     }
 
+    @Override
+    public MonitorType getMonitorType() {
+        return MonitorType.Cluster;
+    }
+
     public void startScheduler() {
         scheduler.scheduleAtFixedRate(this, 0, getMonitorIntervalMilliseconds(), TimeUnit.MILLISECONDS);
     }
@@ -467,136 +473,136 @@ public class ClusterMonitor extends Monitor implements Runnable {
 
     public synchronized void monitor() {
 
-        for (ClusterLevelNetworkPartitionContext networkPartitionContext : getNetworkPartitionCtxts()) {
+        try {
+            for (ClusterLevelNetworkPartitionContext networkPartitionContext : getNetworkPartitionCtxts()) {
 
-            final Collection<InstanceContext> clusterInstanceContexts = networkPartitionContext.
-                    getInstanceIdToInstanceContextMap().values();
+                final Collection<InstanceContext> clusterInstanceContexts = networkPartitionContext.
+                        getInstanceIdToInstanceContextMap().values();
 
-            for (final InstanceContext pInstanceContext : clusterInstanceContexts) {
-                final ClusterInstanceContext instanceContext = (ClusterInstanceContext) pInstanceContext;
-                ClusterInstance instance = (ClusterInstance) this.instanceIdToInstanceMap.
-                        get(instanceContext.getId());
+                for (final InstanceContext pInstanceContext : clusterInstanceContexts) {
+                    final ClusterInstanceContext instanceContext = (ClusterInstanceContext) pInstanceContext;
+                    ClusterInstance instance = (ClusterInstance) this.instanceIdToInstanceMap.
+                            get(instanceContext.getId());
 
-                if ((instance.getStatus().getCode() <= ClusterStatus.Active.getCode()) ||
-                        (instance.getStatus() == ClusterStatus.Inactive && !hasStartupDependents)
-                                && !this.hasFaultyMember) {
+                    if ((instance.getStatus().getCode() <= ClusterStatus.Active.getCode()) ||
+                            (instance.getStatus() == ClusterStatus.Inactive && !hasStartupDependents)
+                                    && !this.hasFaultyMember) {
 
-                    Runnable monitoringRunnable = new Runnable() {
-                        @Override
-                        public void run() {
+                        Runnable monitoringRunnable = new Runnable() {
+                            @Override
+                            public void run() {
 
-                            if (log.isDebugEnabled()) {
-                                log.debug(String.format("Cluster monitor is running: [application-id] %s [cluster-id]: " +
-                                                "%s", getAppId(), getClusterId()));
-                            }
-                            // store primary members in the cluster instance context
-                            List<String> primaryMemberListInClusterInstance = new ArrayList<String>();
+                                if (log.isDebugEnabled()) {
+                                    log.debug(String.format("Cluster monitor is running: [application-id] %s [cluster-id]: " +
+                                            "%s", getAppId(), getClusterId()));
+                                }
+                                // store primary members in the cluster instance context
+                                List<String> primaryMemberListInClusterInstance = new ArrayList<String>();
 
-                            for (ClusterLevelPartitionContext partitionContext :
-                                                            instanceContext.getPartitionCtxts()) {
+                                for (ClusterLevelPartitionContext partitionContext :
+                                        instanceContext.getPartitionCtxts()) {
 
-                                // get active primary members in this cluster instance context
-                                for (MemberContext memberContext : partitionContext.getActiveMembers()) {
-                                    if (isPrimaryMember(memberContext)) {
-                                        primaryMemberListInClusterInstance.add(memberContext.getMemberId());
+                                    // get active primary members in this cluster instance context
+                                    for (MemberContext memberContext : partitionContext.getActiveMembers()) {
+                                        if (isPrimaryMember(memberContext)) {
+                                            primaryMemberListInClusterInstance.add(memberContext.getMemberId());
+                                        }
                                     }
-                                }
 
-                                // get pending primary members in this cluster instance context
-                                for (MemberContext memberContext : partitionContext.getPendingMembers()) {
-                                    if (isPrimaryMember(memberContext)) {
-                                        primaryMemberListInClusterInstance.add(memberContext.getMemberId());
+                                    // get pending primary members in this cluster instance context
+                                    for (MemberContext memberContext : partitionContext.getPendingMembers()) {
+                                        if (isPrimaryMember(memberContext)) {
+                                            primaryMemberListInClusterInstance.add(memberContext.getMemberId());
+                                        }
                                     }
                                 }
 
-                                //obsoleteCheckFactHandle = AutoscalerRuleEvaluator.evaluate(
-                                //        getObsoleteCheckKnowledgeSession(), obsoleteCheckFactHandle, partitionContext);
-
-                            }
-
-                            getScaleCheckKnowledgeSession().setGlobal("primaryMembers", primaryMemberListInClusterInstance);
-                            getMinCheckKnowledgeSession().setGlobal("clusterId", getClusterId());
-                            getMinCheckKnowledgeSession().setGlobal("isPrimary", hasPrimary);
-                            //FIXME when parent chosen the partition
-                            String paritionAlgo = instanceContext.getPartitionAlgorithm();
+                                getScaleCheckKnowledgeSession().setGlobal("primaryMembers", primaryMemberListInClusterInstance);
+                                getMinCheckKnowledgeSession().setGlobal("clusterId", getClusterId());
+                                getMinCheckKnowledgeSession().setGlobal("isPrimary", hasPrimary);
+                                //FIXME when parent chosen the partition
+                                String paritionAlgo = instanceContext.getPartitionAlgorithm();
 
-                            getMinCheckKnowledgeSession().setGlobal("algorithmName",
-                                    paritionAlgo);
+                                getMinCheckKnowledgeSession().setGlobal("algorithmName",
+                                        paritionAlgo);
 
-                            if (log.isDebugEnabled()) {
-                                log.debug(String.format("Running minimum check for cluster instance %s ",
-                                        instanceContext.getId() + " for the cluster: " + clusterId));
-                            }
-
-                            minCheckFactHandle = AutoscalerRuleEvaluator.evaluate(getMinCheckKnowledgeSession(),
-                                    minCheckFactHandle, instanceContext);
+                                if (log.isDebugEnabled()) {
+                                    log.debug(String.format("Running minimum check for cluster instance %s ",
+                                            instanceContext.getId() + " for the cluster: " + clusterId));
+                                }
 
+                                minCheckFactHandle = AutoscalerRuleEvaluator.evaluate(getMinCheckKnowledgeSession(),
+                                        minCheckFactHandle, instanceContext);
 
-                            //checking the status of the cluster
-                            boolean rifReset = instanceContext.isRifReset();
-                            boolean memoryConsumptionReset = instanceContext.isMemoryConsumptionReset();
-                            boolean loadAverageReset = instanceContext.isLoadAverageReset();
-                            boolean averageRequestServedPerInstanceReset
-                                    = instanceContext.isAverageRequestServedPerInstanceReset();
 
-                            if (log.isDebugEnabled()) {
-                                log.debug("Execution point of scaling Rule, [Is rif Reset] : " + rifReset
-                                        + " [Is memoryConsumption Reset] : " + memoryConsumptionReset
-                                        + " [Is loadAverage Reset] : " + loadAverageReset);
-                            }
+                                //checking the status of the cluster
+                                boolean rifReset = instanceContext.isRifReset();
+                                boolean memoryConsumptionReset = instanceContext.isMemoryConsumptionReset();
+                                boolean loadAverageReset = instanceContext.isLoadAverageReset();
+                                boolean averageRequestServedPerInstanceReset
+                                        = instanceContext.isAverageRequestServedPerInstanceReset();
 
-                            if (rifReset || memoryConsumptionReset || loadAverageReset) {
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Execution point of scaling Rule, [Is rif Reset] : " + rifReset
+                                            + " [Is memoryConsumption Reset] : " + memoryConsumptionReset
+                                            + " [Is loadAverage Reset] : " + loadAverageReset);
+                                }
 
-                                log.info("Executing scaling rule as statistics have been reset");
-                                ClusterContext clusterContext = (ClusterContext) ClusterMonitor.this.clusterContext;
+                                if (rifReset || memoryConsumptionReset || loadAverageReset) {
+
+                                    log.info("Executing scaling rule as statistics have been reset");
+                                    ClusterContext clusterContext = (ClusterContext) ClusterMonitor.this.clusterContext;
+
+                                    getScaleCheckKnowledgeSession().setGlobal("clusterId", getClusterId());
+                                    getScaleCheckKnowledgeSession().setGlobal("rifReset", rifReset);
+                                    getScaleCheckKnowledgeSession().setGlobal("mcReset", memoryConsumptionReset);
+                                    getScaleCheckKnowledgeSession().setGlobal("laReset", loadAverageReset);
+                                    getScaleCheckKnowledgeSession().setGlobal("isPrimary", hasPrimary);
+                                    getScaleCheckKnowledgeSession().setGlobal("algorithmName", paritionAlgo);
+                                    getScaleCheckKnowledgeSession().setGlobal("autoscalePolicy",
+                                            clusterContext.getAutoscalePolicy());
+                                    getScaleCheckKnowledgeSession().setGlobal("arspiReset",
+                                            averageRequestServedPerInstanceReset);
+                                    getScaleCheckKnowledgeSession().setGlobal("primaryMembers",
+                                            primaryMemberListInClusterInstance);
+
+                                    if (log.isDebugEnabled()) {
+                                        log.debug(String.format("Running scale check for [cluster instance context] %s ",
+                                                instanceContext.getId()));
+                                        log.debug(" Primary members : " + primaryMemberListInClusterInstance);
+                                    }
 
-                                getScaleCheckKnowledgeSession().setGlobal("clusterId", getClusterId());
-                                getScaleCheckKnowledgeSession().setGlobal("rifReset", rifReset);
-                                getScaleCheckKnowledgeSession().setGlobal("mcReset", memoryConsumptionReset);
-                                getScaleCheckKnowledgeSession().setGlobal("laReset", loadAverageReset);
-                                getScaleCheckKnowledgeSession().setGlobal("isPrimary", hasPrimary);
-                                getScaleCheckKnowledgeSession().setGlobal("algorithmName", paritionAlgo);
-                                getScaleCheckKnowledgeSession().setGlobal("autoscalePolicy",
-                                        clusterContext.getAutoscalePolicy());
-                                getScaleCheckKnowledgeSession().setGlobal("arspiReset",
-                                        averageRequestServedPerInstanceReset);
-                                getScaleCheckKnowledgeSession().setGlobal("primaryMembers",
-                                        primaryMemberListInClusterInstance);
+                                    scaleCheckFactHandle = AutoscalerRuleEvaluator.evaluate(getScaleCheckKnowledgeSession()
+                                            , scaleCheckFactHandle, instanceContext);
 
-                                if (log.isDebugEnabled()) {
-                                    log.debug(String.format("Running scale check for [cluster instance context] %s ",
-                                            instanceContext.getId()));
-                                    log.debug(" Primary members : " + primaryMemberListInClusterInstance);
+                                    instanceContext.setRifReset(false);
+                                    instanceContext.setMemoryConsumptionReset(false);
+                                    instanceContext.setLoadAverageReset(false);
+                                } else if (log.isDebugEnabled()) {
+                                    log.debug(String.format("Scale rule will not run since the LB statistics have not " +
+                                                    "received before this cycle for [cluster instance context] %s [cluster] %s",
+                                            instanceContext.getId(), clusterId));
                                 }
 
-                                scaleCheckFactHandle = AutoscalerRuleEvaluator.evaluate(getScaleCheckKnowledgeSession()
-                                        , scaleCheckFactHandle, instanceContext);
-
-                                instanceContext.setRifReset(false);
-                                instanceContext.setMemoryConsumptionReset(false);
-                                instanceContext.setLoadAverageReset(false);
-                            } else if (log.isDebugEnabled()) {
-                                log.debug(String.format("Scale rule will not run since the LB statistics have not " +
-                                                "received before this cycle for [cluster instance context] %s [cluster] %s",
-                                        instanceContext.getId(), clusterId));
                             }
+                        };
+                        executorService.execute(monitoringRunnable);
+                    }
 
-                        }
-                    };
-                    executorService.execute(monitoringRunnable);
-                }
-
-                for (final ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
-                    Runnable monitoringRunnable = new Runnable() {
-                        @Override
-                        public void run() {
-                            obsoleteCheckFactHandle = AutoscalerRuleEvaluator.evaluate(
-                                    getObsoleteCheckKnowledgeSession(), obsoleteCheckFactHandle, partitionContext);
-                        }
-                    };
-                    executorService.execute(monitoringRunnable);
+                    for (final ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
+                        Runnable monitoringRunnable = new Runnable() {
+                            @Override
+                            public void run() {
+                                obsoleteCheckFactHandle = AutoscalerRuleEvaluator.evaluate(
+                                        getObsoleteCheckKnowledgeSession(), obsoleteCheckFactHandle, partitionContext);
+                            }
+                        };
+                        executorService.execute(monitoringRunnable);
+                    }
                 }
             }
+        } catch (RejectedExecutionException ignore) {
+            log.warn("Cluster monitor execution rejected: [cluster-id] " + getClusterId());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
index 01f2abe..db50431 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
@@ -78,6 +78,11 @@ public class ApplicationMonitor extends ParentComponentMonitor {
     }
 
     @Override
+    public MonitorType getMonitorType() {
+        return MonitorType.Application;
+    }
+
+    @Override
     public void run() {
         try {
             monitor();
@@ -305,36 +310,31 @@ public class ApplicationMonitor extends ParentComponentMonitor {
         DeploymentPolicy deploymentPolicy = getDeploymentPolicy(application);
         String instanceId;
 
-//        if (deploymentPolicy == null) {
-//            //FIXME for docker with deployment policy
-//            ApplicationInstance appInstance = createApplicationInstance(application, null);
-//            instanceIds.add(appInstance.getInstanceId());
-//        } else {
-            for (NetworkPartition networkPartition :
-                    deploymentPolicy.getApplicationLevelNetworkPartitions()) {
-                if (networkPartition.isActiveByDefault()) {
-                    ApplicationLevelNetworkPartitionContext context =
-                            new ApplicationLevelNetworkPartitionContext(networkPartition.getId());
-                    //If application instances found in the ApplicationsTopology,
-                    // then have to add them first before creating new one
-                    ApplicationInstance appInstance = (ApplicationInstance) application.
-                            getInstanceByNetworkPartitionId(context.getId());
-                    if (appInstance != null) {
-                        //use the existing instance in the Topology to create the data
-                        instanceId = handleApplicationInstanceCreation(application, context, appInstance);
-                        initialStartup = false;
-                    } else {
-                        //create new app instance as it doesn't exist in the Topology
-                        instanceId = handleApplicationInstanceCreation(application, context, null);
-
-                    }
-                    instanceIds.add(instanceId);
-                    log.info("Application instance has been added for the [network partition] " +
-                            networkPartition.getId() + " [appInstanceId] " + instanceId);
+        for (NetworkPartition networkPartition :
+                deploymentPolicy.getApplicationLevelNetworkPartitions()) {
+            if (networkPartition.isActiveByDefault()) {
+                ApplicationLevelNetworkPartitionContext context =
+                        new ApplicationLevelNetworkPartitionContext(networkPartition.getId());
+                //If application instances found in the ApplicationsTopology,
+                // then have to add them first before creating new one
+                ApplicationInstance appInstance = (ApplicationInstance) application.
+                        getInstanceByNetworkPartitionId(context.getId());
+                if (appInstance != null) {
+                    //use the existing instance in the Topology to create the data
+                    instanceId = handleApplicationInstanceCreation(application, context, appInstance);
+                    initialStartup = false;
+                } else {
+                    //create new app instance as it doesn't exist in the Topology
+                    instanceId = handleApplicationInstanceCreation(application, context, null);
 
                 }
+                instanceIds.add(instanceId);
+                log.info("Application instance has been added for the [network partition] " +
+                        networkPartition.getId() + " [appInstanceId] " + instanceId);
+
             }
-//        }
+        }
+
         startDependency(application, instanceIds);
         return initialStartup;
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/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 5bc7d63..91aa95f 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
@@ -93,6 +93,11 @@ public class GroupMonitor extends ParentComponentMonitor {
     }
 
     @Override
+    public MonitorType getMonitorType() {
+        return MonitorType.Group;
+    }
+
+    @Override
     public void run() {
         try {
             monitor();

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/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 26c9473..cc904d7 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
@@ -43,6 +43,7 @@ import org.apache.stratos.autoscaler.monitor.events.ScalingDownBeyondMinEvent;
 import org.apache.stratos.autoscaler.monitor.events.ScalingEvent;
 import org.apache.stratos.autoscaler.monitor.events.ScalingUpBeyondMaxEvent;
 import org.apache.stratos.autoscaler.util.AutoscalerConstants;
+import org.apache.stratos.autoscaler.util.AutoscalerUtil;
 import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
 import org.apache.stratos.common.threading.StratosThreadPool;
 import org.apache.stratos.messaging.domain.application.GroupStatus;
@@ -53,7 +54,10 @@ import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
 import java.util.*;
-import java.util.concurrent.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Monitor is to monitor it's child monitors and
@@ -93,7 +97,7 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
         //clusterIdToClusterMonitorsMap = new HashMap<String, AbstractClusterMonitor>();
         this.id = component.getUniqueIdentifier();
         //Building the startup dependencies for this monitor within the immediate children
-        startupDependencyTree = DependencyBuilder.getInstance().buildDependency(component);
+        startupDependencyTree = DependencyBuilder.getInstance().buildDependency(getAppId(), component);
         //Building the scaling dependencies for this monitor within the immediate children
         if ((component.getDependencyOrder() != null) && (component.getDependencyOrder().
                                                             getScalingDependents() != null)) {
@@ -125,35 +129,34 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
      * 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, List<String> instanceIds) {
+    public void startDependency(ParentComponent component, List<String> parentInstanceIds) {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
                 getStartAbleDependencies();
-        startDependency(applicationContexts, instanceIds);
-
+        startDependency(applicationContexts, parentInstanceIds);
     }
 
     /**
      * 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, String instanceId) throws
+    public void startDependency(ParentComponent component, String parentInstanceId) throws
             MonitorNotFoundException {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.
                 getStartAbleDependencies();
-        startDependency(applicationContexts, instanceId);
-
+        List<String> parentInstanceIds = new ArrayList<String>();
+        parentInstanceIds.add(parentInstanceId);
+        startDependency(applicationContexts, parentInstanceIds);
     }
 
     /**
      * 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
+     * @param componentId alias/clusterId of which receive the activated event
      */
-    public boolean startDependency(String id, String instanceId) throws MonitorNotFoundException {
-        List<ApplicationChildContext> applicationContexts = this.startupDependencyTree
-                .getStarAbleDependencies(id);
+    public boolean startDependency(String componentId, String instanceId) throws MonitorNotFoundException {
+        List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.getStarAbleDependencies(componentId);
         List<String> instanceIds = new ArrayList<String>();
         instanceIds.add(instanceId);
         return startDependency(applicationContexts, instanceIds);
@@ -176,10 +179,12 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
             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 found in the hierarchy";
-                throw new MonitorNotFoundException(msg);
+                log.info(String.format("Starting dependent monitor on termination: [application] %s [component] %s",
+                        getAppId(), context.getId()));
+                List<String> parentInstanceIds = new ArrayList<String>();
+                parentInstanceIds.add(instanceId);
+                startMonitor(this, context, parentInstanceIds);
             } else {
                 //starting a new instance of the child
                 Monitor monitor = aliasToActiveMonitorsMap.get(context.getId());
@@ -187,75 +192,38 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
                 monitor.createInstanceOnDemand(instanceId);
             }
         }
-
     }
 
-
     /**
      * To start the dependency of the given application contexts
      *
      * @param applicationContexts the found applicationContexts to be started
      */
-    private boolean startDependency(List<ApplicationChildContext> applicationContexts,
-                                    List<String> instanceIds) {
+    private boolean startDependency(List<ApplicationChildContext> applicationContexts, List<String> parentInstanceIds) {
         if (applicationContexts != null && applicationContexts.isEmpty()) {
             //all the groups/clusters have been started and waiting for activation
-            log.info("No more children to start for [group/application] " + this.id);
+            log.info("No more dependent monitors to be started for component: [type] " + getMonitorType().toString().toLowerCase()
+                    + "[component] " + this.id);
             return false;
 
         }
         for (ApplicationChildContext context : applicationContexts) {
-            if (log.isDebugEnabled()) {
-                log.debug("Dependency check for the Group " + context.getId() + " started");
-            }
             if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
-                //to avoid if it is already started
-                startMonitor(this, context, instanceIds);
+                log.info(String.format("Starting dependent monitor: [application] %s [component] %s",
+                        getAppId(), context.getId()));
+                startMonitor(this, context, parentInstanceIds);
             } else {
-                //starting a new instance of the child
+                log.info(String.format("Dependent monitor already created, creating instance: " +
+                                "[application] %s [component] %s", getAppId(), context.getId()));
+
                 Monitor monitor = aliasToActiveMonitorsMap.get(context.getId());
-                //Creating the new instance
-                for (String instanceId : instanceIds) {
+                // Creating new instance
+                for (String instanceId : parentInstanceIds) {
                     monitor.createInstanceOnDemand(instanceId);
                 }
             }
         }
-
         return true;
-
-    }
-
-    /**
-     * To start the dependency of the given application contexts
-     *
-     * @param applicationContexts the found applicationContexts to be started
-     */
-    private boolean startDependency(List<ApplicationChildContext> applicationContexts, String instanceId)
-            throws MonitorNotFoundException {
-        if (applicationContexts != null && applicationContexts.isEmpty()) {
-            //all the groups/clusters have been started and waiting for activation
-            log.info("There is no child found for the [group]: " + this.id);
-            return false;
-
-        }
-        for (ApplicationChildContext context : applicationContexts) {
-            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);
-            }
-        }
-
-        return true;
-
     }
 
     @Override
@@ -693,15 +661,15 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
 
 
     protected synchronized void startMonitor(ParentComponentMonitor parent,
-                                             ApplicationChildContext context, List<String> instanceIds) {
+                                             ApplicationChildContext context, List<String> parentInstanceIds) {
 	    if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
 		    pendingMonitorsList.add(context.getId());
-		    executorService.submit(new MonitorAdder(parent, context, this.appId, instanceIds));
-		    if (log.isDebugEnabled()) {
-			    log.debug(String.format("Monitor adder has been added: [cluster] %s ", context.getId()));
-		    }
-	    }
+		    executorService.submit(new MonitorAdder(parent, context, this.appId, parentInstanceIds));
 
+            String monitorTypeStr = AutoscalerUtil.findMonitorType(context).toString().toLowerCase();
+            log.info(String.format("Monitor scheduled: [type] %s [component] %s ",
+                        monitorTypeStr, context.getId()));
+	    }
     }
 
     public Map<String, Monitor> getAliasToActiveMonitorsMap() {
@@ -779,46 +747,60 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
         return scalingDependencies;
     }
 
+    public DependencyTree getStartupDependencyTree() {
+        return startupDependencyTree;
+    }
+
     private class MonitorAdder implements Runnable {
 
-        private ApplicationChildContext context;
-        private ParentComponentMonitor parent;
-        private String appId;
-        private List<String> instanceIds;
+        private final ApplicationChildContext context;
+        private final ParentComponentMonitor parent;
+        private final String appId;
+        private final List<String> parentInstanceIds;
+        private final String monitorTypeStr;
 
         public MonitorAdder(ParentComponentMonitor parent, ApplicationChildContext context,
-                            String appId, List<String> instanceIds) {
+                            String appId, List<String> parentInstanceIds) {
             this.parent = parent;
             this.context = context;
             this.appId = appId;
-            this.instanceIds = instanceIds;
+            this.parentInstanceIds = parentInstanceIds;
+            this.monitorTypeStr = AutoscalerUtil.findMonitorType(context).toString().toLowerCase();
         }
 
         public void run() {
-            Monitor monitor = null;
+            long startTime = System.currentTimeMillis();
             int retries = 5;
+            Monitor monitor = null;
             boolean success = false;
             while (!success && retries != 0) {
 
+                startTime = System.currentTimeMillis();
                 if (log.isInfoEnabled()) {
-                    log.info("Monitor is going to be started for [group/cluster] " + context.getId());
+                    log.info(String.format("Starting monitor: [type] %s [component] %s",
+                            monitorTypeStr, context.getId()));
                 }
+
                 try {
-                    monitor = MonitorFactory.getMonitor(parent, context, appId, instanceIds);
+                    monitor = MonitorFactory.getMonitor(parent, context, appId, parentInstanceIds);
                 } catch (DependencyBuilderException e) {
-                    String msg = "Monitor creation failed for: " + context.getId();
+                    String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+                            monitorTypeStr, context.getId());
                     log.warn(msg, e);
                     retries--;
                 } catch (TopologyInConsistentException e) {
-                    String msg = "Monitor creation failed for: " + context.getId();
+                    String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+                            monitorTypeStr, context.getId());
                     log.warn(msg, e);
                     retries--;
                 } catch (PolicyValidationException e) {
-                    String msg = "Monitor creation failed for: " + context.getId();
+                    String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+                            monitorTypeStr, context.getId());
                     log.warn(msg, e);
                     retries--;
                 } catch (PartitionValidationException e) {
-                    String msg = "Monitor creation failed for: " + context.getId();
+                    String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+                            monitorTypeStr, context.getId());
                     log.warn(msg, e);
                     retries--;
                 }
@@ -826,8 +808,8 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
             }
 
             if (monitor == null) {
-                String msg = "Monitor creation failed, even after retrying for 5 times, "
-                        + "for : " + context.getId();
+                String msg = String.format("Monitor creation failed even after retrying for 5 times: "
+                        + "[type] %s [component] ", monitorTypeStr, context.getId());
                 log.error(msg);
                 //TODO parent.notify();
                 throw new RuntimeException(msg);
@@ -835,11 +817,30 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
 
             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()));
+                long endTime = System.currentTimeMillis();
+                long startupTime = (endTime - startTime)/1000;
+                log.info(String.format("Monitor started successfully: [type] %s [component] %s [dependents] %s " +
+                                "[startup-time] %d seconds", monitorTypeStr, context.getId(),
+                        getIdList(context.getApplicationChildContextList()), startupTime));
+            }
+        }
+
+        private String getIdList(List<ApplicationChildContext> applicationChildContextList) {
+            StringBuilder stringBuilder = new StringBuilder();
+            if((applicationChildContextList != null) && (applicationChildContextList.size() > 0)) {
+                for(ApplicationChildContext applicationChildContext : applicationChildContextList) {
+                    stringBuilder.append(applicationChildContext.getId());
+                    if(applicationChildContextList.indexOf(applicationChildContext) <
+                            (applicationChildContextList.size() - 1)) {
+                        stringBuilder.append(", ");
+                    }
+                }
+            } else {
+                stringBuilder.append("none");
             }
+            return stringBuilder.toString();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4bb8188f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
index ffca22e..637a38c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
@@ -273,8 +273,7 @@ public class AutoscalerServiceImpl implements AutoscalerService {
                 ApplicationHolder.releaseReadLock();
             }
 
-            if (!AutoscalerContext.getInstance().containsPendingMonitor(applicationId)
-                    || !AutoscalerContext.getInstance().monitorExists(applicationId)) {
+            if (!AutoscalerContext.getInstance().containsApplicationPendingMonitor(applicationId)) {
                 if (allClusterInitialized) {
                     AutoscalerUtil.getInstance().startApplicationMonitor(applicationId);
                 } else {