Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 9b31646b1 -> 50e9e69b2


adding recovery support for the monitors


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

Branch: refs/heads/4.0.0-grouping
Commit: 50e9e69b2c893ae8f2c989f5ea674de4bd1353e1
Parents: 9b31646
Author: reka <[email protected]>
Authored: Tue Oct 21 15:45:10 2014 +0530
Committer: reka <[email protected]>
Committed: Tue Oct 21 15:45:10 2014 +0530

----------------------------------------------------------------------
 .../grouping/dependency/DependencyTree.java     |  14 ++
 .../grouping/topic/StatusEventPublisher.java    |  48 +++++
 .../monitor/AbstractClusterMonitor.java         |  10 +-
 .../monitor/ApplicationMonitorFactory.java      |  41 +++--
 .../stratos/autoscaler/monitor/Monitor.java     |  14 +-
 .../monitor/ParentComponentMonitor.java         |   2 -
 .../monitor/application/ApplicationMonitor.java |   9 +-
 .../monitor/cluster/ClusterMonitor.java         |  11 +-
 .../monitor/events/MonitorStartAllEvent.java    |  28 +++
 .../autoscaler/monitor/group/GroupMonitor.java  | 177 ++++++++++---------
 .../status/checker/StatusChecker.java           |   2 +-
 .../ClusterCreatedMessageProcessor.java         |   8 +-
 12 files changed, 244 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
index 642a40a..6dbbce3 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
@@ -108,6 +108,20 @@ public class DependencyTree {
         return findParentContextWithId(null, id, this.applicationContextList);
     }
 
+    public List<ApplicationContext> findAllParentContextWithId(String id) {
+        List<ApplicationContext> applicationContexts = new 
ArrayList<ApplicationContext>();
+        return findAllParent(applicationContexts, id);
+    }
+
+    private List<ApplicationContext> findAllParent(List<ApplicationContext> 
parentContexts, String id) {
+        ApplicationContext context = findParentContextWithId(null, id, 
this.applicationContextList);
+        if(context != null) {
+            parentContexts.add(context);
+            findAllParent(parentContexts, context.getId());
+        }
+        return  parentContexts;
+    }
+
 
     private ApplicationContext findParentContextWithId(ApplicationContext 
parent, String id,
                                                        
List<ApplicationContext> contexts) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
index abc03df..2ffff81 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
@@ -58,6 +58,30 @@ public class StatusEventPublisher {
         publishEvent(clusterActivatedEvent);*/
     }
 
+    public static void sendClusterTerminatingEvent(String appId, String 
serviceName, String clusterId) {
+
+        if (log.isInfoEnabled()) {
+            log.info("Publishing Cluster in-activate event for [application]: 
" + appId +
+                    " [cluster]: " + clusterId);
+        }
+
+        /*ClusterActivatedEvent clusterActivatedEvent = new 
ClusterActivatedEvent(appId, serviceName, clusterId);
+
+        publishEvent(clusterActivatedEvent);*/
+    }
+
+    public static void sendClusterTerminatedEvent(String appId, String 
serviceName, String clusterId) {
+
+        if (log.isInfoEnabled()) {
+            log.info("Publishing Cluster in-activate event for [application]: 
" + appId +
+                    " [cluster]: " + clusterId);
+        }
+
+        /*ClusterActivatedEvent clusterActivatedEvent = new 
ClusterActivatedEvent(appId, serviceName, clusterId);
+
+        publishEvent(clusterActivatedEvent);*/
+    }
+
     public static void sendClusterInMaintenanceEvent(String appId, String 
serviceName, String clusterId) {
 
         if (log.isInfoEnabled()) {
@@ -106,6 +130,30 @@ public class StatusEventPublisher {
         publishEvent(groupInActivateEvent);
     }
 
+    public static void sendGroupTerminatingEvent(String appId, String groupId) 
{
+
+        if (log.isInfoEnabled()) {
+            log.info("Publishing Group terminating event for [application]: " 
+ appId +
+                    " [group]: " + groupId);
+        }
+
+        GroupInActivateEvent groupInActivateEvent = new 
GroupInActivateEvent(appId, groupId);
+
+        publishEvent(groupInActivateEvent);
+    }
+
+    public static void sendGroupTerminatedEvent(String appId, String groupId) {
+
+        if (log.isInfoEnabled()) {
+            log.info("Publishing Group terminated event for [application]: " + 
appId +
+                    " [group]: " + groupId);
+        }
+
+        GroupInActivateEvent groupInActivateEvent = new 
GroupInActivateEvent(appId, groupId);
+
+        publishEvent(groupInActivateEvent);
+    }
+
     public static void sendApplicationActivatedEvent(String appId) {
 
         if (log.isInfoEnabled()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
index 3e630fa..beee67a 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
@@ -242,8 +242,14 @@ abstract public class AbstractClusterMonitor extends 
Monitor implements Runnable
         log.info(String.format("[Monitor] %s is notifying the parent" +
                 "on its state change from %s to %s", clusterId, this.status, 
status));
         this.status = status;
-        //notifying the parent monitor about the state change
-        MonitorStatusEventBuilder.handleClusterStatusEvent(this.parent, 
this.status, this.clusterId);
+        /**
+         * notifying the parent monitor about the state change
+         * If the cluster in_active and if it is a in_dependent cluster,
+         * then won't send the notification to parent.
+         */
+        if(status == ClusterStatus.Inactive && !this.hasDependent) {
+            MonitorStatusEventBuilder.handleClusterStatusEvent(this.parent, 
this.status, this.clusterId);
+        }
 
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
index bfc7bbb..6d8f2a3 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
@@ -73,7 +73,7 @@ public class ApplicationMonitorFactory {
         Monitor monitor;
 
         if (context instanceof GroupContext) {
-            monitor = getGroupMonitor(parentMonitor, context.getId(), appId);
+            monitor = getGroupMonitor(parentMonitor, context, appId);
         } else if (context instanceof ClusterContext) {
             monitor = getClusterMonitor(parentMonitor, (ClusterContext) 
context, appId);
             //Start the thread
@@ -89,29 +89,36 @@ public class ApplicationMonitorFactory {
      * This will create the GroupMonitor based on given groupId by going thr 
Topology
      *
      * @param parentMonitor parent of the monitor
-     * @param groupId       groupId of the group
+     * @param context       groupId of the group
      * @param appId         appId of the relevant application
      * @return Group monitor
      * @throws DependencyBuilderException    throws while building dependency 
for app monitor
      * @throws TopologyInConsistentException throws while traversing thr 
topology
      */
-    public static Monitor getGroupMonitor(ParentComponentMonitor 
parentMonitor, String groupId, String appId)
+    public static Monitor getGroupMonitor(ParentComponentMonitor 
parentMonitor, ApplicationContext context, String appId)
             throws DependencyBuilderException,
             TopologyInConsistentException {
         GroupMonitor groupMonitor;
         TopologyManager.acquireReadLockForApplication(appId);
 
         try {
-            Group group = 
TopologyManager.getTopology().getApplication(appId).getGroupRecursively(groupId);
+            Group group = 
TopologyManager.getTopology().getApplication(appId).getGroupRecursively(context.getId());
             groupMonitor = new GroupMonitor(group, appId);
             groupMonitor.setAppId(appId);
-            groupMonitor.setParent(parentMonitor);
-            //TODO
-            /*if (group.getTempStatus() != groupMonitor.getStatus()) {
-                //updating the status, if the group is not in created state 
when creating group Monitor
-                //so that groupMonitor will notify the parent (useful when 
restarting stratos)
-                groupMonitor.setStatus(group.getTempStatus());
-            }*/
+            if(parentMonitor != null) {
+                groupMonitor.setParent(parentMonitor);
+                if(!parentMonitor.isHasDependent() && !context.hasChild()) {
+                    groupMonitor.setHasDependent(true);
+                }
+                //TODO make sure when it is async
+
+                if (group.getStatus() != groupMonitor.getStatus()) {
+                    //updating the status, if the group is not in created 
state when creating group Monitor
+                    //so that groupMonitor will notify the parent (useful when 
restarting stratos)
+                    groupMonitor.setStatus(group.getStatus());
+                }
+            }
+
         } finally {
             TopologyManager.releaseReadLockForApplication(appId);
 
@@ -284,17 +291,21 @@ public class ApplicationMonitorFactory {
 
                 
clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
                 clusterMonitor.setParent(parentMonitor);
+                if(!parentMonitor.isHasDependent() && !context.hasChild()) {
+                    clusterMonitor.setHasDependent(true);
+                }
                 //clusterMonitor.setCurrentStatus(Status.Created);
                 if (log.isInfoEnabled()) {
                     log.info(String.format("Network partition context has been 
added: [network partition] %s",
                             networkPartitionContext.getId()));
                 }
             }
-            //TODO
-            /*if (cluster.getTempStatus() != clusterMonitor.getStatus()) {
+            //TODO to make sure when group monitor is async
+            //if cluster is not in created state then notify the parent monitor
+            if (cluster.getStatus() != clusterMonitor.getStatus()) {
                 //updating the status, so that it will notify the parent
-                clusterMonitor.setStatus(cluster.getTempStatus());
-            }*/
+                clusterMonitor.setStatus(cluster.getStatus());
+            }
         } finally {
             //release read lock for the service and cluster
             TopologyManager.releaseReadLockForCluster(serviceName, clusterId);

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
index 3276c47..b670077 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
@@ -34,8 +34,11 @@ public abstract class Monitor implements EventHandler {
     protected Map<String, Monitor> aliasToActiveMonitorsMap;
     //monitors map, stopped monitors
     protected Map<String, Monitor> aliasToInActiveMonitorsMap;
+    //flag will get set to true in MonitorTerminateAllEvent when termination of
+    // this monitor decided by its parent
+    protected boolean terminateChildren = false;
 
-    protected boolean killChildren;
+    protected boolean hasDependent;
 
     public String getId() {
         return id;
@@ -45,7 +48,6 @@ public abstract class Monitor implements EventHandler {
         this.id = id;
     }
 
-
     public String getAppId() {
         return appId;
     }
@@ -77,4 +79,12 @@ public abstract class Monitor implements EventHandler {
         }
         return hasMonitor;
     }
+
+    public boolean isHasDependent() {
+        return hasDependent;
+    }
+
+    public void setHasDependent(boolean hasDependent) {
+        this.hasDependent = hasDependent;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
index 9948976..0d64e3e 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
@@ -106,8 +106,6 @@ public abstract class ParentComponentMonitor extends 
Monitor {
             if(!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
                 //to avoid if it is already started
                 startMonitor(this, context);
-            } else 
if(this.aliasToInActiveMonitorsMap.containsKey(context.getId())) {
-                //need to trigger the cluster monitor
             }
         }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
index 3e80570..7befc2b 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java
@@ -50,6 +50,7 @@ public class ApplicationMonitor extends 
ParentComponentMonitor {
         super(application);
         //setting the appId for the application
         this.appId = application.getUniqueIdentifier();
+        this.status = application.getStatus();
         //starting the first set of dependencies from its children
         startDependency();
 
@@ -120,8 +121,12 @@ public class ApplicationMonitor extends 
ParentComponentMonitor {
      * @return the found GroupMonitor
      */
     public Monitor findGroupMonitorWithId(String groupId) {
-        return findGroupMonitor(groupId, aliasToActiveMonitorsMap.values());
-
+        Monitor monitor;
+        monitor = findGroupMonitor(groupId, aliasToActiveMonitorsMap.values());
+        if(monitor == null) {
+            monitor = findGroupMonitor(groupId, 
aliasToInActiveMonitorsMap.values());
+        }
+        return monitor;
     }
 
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
index 6043b5c..a129d18 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
@@ -71,20 +71,13 @@ public class ClusterMonitor extends AbstractClusterMonitor {
 
     @Override
     public void run() {
-
-        /*try {
-            // TODO make this configurable(**Remove this as LB will be a 
seperate monitor),
-            // this is the delay the min check of normal cluster monitor to 
wait until LB monitor is added
-            Thread.sleep(60000);
-        } catch (InterruptedException ignore) {
-        }*/
-        //this.status = Status.Running;
         while (!isDestroyed()) {
             if (log.isDebugEnabled()) {
                 log.debug("Cluster monitor is running.. " + this.toString());
             }
             try {
-                if (!ClusterStatus.Inactive.equals(status)) {
+                if ((this.status.getCode() <= ClusterStatus.Active.getCode()) 
||
+                        (this.status == ClusterStatus.Inactive && 
!hasDependent)) {
                     monitor();
                 } else {
                     if (log.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
new file mode 100644
index 0000000..21f83ec
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStartAllEvent.java
@@ -0,0 +1,28 @@
+/*
+ * 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.monitor.events;
+
+/**
+ * This will use to start the child monitors
+ */
+public class MonitorStartAllEvent extends MonitorEvent {
+    public MonitorStartAllEvent(String id) {
+        super(id);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
index 54c37e9..f278fb6 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java
@@ -57,7 +57,7 @@ public class GroupMonitor extends ParentComponentMonitor 
implements EventHandler
             TopologyInConsistentException {
         super(group);
         this.appId = appId;
-        //TODO this.setStatus(group.getTempStatus());
+        this.setStatus(group.getStatus());
         startDependency();
     }
 
@@ -68,6 +68,7 @@ public class GroupMonitor extends ParentComponentMonitor 
implements EventHandler
 
     @Override
     public void onEvent(MonitorTerminateAllEvent terminateAllEvent) {
+        this.terminateChildren = true;
 
     }
 
@@ -82,30 +83,27 @@ public class GroupMonitor extends ParentComponentMonitor 
implements EventHandler
         LifeCycleState status1 = statusEvent.getStatus();
         ApplicationContext context = 
this.dependencyTree.findApplicationContextWithId(id);
         //Events coming from parent are In_Active(in faulty detection), 
Scaling events, termination
-        //TODO if statusEvent is for active, then start the next one if any 
available
         if (!isParent(id)) {
             if (status1 == ClusterStatus.Active || status1 == 
GroupStatus.Active) {
                 try {
-                    //if life cycle is empty, need to start the monitor
+                    //if the activated monitor is in in_active map move it to 
active map
+                    if(this.aliasToInActiveMonitorsMap.containsKey(id)) {
+                        this.aliasToActiveMonitorsMap.put(id, 
this.aliasToInActiveMonitorsMap.remove(id));
+                    }
                     boolean startDep = startDependency(statusEvent.getId());
                     if (log.isDebugEnabled()) {
                         log.debug("started a child: " + startDep + " by the 
group/cluster: " + id);
 
                     }
-                    //updating the life cycle and current status
                     if (!startDep) {
                         StatusChecker.getInstance().onChildStatusChange(id, 
this.id, this.appId);
                     }
-
                 } catch (TopologyInConsistentException e) {
                     //TODO revert the siblings and notify parent, change a 
flag for reverting/un-subscription
                     log.error(e);
                 }
+
             } else if (status1 == ClusterStatus.Inactive || status1 == 
GroupStatus.Inactive) {
-                //TODO if C1 depends on C2, then if C2 is in_active, then by 
getting killdepend as C1 and
-                //TODO need to send in_active for c1. When C1 in_active 
receives, get dependent and
-                //TODO check whether dependent in_active. Then kill c1.
-                //evaluate termination behavior and take action based on that.
 
                 List<ApplicationContext> terminationList;
                 Monitor monitor;
@@ -114,105 +112,116 @@ public class GroupMonitor extends 
ParentComponentMonitor implements EventHandler
                 this.aliasToInActiveMonitorsMap.put(id, 
this.aliasToActiveMonitorsMap.remove(id));
 
                 if (terminationList != null) {
-                    //Move to in_active monitors list
-                    boolean allInActive = false;
-                    //check whether all the children are in_active state
+                    //Checking the termination dependents status
                     for (ApplicationContext terminationContext : 
terminationList) {
-                        //Check for whether all dependent are in_active
-                        if 
(this.aliasToInActiveMonitorsMap.containsKey(terminationContext.getId())) {
-                            monitor = this.aliasToInActiveMonitorsMap.
-                                    get(terminationContext.getId());
-                            //start to kill it
-                            monitor.onEvent(new 
MonitorTerminateAllEvent(terminationContext.getId()));
-
+                        //Check whether dependent is in_active, then start to 
kill it
+                        monitor = this.aliasToActiveMonitorsMap.
+                                get(terminationContext.getId());
+                        //start to kill it
+                        if(monitor.hasMonitors()) {
+                            //it is a group
+                            
StatusEventPublisher.sendGroupTerminatingEvent(this.appId, 
terminationContext.getId());
                         } else {
-                            monitor = this.aliasToActiveMonitorsMap.
-                                                            
get(terminationContext.getId());
-                            if(monitor.hasMonitors()) {
-                                //it is a group
-                                
StatusEventPublisher.sendGroupInActivateEvent(this.appId, 
terminationContext.getId());
-                            } else {
-                                
StatusEventPublisher.sendClusterInActivateEvent(this.appId,
-                                        
((AbstractClusterMonitor)monitor).getServiceId(), terminationContext.getId());
-
-                            }
+                            
StatusEventPublisher.sendClusterTerminatingEvent(this.appId,
+                                    
((AbstractClusterMonitor)monitor).getServiceId(), terminationContext.getId());
 
                         }
                     }
-
-                    if (allInActive) {
-                        //Then kill-all of each termination dependents and get 
a lock for CM
-                        //if start order then can kill only the first one,
-                        // rest of them will get killed based on created event 
of first one.
-                    }
                 } else {
-                    //find any other immediate dependent which is 
in_active/created state
-                    ApplicationContext context1 = 
this.dependencyTree.findParentContextWithId(id);
-                    if(context1 != null) {
-                        
if(this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
-                            monitor = this.aliasToInActiveMonitorsMap.get(id);
-                            //killall
-                            monitor.onEvent(new MonitorTerminateAllEvent(id));
+                log.warn("Wrong inActive event received from [Child] " + id + 
"  to the [parent]"
+                    + " where child is identified as a independent");
+                /*//find any other immediate dependent which is 
in_active/created state
+                ApplicationContext context1 = 
this.dependencyTree.findParentContextWithId(id);
+                if(context1 != null) {
+                    
if(this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
+                        monitor = this.aliasToInActiveMonitorsMap.get(id);
+                        //killall
+                        monitor.onEvent(new MonitorTerminateAllEvent(id));
 
-                        } else {
-                            monitor = 
this.aliasToActiveMonitorsMap.get(context1.getId());
-                        }
                     } else {
-                        //Independent monitor
+                        log.warn("Wrong inActive event received from [Child] " 
+ id + "  to the [parent]"
+                        + " where child is identified as a independent");
                     }
-
+                }*/
                 }
-
-
                 //To update the status of the Group
                 StatusChecker.getInstance().onChildStatusChange(id, this.id, 
this.appId);
 
-            } else if (status1 == ClusterStatus.Created || status1 == 
GroupStatus.Created) {
-                //TODO get dependents
-                List<ApplicationContext> dependents = 
this.dependencyTree.getTerminationDependencies(id);
-                // if no dependencies then start the cluster monitor. if all 
are in created, then start them in the order.
-                if (dependents != null) {
-                    boolean allCreated = false;
-                    //check whether all the children are in_active state
-                    for (ApplicationContext terminationContext : dependents) {
-                        //Check for whether all dependent are in_active
-                        if 
(this.aliasToInActiveMonitorsMap.containsKey(terminationContext.getId())) {
-                            allCreated = true;
-                        } else {
-                            allCreated = false;
-                        }
-                    }
+            } else if (status1 == ClusterStatus.Terminating || status1 == 
GroupStatus.Terminating) {
+                //Check whether hasDependent true
+                if(!this.aliasToInActiveMonitorsMap.containsKey(id)) {
+                    this.aliasToInActiveMonitorsMap.put(id, 
this.aliasToActiveMonitorsMap.remove(id));
+                }
 
-                    String firstChildToBeStarted = null;
+                Monitor monitor = this.aliasToInActiveMonitorsMap.get(id);
+                for(Monitor monitor1 : 
monitor.getAliasToActiveMonitorsMap().values()) {
+                    if(monitor.hasMonitors()) {
+                        
StatusEventPublisher.sendGroupTerminatingEvent(this.appId, monitor1.getId());
+                    } else {
+                        
StatusEventPublisher.sendClusterTerminatingEvent(this.appId,
+                                
((AbstractClusterMonitor)monitor1).getServiceId(), monitor.getId());
+                    }
+                }
+                StatusChecker.getInstance().onChildStatusChange(id, this.id, 
this.appId);
+            } else if (status1 == ClusterStatus.Terminated || status1 == 
GroupStatus.Terminated) {
+                //Check whether all dependent goes Terminated and then start 
them in parallel.
+                this.aliasToInActiveMonitorsMap.remove(id);
+                if(this.status != GroupStatus.Terminating) {
+                    List<ApplicationContext> terminationList;
+                    boolean allDependentTerminated = true;
+                    terminationList = 
this.dependencyTree.getTerminationDependencies(id);
+                    if(terminationList != null) {
+                        for(ApplicationContext context1 : terminationList) {
+                            
if(this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
+                                log.info("Waiting for the [Parent Monitor] " + 
context1.getId()
+                                        + " to be terminated");
+                                allDependentTerminated = false;
+                            } else 
if(this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
+                                log.warn("Dependent [monitor] " + 
context1.getId() + " not in the correct state");
+                                allDependentTerminated = false;
+                            } else {
+                                allDependentTerminated = true;
+                            }
+                        }
 
-                    if (allCreated) {
-                        //start the CM according to startup order and 
releasing the lock for it
-                        try {
-                            //if life cycle is empty, need to start the monitor
-                            boolean startDep = 
startDependency(firstChildToBeStarted);
-                            if (log.isDebugEnabled()) {
-                                log.debug("started a child: " + startDep + " 
by the group/cluster: " + firstChildToBeStarted);
+                        if(allDependentTerminated) {
 
+                        }
+                    } else {
+                        List<ApplicationContext> parentContexts = 
this.dependencyTree.findAllParentContextWithId(id);
+                        boolean canStart = false;
+                        if(parentContexts != null) {
+                            for(ApplicationContext context1 : parentContexts) {
+                                
if(this.aliasToInActiveMonitorsMap.containsKey(context1.getId())) {
+                                    log.info("Waiting for the [Parent Monitor] 
" + context1.getId()
+                                            + " to be terminated");
+                                    canStart = false;
+                                } else 
if(this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
+                                    if(canStart) {
+                                        log.warn("Found the Dependent 
[monitor] " + context1.getId()
+                                                + " in the active list wrong 
state");
+                                    }
+                                } else {
+                                    log.info("[Parent Monitor] " + 
context1.getId()
+                                            + " has already been terminated");
+                                    canStart = true;
+                                }
                             }
-                            //updating the life cycle and current status
-                            if (!startDep) {
-                                
StatusChecker.getInstance().onChildStatusChange(id, firstChildToBeStarted, 
this.appId);
+
+                            if(canStart) {
+                                //start the monitor
                             }
 
-                        } catch (TopologyInConsistentException e) {
-                            //TODO revert the siblings and notify parent, 
change a flag for reverting/un-subscription
-                            log.error(e);
+                        } else {
+                           //Start the monitor
                         }
-                    } else {
-                        //kill other dependents cluster
 
                     }
+                } else {
+                    StatusChecker.getInstance().onChildStatusChange(id, 
this.id, this.appId);
+                    log.info("Executing the un-subscription request for the 
[monitor] " + id);
                 }
             }
-
-
-        } else if (status1 == ClusterStatus.Created || status1 == 
GroupStatus.Created) {
-            //the dependent goes to be created state, so terminate the 
dependents
         }
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
index de6f261..b896378 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
@@ -289,7 +289,7 @@ public class StatusChecker {
                 if (parent instanceof Application) {
                     //send application activated event
                     log.info("sending app in-active found: " + appId);
-                    
StatusEventPublisher.sendApplicationInActivatedEvent(appId);
+                    
StatusEventPublisher.sendApplicationInactivatedEvent(appId);
                 } else if (parent instanceof Group) {
                     //send activation to the parent
                     log.info("sending group in-active found: " + 
parent.getUniqueIdentifier());

http://git-wip-us.apache.org/repos/asf/stratos/blob/50e9e69b/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 71df7ce..bcb7ea4 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
@@ -21,6 +21,7 @@ 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.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.Service;
 import org.apache.stratos.messaging.domain.topology.Topology;
 import org.apache.stratos.messaging.event.topology.ClusterCreatedEvent;
@@ -96,7 +97,7 @@ public class ClusterCreatedMessageProcessor extends 
MessageProcessor {
         }
 
         // Validate event properties
-        Cluster cluster = event.getCluster();
+        /*Cluster cluster = event.getCluster();
         if(cluster == null) {
             String msg = "Cluster object of cluster created event is null.";
             log.error(msg);
@@ -104,7 +105,7 @@ public class ClusterCreatedMessageProcessor extends 
MessageProcessor {
         }
         if (cluster.getHostNames().isEmpty()) {
             throw new RuntimeException("Host name/s not found in cluster 
created event");
-        }
+        }*/
         // Validate event against the existing topology
         Service service = topology.getService(event.getServiceName());
         if (service == null) {
@@ -122,7 +123,8 @@ public class ClusterCreatedMessageProcessor extends 
MessageProcessor {
         } else {
 
             // Apply changes to the topology
-            service.addCluster(cluster);
+            Cluster cluster = service.getCluster(event.getClusterId());
+            cluster.setStatus(ClusterStatus.Created);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster created: %s",
                         cluster.toString()));

Reply via email to