Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 4e4ba5b38 -> b56e32852
removing ApplicationRemovedEvent, ApplicationRemovedEventListener and ApplicationRemovedMessageProcessor Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/b56e3285 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/b56e3285 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/b56e3285 Branch: refs/heads/4.0.0-grouping Commit: b56e3285239b2c070d7e78062ae8dd9e26131e50 Parents: 4e4ba5b Author: Isuru Haththotuwa <[email protected]> Authored: Mon Oct 27 13:08:58 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Mon Oct 27 13:08:58 2014 +0530 ---------------------------------------------------------------------- .../AutoscalerTopologyEventReceiver.java | 97 ++++++++++--- .../controller/topology/TopologyBuilder.java | 4 +- .../topology/TopologyEventPublisher.java | 18 +-- .../StratosManagerTopologyEventReceiver.java | 13 +- .../event/topology/ApplicationRemovedEvent.java | 62 -------- .../topology/ApplicationTerminatedEvent.java | 15 +- .../ApplicationRemovedEventListener.java | 26 ---- ...pStatusGroupTerminatingMessageProcessor.java | 8 +- .../ApplicationRemovedMessageProcessor.java | 142 ------------------- .../ApplicationTerminatedMessageProcessor.java | 76 +++++++--- .../topology/TopologyMessageProcessorChain.java | 6 - 11 files changed, 166 insertions(+), 301 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/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 654d5b2..89fe51f 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 @@ -419,28 +419,83 @@ public class AutoscalerTopologyEventReceiver implements Runnable { } }); - topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener() { +// topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener() { +// @Override +// protected void onEvent(Event event) { +// +// log.info("[ApplicationRemovedEvent] Received: " + event.getClass()); +// +// ApplicationRemovedEvent applicationRemovedEvent = (ApplicationRemovedEvent) event; +// +// //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 +// ApplicationMonitor monitor = AutoscalerContext.getInstance(). +// getAppMonitor(applicationRemovedEvent.getApplicationId()); +// if (monitor != null) { +// //List<String> clusters = monitor. +// // findClustersOfApplication(applicationRemovedEvent.getApplicationId()); +// for (ClusterDataHolder clusterData : clusterDataHolders) { +// //stopping the cluster monitor and remove it from the AS +// ((ClusterMonitor) AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId())). +// setDestroyed(true); +// AutoscalerContext.getInstance().removeMonitor(clusterData.getClusterId()); +// } +// //removing the application monitor +// AutoscalerContext.getInstance(). +// removeAppMonitor(applicationRemovedEvent.getApplicationId()); +// } else { +// log.warn("Application Monitor cannot be found for the removed [application] " +// + applicationRemovedEvent.getApplicationId()); +// } +// +// +// } finally { +// //release read lock +// if (clusterDataHolders != null) { +// for (ClusterDataHolder clusterData : clusterDataHolders) { +// TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(), +// clusterData.getClusterId()); +// } +// } +// TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getApplicationId()); +// } +// +// } +// }); + + topologyEventReceiver.addEventListener(new ApplicationTerminatedEventListener() { @Override protected void onEvent(Event event) { - log.info("[ApplicationRemovedEvent] Received: " + event.getClass()); + log.info("[ApplicationTerminatedEvent] Received: " + event.getClass()); - ApplicationRemovedEvent applicationRemovedEvent = (ApplicationRemovedEvent) event; + ApplicationTerminatedEvent applicationRemovedEvent = (ApplicationTerminatedEvent) event; + // no need to access the locks since the Topology is not accessed //acquire read lock - TopologyManager.acquireReadLockForApplication(applicationRemovedEvent.getApplicationId()); + //TopologyManager.acquireReadLockForApplication(applicationRemovedEvent.getAppId()); Set<ClusterDataHolder> clusterDataHolders = applicationRemovedEvent.getClusterData(); - if (clusterDataHolders != null) { - for (ClusterDataHolder clusterData : clusterDataHolders) { - TopologyManager.acquireReadLockForCluster(clusterData.getServiceType(), - clusterData.getClusterId()); - } - } +// 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 ApplicationMonitor monitor = AutoscalerContext.getInstance(). - getAppMonitor(applicationRemovedEvent.getApplicationId()); + getAppMonitor(applicationRemovedEvent.getAppId()); if (monitor != null) { //List<String> clusters = monitor. // findClustersOfApplication(applicationRemovedEvent.getApplicationId()); @@ -452,22 +507,22 @@ public class AutoscalerTopologyEventReceiver implements Runnable { } //removing the application monitor AutoscalerContext.getInstance(). - removeAppMonitor(applicationRemovedEvent.getApplicationId()); + removeAppMonitor(applicationRemovedEvent.getAppId()); } else { - log.warn("Application Monitor cannot be found for the removed [application] " - + applicationRemovedEvent.getApplicationId()); + log.warn("Application Monitor cannot be found for the terminated [application] " + + applicationRemovedEvent.getAppId()); } } finally { //release read lock - if (clusterDataHolders != null) { - for (ClusterDataHolder clusterData : clusterDataHolders) { - TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(), - clusterData.getClusterId()); - } - } - TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getApplicationId()); +// if (clusterDataHolders != null) { +// for (ClusterDataHolder clusterData : clusterDataHolders) { +// TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(), +// clusterData.getClusterId()); +// } +// } +// TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getAppId()); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/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 3e04311..f4606b8 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 @@ -1044,8 +1044,8 @@ public class TopologyBuilder { log.info("Removed application [ " + event.getAppId() + " ] from Topology"); - TopologyEventPublisher.sendApplicationRemovedEvent(event.getAppId(), - clusterData, tenantId, tenantDomain); + TopologyEventPublisher.sendApplicationTerminatedEvent(new ApplicationTerminatedEvent(event.getAppId(), + clusterData, tenantId, tenantDomain)); } } finally { http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/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 cd13111..a3feb4d 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 @@ -103,15 +103,15 @@ public class TopologyEventPublisher { publishEvent(new ApplicationUndeployedEvent(applicationId, clusterData)); } - 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, clusterData, tenantId, 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, clusterData, tenantId, tenantDomain)); +// } public static void sendClusterRemovedEvent(ClusterContext ctxt, String deploymentPolicy) { http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyEventReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyEventReceiver.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyEventReceiver.java index 699af72..6e8552b 100644 --- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyEventReceiver.java +++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyEventReceiver.java @@ -355,21 +355,22 @@ public class StratosManagerTopologyEventReceiver implements Runnable { }); //add listener - topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener() { + topologyEventReceiver.addEventListener(new ApplicationTerminatedEventListener() { @Override protected void onEvent(Event event) { - ApplicationRemovedEvent appRemovedEvent = (ApplicationRemovedEvent) event; + ApplicationTerminatedEvent appRemovedEvent = (ApplicationTerminatedEvent) event; - log.info("[ApplicationRemovedEventListener] Received: " + event.getClass()); + log.info("[ApplicationTerminatedEvent] Received: " + event.getClass()); try { + // no need to lock since Topology is not accessed //TopologyManager.acquireReadLock(); - TopologyManager.acquireReadLockForApplication(appRemovedEvent.getApplicationId()); + //TopologyManager.acquireReadLockForApplication(appRemovedEvent.getAppId()); // create and persist Application subscritpion CartridgeSubscriptionManager cartridgeSubscriptionManager = new CartridgeSubscriptionManager(); - String appId = appRemovedEvent.getApplicationId(); + String appId = appRemovedEvent.getAppId(); int tenantId = appRemovedEvent.getTenantId(); String domain = appRemovedEvent.getTenantDomain(); @@ -393,7 +394,7 @@ public class StratosManagerTopologyEventReceiver implements Runnable { } } finally { //TopologyManager.releaseReadLock(); - TopologyManager.releaseReadLockForApplication(appRemovedEvent.getApplicationId()); + //TopologyManager.releaseReadLockForApplication(appRemovedEvent.getAppId()); } } }); http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/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 deleted file mode 100644 index 3d5b9a4..0000000 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationRemovedEvent.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.event.topology; - - -import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; - -import java.util.Set; - -public class ApplicationRemovedEvent extends TopologyEvent { - - /** - * - */ - private static final long serialVersionUID = -5499420725533165623L; - private final String applicationId; - private Set<ClusterDataHolder> clusterData; - - private String tenantDomain; - private int tenantId; - - public ApplicationRemovedEvent(String applicationId, Set<ClusterDataHolder> clusterData, - int tenantId, String tenantDomain) { - this.applicationId = applicationId; - this.clusterData = clusterData; - this.tenantId = tenantId; - this.tenantDomain = tenantDomain; - } - - public String getApplicationId() { - return applicationId; - } - - public int getTenantId() { - return tenantId; - } - - public String getTenantDomain() { - return tenantDomain; - } - - public Set<ClusterDataHolder> getClusterData() { - return clusterData; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationTerminatedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationTerminatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationTerminatedEvent.java index 6607a02..fa0cd26 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationTerminatedEvent.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ApplicationTerminatedEvent.java @@ -28,10 +28,15 @@ import java.util.Set; public class ApplicationTerminatedEvent extends TopologyEvent { private final String appId; private final Set<ClusterDataHolder> clusterData; + private String tenantDomain; + private int tenantId; - public ApplicationTerminatedEvent(String appId, Set<ClusterDataHolder> clusterData) { + public ApplicationTerminatedEvent(String appId, Set<ClusterDataHolder> clusterData, + int tenantId, String tenantDomain) { this.appId = appId; this.clusterData = clusterData; + this.tenantId = tenantId; + this.tenantDomain = tenantDomain; } public String getAppId() { @@ -41,4 +46,12 @@ public class ApplicationTerminatedEvent extends TopologyEvent { public Set<ClusterDataHolder> getClusterData() { return clusterData; } + + public String getTenantDomain() { + return tenantDomain; + } + + public int getTenantId() { + return tenantId; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ApplicationRemovedEventListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ApplicationRemovedEventListener.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ApplicationRemovedEventListener.java deleted file mode 100644 index c3a1178..0000000 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/topology/ApplicationRemovedEventListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.listener.topology; - -import org.apache.stratos.messaging.listener.EventListener; - -public abstract class ApplicationRemovedEventListener extends EventListener { - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/status/AppStatusGroupTerminatingMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/status/AppStatusGroupTerminatingMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/status/AppStatusGroupTerminatingMessageProcessor.java index 7445695..75012e0 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/status/AppStatusGroupTerminatingMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/status/AppStatusGroupTerminatingMessageProcessor.java @@ -21,7 +21,7 @@ package org.apache.stratos.messaging.message.processor.application.status; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.messaging.event.topology.GroupTerminatingEvent; +import org.apache.stratos.messaging.event.application.status.AppStatusGroupTerminatingEvent; import org.apache.stratos.messaging.message.processor.MessageProcessor; import org.apache.stratos.messaging.util.Util; @@ -37,10 +37,10 @@ public class AppStatusGroupTerminatingMessageProcessor extends MessageProcessor @Override public boolean process(String type, String message, Object object) { - if (GroupTerminatingEvent.class.getName().equals(type)) { + if (AppStatusGroupTerminatingEvent.class.getName().equals(type)) { // Parse complete message and build event - GroupTerminatingEvent event = - (GroupTerminatingEvent) Util.jsonToObject(message, GroupTerminatingEvent.class); + AppStatusGroupTerminatingEvent event = + (AppStatusGroupTerminatingEvent) Util.jsonToObject(message, AppStatusGroupTerminatingEvent.class); if (log.isDebugEnabled()) { log.debug("Received GroupTerminatingEvent: " + event.toString()); http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/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 deleted file mode 100644 index 5e02565..0000000 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationRemovedMessageProcessor.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.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; -import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater; -import org.apache.stratos.messaging.util.Util; - -import java.util.Set; - -public class ApplicationRemovedMessageProcessor extends MessageProcessor { - - private static final Log log = LogFactory.getLog(ApplicationCreatedMessageProcessor.class); - - private MessageProcessor nextProcessor; - - @Override - public void setNext(MessageProcessor nextProcessor) { - this.nextProcessor = nextProcessor; - } - - @Override - public boolean process(String type, String message, Object object) { - - if (log.isDebugEnabled()) { - log.debug("ApplicationRemovedMessageProcessor processing " + object); - } - - Topology topology = (Topology) object; - - if (ApplicationRemovedEvent.class.getName().equals(type)) { - if (!topology.isInitialized()) { - if (log.isDebugEnabled()) { - log.debug("ApplicationRemovedMessageProcessor topology not initialized ... " + object); - } - return false; - } - - ApplicationRemovedEvent event = (ApplicationRemovedEvent) Util.jsonToObject(message, ApplicationRemovedEvent.class); - if (event == null) { - log.error("Unable to convert the JSON message to ApplicationCreatedEvent"); - return false; - } - - TopologyUpdater.acquireWriteLockForApplications(); - Set<ClusterDataHolder> clusterDataHolders = event.getClusterData(); - if (clusterDataHolders != null) { - for (ClusterDataHolder clusterData : clusterDataHolders) { - TopologyUpdater.acquireWriteLockForService(clusterData.getServiceType()); - } - } - - try { - return doProcess(event, topology); - - } finally { - if (clusterDataHolders != null) { - for (ClusterDataHolder clusterData : clusterDataHolders) { - TopologyUpdater.releaseWriteLockForService(clusterData.getServiceType()); - } - } - TopologyUpdater.releaseWriteLockForApplications(); - } - - } else { - if (nextProcessor != null) { - // ask the next processor to take care of the message. - return nextProcessor.process(type, message, topology); - } else { - throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message)); - } - } - } - - private boolean doProcess (ApplicationRemovedEvent event, Topology topology) { - - // check if required properties are available - if (event.getApplicationId() == null) { - String errorMsg = "Application Id of application removed event is invalid"; - log.error(errorMsg); - throw new RuntimeException(errorMsg); - } - - if (event.getTenantDomain()== null) { - String errorMsg = "Application tenant domain of application removed event is invalid"; - log.error(errorMsg); - throw new RuntimeException(errorMsg); - } - - // check if an Application with same name exists in topology - String appId = event.getApplicationId(); - if (topology.applicationExists(appId)) { - log.warn("Application with id [ " + appId + " ] still exists in Topology, removing it"); - 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 "); - } - - notifyEventListeners(event); - return true; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationTerminatedMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationTerminatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationTerminatedMessageProcessor.java index 2d22c6c..49a8d22 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationTerminatedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ApplicationTerminatedMessageProcessor.java @@ -20,14 +20,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.Application; -import org.apache.stratos.messaging.domain.topology.ApplicationStatus; -import org.apache.stratos.messaging.domain.topology.Topology; +import org.apache.stratos.messaging.domain.topology.*; import org.apache.stratos.messaging.event.topology.ApplicationInactivatedEvent; +import org.apache.stratos.messaging.event.topology.ApplicationTerminatedEvent; import org.apache.stratos.messaging.message.processor.MessageProcessor; import org.apache.stratos.messaging.message.processor.topology.updater.TopologyUpdater; import org.apache.stratos.messaging.util.Util; +import java.util.Set; + /** * This processor responsible to process the application Inactivation even and update the Topology. */ @@ -48,22 +49,33 @@ public class ApplicationTerminatedMessageProcessor extends MessageProcessor { public boolean process(String type, String message, Object object) { Topology topology = (Topology) object; - if (ApplicationInactivatedEvent.class.getName().equals(type)) { + if (ApplicationTerminatedEvent.class.getName().equals(type)) { // Return if topology has not been initialized if (!topology.isInitialized()) return false; // Parse complete message and build event - ApplicationInactivatedEvent event = (ApplicationInactivatedEvent) Util. - jsonToObject(message, ApplicationInactivatedEvent.class); + ApplicationTerminatedEvent event = (ApplicationTerminatedEvent) Util. + jsonToObject(message, ApplicationTerminatedEvent.class); TopologyUpdater.acquireWriteLockForApplication(event.getAppId()); + Set<ClusterDataHolder> clusterDataHolders = event.getClusterData(); + if (clusterDataHolders != null) { + for (ClusterDataHolder clusterData : clusterDataHolders) { + TopologyUpdater.acquireWriteLockForService(clusterData.getServiceType()); + } + } try { return doProcess(event, topology); } finally { TopologyUpdater.releaseWriteLockForApplication(event.getAppId()); + if (clusterDataHolders != null) { + for (ClusterDataHolder clusterData : clusterDataHolders) { + TopologyUpdater.releaseWriteLockForService(clusterData.getServiceType()); + } + } } } else { @@ -76,27 +88,47 @@ public class ApplicationTerminatedMessageProcessor extends MessageProcessor { } } - private boolean doProcess (ApplicationInactivatedEvent event, Topology topology) { + private boolean doProcess (ApplicationTerminatedEvent event, Topology topology) { - // Validate event against the existing topology - Application application = topology.getApplication(event.getAppId()); - if (application == null) { - if (log.isWarnEnabled()) { - log.warn(String.format("Application does not exist: [service] %s", - event.getAppId())); - } - return false; - } else { - // Apply changes to the topology - if (!application.isStateTransitionValid(ApplicationStatus.Terminated)) { - log.error("Invalid State transfer from [ " + application.getStatus() + - " ] to [ " + ApplicationStatus.Terminated + " ]"); + // check if required properties are available + if (event.getAppId() == null) { + String errorMsg = "Application Id of application removed event is invalid"; + log.error(errorMsg); + throw new RuntimeException(errorMsg); + } + + if (event.getTenantDomain()== null) { + String errorMsg = "Application tenant domain of application removed event is invalid"; + log.error(errorMsg); + throw new RuntimeException(errorMsg); + } + + // check if an Application with same name exists in topology + String appId = event.getAppId(); + if (topology.applicationExists(appId)) { + log.warn("Application with id [ " + appId + " ] still exists in Topology, removing it"); + 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!"); + } } - application.setStatus(ApplicationStatus.Terminated); + } + if (log.isDebugEnabled()) { + log.debug("ApplicationRemovedMessageProcessor notifying listener "); } - // Notify event listeners notifyEventListeners(event); return true; http://git-wip-us.apache.org/repos/asf/stratos/blob/b56e3285/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java index 1b7ba13..4f6d3a9 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java @@ -50,7 +50,6 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain { private GroupInActivateProcessor groupInActivateProcessor; private ApplicationCreatedMessageProcessor applicationCreatedMessageProcessor; private ApplicationUndeployedMessageProcessor applicationUndeployedMessageProcessor; - private ApplicationRemovedMessageProcessor applicationRemovedMessageProcessor; private ApplicationActivatedMessageProcessor applicationActivatedMessageProcessor; private ApplicationInactivatedMessageProcessor applicationInactivatedMessageProcessor; private ApplicationTerminatedMessageProcessor applicationTerminatedMessageProcessor; @@ -128,9 +127,6 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain { applicationUndeployedMessageProcessor = new ApplicationUndeployedMessageProcessor(); add(applicationUndeployedMessageProcessor); - applicationRemovedMessageProcessor = new ApplicationRemovedMessageProcessor(); - add(applicationRemovedMessageProcessor); - applicationActivatedMessageProcessor = new ApplicationActivatedMessageProcessor(); add(applicationActivatedMessageProcessor); @@ -193,8 +189,6 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain { applicationCreatedMessageProcessor.addEventListener(eventListener); } else if (eventListener instanceof ApplicationUndeployedEventListener) { applicationUndeployedMessageProcessor.addEventListener(eventListener); - } else if (eventListener instanceof ApplicationRemovedEventListener) { - applicationRemovedMessageProcessor.addEventListener(eventListener); } else if (eventListener instanceof ApplicationActivatedEventListener) { applicationActivatedMessageProcessor.addEventListener(eventListener); } else if (eventListener instanceof ApplicationInActivateEventListener){
