You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/10/30 05:14:03 UTC
[39/50] [abbrv] git commit: refactoring current undeployment logic in
Autoscaler
refactoring current undeployment logic in Autoscaler
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/6fbb9525
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/6fbb9525
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/6fbb9525
Branch: refs/heads/docker-grouping-merge
Commit: 6fbb9525bd5555a2589fb7475c1e99aa98af38a7
Parents: 55e3eff
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Wed Oct 29 15:42:06 2014 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Wed Oct 29 15:42:16 2014 +0530
----------------------------------------------------------------------
.../AutoscalerTopologyEventReceiver.java | 171 ++++++++++---------
1 file changed, 93 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/6fbb9525/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 d66795c..c866339 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
@@ -354,87 +354,102 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
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().
- getAppMonitor(applicationUndeployedEvent.getApplicationId());
-
- if (appMonitor != null) {
- // update the status as Terminating
- appMonitor.setStatus(ApplicationStatus.Terminating);
+ ApplicationMonitor appMonitor = AutoscalerContext.getInstance().
+ getAppMonitor(applicationUndeployedEvent.getApplicationId());
-// List<String> clusters = appMonitor.
-// findClustersOfApplication(applicationUndeployedEvent.getApplicationId());
+ if (appMonitor != null) {
+ // set Application Monitor state to 'Terminating'
+ appMonitor.setStatus(ApplicationStatus.Terminating);
- boolean clusterMonitorsFound = false;
- for (ClusterDataHolder clusterData : clusterDataHolders) {
- //stopping the cluster monitor and remove it from the AS
- ClusterMonitor clusterMonitor =
- ((ClusterMonitor) AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId()));
- if (clusterMonitor != null) {
- clusterMonitorsFound = true;
- clusterMonitor.setDestroyed(true);
- //clusterMonitor.terminateAllMembers();
- if (clusterMonitor.getStatus() == ClusterStatus.Active) {
- // terminated gracefully
- clusterMonitor.setStatus(ClusterStatus.Terminating);
- InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterData.getClusterId());
- } else {
- // if not active, forcefully terminate
- clusterMonitor.setStatus(ClusterStatus.Terminating);
- clusterMonitor.terminateAllMembers();
-// try {
-// // TODO: introduce a task to do this cleanup
-// CloudControllerClient.getInstance().terminateAllInstances(clusterData.getClusterId());
-// } catch (TerminationException e) {
-// log.error("Unable to terminate instances for [ cluster id ] " +
-// clusterData.getClusterId(), e);
-// }
- }
- } else {
- log.warn("No Cluster Monitor found for cluster id " + clusterData.getClusterId());
- // if Cluster Monitor is not found, still the Cluster Terminated
- // should be sent to update the parent Monitor
- StatusEventPublisher.sendClusterTerminatedEvent(
- applicationUndeployedEvent.getApplicationId(),
- clusterData.getServiceType(), clusterData.getClusterId());
- }
- }
-
- // if by any chance, the cluster monitors have failed, we still need to undeploy this application
- // hence, check if the Cluster Monitors are not found and send the Application Terminated event
- if (!clusterMonitorsFound) {
- StatusEventPublisher.sendApplicationTerminatedEvent(
- applicationUndeployedEvent.getApplicationId(), clusterDataHolders);
- }
-
- } else {
- log.warn("Application Monitor cannot be found for the undeployed [application] "
- + applicationUndeployedEvent.getApplicationId());
- // send the App Terminated event to cleanup
- StatusEventPublisher.sendApplicationTerminatedEvent(
- applicationUndeployedEvent.getApplicationId(), clusterDataHolders);
- }
-
- } finally {
- if (clusterDataHolders != null) {
- for (ClusterDataHolder clusterData : clusterDataHolders) {
- TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(),
- clusterData.getClusterId());
- }
- }
- TopologyManager.
- releaseReadLockForApplication(applicationUndeployedEvent.getApplicationId());
+ } else {
+ // ApplicationMonitor is not found, send Terminating event to clean up
+ StatusEventPublisher.sendApplicationTerminatedEvent(
+ applicationUndeployedEvent.getApplicationId(), applicationUndeployedEvent.getClusterData());
}
+
+// 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().
+// getAppMonitor(applicationUndeployedEvent.getApplicationId());
+//
+// if (appMonitor != null) {
+// // update the status as Terminating
+// appMonitor.setStatus(ApplicationStatus.Terminating);
+//
+//// List<String> clusters = appMonitor.
+//// findClustersOfApplication(applicationUndeployedEvent.getApplicationId());
+//
+// boolean clusterMonitorsFound = false;
+// for (ClusterDataHolder clusterData : clusterDataHolders) {
+// //stopping the cluster monitor and remove it from the AS
+// ClusterMonitor clusterMonitor =
+// ((ClusterMonitor) AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId()));
+// if (clusterMonitor != null) {
+// clusterMonitorsFound = true;
+// clusterMonitor.setDestroyed(true);
+// //clusterMonitor.terminateAllMembers();
+// if (clusterMonitor.getStatus() == ClusterStatus.Active) {
+// // terminated gracefully
+// clusterMonitor.setStatus(ClusterStatus.Terminating);
+// InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterData.getClusterId());
+// } else {
+// // if not active, forcefully terminate
+// clusterMonitor.setStatus(ClusterStatus.Terminating);
+// clusterMonitor.terminateAllMembers();
+//// try {
+//// // TODO: introduce a task to do this cleanup
+//// CloudControllerClient.getInstance().terminateAllInstances(clusterData.getClusterId());
+//// } catch (TerminationException e) {
+//// log.error("Unable to terminate instances for [ cluster id ] " +
+//// clusterData.getClusterId(), e);
+//// }
+// }
+// } else {
+// log.warn("No Cluster Monitor found for cluster id " + clusterData.getClusterId());
+// // if Cluster Monitor is not found, still the Cluster Terminated
+// // should be sent to update the parent Monitor
+// StatusEventPublisher.sendClusterTerminatedEvent(
+// applicationUndeployedEvent.getApplicationId(),
+// clusterData.getServiceType(), clusterData.getClusterId());
+// }
+// }
+//
+// // if by any chance, the cluster monitors have failed, we still need to undeploy this application
+// // hence, check if the Cluster Monitors are not found and send the Application Terminated event
+// if (!clusterMonitorsFound) {
+// StatusEventPublisher.sendApplicationTerminatedEvent(
+// applicationUndeployedEvent.getApplicationId(), clusterDataHolders);
+// }
+//
+// } else {
+// log.warn("Application Monitor cannot be found for the undeployed [application] "
+// + applicationUndeployedEvent.getApplicationId());
+// // send the App Terminated event to cleanup
+// StatusEventPublisher.sendApplicationTerminatedEvent(
+// applicationUndeployedEvent.getApplicationId(), clusterDataHolders);
+// }
+//
+// } finally {
+// if (clusterDataHolders != null) {
+// for (ClusterDataHolder clusterData : clusterDataHolders) {
+// TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(),
+// clusterData.getClusterId());
+// }
+// }
+// TopologyManager.
+// releaseReadLockForApplication(applicationUndeployedEvent.getApplicationId());
+// }
}
});