Repository: stratos Updated Branches: refs/heads/master bee0d764a -> d1a5ce4ae
fixing monitors getting executed in order to satisfy the minimum count when the application is undeploying Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2f6a191a Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2f6a191a Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2f6a191a Branch: refs/heads/master Commit: 2f6a191a806709d78a87ae83055589be58563c65 Parents: e59a6e1 Author: reka <[email protected]> Authored: Thu Aug 20 12:25:06 2015 +0530 Committer: reka <[email protected]> Committed: Thu Aug 20 14:00:28 2015 +0530 ---------------------------------------------------------------------- .../monitor/component/ApplicationMonitor.java | 21 ++-- .../monitor/component/GroupMonitor.java | 108 ++++++++++--------- 2 files changed, 69 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/2f6a191a/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 41b6e1f..70ee9d4 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 @@ -147,20 +147,21 @@ public class ApplicationMonitor extends ParentComponentMonitor { new ConcurrentHashMap<String, ScalingUpBeyondMaxEvent>()); } } - - Application application = ApplicationHolder.getApplications().getApplication(appId); - if (application != null) { - List<String> defaultNetworkPartitions = getDefaultNetworkPartitions(application); - //Checking for whether minimum application instances are there. - if (defaultNetworkPartitions != null) { - checkForMinimumApplicationInstances(application, defaultNetworkPartitions); - } + //When the application is getting un-deployed, need to avoid + // checking the minimum count sanctification + if (!isTerminating()) { + Application application = ApplicationHolder.getApplications().getApplication(appId); + if (application != null) { + List<String> defaultNetworkPartitions = getDefaultNetworkPartitions(application); + //Checking for whether minimum application instances are there. + if (defaultNetworkPartitions != null) { + checkForMinimumApplicationInstances(application, defaultNetworkPartitions); + } /*//Checking for whether any application instances need to be terminated. checkForApplicationInstanceTermination(application, defaultNetworkPartitions);*/ + } } - - } }; executorService.execute(monitoringRunnable); http://git-wip-us.apache.org/repos/asf/stratos/blob/2f6a191a/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 c3e89ee..bc3052a 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 @@ -155,65 +155,73 @@ public class GroupMonitor extends ParentComponentMonitor { } } - Collection<Instance> parentInstances = parent.getInstances(); - - for (Instance parentInstance : parentInstances) { - if (parentInstance.getNetworkPartitionId().equals(networkPartitionContext.getId())) { - int nonTerminatedInstancesCount = networkPartitionContext. - getNonTerminatedInstancesCount(parentInstance.getInstanceId()); - int minInstances = networkPartitionContext. - getMinInstanceCount(); - int maxInstances = networkPartitionContext. - getMaxInstanceCount(); - int activeInstances = networkPartitionContext. - getActiveInstancesCount(parentInstance.getInstanceId()); - - if (nonTerminatedInstancesCount < minInstances) { - int instancesToBeCreated = minInstances - nonTerminatedInstancesCount; - for (int i = 0; i < instancesToBeCreated; i++) { - for (InstanceContext parentInstanceContext : parent. - getNetworkPartitionContext(networkPartitionContext.getId()). - getInstanceIdToInstanceContextMap().values()) { - //keep on scale-up/scale-down only if the application is active - ApplicationMonitor appMonitor = AutoscalerContext.getInstance(). - getAppMonitor(appId); - int activeAppInstances = appMonitor. + ApplicationMonitor applicationMonitor = AutoscalerContext.getInstance(). + getAppMonitor(appId); + + //When the application is getting un-deployed, need to avoid + // checking the minimum count sanctification + if (!applicationMonitor.isTerminating()) { + Collection<Instance> parentInstances = parent.getInstances(); + + for (Instance parentInstance : parentInstances) { + if (parentInstance.getNetworkPartitionId().equals(networkPartitionContext.getId())) { + int nonTerminatedInstancesCount = networkPartitionContext. + getNonTerminatedInstancesCount(parentInstance.getInstanceId()); + int minInstances = networkPartitionContext. + getMinInstanceCount(); + int maxInstances = networkPartitionContext. + getMaxInstanceCount(); + int activeInstances = networkPartitionContext. + getActiveInstancesCount(parentInstance.getInstanceId()); + + if (nonTerminatedInstancesCount < minInstances) { + int instancesToBeCreated = minInstances - nonTerminatedInstancesCount; + for (int i = 0; i < instancesToBeCreated; i++) { + for (InstanceContext parentInstanceContext : parent. getNetworkPartitionContext(networkPartitionContext.getId()). - getActiveInstancesCount(); - if (activeAppInstances > 0) { - //Creating new group instance based on the existing parent instances - log.info("Creating a group instance of [application] " - + appId + " [group] " + id + - " as the the minimum required instances are not met"); - - createInstanceOnDemand(parentInstanceContext.getId()); + getInstanceIdToInstanceContextMap().values()) { + //keep on scale-up/scale-down only if the application is active + ApplicationMonitor appMonitor = AutoscalerContext.getInstance(). + getAppMonitor(appId); + int activeAppInstances = appMonitor. + getNetworkPartitionContext(networkPartitionContext.getId()). + getActiveInstancesCount(); + if (activeAppInstances > 0) { + //Creating new group instance based on the existing parent instances + log.info("Creating a group instance of [application] " + + appId + " [group] " + id + + " as the the minimum required instances are not met"); + + createInstanceOnDemand(parentInstanceContext.getId()); + } } - } + } } - } - //If the active instances are higher than the max instances, - // the group instance has to get terminated - if (activeInstances > maxInstances) { - int instancesToBeTerminated = activeInstances - maxInstances; - List<InstanceContext> contexts = - networkPartitionContext.getInstanceIdToInstanceContextMap( - parentInstance.getInstanceId()); - List<InstanceContext> contextList = new ArrayList<InstanceContext>(contexts); - for (int i = 0; i < instancesToBeTerminated; i++) { - InstanceContext instanceContext = contextList.get(i); - //scale down only when extra instances found - log.info("Terminating a group instance of [application] " - + appId + " [group] " + id + " as it exceeded the " + - "maximum no of instances by " + instancesToBeTerminated); - - handleScalingDownBeyondMin((ParentInstanceContext) instanceContext, - networkPartitionContext, true); + //If the active instances are higher than the max instances, + // the group instance has to get terminated + if (activeInstances > maxInstances) { + int instancesToBeTerminated = activeInstances - maxInstances; + List<InstanceContext> contexts = + networkPartitionContext.getInstanceIdToInstanceContextMap( + parentInstance.getInstanceId()); + List<InstanceContext> contextList = new ArrayList<InstanceContext>(contexts); + for (int i = 0; i < instancesToBeTerminated; i++) { + InstanceContext instanceContext = contextList.get(i); + //scale down only when extra instances found + log.info("Terminating a group instance of [application] " + + appId + " [group] " + id + " as it exceeded the " + + "maximum no of instances by " + instancesToBeTerminated); + + handleScalingDownBeyondMin((ParentInstanceContext) instanceContext, + networkPartitionContext, true); + } } } } } + } } };
