Repository: stratos Updated Branches: refs/heads/4.0.0-grouping cbcb376fd -> a13091a6c
fixing application/group activation and locking Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/dc8067a9 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/dc8067a9 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/dc8067a9 Branch: refs/heads/4.0.0-grouping Commit: dc8067a9a382597aa9eb3ef89fe098ad40d900b7 Parents: 10ed5ef Author: reka <[email protected]> Authored: Thu Oct 9 15:10:23 2014 +0530 Committer: reka <[email protected]> Committed: Thu Oct 9 15:10:23 2014 +0530 ---------------------------------------------------------------------- .../apache/stratos/autoscaler/Constants.java | 4 + .../grouping/dependency/DependencyBuilder.java | 9 +- .../grouping/dependency/DependencyTree.java | 1 - .../context/ApplicationContextFactory.java | 52 +++++++---- .../AutoscalerTopologyEventReceiver.java | 44 +++++---- .../monitor/AbstractClusterMonitor.java | 1 + .../stratos/autoscaler/monitor/Monitor.java | 97 ++++++++++++-------- .../monitor/application/ApplicationMonitor.java | 6 +- .../autoscaler/monitor/group/GroupMonitor.java | 12 ++- .../status/checker/StatusChecker.java | 34 +++---- .../stratos/autoscaler/util/AutoscalerUtil.java | 1 + 11 files changed, 157 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 a448406..59717f7 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 @@ -76,4 +76,8 @@ public class Constants { public static final String KILL_NONE = "kill-none"; public static final String KILL_ALL = "kill-all"; public static final String KILL_DEPENDENTS = "kill-dependents"; + public static final String GROUP = "group"; + public static final String CARTRIDGE = "cartridge"; + + } http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 index fcdaade..5a1e4fd 100644 --- 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 @@ -32,7 +32,7 @@ import java.util.Set; /** * This is to build the startup/termination dependencies - * across all the groups and clusters + * across immediate children according to the start order defined. */ public class DependencyBuilder { private static final Log log = LogFactory.getLog(DependencyBuilder.class); @@ -97,8 +97,9 @@ public class DependencyBuilder { if (start != null) { ApplicationContext applicationContext = ApplicationContextFactory. - getApplicationContext(start, component, dependencyTree); - String id = applicationContext.getId(); //TODO change the id + getApplicationContext(start, component, + dependencyTree.isKillDependent()); + String id = applicationContext.getId(); ApplicationContext existingApplicationContext = dependencyTree.findApplicationContextWithId(id); @@ -131,7 +132,7 @@ public class DependencyBuilder { } } } - //TODO need to parser the scalable dependencies + //TODO need to parser the scalable dependencies } http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 a5b9ce2..d3dded3 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 @@ -166,7 +166,6 @@ public class DependencyTree { return childContexts; } - public boolean isKillAll() { return killAll; } http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 index dfd8fa9..6e10633 100644 --- 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 @@ -18,44 +18,64 @@ */ package org.apache.stratos.autoscaler.grouping.dependency.context; -import org.apache.stratos.autoscaler.grouping.dependency.DependencyTree; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.autoscaler.Constants; +import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; import org.apache.stratos.messaging.domain.topology.ParentComponent; /** * Factory to create new GroupContext or ClusterContext */ public class ApplicationContextFactory { + private static final Log log = LogFactory.getLog(ApplicationContextFactory.class); + /** + * Will return the GroupContext/ClusterContext based on the type in start order + * @param startOrder reference of group/cluster in the start order + * @param component The component which used to build the dependency + * @param isKillDependent kill dependent behaviour of this component + * @return Context + */ public static ApplicationContext getApplicationContext(String startOrder, ParentComponent component, - DependencyTree dependencyTree) { + boolean isKillDependent) { String id; ApplicationContext applicationContext = null; - if (startOrder.contains("group")) { + if (startOrder.contains(Constants.GROUP)) { + //getting the group alias 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")) { + applicationContext = new GroupContext(id, + isKillDependent); + } else if (startOrder.contains(Constants.CARTRIDGE)) { + //getting the cluster alias id = getClusterFromStartupOrder(startOrder); - //TODO getting the cluster id of the using cartridge name - applicationContext = new ClusterContext(component.getClusterData(id).getClusterId(), - dependencyTree.isKillDependent()); + //getting the cluster-id from cluster alias + ClusterDataHolder clusterDataHolder = component.getClusterDataMap().get(id); + applicationContext = new ClusterContext(clusterDataHolder.getClusterId(), + isKillDependent); } else { - //TODO throw exception + log.warn("[Startup Order]: " + startOrder + " contains unknown reference"); } return applicationContext; } + /** + * Utility method to get the group alias from the startup order Eg: group.mygroup + * @param startupOrder startup order + * @return group alias + */ public static String getGroupFromStartupOrder(String startupOrder) { - return startupOrder.substring(6); + return startupOrder.substring(Constants.GROUP.length() + 1); } + /** + * Utility method to get the cluster alias from startup order Eg: cartridge.myphp + * @param startupOrder startup order + * @return cluster alias + */ public static String getClusterFromStartupOrder(String startupOrder) { - return startupOrder.substring(10); + return startupOrder.substring(Constants.CARTRIDGE.length() + 1); } - - - } http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java index b7d671f..3930e83 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java @@ -114,24 +114,27 @@ public class AutoscalerTopologyEventReceiver implements Runnable { topologyEventReceiver.addEventListener(new ApplicationCreatedEventListener() { @Override protected void onEvent(Event event) { - - log.info("[ApplicationCreatedEvent] Received: " + event.getClass()); - - ApplicationCreatedEvent applicationCreatedEvent = (ApplicationCreatedEvent) event; - - //acquire read lock - //TopologyManager.acquireReadLock(); - TopologyManager.acquireReadLockForApplication(applicationCreatedEvent.getApplication().getUniqueIdentifier()); - try { - //start the application monitor - //TODO catch exception by ApplicationMonitor - startApplicationMonitor(applicationCreatedEvent.getApplication()); + log.info("[ApplicationCreatedEvent] Received: " + event.getClass()); + ApplicationCreatedEvent applicationCreatedEvent = (ApplicationCreatedEvent) event; + try { - } finally { - //release read lock - TopologyManager.releaseReadLockForApplication(applicationCreatedEvent.getApplication().getUniqueIdentifier()); - //TopologyManager.releaseReadLock(); + //acquire read lock + TopologyManager.acquireReadLockForApplication( + applicationCreatedEvent.getApplication().getUniqueIdentifier()); + //start the application monitor + startApplicationMonitor(applicationCreatedEvent.getApplication()); + } catch (Exception e) { + String msg = "Error processing event " + e.getLocalizedMessage(); + log.error(msg, e); + } finally { + //release read lock + TopologyManager.releaseReadLockForApplication( + applicationCreatedEvent.getApplication().getUniqueIdentifier()); + } + } catch (ClassCastException e) { + String msg = "Error while casting the event " + e.getLocalizedMessage(); + log.error(msg, e); } } @@ -153,7 +156,7 @@ public class AutoscalerTopologyEventReceiver implements Runnable { clusterMonitor.setStatus(Status.Activated); //starting the status checker to decide on the status of it's parent - StatusChecker.getInstance().onClusterStatusChange(clusterId, appId); + //StatusChecker.getInstance().onClusterStatusChange(clusterId, appId); } }); @@ -174,7 +177,7 @@ public class AutoscalerTopologyEventReceiver implements Runnable { monitor.setStatus(Status.Activated); //starting the status checker to decide on the status of it's parent - StatusChecker.getInstance().onGroupStatusChange(groupId, appId); + //StatusChecker.getInstance().onGroupStatusChange(groupId, appId); } }); @@ -189,9 +192,6 @@ public class AutoscalerTopologyEventReceiver implements Runnable { ApplicationMonitor appMonitor = AutoscalerContext.getInstance().getAppMonitor(appId); appMonitor.setStatus(Status.Activated); - //TODO update appmonitor - //starting the status checker to decide on the status of it's parent - //StatusChecker.getInstance().onClusterStatusChange(clusterId, appId); } }); @@ -205,7 +205,6 @@ public class AutoscalerTopologyEventReceiver implements Runnable { ApplicationRemovedEvent applicationRemovedEvent = (ApplicationRemovedEvent) event; //acquire read lock - //TopologyManager.acquireReadLock(); TopologyManager.acquireReadLockForApplication(applicationRemovedEvent.getApplicationId()); try { @@ -232,7 +231,6 @@ public class AutoscalerTopologyEventReceiver implements Runnable { } finally { //release read lock TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getApplicationId()); - //TopologyManager.releaseReadLock(); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 d48fdb4..9aa75b4 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 @@ -255,6 +255,7 @@ abstract public class AbstractClusterMonitor implements EventHandler, Runnable { public void setParent(Monitor parent) { this.parent = parent; + this.appId = parent.getAppId(); } @Override http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 475cb4f..65ab790 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 @@ -38,10 +38,9 @@ import org.apache.stratos.autoscaler.util.AutoscalerUtil; import org.apache.stratos.messaging.domain.topology.*; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; -import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Monitor is to monitor it's child monitors and @@ -62,6 +61,8 @@ public abstract class Monitor implements EventHandler { protected ParentComponent component; //status of the monitor whether it is running/in_maintainable/terminated protected Status status; + //Application id of this particular monitor + protected String appId; public Monitor(ParentComponent component) throws DependencyBuilderException { aliasToGroupMonitorsMap = new HashMap<String, GroupMonitor>(); @@ -73,6 +74,7 @@ public abstract class Monitor implements EventHandler { /** * Will monitor the immediate children upon any event triggers from parent/children + * * @param statusEvent will be sent by parent/children with the current status */ protected abstract void monitor(MonitorStatusEvent statusEvent); @@ -106,7 +108,7 @@ public abstract class Monitor implements EventHandler { * @param applicationContexts the found applicationContexts to be started */ private boolean startDependency(List<ApplicationContext> applicationContexts) - throws TopologyInConsistentException{ + throws TopologyInConsistentException { if (applicationContexts == null) { //all the groups/clusters have been started and waiting for activation log.info("There is no child found for the [group]: " + this.id); @@ -124,27 +126,32 @@ public abstract class Monitor implements EventHandler { 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); + //acquire read lock for the service and cluster + TopologyManager.acquireReadLockForCluster(clusterId, serviceName); + try { + 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 { + String msg = "[Cluster] " + clusterId + " cannot be found in the " + + "Topology for [service] " + serviceName; + throw new TopologyInConsistentException(msg); } - startClusterMonitor(this, cluster); } else { - String msg = "[Cluster] " + clusterId + " cannot be found in the " + - "Topology for [service] " + serviceName; + String msg = "[Service] " + serviceName + " cannot be found in the Topology"; throw new TopologyInConsistentException(msg); - } - } else { - String msg = "[Service] " + serviceName + " cannot be found in the Topology"; - throw new TopologyInConsistentException(msg); + } + } finally { + //release read lock for the service and cluster + TopologyManager.releaseReadLockForCluster(clusterId, serviceName); } - //TopologyManager.releaseReadLock(); } } return true; @@ -152,22 +159,27 @@ public abstract class Monitor implements EventHandler { } protected synchronized void startClusterMonitor(Monitor parent, Cluster cluster) { - ScheduledExecutorService adder = Executors.newSingleThreadScheduledExecutor(); + Thread th = null; if (cluster.isLbCluster() && !this.clusterIdToClusterMonitorsMap.containsKey(cluster.getClusterId())) { - adder.scheduleAtFixedRate(new LBClusterMonitorAdder( - cluster), 5, 5, TimeUnit.SECONDS); + th = new Thread(new LBClusterMonitorAdder( + cluster)); } else if (!cluster.isLbCluster() && !this.clusterIdToClusterMonitorsMap.containsKey(cluster.getClusterId())) { - adder.scheduleAtFixedRate(new ClusterMonitorAdder(parent, cluster), 5, 5, TimeUnit.SECONDS); - + th = new Thread( + new ClusterMonitorAdder(parent, cluster)); if (log.isDebugEnabled()) { log.debug(String .format("Cluster monitor Adder has been added: [cluster] %s ", cluster.getClusterId())); } } - if (adder != null) { - //adderIdToExecutorServiceMap.put(cluster.getClusterId(), adder); + if (th != null) { + th.start(); + /*try { + th.join(); + } catch (InterruptedException ignore) { + }*/ + log.info(String .format("Cluster monitor thread has been started successfully: [cluster] %s ", cluster.getClusterId())); @@ -175,25 +187,24 @@ public abstract class Monitor implements EventHandler { } protected synchronized void startGroupMonitor(Monitor parent, String dependency, ParentComponent component) { - ScheduledExecutorService adder = Executors.newSingleThreadScheduledExecutor(); - + Thread th = null; if (!this.aliasToGroupMonitorsMap.containsKey(dependency)) { if (log.isDebugEnabled()) { log.debug(String .format("Group monitor Adder has been added: [group] %s ", dependency)); } - adder.scheduleAtFixedRate(new GroupMonitorAdder(parent, dependency, component), 5, 5, TimeUnit.SECONDS); - + th = new Thread( + new GroupMonitorAdder(parent, dependency, component)); } - if (adder != null) { + if (th != null) { + th.start(); /*try { - adder.awaitTermination(30, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); + th.join(); + } catch (InterruptedException ignore) { }*/ - //adderIdToExecutorServiceMap.put(((Group)component).getAlias(), adder); + log.info(String .format("Group monitor thread has been started successfully: [group] %s ", dependency)); @@ -236,6 +247,14 @@ public abstract class Monitor implements EventHandler { return this.clusterIdToClusterMonitorsMap.get(clusterId); } + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + private class ClusterMonitorAdder implements Runnable { private Cluster cluster; private Monitor parent; @@ -250,10 +269,10 @@ public abstract class Monitor implements EventHandler { int retries = 5; boolean success = false; do { - /*try { + try { Thread.sleep(5000); } catch (InterruptedException e1) { - }*/ + } try { if (log.isDebugEnabled()) { log.debug("CLuster monitor is going to be started for [cluster] " http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 90390e0..2ad2a0e 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 @@ -230,7 +230,11 @@ public class ApplicationMonitor extends Monitor { if(context.getStatusLifeCycle().isEmpty()) { try { //if life cycle is empty, need to start the monitor - startDependency(statusEvent.getId()); + boolean dependencyStarted = startDependency(statusEvent.getId()); + if(!dependencyStarted) { + //Have to check whether all other dependencies started + + } //updating the life cycle context.addStatusToLIfeCycle(statusEvent.getStatus()); } catch (TopologyInConsistentException e) { http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 99d5305..f9a1a67 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 @@ -29,6 +29,7 @@ import org.apache.stratos.autoscaler.monitor.MonitorStatusEventBuilder; import org.apache.stratos.autoscaler.monitor.events.ClusterStatusEvent; import org.apache.stratos.autoscaler.monitor.events.GroupStatusEvent; import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent; +import org.apache.stratos.autoscaler.status.checker.StatusChecker; import org.apache.stratos.messaging.domain.topology.Group; import org.apache.stratos.messaging.domain.topology.Status; import org.apache.stratos.messaging.event.application.status.StatusEvent; @@ -76,16 +77,20 @@ public class GroupMonitor extends Monitor implements EventHandler { @Override protected void monitor(MonitorStatusEvent statusEvent) { + String id = statusEvent.getId(); ApplicationContext context = this.dependencyTree. - findApplicationContextWithId(statusEvent.getId()); + findApplicationContextWithId(id); if(context.getStatusLifeCycle().isEmpty()) { try { //if life cycle is empty, need to start the monitor boolean startDep = startDependency(statusEvent.getId()); - //updating the life cycle + //updating the life cycle and current status + context.setStatus(status); context.addStatusToLIfeCycle(statusEvent.getStatus()); if(!startDep) { - + //Checking in the children whether all are active, + // since no dependency found to be started. + StatusChecker.getInstance().onChildStatusChange(id, this.component, this.appId); } } catch (TopologyInConsistentException e) { //TODO revert the siblings and notify parent, change a flag for reverting/un-subscription @@ -103,6 +108,7 @@ public class GroupMonitor extends Monitor implements EventHandler { public void setParent(Monitor parent) { this.parent = parent; + this.appId = parent.getAppId(); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/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 bb9c016..78e9793 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 @@ -86,28 +86,28 @@ public class StatusChecker { } /** - * @param groupId - * @param appId - */ - public void onGroupStatusChange(final String groupId, final String appId) { - updateChild(groupId, appId); - } - - /** - * @param clusterId - * @param appId + * @param idOfChild + * @param component */ - public void onClusterStatusChange(final String clusterId, final String appId) { - updateChild(clusterId, appId); + public void onChildStatusChange(final String idOfChild, final ParentComponent component, + final String appId) { + updateChild(idOfChild, component, appId); } - private void updateChild(final String clusterId, final String appId) { + private void updateChild(final String idOfChild, final ParentComponent component, final String appId) { Runnable group = new Runnable() { public void run() { - Application application = TopologyManager.getTopology().getApplication(appId); - Map<String, ClusterDataHolder> clusterIds = application.getClusterDataMap(); - Map<String, Group> groups = application.getAliasToGroupMap(); - updateChildStatus(appId, clusterId, groups, clusterIds, application); + try { + //TODO getting lock + TopologyManager.acquireReadLockForApplication(appId); + Map<String, ClusterDataHolder> clusterIds = component.getClusterDataMap(); + Map<String, Group> groups = component.getAliasToGroupMap(); + updateChildStatus(appId, idOfChild, groups, clusterIds, component); + } finally { + TopologyManager.releaseReadLockForApplication(appId); + + } + } }; Thread groupThread = new Thread(group); http://git-wip-us.apache.org/repos/asf/stratos/blob/dc8067a9/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java index 5fd74ae..cd8578e 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java @@ -336,6 +336,7 @@ public class AutoscalerUtil { TopologyInConsistentException { ApplicationMonitor applicationMonitor = new ApplicationMonitor(application); + applicationMonitor.setAppId(application.getUniqueIdentifier()); return applicationMonitor; }
