You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2014/10/28 16:58:20 UTC

[1/2] git commit: fixing STRATOS-921

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 <is...@apache.org>
Authored: Tue Oct 28 19:59:23 2014 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
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;


[2/2] git commit: sending Cluster Terminated event when the Cluster Monitor is not available/failed

Posted by is...@apache.org.
sending Cluster Terminated event when the Cluster Monitor is not available/failed


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/128fe3e0
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/128fe3e0
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/128fe3e0

Branch: refs/heads/4.0.0-grouping
Commit: 128fe3e08b531f1353102282c0e6f17038902b66
Parents: 636d9bb
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Oct 28 21:26:51 2014 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Oct 28 21:26:51 2014 +0530

----------------------------------------------------------------------
 .../receiver/topology/AutoscalerTopologyEventReceiver.java      | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/128fe3e0/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 bff46c2..1423385 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
@@ -395,6 +395,11 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                                 }
                             } 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());
                             }
                         }