Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 2536b30b3 -> 622ce9fb6
hierarchical locking contd. Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/622ce9fb Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/622ce9fb Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/622ce9fb Branch: refs/heads/4.0.0-grouping Commit: 622ce9fb6aa9b6ab4613626b32c805ff74d868cd Parents: 4ace39c Author: Isuru Haththotuwa <[email protected]> Authored: Tue Oct 7 19:08:25 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Tue Oct 7 19:08:54 2014 +0530 ---------------------------------------------------------------------- .../impl/CloudControllerServiceImpl.java | 6 - .../controller/topology/TopologyBuilder.java | 7 +- .../topology/TopologyEventPublisher.java | 6 +- .../event/topology/ApplicationRemovedEvent.java | 15 +- .../ApplicationActivatedMessageProcessor.java | 2 - .../ApplicationCreatedMessageProcessor.java | 9 + .../ApplicationRemovedMessageProcessor.java | 23 ++ .../topology/ClusterActivatedProcessor.java | 2 - .../ClusterCreatedMessageProcessor.java | 2 - .../ClusterMaintenanceModeMessageProcessor.java | 2 - .../ClusterRemovedMessageProcessor.java | 2 - .../topology/GroupActivatedProcessor.java | 2 - .../receiver/topology/TopologyManager.java | 80 ------- .../topology/locking/TopologyLockingTest.java | 209 +++++++++++++++++++ 14 files changed, 263 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java index a6f74df..df2c217 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java @@ -35,7 +35,6 @@ import org.apache.stratos.cloud.controller.interfaces.Iaas; import org.apache.stratos.cloud.controller.persist.Deserializer; import org.apache.stratos.cloud.controller.pojo.*; import org.apache.stratos.cloud.controller.pojo.application.ApplicationContext; -import org.apache.stratos.cloud.controller.pojo.payload.MetaDataHolder; import org.apache.stratos.cloud.controller.publisher.CartridgeInstanceDataPublisher; import org.apache.stratos.cloud.controller.registry.RegistryManager; import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; @@ -49,11 +48,6 @@ import org.apache.stratos.messaging.domain.topology.ConfigCompositeApplication; import org.apache.stratos.messaging.domain.topology.Member; import org.apache.stratos.messaging.domain.topology.MemberStatus; import org.apache.stratos.messaging.util.Constants; -import org.apache.stratos.metadata.client.DefaultMetaDataServiceClient; -import org.apache.stratos.metadata.client.MetaDataServiceClient; -import org.apache.stratos.metadata.client.config.MetaDataClientConfig; -import org.apache.stratos.metadata.client.exception.MetaDataServiceClientExeption; -import org.apache.stratos.metadata.client.exception.RestClientException; import org.jclouds.compute.ComputeService; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadataBuilder; http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java index 30b1b00..4aa7023 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java @@ -664,12 +664,13 @@ public class TopologyBuilder { if (!topology.applicationExists(applicationId)) { log.warn("Application with id [ " + applicationId + " ] doesn't exist in Topology"); - TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, tenantId, tenantDomain); + //TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, tenantId, tenantDomain); } else { Application application = topology.getApplication(applicationId); + Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively(); // remove clusters - for (ClusterDataHolder clusterDataHolder : application.getClusterDataRecursively()) { + for (ClusterDataHolder clusterDataHolder : clusterData) { Service service = topology.getService(clusterDataHolder.getServiceType()); if (service != null) { // remove Cluster @@ -696,7 +697,7 @@ public class TopologyBuilder { log.info("Removed application [ " + applicationId + " ] from Topology"); - TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, tenantId, tenantDomain); + TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, clusterData, tenantId, tenantDomain); } } finally { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java index 53efeaa..a6d8350 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java @@ -39,6 +39,7 @@ import org.apache.stratos.messaging.util.Constants; import java.util.List; import java.util.Properties; +import java.util.Set; /** * this is to send the relevant events from cloud controller to topology topic @@ -99,13 +100,14 @@ public class TopologyEventPublisher { publishEvent(new ApplicationCreatedEvent(application, clusters)); } - public static void sendApplicationRemovedEvent(String applicationId, int tenantId, String tenantDomain) { + public static void sendApplicationRemovedEvent(String applicationId, Set<ClusterDataHolder> clusterData, + int tenantId, String tenantDomain) { if(log.isInfoEnabled() || log.isDebugEnabled()) { log.info("Publishing Application removed event: " + applicationId + " tenantId: " + tenantId); } - publishEvent(new ApplicationRemovedEvent(applicationId, tenantId, tenantDomain)); + publishEvent(new ApplicationRemovedEvent(applicationId, clusterData, tenantId, tenantDomain)); } public static void sendClusterRemovedEvent(ClusterContext ctxt, String deploymentPolicy) { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationRemovedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationRemovedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationRemovedEvent.java index 1e51321..8b0f2cb 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationRemovedEvent.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationRemovedEvent.java @@ -19,6 +19,11 @@ package org.apache.stratos.messaging.event.topology; + +import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; + +import java.util.Set; + public class ApplicationRemovedEvent extends TopologyEvent { /** @@ -26,11 +31,15 @@ public class ApplicationRemovedEvent extends TopologyEvent { */ private static final long serialVersionUID = -5499420725533165623L; private String applicationId; + private Set<ClusterDataHolder> clusterData; + private String tenantDomain; private int tenantId; - public ApplicationRemovedEvent (String applicationId, int tenantId, String tenantDomain) { + public ApplicationRemovedEvent (String applicationId, Set<ClusterDataHolder> clusterData, + int tenantId, String tenantDomain) { this.applicationId = applicationId; + this.clusterData = clusterData; this.tenantId = tenantId; this.tenantDomain = tenantDomain; } @@ -46,4 +55,8 @@ public class ApplicationRemovedEvent extends TopologyEvent { public String getTenantDomain() { return tenantDomain; } + + public Set<ClusterDataHolder> getClusterData() { + return clusterData; + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java index 803a871..4211830 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationActivatedMessageProcessor.java @@ -57,7 +57,6 @@ public class ApplicationActivatedMessageProcessor extends MessageProcessor { ApplicationActivatedEvent event = (ApplicationActivatedEvent) Util. jsonToObject(message, ApplicationActivatedEvent.class); - TopologyManager.acquireReadLockForApplications(); TopologyManager.acquireWriteLockForApplication(event.getAppId()); try { @@ -65,7 +64,6 @@ public class ApplicationActivatedMessageProcessor extends MessageProcessor { } finally { TopologyManager.releaseWriteLockForApplication(event.getAppId()); - TopologyManager.releaseReadLockForApplications(); } } else { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationCreatedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationCreatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationCreatedMessageProcessor.java index 4368bd7..c47867e 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationCreatedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationCreatedMessageProcessor.java @@ -22,12 +22,15 @@ package org.apache.stratos.messaging.message.processor.topology; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.messaging.domain.topology.Cluster; +import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; import org.apache.stratos.messaging.domain.topology.Topology; import org.apache.stratos.messaging.event.topology.ApplicationCreatedEvent; import org.apache.stratos.messaging.message.processor.MessageProcessor; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import org.apache.stratos.messaging.util.Util; +import java.util.Set; + public class ApplicationCreatedMessageProcessor extends MessageProcessor { private static final Log log = LogFactory.getLog(ApplicationCreatedMessageProcessor.class); @@ -55,11 +58,17 @@ public class ApplicationCreatedMessageProcessor extends MessageProcessor { } TopologyManager.acquireWriteLockForApplications(); + for (ClusterDataHolder clusterData : event.getApplication().getClusterDataRecursively()) { + TopologyManager.acquireWriteLockForService(clusterData.getServiceType()); + } try { return doProcess(event, topology); } finally { + for (ClusterDataHolder clusterData : event.getApplication().getClusterDataRecursively()) { + TopologyManager.releaseWriteLockForService(clusterData.getServiceType()); + } TopologyManager.releaseWriteLockForApplications(); } http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationRemovedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationRemovedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationRemovedMessageProcessor.java index ed6c2d4..629f21b 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationRemovedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationRemovedMessageProcessor.java @@ -21,6 +21,8 @@ package org.apache.stratos.messaging.message.processor.topology; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; +import org.apache.stratos.messaging.domain.topology.Service; import org.apache.stratos.messaging.domain.topology.Topology; import org.apache.stratos.messaging.event.topology.ApplicationRemovedEvent; import org.apache.stratos.messaging.message.processor.MessageProcessor; @@ -62,12 +64,18 @@ public class ApplicationRemovedMessageProcessor extends MessageProcessor { } TopologyManager.acquireWriteLockForApplications(); + for (ClusterDataHolder clusterData : event.getClusterData()) { + TopologyManager.acquireWriteLockForService(clusterData.getServiceType()); + } try { return doProcess(event, topology); } finally { TopologyManager.releaseWriteLockForApplications(); + for (ClusterDataHolder clusterData : event.getClusterData()) { + TopologyManager.releaseWriteLockForService(clusterData.getServiceType()); + } } } else { @@ -102,6 +110,21 @@ public class ApplicationRemovedMessageProcessor extends MessageProcessor { topology.removeApplication(appId); } + if (event.getClusterData() != null) { + // remove the Clusters from the Topology + for (ClusterDataHolder clusterData : event.getClusterData()) { + Service service = topology.getService(clusterData.getServiceType()); + if (service != null) { + service.removeCluster(clusterData.getClusterId()); + if (log.isDebugEnabled()) { + log.debug("Removed the Cluster " + clusterData.getClusterId() + " from Topology"); + } + } else { + log.warn("Service " + clusterData.getServiceType() + " not found in Topology!"); + } + } + } + if (log.isDebugEnabled()) { log.debug("ApplicationRemovedMessageProcessor notifying listener "); } http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java index 78f772b..601cfb2 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterActivatedProcessor.java @@ -58,14 +58,12 @@ public class ClusterActivatedProcessor extends MessageProcessor { ClusterActivatedEvent event = (ClusterActivatedEvent) Util. jsonToObject(message, ClusterActivatedEvent.class); - TopologyManager.acquireReadLockForServices(); TopologyManager.acquireWriteLockForService(event.getServiceName()); try { return doProcess(event, topology); } finally { TopologyManager.releaseWriteLockForService(event.getServiceName()); - TopologyManager.releaseReadLockForServices(); } } else { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java index 94b9650..6eddfd3 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedMessageProcessor.java @@ -53,14 +53,12 @@ public class ClusterCreatedMessageProcessor extends MessageProcessor { // Parse complete message and build event ClusterCreatedEvent event = (ClusterCreatedEvent) Util.jsonToObject(message, ClusterCreatedEvent.class); - TopologyManager.acquireReadLockForServices(); TopologyManager.acquireWriteLockForService(event.getServiceName()); try { return doProcess(event, topology); } finally { TopologyManager.releaseWriteLockForService(event.getServiceName()); - TopologyManager.releaseReadLockForServices(); } } else { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java index 8629363..0b10504 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterMaintenanceModeMessageProcessor.java @@ -50,14 +50,12 @@ public class ClusterMaintenanceModeMessageProcessor extends MessageProcessor { ClusterMaintenanceModeEvent event = (ClusterMaintenanceModeEvent) Util. jsonToObject(message, ClusterMaintenanceModeEvent.class); - TopologyManager.acquireReadLockForServices(); TopologyManager.acquireWriteLockForService(event.getServiceName()); try { return doProcess(event, topology); } finally { TopologyManager.releaseWriteLockForService(event.getServiceName()); - TopologyManager.releaseReadLockForServices(); } } else { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterRemovedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterRemovedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterRemovedMessageProcessor.java index 1dfb929..fb45cd3 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterRemovedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterRemovedMessageProcessor.java @@ -51,14 +51,12 @@ public class ClusterRemovedMessageProcessor extends MessageProcessor { // Parse complete message and build event ClusterRemovedEvent event = (ClusterRemovedEvent) Util.jsonToObject(message, ClusterRemovedEvent.class); - TopologyManager.acquireReadLockForServices(); TopologyManager.acquireWriteLockForService(event.getServiceName()); try { return doProcess(event, topology); } finally { TopologyManager.releaseWriteLockForService(event.getServiceName()); - TopologyManager.releaseReadLockForServices(); } } else { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java index 7200431..3bf5fad 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/GroupActivatedProcessor.java @@ -51,7 +51,6 @@ public class GroupActivatedProcessor extends MessageProcessor { GroupActivatedEvent event = (GroupActivatedEvent) Util. jsonToObject(message, GroupActivatedEvent.class); - TopologyManager.acquireReadLockForApplications(); TopologyManager.acquireWriteLockForApplication(event.getAppId()); try { @@ -59,7 +58,6 @@ public class GroupActivatedProcessor extends MessageProcessor { } finally { TopologyManager.releaseWriteLockForApplication(event.getAppId()); - TopologyManager.releaseReadLockForApplications(); } } else { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java index 2ffd7f6..ed3b16a 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java @@ -21,13 +21,10 @@ package org.apache.stratos.messaging.message.receiver.topology; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.messaging.domain.topology.Application; -import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; import org.apache.stratos.messaging.domain.topology.Topology; import org.apache.stratos.messaging.domain.topology.locking.TopologyLock; import org.apache.stratos.messaging.domain.topology.locking.TopologyLockHierarchy; -import java.util.Set; import java.util.concurrent.locks.ReentrantReadWriteLock; /** @@ -335,27 +332,6 @@ public class TopologyManager { // acquire read lock for all Applications acquireReadLockForApplications(); - // get the Application's cluster's and acquire read locks - Application application = topology.getApplication(appId); - if (application == null) { - log.warn("Application " + appId + " is not found in the Topology"); - - } else { - - Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively(); - if (clusterData != null && !clusterData.isEmpty()) { - for (ClusterDataHolder clusterDataHolder : clusterData) { - // acquire read locks for services and clusters - acquireReadLockForCluster(clusterDataHolder.getServiceType(), clusterDataHolder.getClusterId()); - } - - } else { - if (log.isDebugEnabled()) { - log.debug("No Cluster Data found in Application " + appId); - } - } - } - TopologyLock topologyAppLock = topologyLockHierarchy.getTopologyLockForApplication(appId); if (topologyAppLock == null) { handleLockNotFound("Topology lock not found for Application " + appId); @@ -385,25 +361,6 @@ public class TopologyManager { // release read lock for all Applications releaseReadLockForApplications(); - - // get the Application's cluster information - Application application = topology.getApplication(appId); - if (application == null) { - log.warn("Application " + appId + " is not found in the Topology"); - - } else { - Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively(); - if (clusterData != null && !clusterData.isEmpty()) { - for (ClusterDataHolder clusterDataHolder : clusterData) { - // release read locks for clusters and services - releaseReadLockForCluster(clusterDataHolder.getServiceType(), clusterDataHolder.getClusterId()); - } - } else { - if (log.isDebugEnabled()) { - log.debug("No Cluster Data found in Application " + appId); - } - } - } } public static synchronized void acquireWriteLockForApplication (String appId) { @@ -411,24 +368,6 @@ public class TopologyManager { // acquire read lock for all Applications acquireReadLockForApplications(); - // get the Application's cluster's and acquire read locks - Application application = topology.getApplication(appId); - if (application == null) { - log.warn("Application " + appId + " is not found in the Topology"); - - } else { - Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively(); - if (clusterData != null && !clusterData.isEmpty()) { - for (ClusterDataHolder clusterDataHolder : clusterData) { - acquireWriteLockForCluster(clusterDataHolder.getServiceType(), clusterDataHolder.getClusterId()); - } - } else { - if (log.isDebugEnabled()) { - log.debug("No Cluster Data found in Application " + appId); - } - } - } - TopologyLock topologyAppLock = topologyLockHierarchy.getTopologyLockForApplication(appId); if (topologyAppLock == null) { handleLockNotFound("Topology lock not found for Application " + appId); @@ -458,25 +397,6 @@ public class TopologyManager { // release read lock for all Applications releaseReadLockForApplications(); - - // get the Application's cluster's and acquire read - Application application = topology.getApplication(appId); - if (application == null) { - log.warn("Application " + appId + " is not found in the Topology"); - - } else { - Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively(); - if (clusterData != null && !clusterData.isEmpty()) { - for (ClusterDataHolder clusterDataHolder : clusterData) { - // release read locks for clusters and services - releaseWriteLockForCluster(clusterDataHolder.getServiceType(), clusterDataHolder.getClusterId()); - } - } else { - if (log.isDebugEnabled()) { - log.debug("No Cluster Data found in Application " + appId); - } - } - } } private static void handleLockNotFound (String errorMsg) { http://git-wip-us.apache.org/repos/asf/stratos/blob/622ce9fb/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/topology/locking/TopologyLockingTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/topology/locking/TopologyLockingTest.java b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/topology/locking/TopologyLockingTest.java new file mode 100644 index 0000000..5d33904 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/test/java/org/apache/stratos/messaging/topology/locking/TopologyLockingTest.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.messaging.topology.locking; + +import org.apache.stratos.messaging.domain.topology.*; +import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; +import org.junit.*; + +import java.util.HashMap; +import java.util.Map; + +//@RunWith(ConcurrentRunner.class) +//@Concurrent(threads = 12) +public class TopologyLockingTest { + + private static Topology topology; + + @BeforeClass + public static void setUpBeforeClass() { + System.out.println("Setting up TopologyLockingTest"); + topology = TopologyManager.getTopology(); + + //add Services + topology.addService(new Service("service1", ServiceType.SingleTenant)); + topology.addService(new Service("service2", ServiceType.SingleTenant)); + topology.addService(new Service("service3", ServiceType.SingleTenant)); + topology.addService(new Service("service4", ServiceType.SingleTenant)); + + // add Clusters + topology.getService("service1").addCluster(new Cluster("service1", "service1.cluster1.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + topology.getService("service1").addCluster(new Cluster("service1", "service1.cluster2.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + + topology.getService("service2").addCluster(new Cluster("service2", "service2.cluster1.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + topology.getService("service2").addCluster(new Cluster("service2", "service2.cluster2.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + + topology.getService("service3").addCluster(new Cluster("service3", "service3.cluster1.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + topology.getService("service3").addCluster(new Cluster("service3", "service3.cluster2.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + + topology.getService("service4").addCluster(new Cluster("service4", "service4.cluster1.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + topology.getService("service4").addCluster(new Cluster("service4", "service4.cluster2.domain", + "dummyDeploymentPolicy", "dummyAutoscalePolicy", null)); + + // Create Application 1 + Application app1 = new Application("app1"); + Map<String, ClusterDataHolder> clusterDataMap1 = new HashMap<String, ClusterDataHolder>(); + clusterDataMap1.put("alias1", new ClusterDataHolder("service1", "service1.cluster1.domain")); + clusterDataMap1.put("alias2", new ClusterDataHolder("service1", "service1.cluster2.domain")); + clusterDataMap1.put("alias3", new ClusterDataHolder("service2", "service2.cluster1.domain")); + clusterDataMap1.put("alias4", new ClusterDataHolder("service2", "service2.cluster2.domain")); + + // add cluster data to Application + app1.setClusterData(clusterDataMap1); + + // add Applicaiton to Topology + topology.addApplication(app1); + + // Create Application 2 + Application app2 = new Application("app2"); + Map<String, ClusterDataHolder> clusterDataMap2 = new HashMap<String, ClusterDataHolder>(); + clusterDataMap2.put("alias5", new ClusterDataHolder("service3", "service3.cluster1.domain")); + clusterDataMap2.put("alias6", new ClusterDataHolder("service3", "service3.cluster2.domain")); + clusterDataMap2.put("alias7", new ClusterDataHolder("service4", "service4.cluster1.domain")); + clusterDataMap2.put("alias8", new ClusterDataHolder("service4", "service4.cluster2.domain")); + + // add cluster data to Application + app2.setClusterData(clusterDataMap2); + + // add Applicaiton to Topology + topology.addApplication(app2); + } + + @Test + public void testAqcuireAndReleaseReadLocksForServices1To2 () { + + TopologyManager.acquireReadLockForService("service1"); + TopologyManager.acquireReadLockForService("service2"); + + TopologyManager.releaseReadLockForService("service1"); + TopologyManager.releaseReadLockForService("service2"); + } + + @Test + public void testAqcuireAndReleaseReadLocksForServices3To4 () { + + TopologyManager.acquireReadLockForService("service3"); + TopologyManager.acquireReadLockForService("service4"); + + TopologyManager.releaseReadLockForService("service3"); + TopologyManager.releaseReadLockForService("service4"); + } + + @Test + public void testAqcuireAndReleaseWriteLocksForServices1To2 () { + + TopologyManager.acquireWriteLockForService("service1"); + TopologyManager.acquireWriteLockForService("service2"); + + TopologyManager.releaseWriteLockForService("service1"); + TopologyManager.releaseWriteLockForService("service2"); + } + + @Test + public void testAqcuireAndReleaseWriteLocksForServices3To4 () { + + TopologyManager.acquireWriteLockForService("service3"); + TopologyManager.acquireWriteLockForService("service4"); + + TopologyManager.releaseWriteLockForService("service3"); + TopologyManager.releaseWriteLockForService("service4"); + } + + @Test + public void testAqcuireAndReleaseReadLocksForClustersOfService1 () { + + TopologyManager.acquireReadLockForCluster("service1", "service1.cluster1.domain"); + TopologyManager.acquireReadLockForCluster("service1", "service1.cluster2.domain"); + + TopologyManager.releaseReadLockForCluster("service1", "service1.cluster1.domain"); + TopologyManager.releaseReadLockForCluster("service1", "service1.cluster2.domain"); + } + + @Test + public void testAqcuireAndReleaseReadLocksForClustersOfService2 () { + + TopologyManager.acquireReadLockForCluster("service2", "service2.cluster1.domain"); + TopologyManager.acquireReadLockForCluster("service2", "service2.cluster2.domain"); + + TopologyManager.releaseReadLockForCluster("service2", "service2.cluster1.domain"); + TopologyManager.releaseReadLockForCluster("service2", "service2.cluster2.domain"); + } + + @Test + public void testAqcuireAndReleaseWriteLocksForClustersOfService1 () { + + TopologyManager.acquireWriteLockForCluster("service1", "service1.cluster1.domain"); + TopologyManager.acquireWriteLockForCluster("service1", "service1.cluster2.domain"); + + TopologyManager.acquireWriteLockForCluster("service1", "service1.cluster1.domain"); + TopologyManager.acquireWriteLockForCluster("service1", "service1.cluster2.domain"); + } + + @Test + public void testAqcuireAndReleaseWriteLocksForClustersOfService2 () { + + TopologyManager.acquireWriteLockForCluster("service2", "service2.cluster1.domain"); + TopologyManager.acquireWriteLockForCluster("service2", "service2.cluster2.domain"); + + TopologyManager.acquireWriteLockForCluster("service2", "service2.cluster1.domain"); + TopologyManager.acquireWriteLockForCluster("service2", "service2.cluster2.domain"); + } + + @Test + public void testAcquireAndReleaseReadLockForApp1 () { + + TopologyManager.acquireReadLockForApplication("app1"); + TopologyManager.releaseReadLockForApplication("app1"); + } + + @Test + public void testAcquireAndReleaseWriteLockForApp1 () { + + TopologyManager.acquireWriteLockForApplication("app1"); + TopologyManager.releaseWriteLockForApplication("app1"); + } + + @Test + public void testAcquireAndReleaseReadLockForApp2 () { + + TopologyManager.acquireReadLockForApplication("app2"); + TopologyManager.releaseReadLockForApplication("app2"); + } + + @Test + public void testAcquireAndReleaseWriteLockForApp2 () { + + TopologyManager.acquireWriteLockForApplication("app2"); + TopologyManager.releaseWriteLockForApplication("app2"); + } + + @AfterClass + public static void tearDownAfterClass() { + System.out.println("Cleaning up TopologyLockingTest"); + topology = null; + } +}
