Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 0626aefea -> bdd9443ed


adding dependency tree buildig support from Comsite application to autoscaler


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

Branch: refs/heads/4.0.0-grouping
Commit: bdd9443edbbff480f49c1be4b983e2a74dba05f2
Parents: 0626aef
Author: reka <[email protected]>
Authored: Thu Oct 2 18:48:59 2014 +0530
Committer: reka <[email protected]>
Committed: Thu Oct 2 18:48:59 2014 +0530

----------------------------------------------------------------------
 .../apache/stratos/autoscaler/Constants.java    |   5 +
 .../autoscaler/grouping/DependencyBuilder.java  | 107 -----------
 .../grouping/dependency/DependencyBuilder.java  | 189 ++++++++++++++++++
 .../grouping/dependency/DependencyTree.java     | 190 +++++++++++++++++++
 .../dependency/context/ApplicationContext.java  |  74 ++++++++
 .../context/ApplicationContextFactory.java      |  61 ++++++
 .../dependency/context/ClusterContext.java      |  28 +++
 .../dependency/context/GroupContext.java        |  28 +++
 .../monitor/ApplicationMonitorFactory.java      |  30 +++
 .../stratos/autoscaler/monitor/Monitor.java     | 161 +++++++++++-----
 .../monitor/application/ApplicationMonitor.java | 107 ++---------
 .../autoscaler/monitor/group/GroupMonitor.java  |  75 +-------
 .../messaging/domain/topology/StartupOrder.java |  11 ++
 .../messaging/domain/topology/Status.java       |   7 +-
 14 files changed, 758 insertions(+), 315 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
index 8b2f787..a448406 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
@@ -71,4 +71,9 @@ public class Constants {
 
     //member expiry interval
     public static final String MEMBER_EXPIRY_INTERVAL = 
"member.expiry.interval";
+
+    //Grouping
+    public static final String KILL_NONE = "kill-none";
+    public static final String KILL_ALL = "kill-all";
+    public static final String KILL_DEPENDENTS = "kill-dependents";
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/DependencyBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/DependencyBuilder.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/DependencyBuilder.java
deleted file mode 100644
index c1214d9..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/DependencyBuilder.java
+++ /dev/null
@@ -1,107 +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.autoscaler.grouping;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.topology.*;
-
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Set;
-
-/**
- * This is to build the startup/termination dependencies
- * across all the groups and clusters
- */
-public class DependencyBuilder {
-    private static final Log log = LogFactory.getLog(DependencyBuilder.class);
-
-    public static Queue<String> getStartupOrder(ParentBehavior component) {
-
-        Queue<String> startup = new LinkedList<String>();
-        DependencyOrder dependencyOrder = component.getDependencyOrder();
-        if (dependencyOrder != null) {
-            Set<StartupOrder> startupOrderSet = 
dependencyOrder.getStartupOrders();
-            for (StartupOrder startupOrder : startupOrderSet) {
-
-                String start = startupOrder.getStart();
-                String after = startupOrder.getAfter();
-
-                if (!startup.contains(start)) {
-                    startup.add(start);
-                    if (!startup.contains(after)) {
-                        startup.add(after);
-
-                    } else {
-                        //TODO throw exception since after is there before 
start
-                    }
-                } else {
-                    if (!startup.contains(after)) {
-                        startup.add(after);
-                    } else {
-                        //TODO throw exception since start and after already 
there
-                    }
-                }
-            }
-        }
-        //TODO adding all the missed groups or clusters as the top child to 
the list
-        //TODO handle by application and group itself groupName and serviceName
-
-        if (component instanceof Application) {
-            if(log.isDebugEnabled()) {
-                log.debug("Building dependency for the Application/Group " +
-                        ((Application) component).getId());
-            }
-            for (Group group : component.getAliasToGroupMap().values()) {
-                if (!startup.contains("group." + group.getAlias())) {
-                    startup.add("group." + group.getAlias());
-                }
-            }
-
-            Set<String> cartridgeAliases = 
component.getClusterDataMap().keySet();
-
-            for (String carAlias : cartridgeAliases) {
-                if (!startup.contains("cartridge." + carAlias)) {
-                    startup.add("cartridge." + carAlias);
-
-                }
-            }
-        } else if (component instanceof Group) {
-            if(log.isDebugEnabled()) {
-                log.debug("Building dependency for the Application/Group " +
-                        ((Group) component).getAlias());
-            }
-            for (Group group : component.getAliasToGroupMap().values()) {
-                if (!startup.contains("group." + group.getName())) {
-                    startup.add("group." + group.getName());
-                }
-            }
-            for (ClusterDataHolder dataHolder : 
component.getClusterDataMap().values()) {
-                if (!startup.contains("cartridge." + 
dataHolder.getServiceType())) {
-                    startup.add("cartridge." + dataHolder.getServiceType());
-
-                }
-            }
-        }
-        return startup;
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
new file mode 100644
index 0000000..7d8ff2d
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
@@ -0,0 +1,189 @@
+/*
+ * 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.dependency;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.*;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContextFactory;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ClusterContext;
+import org.apache.stratos.autoscaler.grouping.dependency.context.GroupContext;
+import org.apache.stratos.messaging.domain.topology.*;
+
+import java.util.Set;
+
+/**
+ * This is to build the startup/termination dependencies
+ * across all the groups and clusters
+ */
+public class DependencyBuilder {
+    private static final Log log = LogFactory.getLog(DependencyBuilder.class);
+
+    private DependencyBuilder() {
+
+    }
+
+    private static class Holder {
+        private static final DependencyBuilder INSTANCE = new 
DependencyBuilder();
+    }
+
+    public static DependencyBuilder getInstance() {
+        return Holder.INSTANCE;
+    }
+
+    /**
+     * This will build the dependency tree based on the given dependency order
+     * @param component it will give the necessary information to build the 
tree
+     * @return the dependency tree out of the dependency orders
+     */
+    public DependencyTree buildDependency(ParentBehavior component) {
+        Group group = (Group) component;
+        DependencyTree dependencyTree = new DependencyTree(group.getAlias());
+        DependencyOrder dependencyOrder = component.getDependencyOrder();
+
+        if (dependencyOrder != null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Building dependency for the Application/Group " +
+                        group.getAlias());
+            }
+
+            //Parsing the kill behaviour
+            String killBehavior = dependencyOrder.getKillbehavior();
+
+            if (Constants.KILL_NONE.equals(killBehavior)) {
+                dependencyTree.setKillNone(true);
+            } else if (Constants.KILL_ALL.equals(killBehavior)) {
+                dependencyTree.setKillAll(true);
+            } else if (Constants.KILL_DEPENDENTS.equals(killBehavior)) {
+                dependencyTree.setKillDependent(true);
+            }
+            if (log.isDebugEnabled()) {
+                log.debug("Setting the [killBehavior] " + killBehavior + " to 
the " +
+                        "[dependency-tree] " + dependencyTree.getId());
+            }
+
+            //Parsing the start up order
+            Set<StartupOrder> startupOrderSet = 
dependencyOrder.getStartupOrders();
+            ApplicationContext foundContext = null;
+            for (StartupOrder startupOrder : startupOrderSet) {
+                foundContext = null;
+                for (String start : startupOrder.getStartList()) {
+                    ApplicationContext applicationContext = 
ApplicationContextFactory.
+                                    getApplicationContext(start, component, 
dependencyTree);
+                    String id = applicationContext.getId(); //TODO change the 
id
+
+                    ApplicationContext existingApplicationContext =
+                            dependencyTree.findApplicationContextWithId(id);
+                    if (existingApplicationContext == null) {
+                        if (foundContext != null) {
+                            //appending the start up order to existing 
group/cluster
+                            
foundContext.addApplicationContext(applicationContext);
+                            if (log.isDebugEnabled()) {
+                                log.debug("Found an existing [dependency] " + 
foundContext.getId() +
+                                        " and adding the [dependency] " + id + 
" as the child");
+                            }
+                        } else {
+                            //adding list of startup order to the dependency 
tree
+                            
dependencyTree.addApplicationContext(applicationContext);
+                        }
+                    } else {
+                        if (foundContext == null) {
+                            //assigning the found context to the later use.
+                            foundContext = existingApplicationContext;
+                            if (log.isDebugEnabled()) {
+                                log.debug("Found an existing [dependency] " + 
id + " and setting it " +
+                                        "for the next dependency to follow");
+                            }
+                        } else {
+                            //TODO Throw exception, since another same start 
order already found
+                            log.warn("Startup order is not consistent. It 
contains the group/cluster " +
+                                    "which has been used more than one in 
another startup order");
+                        }
+
+                    }
+
+                }
+
+            }
+
+            //TODO need to parser the scalable dependencies
+        }
+
+
+        //adding the rest of the children who are independent to the top level
+        // as they can start in parallel.
+        for (Group group1 : component.getAliasToGroupMap().values()) {
+            if (dependencyTree.findApplicationContextWithId(group1.getAlias()) 
== null) {
+                dependencyTree.addApplicationContext(new 
GroupContext(group1.getAlias(),
+                        dependencyTree.isKillDependent()));
+            }
+        }
+        for (ClusterDataHolder dataHolder : 
component.getClusterDataMap().values()) {
+            if 
(dependencyTree.findApplicationContextWithId(dataHolder.getClusterId()) == 
null) {
+                dependencyTree.addApplicationContext(new 
ClusterContext(dataHolder.getClusterId(),
+                        dependencyTree.isKillDependent()));
+
+            }
+        }
+        return null;
+    }
+
+    /*public static Queue<String> getStartupOrder(ParentBehavior component) {
+
+
+        Queue<String> startup = new LinkedList<String>();
+        DependencyOrder dependencyOrder = component.getDependencyOrder();
+        if (dependencyOrder != null) {
+            Set<StartupOrder> startupOrderSet = 
dependencyOrder.getStartupOrders();
+            for (StartupOrder startupOrder : startupOrderSet) {
+
+                String start = startupOrder.getStart();
+                String after = startupOrder.getAfter();
+
+                if (!startup.contains(start)) {
+                    startup.add(start);
+                    if (!startup.contains(after)) {
+                        startup.add(after);
+
+                    } else {
+                        //TODO throw exception since after is there before 
start
+                    }
+                } else {
+                    if (!startup.contains(after)) {
+                        startup.add(after);
+                    } else {
+                        //TODO throw exception since start and after already 
there
+                    }
+                }
+            }
+        }
+        //TODO adding all the missed groups or clusters as the top child to 
the list
+        //TODO handle by application and group itself groupName and serviceName
+
+        if (component instanceof Application) {
+
+        } else if (component instanceof Group) {
+
+        }
+        return startup;
+
+    }*/
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/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
new file mode 100644
index 0000000..1c6b28f
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyTree.java
@@ -0,0 +1,190 @@
+/*
+ * 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.dependency;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
+import org.apache.stratos.messaging.domain.topology.Status;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This is to contain the dependency tree of an application/group
+ */
+public class DependencyTree {
+    private static final Log log = LogFactory.getLog(DependencyTree.class);
+
+    private List<ApplicationContext> applicationContextList;
+
+    private Status status;
+
+    private boolean started;
+
+    private boolean terminated;
+
+    private boolean killAll;
+
+    private boolean killNone;
+
+    private boolean killDependent;
+
+    private String id;
+
+    public DependencyTree(String id) {
+        applicationContextList = new ArrayList<ApplicationContext>();
+        this.setId(id);
+    }
+
+    public List<ApplicationContext> getApplicationContextList() {
+        return applicationContextList;
+    }
+
+    public void setApplicationContextList(List<ApplicationContext> 
applicationContextList) {
+        this.applicationContextList = applicationContextList;
+    }
+
+    public void addApplicationContext(ApplicationContext applicationContext) {
+        applicationContextList.add(applicationContext);
+
+    }
+
+    /**
+     * Find an ApplicationContext from dependency tree with the given id
+     * @param id the alias/id of group/cluster
+     * @return ApplicationContext of the given id
+     */
+    public ApplicationContext findApplicationContextWithId(String id) {
+        return findApplicationContextWithId(id, applicationContextList);
+    }
+
+    /**
+     * Find the ApplicationContext using Breadth first search.
+     * @param id the alias/id of group/cluster
+     * @param contexts the list of contexts in the same level of the tree
+     * @return ApplicationContext of the given id
+     */
+    private ApplicationContext findApplicationContextWithId(String id, 
List<ApplicationContext> contexts) {
+        for(ApplicationContext context: contexts) {
+            if(context.getId().equals(id)) {
+                return context;
+            }
+        }
+        //if not found in the top level search recursively
+        for(ApplicationContext context: contexts) {
+                return findApplicationContextWithId(id, 
context.getApplicationContextList());
+        }
+        return null;
+    }
+
+    /**
+     * Getting the next start able dependencies upon the activate event
+     * received for a group/cluster which is part of this tree.
+     * @param id the alias/id of group/cluster which received the activated 
event.
+     * @return list of dependencies
+     */
+    public List<ApplicationContext> getStarAbleDependencies(String id) {
+        //finding the application context which received the activated event 
and
+        // returning it's immediate children as the dependencies.
+        ApplicationContext context = findApplicationContextWithId(id);
+        return context.getApplicationContextList();
+    }
+
+    /**
+     * Getting the next start able dependencies upon the monitor 
initialization.
+     * @return list of dependencies
+     */
+    public List<ApplicationContext> getStarAbleDependencies() {
+        //returning the top level as the monitor is in initializing state
+        return this.applicationContextList;
+    }
+
+    /**
+     * When one group/cluster terminates/in_maintenance, need to consider 
about other
+     * dependencies
+     * @param id the alias/id of group/cluster in which terminated event 
received
+     * @return
+     */
+    public List<ApplicationContext> getKillDependencies(String id) {
+        ApplicationContext applicationContext = 
findApplicationContextWithId(id);
+        if(killDependent) {
+            return applicationContext.getApplicationContextList();
+        }
+        return null;
+    }
+
+
+
+    public boolean isKillAll() {
+        return killAll;
+    }
+
+    public void setKillAll(boolean killAll) {
+        this.killAll = killAll;
+    }
+
+    public boolean isKillNone() {
+        return killNone;
+    }
+
+    public void setKillNone(boolean killNone) {
+        this.killNone = killNone;
+    }
+
+    public boolean isStarted() {
+        return started;
+    }
+
+    public void setStarted(boolean started) {
+        this.started = started;
+    }
+
+    public boolean isTerminated() {
+        return terminated;
+    }
+
+    public void setTerminated(boolean terminated) {
+        this.terminated = terminated;
+    }
+
+    public Status getStatus() {
+        return status;
+    }
+
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+
+    public boolean isKillDependent() {
+        return killDependent;
+    }
+
+    public void setKillDependent(boolean killDependent) {
+        this.killDependent = killDependent;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
new file mode 100644
index 0000000..d9b6df8
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContext.java
@@ -0,0 +1,74 @@
+/*
+ * 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.dependency.context;
+
+import org.apache.stratos.messaging.domain.topology.Status;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This is to keep track of the
+ */
+public abstract class ApplicationContext {
+    private List<ApplicationContext> applicationContextList;
+
+    private String id;
+    protected boolean started;
+    protected boolean terminated;
+
+    private Status status;
+
+    protected boolean killDependent;
+
+    public ApplicationContext(String id, boolean killDependent) {
+        applicationContextList = new ArrayList<ApplicationContext>();
+        this.killDependent = killDependent;
+        this.id = id;
+    }
+
+    public List<ApplicationContext> getApplicationContextList() {
+        return applicationContextList;
+    }
+
+    public void setApplicationContextList(List<ApplicationContext> 
applicationContextList) {
+        this.applicationContextList = applicationContextList;
+    }
+
+    public void addApplicationContext(ApplicationContext applicationContext) {
+        applicationContextList.add(applicationContext);
+
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Status getStatus() {
+        return status;
+    }
+
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContextFactory.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContextFactory.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContextFactory.java
new file mode 100644
index 0000000..737a27d
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ApplicationContextFactory.java
@@ -0,0 +1,61 @@
+/*
+ * 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.dependency.context;
+
+import org.apache.stratos.autoscaler.grouping.dependency.DependencyTree;
+import org.apache.stratos.messaging.domain.topology.ParentBehavior;
+
+/**
+ * Factory to create new GroupContext or ClusterContext
+ */
+public class ApplicationContextFactory {
+
+    public static ApplicationContext getApplicationContext(String startOrder,
+                                                           ParentBehavior 
component,
+                                                           DependencyTree 
dependencyTree) {
+        String id;
+        ApplicationContext applicationContext = null;
+        if (startOrder.contains("group")) {
+            id = getGroupFromStartupOrder(startOrder);
+            //TODO getting the alias of the group using groupName
+            applicationContext = new 
GroupContext(component.getGroup(id).getAlias(),
+                    dependencyTree.isKillDependent());
+        } else if (startOrder.contains("cartridge")) {
+            id = getClusterFromStartupOrder(startOrder);
+            //TODO getting the cluster id of the using cartridge name
+            applicationContext = new 
ClusterContext(component.getClusterData(id).getClusterId(),
+                    dependencyTree.isKillDependent());
+        } else {
+            //TODO throw exception
+        }
+        return applicationContext;
+
+    }
+
+    public static String getGroupFromStartupOrder(String startupOrder) {
+        return startupOrder.substring(6);
+    }
+
+    public static String getClusterFromStartupOrder(String startupOrder) {
+        return startupOrder.substring(10);
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ClusterContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ClusterContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ClusterContext.java
new file mode 100644
index 0000000..23ea039
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/ClusterContext.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.grouping.dependency.context;
+
+/**
+ * Created by reka on 10/1/14.
+ */
+public class ClusterContext extends ApplicationContext {
+    public ClusterContext(String id, boolean killDependent) {
+        super(id ,killDependent);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/GroupContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/GroupContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/GroupContext.java
new file mode 100644
index 0000000..0e65d2b
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/context/GroupContext.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.grouping.dependency.context;
+
+/**
+ * Created by reka on 10/1/14.
+ */
+public class GroupContext extends ApplicationContext {
+    public GroupContext(String id, boolean killDependent) {
+        super(id ,killDependent);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/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
new file mode 100644
index 0000000..d75780e
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ApplicationMonitorFactory.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Created by reka on 10/2/14.
+ */
+public class ApplicationMonitorFactory {
+    private static final Log log = 
LogFactory.getLog(ApplicationMonitorFactory.class);
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/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 215c222..122c815 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
@@ -23,98 +23,128 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.AutoscalerContext;
 import org.apache.stratos.autoscaler.exception.PartitionValidationException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
-import org.apache.stratos.autoscaler.grouping.DependencyBuilder;
+import org.apache.stratos.autoscaler.grouping.dependency.DependencyBuilder;
+import org.apache.stratos.autoscaler.grouping.dependency.DependencyTree;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ClusterContext;
+import org.apache.stratos.autoscaler.grouping.dependency.context.GroupContext;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.cluster.LbClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
 import org.apache.stratos.autoscaler.util.AutoscalerUtil;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Group;
-import org.apache.stratos.messaging.domain.topology.ParentBehavior;
-import org.apache.stratos.messaging.domain.topology.Status;
-import org.apache.stratos.messaging.event.Event;
+import org.apache.stratos.messaging.domain.topology.*;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
 import java.util.*;
+import java.util.concurrent.ScheduledExecutorService;
 
 /**
  * Monitor is to monitor it's child monitors and
  * control them according to the dependencies respectively.
  */
 public abstract class Monitor extends Observable implements Observer {
-
     private static final Log log = LogFactory.getLog(Monitor.class);
 
     protected String id;
 
-    protected Map<String, GroupMonitor> groupMonitors;
-    protected Map<String, AbstractClusterMonitor> abstractClusterMonitors;
+    protected Map<String, GroupMonitor> aliasToGroupMonitorsMap;
+
+    protected Map<String, AbstractClusterMonitor> 
clusterIdToClusterMonitorsMap;
+
+    protected Map<String, ScheduledExecutorService> 
clusterIdToExecutorServiceMap;
 
-    protected Queue<String> preOrderTraverse = new LinkedList<String>();
+    private Map<String, ScheduledExecutorService> adderIdToExecutorServiceMap;
+
+    //protected Queue<String> preOrderTraverse;
+
+    protected DependencyTree dependencyTree;
 
     protected ParentBehavior component;
 
     protected Status status;
 
     public Monitor(ParentBehavior component) {
-        groupMonitors = new HashMap<String, GroupMonitor>();
-        abstractClusterMonitors = new HashMap<String, 
AbstractClusterMonitor>();
+        aliasToGroupMonitorsMap = new HashMap<String, GroupMonitor>();
+        clusterIdToClusterMonitorsMap = new HashMap<String, 
AbstractClusterMonitor>();
+        clusterIdToExecutorServiceMap = new HashMap<String, 
ScheduledExecutorService>();
+        adderIdToExecutorServiceMap = new HashMap<String, 
ScheduledExecutorService>();
+        //preOrderTraverse = new LinkedList<String>();
         this.component = component;
-        preOrderTraverse = DependencyBuilder.getStartupOrder(component);
-
-        //startDependency();
+        dependencyTree = 
DependencyBuilder.getInstance().buildDependency(component);
     }
 
-    protected abstract void startDependency();
-
+    public abstract void monitor();
 
-    public Map<String, GroupMonitor> getGroupMonitors() {
-        return groupMonitors;
+    public Map<String, GroupMonitor> getAliasToGroupMonitorsMap() {
+        return aliasToGroupMonitorsMap;
     }
 
-    public void setGroupMonitors(Map<String, GroupMonitor> groupMonitors) {
-        this.groupMonitors = groupMonitors;
+    public String getId() {
+        return this.id;
     }
 
-    public Map<String, AbstractClusterMonitor> getAbstractClusterMonitors() {
-        return abstractClusterMonitors;
+    public void setId(String id) {
+        this.id = id;
     }
 
-    public void addAbstractMonitor(AbstractClusterMonitor monitor) {
-       this.abstractClusterMonitors.put(monitor.getClusterId(), monitor);
-    }
+    public void startDependency() {
+        //start the first dependency
+        List<ApplicationContext> applicationContexts = 
dependencyTree.getStarAbleDependencies();
+        startDependency(applicationContexts);
 
-    public AbstractClusterMonitor getAbstractMonitor(String clusterId) {
-        return this.abstractClusterMonitors.get(clusterId);
     }
 
-    public void setAbstractClusterMonitors(Map<String, AbstractClusterMonitor> 
abstractClusterMonitors) {
-        this.abstractClusterMonitors = abstractClusterMonitors;
+    public void startDependency(String id) {
+        List<ApplicationContext> applicationContexts = 
dependencyTree.getStarAbleDependencies(id);
+        startDependency(applicationContexts);
     }
 
-    public abstract void monitor();
-
-    /**
-     * Triggered when an event is received.
-     * @param event
-     */
-    protected abstract void onEvent(Event event);
-
-    public String getId() {
-        return this.id;
-    }
+    private void startDependency(List<ApplicationContext> applicationContexts) 
{
+        if(applicationContexts == null) {
+            //all the groups/clusters have been started and waiting for 
activation
+            log.warn("There is no child found for the [group]: " + this.id );
+        }
+        for (ApplicationContext context : applicationContexts) {
+            if (log.isDebugEnabled()) {
+                log.debug("Dependency check for the Group " + context.getId() 
+ " started");
+            }
+            if (context instanceof GroupContext) {
+                startGroupMonitor(this, context.getId(), component);
+            } else if (context instanceof ClusterContext) {
+                ClusterDataHolder clusterDataHolder = 
component.getClusterData(context.getId());
+                String clusterId = clusterDataHolder.getClusterId();
+                String serviceName = clusterDataHolder.getServiceType();
+                Cluster cluster;
+                //TopologyManager.acquireReadLock();
+                Topology topology = TopologyManager.getTopology();
+                if (topology.serviceExists(serviceName)) {
+                    Service service = topology.getService(serviceName);
+                    if (service.clusterExists(clusterId)) {
+                        cluster = service.getCluster(clusterId);
+                        if (log.isDebugEnabled()) {
+                            log.debug("Dependency check starting the 
[cluster]" + clusterId);
+                        }
+                        startClusterMonitor(this, cluster);
+                    } else {
+                        log.warn("[Cluster] " + clusterId + " cannot be found 
in the " +
+                                "Topology for [service] " + serviceName);
+                    }
+                } else {
+                    log.warn("[Service] " + serviceName + " cannot be found in 
the Topology");
+                }
+                //TopologyManager.releaseReadLock();
+            }
+        }
 
-    public void setId(String id) {
-        this.id = id;
     }
 
-    
     protected synchronized void startClusterMonitor(Monitor parent, Cluster 
cluster) {
         Thread th = null;
         if (cluster.isLbCluster()
-                && 
!this.abstractClusterMonitors.containsKey(cluster.getClusterId())) {
+                && 
!this.clusterIdToClusterMonitorsMap.containsKey(cluster.getClusterId())) {
             th = new Thread(new LBClusterMonitorAdder(
                     cluster));
-        } else if (!cluster.isLbCluster() && 
!this.abstractClusterMonitors.containsKey(cluster.getClusterId())) {
+        } else if (!cluster.isLbCluster() && 
!this.clusterIdToClusterMonitorsMap.containsKey(cluster.getClusterId())) {
             th = new Thread(
                     new ClusterMonitorAdder(parent, cluster));
             if (log.isDebugEnabled()) {
@@ -129,8 +159,7 @@ public abstract class Monitor extends Observable implements 
Observer {
                 th.join();
             } catch (InterruptedException ignore) {
             }*/
-
-                log.info(String
+            log.info(String
                         .format("Cluster monitor thread has been started 
successfully: [cluster] %s ",
                                 cluster.getClusterId()));
         }
@@ -138,7 +167,7 @@ public abstract class Monitor extends Observable implements 
Observer {
 
     protected synchronized void startGroupMonitor(Monitor parent, String 
dependency, ParentBehavior component) {
         Thread th = null;
-        if (!this.groupMonitors.containsKey(dependency)) {
+        if (!this.aliasToGroupMonitorsMap.containsKey(dependency)) {
             if (log.isDebugEnabled()) {
                 log.debug(String
                         .format("Group monitor Adder has been added: [group] 
%s ",
@@ -165,6 +194,14 @@ public abstract class Monitor extends Observable 
implements Observer {
         return status;
     }
 
+    public Map<String, ScheduledExecutorService> 
getAdderIdToExecutorServiceMap() {
+        return adderIdToExecutorServiceMap;
+    }
+
+    public void setAdderIdToExecutorServiceMap(Map<String, 
ScheduledExecutorService> adderIdToExecutorServiceMap) {
+        this.adderIdToExecutorServiceMap = adderIdToExecutorServiceMap;
+    }
+
     private class ClusterMonitorAdder implements Runnable {
         private Cluster cluster;
         private Monitor parent;
@@ -220,7 +257,7 @@ public abstract class Monitor extends Observable implements 
Observer {
             th.start();
 
             AutoscalerContext.getInstance().addMonitor(monitor);
-            abstractClusterMonitors.put(cluster.getClusterId(), monitor);
+            clusterIdToClusterMonitorsMap.put(cluster.getClusterId(), monitor);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster monitor has been added 
successfully: [cluster] %s",
                         cluster.getClusterId()));
@@ -275,7 +312,7 @@ public abstract class Monitor extends Observable implements 
Observer {
                 throw new RuntimeException(msg);
             }
 
-            groupMonitors.put(dependency, monitor);
+            aliasToGroupMonitorsMap.put(dependency, monitor);
             parent.addObserver(monitor);
 
             if (log.isInfoEnabled()) {
@@ -327,7 +364,7 @@ public abstract class Monitor extends Observable implements 
Observer {
             Thread th = new Thread(monitor);
             th.start();
             AutoscalerContext.getInstance().addLbMonitor(monitor);
-            abstractClusterMonitors.put(cluster.getClusterId(), monitor);
+            clusterIdToClusterMonitorsMap.put(cluster.getClusterId(), monitor);
             if (log.isInfoEnabled()) {
                 log.info(String.format("LB Cluster monitor has been added 
successfully: [cluster] %s",
                         cluster.getClusterId()));
@@ -335,5 +372,25 @@ public abstract class Monitor extends Observable 
implements Observer {
         }
     }
 
+    public void setAliasToGroupMonitorsMap(Map<String, GroupMonitor> 
aliasToGroupMonitorsMap) {
+        this.aliasToGroupMonitorsMap = aliasToGroupMonitorsMap;
+    }
+
+    public Map<String, AbstractClusterMonitor> 
getClusterIdToClusterMonitorsMap() {
+        return clusterIdToClusterMonitorsMap;
+    }
+
+    public void addAbstractMonitor(AbstractClusterMonitor monitor) {
+        this.clusterIdToClusterMonitorsMap.put(monitor.getClusterId(), 
monitor);
+    }
+
+    public AbstractClusterMonitor getAbstractMonitor(String clusterId) {
+        return this.clusterIdToClusterMonitorsMap.get(clusterId);
+    }
+
+    public void setClusterIdToClusterMonitorsMap(Map<String, 
AbstractClusterMonitor> clusterIdToClusterMonitorsMap) {
+        this.clusterIdToClusterMonitorsMap = clusterIdToClusterMonitorsMap;
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/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 ac2b556..eeef1d4 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
@@ -24,9 +24,8 @@ import 
org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
-import org.apache.stratos.messaging.domain.topology.*;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+import org.apache.stratos.messaging.domain.topology.Application;
+import org.apache.stratos.messaging.domain.topology.Status;
 
 import java.util.*;
 
@@ -39,12 +38,7 @@ public class ApplicationMonitor extends Monitor {
     public ApplicationMonitor(Application application) {
         super(application);
         this.id = application.getId();
-        if (preOrderTraverse.isEmpty()) {
-            log.warn("the child group/cluster cannot be found for the 
Application " + id);
-        } else {
-            startDependency();
-        }
-        //keep
+        startDependency();
     }
 
     @Override
@@ -56,67 +50,12 @@ public class ApplicationMonitor extends Monitor {
             log.info(String.format("[Monitor] %s got notified from the [child] 
%s" +
                     "on its state change from %s to %s", id, notifier, 
this.status, status));
             if (childStatus == Status.Activated) {
-                //start the next dependency
-                if (!preOrderTraverse.isEmpty()) {
-                    startDependency();
-                }
-            }
-        }
-    }
-
-    @Override
-    protected void onEvent(Event event) {
-
-    }
+                //update the notifier as active in the dependency tree
 
-    @Override
-    protected void startDependency() {
-        //Need to get the order every time as group/cluster might already been 
started
-        //TODO breadth first search in a tree and find the parallel one
-        //TODO build up the tree with ordered manner
-
-        // start the first dependency
-        if (!preOrderTraverse.isEmpty()) {
-            String dependency = preOrderTraverse.poll();
-            if (log.isDebugEnabled()) {
-                log.debug("Dependency check for the [group] " + dependency + " 
started");
-            }
-            if (dependency.contains("group")) {
-                String groupId = dependency.substring(6);
-                if (log.isDebugEnabled()) {
-                    log.debug("Dependency check starting the [group]" + 
groupId);
-                }
-                startGroupMonitor(this, groupId, component);
-            } else if (dependency.contains("cartridge")) {
-                ClusterDataHolder clusterDataHolder = 
component.getClusterData(dependency.substring(10));
-                String clusterId = clusterDataHolder.getClusterId();
-                String serviceName = clusterDataHolder.getServiceType();
-                Cluster cluster = null;
-                //TopologyManager.acquireReadLock();
-                Topology topology = TopologyManager.getTopology();
-                if (topology.serviceExists(serviceName)) {
-                    Service service = topology.getService(serviceName);
-                    if (service.clusterExists(clusterId)) {
-                        cluster = service.getCluster(clusterId);
-                        if (log.isDebugEnabled()) {
-                            log.debug("Dependency check starting the 
[cluster]" + clusterId);
-                        }
-                        startClusterMonitor(this, cluster);
-                    } else {
-                        log.warn("[Cluster] " + clusterId + " cannot be found 
in the " +
-                                "Topology for [service] " + serviceName);
-                    }
-                } else {
-                    log.warn("[Service] " + serviceName + " cannot be found in 
the Topology");
-                }
-                //TopologyManager.releaseReadLock();
+                //start the next dependency
+                startDependency(notifier);
             }
-        } else {
-            //all the groups/clusters have been started and waiting for 
activation
-            log.info("All the groups/clusters of the [Application]: " + 
this.id + " have been started.");
         }
-
-
     }
 
 
@@ -127,14 +66,14 @@ public class ApplicationMonitor extends Monitor {
      * @return the found GroupMonitor
      */
     public GroupMonitor findGroupMonitorWithId(String groupId) {
-        return findGroupMonitor(groupId, groupMonitors.values());
+        return findGroupMonitor(groupId, aliasToGroupMonitorsMap.values());
 
     }
 
     public List<String> findClustersOfApplication(String appId) {
         List<String> clusters = new ArrayList<String>();
         //considering only one level
-        for (AbstractClusterMonitor monitor : 
this.abstractClusterMonitors.values()) {
+        for (AbstractClusterMonitor monitor : 
this.clusterIdToClusterMonitorsMap.values()) {
             clusters.add(monitor.getClusterId());
         }
         //TODO rest
@@ -150,7 +89,7 @@ public class ApplicationMonitor extends Monitor {
      * @return
      */
     public AbstractClusterMonitor findClusterMonitorWithId(String clusterId) {
-        return findClusterMonitor(clusterId, abstractClusterMonitors.values(), 
groupMonitors.values());
+        return findClusterMonitor(clusterId, 
clusterIdToClusterMonitorsMap.values(), aliasToGroupMonitorsMap.values());
 
     }
 
@@ -166,8 +105,8 @@ public class ApplicationMonitor extends Monitor {
 
         for (GroupMonitor groupMonitor : groupMonitors) {
             return findClusterMonitor(clusterId,
-                    groupMonitor.getAbstractClusterMonitors().values(),
-                    groupMonitor.getGroupMonitors().values());
+                    groupMonitor.getClusterIdToClusterMonitorsMap().values(),
+                    groupMonitor.getAliasToGroupMonitorsMap().values());
         }
         return null;
 
@@ -180,8 +119,8 @@ public class ApplicationMonitor extends Monitor {
                 return monitor;
             } else {
                 // check if this Group has nested sub Groups. If so, traverse 
them as well
-                if (monitor.getGroupMonitors() != null) {
-                    return findGroupMonitor(id, 
monitor.getGroupMonitors().values());
+                if (monitor.getAliasToGroupMonitorsMap() != null) {
+                    return findGroupMonitor(id, 
monitor.getAliasToGroupMonitorsMap().values());
                 }
             }
         }
@@ -195,12 +134,12 @@ public class ApplicationMonitor extends Monitor {
 
     private Monitor findParentMonitorForGroup(String groupId, Monitor monitor) 
{
         //if this monitor has the group, return it as the parent
-        if (monitor.getGroupMonitors().containsKey(groupId)) {
+        if (monitor.getAliasToGroupMonitorsMap().containsKey(groupId)) {
             return monitor;
         } else {
-            if (monitor.getGroupMonitors() != null) {
+            if (monitor.getAliasToGroupMonitorsMap() != null) {
                 //check whether the children has the group and find its parent
-                for (GroupMonitor groupMonitor : 
monitor.getGroupMonitors().values()) {
+                for (GroupMonitor groupMonitor : 
monitor.getAliasToGroupMonitorsMap().values()) {
                     return findParentMonitorForGroup(groupId, groupMonitor);
 
                 }
@@ -216,12 +155,12 @@ public class ApplicationMonitor extends Monitor {
 
     private Monitor findParentMonitorForCluster(String clusterId, Monitor 
monitor) {
         //if this monitor has the group, return it as the parent
-        if (monitor.getAbstractClusterMonitors().containsKey(clusterId)) {
+        if (monitor.getClusterIdToClusterMonitorsMap().containsKey(clusterId)) 
{
             return monitor;
         } else {
-            if (monitor.getGroupMonitors() != null) {
+            if (monitor.getAliasToGroupMonitorsMap() != null) {
                 //check whether the children has the group and find its parent
-                for (GroupMonitor groupMonitor : 
monitor.getGroupMonitors().values()) {
+                for (GroupMonitor groupMonitor : 
monitor.getAliasToGroupMonitorsMap().values()) {
                     return findParentMonitorForCluster(clusterId, 
groupMonitor);
 
                 }
@@ -243,12 +182,4 @@ public class ApplicationMonitor extends Monitor {
                 "state changes from %s to %s", id, this.status, status));
         this.status = status;
     }
-
-    public Queue<String> getPreOrderTraverse() {
-        return preOrderTraverse;
-    }
-
-    public void setPreOrderTraverse(Queue<String> preOrderTraverse) {
-        this.preOrderTraverse = preOrderTraverse;
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/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 cfab9de..376d5d4 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
@@ -20,15 +20,15 @@ package org.apache.stratos.autoscaler.monitor.group;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.grouping.DependencyBuilder;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ApplicationContext;
+import 
org.apache.stratos.autoscaler.grouping.dependency.context.ClusterContext;
+import org.apache.stratos.autoscaler.grouping.dependency.context.GroupContext;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
 import org.apache.stratos.messaging.domain.topology.*;
-import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
 import java.util.List;
-import java.util.Map;
 import java.util.Observable;
 
 /**
@@ -41,26 +41,23 @@ public class GroupMonitor extends Monitor {
     public GroupMonitor(Group group) {
         super(group);
         this.id = group.getAlias();
-        if(preOrderTraverse.isEmpty()) {
-            log.warn("the child group/cluster cannot be found for the Group " 
+ id);
-        } else {
-            startDependency();
-        }
+        startDependency();
+
     }
 
     @Override
     public void update(Observable observable, Object event) {
-        if(event instanceof MonitorStatusEvent) {
+        if (event instanceof MonitorStatusEvent) {
             MonitorStatusEvent statusEvent = (MonitorStatusEvent) event;
             Status childStatus = statusEvent.getStatus();
             String notifier = statusEvent.getNotifierId();
             log.info(String.format("[Monitor] %s got notified from the [child] 
%s" +
                     "on its state change from %s to %s", id, notifier, 
this.status, status));
-            if(childStatus == Status.Activated) {
+            if (childStatus == Status.Activated) {
                 //start the next dependency
-                if(!preOrderTraverse.isEmpty()) {
-                    startDependency();
-                }
+                startDependency(notifier);
+            } else if(childStatus == Status.In_Maintenance) {
+
             }
 
         }
@@ -76,63 +73,11 @@ public class GroupMonitor extends Monitor {
     }
 
     @Override
-    public void startDependency() {
-        //Need to get the order every time as group/cluster might already been 
started
-        //TODO breadth first search in a tree and find the parallel one
-        //TODO build up the tree with ordered manner
 
-        preOrderTraverse = DependencyBuilder.getStartupOrder(component);
-
-        //start the first dependency
-        if(!preOrderTraverse.isEmpty()) {
-            String dependency = preOrderTraverse.poll();
-            if(log.isDebugEnabled()) {
-                log.debug("Dependency check for the Group " + dependency + " 
started");
-            }
-            if (dependency.contains("group")) {
-                for(Group group: component.getAliasToGroupMap().values()) {
-                    if(group.getName().equals(dependency.substring(6))) {
-                        startGroupMonitor(this, group.getAlias(), component);
-                    }
-                }
-            } else if (dependency.contains("cartridge")) {
-                ClusterDataHolder clusterDataHolder = 
component.getClusterData(dependency.substring(10));
-                String clusterId = clusterDataHolder.getClusterId();
-                String serviceName = clusterDataHolder.getServiceType();
-                Cluster cluster = null;
-                //TopologyManager.acquireReadLock();
-                Topology topology = TopologyManager.getTopology();
-                if (topology.serviceExists(serviceName)) {
-                    Service service = topology.getService(serviceName);
-                    if (service.clusterExists(clusterId)) {
-                        cluster = service.getCluster(clusterId);
-                        if (log.isDebugEnabled()) {
-                            log.debug("Dependency check starting the 
[cluster]" + clusterId);
-                        }
-                        startClusterMonitor(this, cluster);
-                    } else {
-                        log.warn("[Cluster] " + clusterId + " cannot be found 
in the " +
-                                "Topology for [service] " + serviceName);
-                    }
-                } else {
-                    log.warn("[Service] " + serviceName + " cannot be found in 
the Topology");
-                }
-                //TopologyManager.releaseReadLock();
-            }
-        } else {
-            //all the groups/clusters have been started and waiting for 
activation
-            log.info("All the groups/clusters of the [group]: " + this.id + " 
have been started.");
-        }
-    }
 
     //monitor the status of the cluster and the groups
     public void monitor() {
 
 
     }
-
-    @Override
-    protected void onEvent(Event event) {
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
index ba2cc2e..220380e 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
@@ -20,6 +20,7 @@
 package org.apache.stratos.messaging.domain.topology;
 
 import java.io.Serializable;
+import java.util.List;
 
 public class StartupOrder implements Serializable {
 
@@ -27,6 +28,8 @@ public class StartupOrder implements Serializable {
 
     private String after;
 
+    private List<String> startList;
+
     public StartupOrder (String start, String after) {
         this.start = start;
         this.after = after;
@@ -39,4 +42,12 @@ public class StartupOrder implements Serializable {
     public String getAfter() {
         return after;
     }
+
+    public List<String> getStartList() {
+        return startList;
+    }
+
+    public void setStartList(List<String> startList) {
+        this.startList = startList;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bdd9443e/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Status.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Status.java
 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Status.java
index fafb4e8..7ba27fc 100644
--- 
a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Status.java
+++ 
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Status.java
@@ -22,9 +22,10 @@ package org.apache.stratos.messaging.domain.topology;
 public enum Status {
 
     Created(1),
-    In_Maintenance(2),
-    Running(3),
-    Activated(4);
+    Running(2),
+    Activated(3),
+    In_Maintenance(4),
+    Removed(5);
 
     private int code;
 

Reply via email to