You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2015/06/30 10:41:03 UTC

stratos git commit: fixing NPE in group monitor and Application monitor when application bursting happen with undeployment

Repository: stratos
Updated Branches:
  refs/heads/master 4fa2e5e31 -> 8edde2bce


fixing NPE in group monitor and Application monitor when application bursting happen with undeployment


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

Branch: refs/heads/master
Commit: 8edde2bce53045400e6ba19db88f5a6c11e2f2b4
Parents: 4fa2e5e
Author: reka <rt...@gmail.com>
Authored: Tue Jun 30 14:10:40 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Tue Jun 30 14:10:40 2015 +0530

----------------------------------------------------------------------
 .../InstanceNotificationPublisher.java          |   3 +-
 .../AutoscalerTopologyEventReceiver.java        |   5 +-
 .../monitor/cluster/ClusterMonitor.java         |  56 ++++++++++
 .../monitor/component/ApplicationMonitor.java   |   6 +-
 .../monitor/component/GroupMonitor.java         | 104 +++++++++----------
 5 files changed, 118 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/8edde2bc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
index 94af7c1..a33329a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java
@@ -52,7 +52,8 @@ public class InstanceNotificationPublisher {
     }
 
     public synchronized void sendInstanceCleanupEventForCluster(String clusterId, String instanceId) {
-        log.info(String.format("Publishing Instance Cleanup Event: [cluster] %s", clusterId));
+        log.info(String.format("Publishing Instance Cleanup Event: [cluster] %s " +
+                "[cluster-instance] %s", clusterId, instanceId));
         publish(new InstanceCleanupClusterEvent(clusterId, instanceId));
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/8edde2bc/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 1481440..34098ee 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
@@ -281,10 +281,13 @@ public class AutoscalerTopologyEventReceiver {
                 //changing the status in the monitor, will notify its parent monitor
                 ClusterInstance clusterInstance = (ClusterInstance) monitor.getInstance(clusterInstanceId);
                 if (clusterInstance.getPreviousState() == ClusterStatus.Active) {
-                    // terminated gracefully
+                    // terminating all the active members gracefully
                     monitor.notifyParentMonitor(ClusterStatus.Terminating, clusterInstanceId);
                     InstanceNotificationPublisher.getInstance().
                             sendInstanceCleanupEventForCluster(clusterId, clusterInstanceId);
+                    //Terminating the pending members
+                    monitor.terminatePendingMembers(clusterInstanceId,
+                            clusterInstance.getNetworkPartitionId());
                 } else {
                     monitor.notifyParentMonitor(ClusterStatus.Terminating, clusterInstanceId);
                     monitor.terminateAllMembers(clusterInstanceId, clusterInstance.getNetworkPartitionId());

http://git-wip-us.apache.org/repos/asf/stratos/blob/8edde2bc/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 a92edde..2f0c4ac 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
@@ -1345,6 +1345,62 @@ public class ClusterMonitor extends Monitor {
         memberTerminator.start();
     }
 
+    public void terminatePendingMembers(final String instanceId, final String networkPartitionId) {
+        final ClusterMonitor monitor = this;
+        Thread memberTerminator = new Thread(new Runnable() {
+            public void run() {
+
+                ClusterInstanceContext instanceContext =
+                        (ClusterInstanceContext) getAllNetworkPartitionCtxts().get(networkPartitionId)
+                                .getInstanceContext(instanceId);
+                boolean allMovedToObsolete = true;
+                for (ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
+                    if (log.isInfoEnabled()) {
+                        log.info("Starting to terminate all members in cluster [" + getClusterId() + "] " +
+                                "Network Partition [" + instanceContext.getNetworkPartitionId() + "], Partition [" +
+                                partitionContext.getPartitionId() + "]");
+                    }
+
+                    if (AutoscalerContext.getInstance().getAppMonitor(getAppId()).isForce()) {
+                        log.info(String.format("Terminating all remaining members of partition [partition-id] %s [application-id] %s", partitionContext.getPartitionId(), getAppId()));
+                        partitionContext.terminateAllRemainingInstances();
+                    }
+                    //Need to terminate pending members
+                    Iterator<MemberContext> pendingIterator = partitionContext.getPendingMembers().listIterator();
+                    List<String> pendingMemberIdList = new ArrayList<String>();
+                    while (pendingIterator.hasNext()) {
+                        MemberContext pendingMemberContext = pendingIterator.next();
+                        pendingMemberIdList.add(pendingMemberContext.getMemberId());
+
+                    }
+                    for (String memberId : pendingMemberIdList) {
+                        // pending members
+                        if (log.isDebugEnabled()) {
+                            log.debug("Moving pending member [member id] " + memberId + " to obsolete list");
+                        }
+                        partitionContext.movePendingMemberToObsoleteMembers(memberId);
+                    }
+
+                    /*
+                    if (partitionContext.getTotalMemberCount() == 0) {
+                        allMovedToObsolete = allMovedToObsolete && true;
+                    } else {
+                        allMovedToObsolete = false;
+                    }
+                    */
+                    allMovedToObsolete = partitionContext.getTotalMemberCount() == 0;
+                }
+
+                if (allMovedToObsolete) {
+                    monitor.monitor();
+                }
+            }
+        }, "Member Terminator - [cluster id] " + getClusterId());
+
+        memberTerminator.start();
+    }
+
+
     public Map<String, ClusterLevelNetworkPartitionContext> getAllNetworkPartitionCtxts() {
         return (this.clusterContext).getNetworkPartitionCtxts();
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/8edde2bc/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 7ccfd22..89b9d17 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
@@ -151,7 +151,9 @@ public class ApplicationMonitor extends ParentComponentMonitor {
                 if (application != null) {
                     List<String> defaultNetworkPartitions = getDefaultNetworkPartitions(application);
                     //Checking for whether minimum application instances are there.
-                    checkForMinimumApplicationInstances(application, defaultNetworkPartitions);
+                    if(defaultNetworkPartitions != null) {
+                        checkForMinimumApplicationInstances(application, defaultNetworkPartitions);
+                    }
 
                     /*//Checking for whether any application instances need to be terminated.
                     checkForApplicationInstanceTermination(application, defaultNetworkPartitions);*/
@@ -268,7 +270,7 @@ public class ApplicationMonitor extends ParentComponentMonitor {
                 getNetworkPartitionAlgorithmContext(appId);
         ApplicationPolicy applicationPolicy = PolicyManager.getInstance().
                 getApplicationPolicy(application.getApplicationPolicyId());
-        List<String> defaultNetworkPartitions = new ArrayList<String>();
+        List<String> defaultNetworkPartitions = null;
 
         if (applicationPolicy != null) {
             String networkPartitionAlgorithmName = applicationPolicy.getAlgorithm();

http://git-wip-us.apache.org/repos/asf/stratos/blob/8edde2bc/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 4f60af9..72a8dcf 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
@@ -156,71 +156,71 @@ public class GroupMonitor extends ParentComponentMonitor {
                         }
                     }
 
-                    ParentLevelNetworkPartitionContext parentLevelNetworkPartitionContext
+                    ParentLevelNetworkPartitionContext parentNetworkPartitionContext
                             = (ParentLevelNetworkPartitionContext) networkPartitionContext;
                     Collection<Instance> parentInstances = parent.getInstances();
 
                     for (Instance parentInstance : parentInstances) {
-                        int nonTerminatedInstancesCount = parentLevelNetworkPartitionContext.
-                                getNonTerminatedInstancesCount(parentInstance.getInstanceId());
-                        int minInstances = parentLevelNetworkPartitionContext.
-                                getMinInstanceCount();
-                        int maxInstances = parentLevelNetworkPartitionContext.
-                                getMaxInstanceCount();
-                        int activeInstances = parentLevelNetworkPartitionContext.
-                                getActiveInstancesCount(parentInstance.getInstanceId());
-
-                        if (nonTerminatedInstancesCount < minInstances) {
-                            int instancesToBeCreated = minInstances - nonTerminatedInstancesCount;
-                            for (int i = 0; i < instancesToBeCreated; i++) {
-                                for (InstanceContext parentInstanceContext : parent.
-                                        getNetworkPartitionContext(parentLevelNetworkPartitionContext.getId()).
-                                        getInstanceIdToInstanceContextMap().values()) {
-                                    //keep on scale-up/scale-down only if the application is active
-                                    ApplicationMonitor appMonitor = AutoscalerContext.getInstance().
-                                            getAppMonitor(appId);
-                                    int activeAppInstances = ((ParentLevelNetworkPartitionContext) appMonitor.
-                                            getNetworkPartitionContext(parentLevelNetworkPartitionContext.getId())).
-                                            getActiveInstancesCount();
-                                    if (activeAppInstances > 0) {
-                                        //Creating new group instance based on the existing parent instances
-                                        if (log.isDebugEnabled()) {
-                                            log.debug("Creating a group instance of [application] "
-                                                    + appId + " [group] " + id +
-                                                    " as the the minimum required instances are not met");
-
+                        if(parentInstance.getNetworkPartitionId().equals(parentNetworkPartitionContext.getId())) {
+                            int nonTerminatedInstancesCount = parentNetworkPartitionContext.
+                                    getNonTerminatedInstancesCount(parentInstance.getInstanceId());
+                            int minInstances = parentNetworkPartitionContext.
+                                    getMinInstanceCount();
+                            int maxInstances = parentNetworkPartitionContext.
+                                    getMaxInstanceCount();
+                            int activeInstances = parentNetworkPartitionContext.
+                                    getActiveInstancesCount(parentInstance.getInstanceId());
+
+                            if (nonTerminatedInstancesCount < minInstances) {
+                                int instancesToBeCreated = minInstances - nonTerminatedInstancesCount;
+                                for (int i = 0; i < instancesToBeCreated; i++) {
+                                    for (InstanceContext parentInstanceContext : parent.
+                                            getNetworkPartitionContext(parentNetworkPartitionContext.getId()).
+                                            getInstanceIdToInstanceContextMap().values()) {
+                                        //keep on scale-up/scale-down only if the application is active
+                                        ApplicationMonitor appMonitor = AutoscalerContext.getInstance().
+                                                getAppMonitor(appId);
+                                        int activeAppInstances = ((ParentLevelNetworkPartitionContext) appMonitor.
+                                                getNetworkPartitionContext(parentNetworkPartitionContext.getId())).
+                                                getActiveInstancesCount();
+                                        if (activeAppInstances > 0) {
+                                            //Creating new group instance based on the existing parent instances
+                                            if (log.isDebugEnabled()) {
+                                                log.debug("Creating a group instance of [application] "
+                                                        + appId + " [group] " + id +
+                                                        " as the the minimum required instances are not met");
+
+                                            }
+                                            createInstanceOnDemand(parentInstanceContext.getId());
                                         }
-                                        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 =
-                                    ((ParentLevelNetworkPartitionContext) 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
-                                if (log.isDebugEnabled()) {
-                                    log.debug("Terminating a group instance of [application] "
-                                            + appId + " [group] " + id + " as it exceeded the " +
-                                            "maximum no of instances by " + instancesToBeTerminated);
+                            //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 =
+                                        ((ParentLevelNetworkPartitionContext) 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
+                                    if (log.isDebugEnabled()) {
+                                        log.debug("Terminating a group instance of [application] "
+                                                + appId + " [group] " + id + " as it exceeded the " +
+                                                "maximum no of instances by " + instancesToBeTerminated);
 
-                                }
-                                handleScalingDownBeyondMin(instanceContext,
-                                        networkPartitionContext, true);
+                                    }
+                                    handleScalingDownBeyondMin(instanceContext,
+                                            networkPartitionContext, true);
 
+                                }
                             }
                         }
                     }
-
-
                 }
             }
         };