Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 4b1d3a656 -> 25221cc3f
adding missing locks in application undeployment and removal Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/25221cc3 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/25221cc3 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/25221cc3 Branch: refs/heads/4.0.0-grouping Commit: 25221cc3f2a0f73997fa9a793700f99c4adfb802 Parents: 4b1d3a6 Author: Isuru Haththotuwa <[email protected]> Authored: Fri Oct 24 11:42:08 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Fri Oct 24 15:47:28 2014 +0530 ---------------------------------------------------------------------- .../AutoscalerTopologyEventReceiver.java | 34 +++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/25221cc3/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java index 93b3123..211bcd2 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java @@ -35,10 +35,7 @@ import org.apache.stratos.autoscaler.monitor.group.GroupMonitor; import org.apache.stratos.autoscaler.partition.PartitionManager; import org.apache.stratos.autoscaler.policy.PolicyManager; import org.apache.stratos.autoscaler.status.checker.StatusChecker; -import org.apache.stratos.messaging.domain.topology.Application; -import org.apache.stratos.messaging.domain.topology.ApplicationStatus; -import org.apache.stratos.messaging.domain.topology.ClusterStatus; -import org.apache.stratos.messaging.domain.topology.GroupStatus; +import org.apache.stratos.messaging.domain.topology.*; import org.apache.stratos.messaging.event.Event; import org.apache.stratos.messaging.event.topology.*; import org.apache.stratos.messaging.listener.topology.*; @@ -46,6 +43,7 @@ import org.apache.stratos.messaging.message.receiver.topology.TopologyEventRecei import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import java.util.List; +import java.util.Set; /** * Autoscaler topology receiver. @@ -306,7 +304,16 @@ public class AutoscalerTopologyEventReceiver implements Runnable { log.info("[ApplicationUndeployedEvent] Received: " + event.getClass()); ApplicationUndeployedEvent applicationUndeployedEvent = (ApplicationUndeployedEvent) event; + + // acquire reead locks for application and relevant clusters TopologyManager.acquireReadLockForApplication(applicationUndeployedEvent.getApplicationId()); + Set<ClusterDataHolder> clusterDataHolders = applicationUndeployedEvent.getClusterData(); + if (clusterDataHolders != null) { + for (ClusterDataHolder clusterData : clusterDataHolders) { + TopologyManager.acquireReadLockForCluster(clusterData.getServiceType(), + clusterData.getClusterId()); + } + } try { ApplicationMonitor appMonitor = AutoscalerContext.getInstance(). @@ -338,6 +345,12 @@ public class AutoscalerTopologyEventReceiver implements Runnable { } } finally { + if (clusterDataHolders != null) { + for (ClusterDataHolder clusterData : clusterDataHolders) { + TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(), + clusterData.getClusterId()); + } + } TopologyManager. releaseReadLockForApplication(applicationUndeployedEvent.getApplicationId()); } @@ -355,6 +368,13 @@ public class AutoscalerTopologyEventReceiver implements Runnable { //acquire read lock TopologyManager.acquireReadLockForApplication(applicationRemovedEvent.getApplicationId()); + Set<ClusterDataHolder> clusterDataHolders = applicationRemovedEvent.getClusterData(); + if (clusterDataHolders != null) { + for (ClusterDataHolder clusterData : clusterDataHolders) { + TopologyManager.acquireReadLockForCluster(clusterData.getServiceType(), + clusterData.getClusterId()); + } + } try { //TODO remove monitors as well as any starting or pending threads @@ -379,6 +399,12 @@ public class AutoscalerTopologyEventReceiver implements Runnable { } finally { //release read lock + if (clusterDataHolders != null) { + for (ClusterDataHolder clusterData : clusterDataHolders) { + TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(), + clusterData.getClusterId()); + } + } TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getApplicationId()); }
