Repository: stratos Updated Branches: refs/heads/4.0.0-grouping ae75efc37 -> 128fe3e08
fixing STRATOS-921 Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/636d9bb0 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/636d9bb0 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/636d9bb0 Branch: refs/heads/4.0.0-grouping Commit: 636d9bb0e85a6e91d454157cdce61851738c0a6d Parents: ae75efc Author: Isuru Haththotuwa <[email protected]> Authored: Tue Oct 28 19:59:23 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Tue Oct 28 19:59:34 2014 +0530 ---------------------------------------------------------------------- .../topic/InstanceNotificationPublisher.java | 42 ++++++++++++++++++++ .../AutoscalerTopologyEventReceiver.java | 32 ++++++++++++--- .../impl/CloudControllerServiceImpl.java | 2 +- 3 files changed, 69 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/636d9bb0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/InstanceNotificationPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/InstanceNotificationPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/InstanceNotificationPublisher.java new file mode 100644 index 0000000..d745d79 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/InstanceNotificationPublisher.java @@ -0,0 +1,42 @@ +/* + * 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.autoscaler.grouping.topic; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.messaging.broker.publish.EventPublisher; +import org.apache.stratos.messaging.broker.publish.EventPublisherPool; +import org.apache.stratos.messaging.event.Event; +import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent; +import org.apache.stratos.messaging.util.Constants; + +public class InstanceNotificationPublisher { + private static final Log log = LogFactory.getLog(InstanceNotificationPublisher.class); + + private static void publish(Event event) { + EventPublisher instanceNotifyingEvent = EventPublisherPool.getPublisher(Constants.INSTANCE_NOTIFIER_TOPIC); + instanceNotifyingEvent.publish(event); + } + + public static void sendInstanceCleanupEventForCluster(String clusterId) { + log.info(String.format("Publishing Instance Cleanup Event: [cluster] %s", clusterId)); + publish(new InstanceCleanupClusterEvent(clusterId)); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/636d9bb0/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 99aa69c..bff46c2 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 @@ -27,6 +27,7 @@ import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy; import org.apache.stratos.autoscaler.exception.DependencyBuilderException; import org.apache.stratos.autoscaler.exception.TerminationException; import org.apache.stratos.autoscaler.exception.TopologyInConsistentException; +import org.apache.stratos.autoscaler.grouping.topic.InstanceNotificationPublisher; import org.apache.stratos.autoscaler.grouping.topic.StatusEventPublisher; import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor; import org.apache.stratos.autoscaler.monitor.ApplicationMonitorFactory; @@ -377,8 +378,21 @@ public class AutoscalerTopologyEventReceiver implements Runnable { if (clusterMonitor != null) { clusterMonitorsFound = true; clusterMonitor.setDestroyed(true); - clusterMonitor.terminateAllMembers(); - clusterMonitor.setStatus(ClusterStatus.Terminating); + //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); + try { + 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()); } @@ -526,16 +540,22 @@ public class AutoscalerTopologyEventReceiver implements Runnable { // 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()); + ClusterMonitor clusterMonitor = ((ClusterMonitor) + AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId())); + if (clusterMonitor != null) { + clusterMonitor.setDestroyed(true); + AutoscalerContext.getInstance().removeMonitor(clusterData.getClusterId()); + } else { + log.warn("Cluster Monitor not found for [ cluster id ] " + + clusterData.getClusterId() + ", unable to remove"); + } } //removing the application monitor AutoscalerContext.getInstance(). removeAppMonitor(applicationRemovedEvent.getAppId()); } else { log.warn("Application Monitor cannot be found for the terminated [application] " - + applicationRemovedEvent.getAppId()); + + applicationRemovedEvent.getAppId() + ", unable to remove"); } http://git-wip-us.apache.org/repos/asf/stratos/blob/636d9bb0/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 6a337ba..6e003b1 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 @@ -916,7 +916,7 @@ public class CloudControllerServiceImpl implements CloudControllerService { List<MemberContext> ctxts = dataHolder.getMemberContextsOfClusterId(clusterId); - if(ctxts == null) { + if(ctxts == null || ctxts.isEmpty()) { String msg = "Instance termination failed. No members found for cluster id: "+clusterId; log.warn(msg); return;
