Repository: stratos Updated Branches: refs/heads/master c8bba8d01 -> 873f0969a
refatoring monitors Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/50244935 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/50244935 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/50244935 Branch: refs/heads/master Commit: 50244935dd69570b7a1cd45dc6cda0c711ac63ed Parents: 8769c4b Author: reka <[email protected]> Authored: Thu Nov 20 23:08:23 2014 +0530 Committer: reka <[email protected]> Committed: Thu Nov 20 23:08:23 2014 +0530 ---------------------------------------------------------------------- .../applications/dependency/DependencyTree.java | 20 -- .../autoscaler/monitor/EventHandler.java | 7 - .../stratos/autoscaler/monitor/Monitor.java | 115 ++++---- .../monitor/ParentComponentMonitor.java | 257 ++++++++++------- .../monitor/application/ApplicationMonitor.java | 10 +- .../monitor/cluster/AbstractClusterMonitor.java | 5 - .../autoscaler/monitor/group/GroupMonitor.java | 73 ++--- .../status/checker/StatusChecker.java | 286 +++++++------------ 8 files changed, 320 insertions(+), 453 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java index c8fe80e..d0e35a7 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java @@ -35,10 +35,6 @@ public class DependencyTree { private List<ApplicationChildContext> scalingDependencyApplicationContextList; - private boolean started; - - private boolean terminated; - private TerminationBehavior terminationBehavior; private boolean startupOder; @@ -276,20 +272,4 @@ public class DependencyTree { this.id = id; } - public boolean isStartupOder() { - return startupOder; - } - - public void setStartupOder(boolean startupOder) { - this.startupOder = startupOder; - } - - public boolean isReverseStartupOrder() { - return reverseStartupOrder; - } - - public void setReverseStartupOrder(boolean reverseStartupOrder) { - this.reverseStartupOrder = reverseStartupOrder; - } - } http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java index 141e6f9..13fd6b0 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/EventHandler.java @@ -55,13 +55,6 @@ public interface EventHandler { public abstract void onParentScalingEvent(MonitorScalingEvent scalingEvent); /** - * Triggered when termination decision is made. - * - * @param terminateAllEvent - */ - public abstract void onEvent(MonitorTerminateAllEvent terminateAllEvent); - - /** * Triggered when scaling decision is made. * * @param scalingEvent http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/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 bb3ba2d..989ba21 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 @@ -18,9 +18,6 @@ */ package org.apache.stratos.autoscaler.monitor; -import java.util.List; -import java.util.Map; - /** * Abstract class for the monitoring functionality in autoscaler. */ @@ -31,107 +28,99 @@ public abstract class Monitor implements EventHandler { protected String appId; //Parent monitor of this monitor, for appMonitor parent will be none. protected ParentComponentMonitor parent; - //monitors map, key=GroupAlias/clusterId and value=GroupMonitor/AbstractClusterMonitor - protected Map<String, Monitor> aliasToActiveMonitorsMap; - //monitors map, stopped monitors - protected List<String> inactiveMonitorsList; - - protected List<String> terminatingMonitorsList; - - //flag will get set to true in MonitorTerminateAllEvent when termination of - // this monitor decided by its parent - protected boolean terminateChildren = false; - + //has startup dependents protected boolean hasStartupDependents; - + //has scaling dependents protected boolean hasScalingDependents; + /** + * Return the id of the monitor + * + * @return id + */ public String getId() { return id; } + /** + * Set the id of the monitor + * + * @param id + */ public void setId(String id) { this.id = id; } + /** + * To get the appId of the monitor + * + * @return app id + */ public String getAppId() { return appId; } + /** + * To set the app id of the monitor + * + * @param appId + */ public void setAppId(String appId) { this.appId = appId; } - public Map<String, Monitor> getAliasToActiveMonitorsMap() { - return aliasToActiveMonitorsMap; - } - - public void setAliasToActiveMonitorsMap(Map<String, Monitor> aliasToActiveMonitorsMap) { - this.aliasToActiveMonitorsMap = aliasToActiveMonitorsMap; - } - + /** + * To get the parent of the monitor + * + * @return the parent + */ public ParentComponentMonitor getParent() { return parent; } + /** + * To set the parent of the monitor + * + * @param parent + */ public void setParent(ParentComponentMonitor parent) { this.parent = parent; this.appId = parent.getAppId(); } - public boolean hasActiveMonitors() { - boolean hasMonitor = false; - if ((this.aliasToActiveMonitorsMap != null && !this.aliasToActiveMonitorsMap.isEmpty())) { - hasMonitor = true; - } - return hasMonitor; - } - - public boolean hasMonitors() { - - return this.aliasToActiveMonitorsMap != null; - } - + /** + * Return whether this monitor has startup dependencies + * + * @return hasStartupDependents + */ public boolean hasStartupDependents() { return hasStartupDependents; } + /** + * Return whether this monitor has scaling dependencies + * + * @return startup dependencies exist or not + */ public boolean hasScalingDependents() { return hasScalingDependents; } + /** + * To set whether monitor has any startup dependencies + * + * @param hasDependent + */ public void setHasStartupDependents(boolean hasDependent) { this.hasStartupDependents = hasDependent; } + /** + * To set whether monitor has any scaling dependencies + * + * @param hasDependent + */ public void setHasScalingDependents(boolean hasDependent) { this.hasScalingDependents = hasDependent; } - - public boolean hasIndependentChild() { - boolean hasInDepChild = false; - for (Monitor monitor : this.aliasToActiveMonitorsMap.values()) { - if (!monitor.hasStartupDependents()) { - hasInDepChild = true; - break; - } - } - return hasInDepChild; - } - - public List<String> getAliasToInActiveMonitorsMap() { - return this.inactiveMonitorsList; - } - - public void setAliasToInActiveMonitorsMap(List<String> inactiveMonitorsList) { - this.inactiveMonitorsList = inactiveMonitorsList; - } - - public List<String> getTerminatingMonitorsList() { - return terminatingMonitorsList; - } - - public void setTerminatingMonitorsList(List<String> terminatingMonitorsList) { - this.terminatingMonitorsList = terminatingMonitorsList; - } } http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java index 320773d..bc33c55 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java @@ -24,7 +24,6 @@ import org.apache.stratos.autoscaler.applications.ApplicationHolder; import org.apache.stratos.autoscaler.applications.dependency.DependencyBuilder; import org.apache.stratos.autoscaler.applications.dependency.DependencyTree; import org.apache.stratos.autoscaler.applications.dependency.context.ApplicationChildContext; -import org.apache.stratos.autoscaler.applications.pojo.ApplicationClusterContext; import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder; import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher; import org.apache.stratos.autoscaler.exception.DependencyBuilderException; @@ -43,6 +42,7 @@ import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Monitor is to monitor it's child monitors and @@ -53,9 +53,14 @@ public abstract class ParentComponentMonitor extends Monitor { //The monitors dependency tree with all the start-able/kill-able dependencies protected DependencyTree startupDependencyTree; - //The monitors dependency tree with all the scaling dependencies protected DependencyTree scalingDependencyTree; + //monitors map, key=GroupAlias/clusterId and value=GroupMonitor/AbstractClusterMonitor + protected Map<String, Monitor> aliasToActiveMonitorsMap; + //monitors map, stopped monitors + protected List<String> inactiveMonitorsList; + //terminating monitors list + protected List<String> terminatingMonitorsList; public ParentComponentMonitor(ParentComponent component) throws DependencyBuilderException { aliasToActiveMonitorsMap = new HashMap<String, Monitor>(); @@ -65,12 +70,76 @@ public abstract class ParentComponentMonitor extends Monitor { this.id = component.getUniqueIdentifier(); //Building the startup dependencies for this monitor within the immediate children startupDependencyTree = DependencyBuilder.getInstance().buildDependency(component); - //Building the scaling dependencies for this monitor within the immediate children scalingDependencyTree = DependencyBuilder.getInstance().buildDependency(component); } /** + * This will start the parallel dependencies at once from the top level. + * it will get invoked when the monitor starts up only. + */ + public void startDependency() throws TopologyInConsistentException { + //start the first dependency + List<ApplicationChildContext> applicationContexts = this.startupDependencyTree. + getStarAbleDependencies(); + startDependency(applicationContexts); + + } + + /** + * This will get invoked based on the activation event of its one of the child + * + * @param id alias/clusterId of which receive the activated event + */ + public boolean startDependency(String id) throws TopologyInConsistentException { + List<ApplicationChildContext> applicationContexts = this.startupDependencyTree + .getStarAbleDependencies(id); + return startDependency(applicationContexts); + } + + /** + * This will start the parallel dependencies at once from the top level + * by traversing to find the terminated dependencies. + * it will get invoked when start a child monitor on termination of a sub tree + */ + public void startDependencyOnTermination() throws TopologyInConsistentException { + //start the first dependency which went to terminated + List<ApplicationChildContext> applicationContexts = this.startupDependencyTree. + getStarAbleDependenciesByTermination(); + startDependency(applicationContexts); + + } + + + /** + * To start the dependency of the given application contexts + * + * @param applicationContexts the found applicationContexts to be started + */ + private boolean startDependency(List<ApplicationChildContext> applicationContexts) + throws TopologyInConsistentException { + if (applicationContexts != null && applicationContexts.isEmpty()) { + //all the groups/clusters have been started and waiting for activation + log.info("There is no child found for the [group]: " + this.id); + return false; + + } + for (ApplicationChildContext context : applicationContexts) { + if (log.isDebugEnabled()) { + log.debug("Dependency check for the Group " + context.getId() + " started"); + } + if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) { + //to avoid if it is already started + context.setTerminated(false); + startMonitor(this, context); + } + } + + return true; + + } + + /** * This will start the child monitors based on the active of siblings according to start up order * * @param eventId parent id of the event which received @@ -101,24 +170,6 @@ public abstract class ParentComponentMonitor extends Monitor { } - // move to inactive monitors list to use in the Terminated event - protected synchronized void markMonitorAsInactive(String monitorKey) { - - if (!this.inactiveMonitorsList.contains(monitorKey)) { - this.inactiveMonitorsList.add(monitorKey); - } - } - - // move to inactive monitors list to use in the Terminated event - protected synchronized void markMonitorAsTerminating(String monitorKey) { - if (!this.terminatingMonitorsList.contains(monitorKey)) { - if (this.inactiveMonitorsList.contains(monitorKey)) { - this.inactiveMonitorsList.remove(monitorKey); - } - this.terminatingMonitorsList.add(monitorKey); - } - } - /** * @param eventId */ @@ -163,7 +214,7 @@ public abstract class ParentComponentMonitor extends Monitor { get(terminationContext.getId()); //start to kill it if (monitor != null) { - if (monitor.hasActiveMonitors()) { + if (monitor instanceof GroupMonitor) { //it is a group, so not sending terminating as it can be in inActive. If group needs terminating, //it will be handled by the terminating case of its children if (terminateAll || !notifier.equals(monitor.getId())) { @@ -189,6 +240,7 @@ public abstract class ParentComponentMonitor extends Monitor { /** * Act upon one of its children got terminated + * * @param eventId id of the notifier */ @@ -196,28 +248,26 @@ public abstract class ParentComponentMonitor extends Monitor { List<ApplicationChildContext> terminationList; boolean allDependentTerminated = false; - ApplicationChildContext context = this.startupDependencyTree.findApplicationContextWithIdInPrimaryTree(eventId); + ApplicationChildContext context = this.startupDependencyTree. + findApplicationContextWithIdInPrimaryTree(eventId); context.setTerminated(true); - terminationList = this.startupDependencyTree.getTerminationDependencies(eventId); - - - /** - * Make sure that all the dependents have been terminated properly to start the recovery - */ + //Make sure that all the dependents have been terminated properly to start the recovery if (terminationList != null) { allDependentTerminated = allDependentTerminated(terminationList); } - List<ApplicationChildContext> parentContexts = this.startupDependencyTree.findAllParentContextWithId(eventId); + List<ApplicationChildContext> parentContexts = this.startupDependencyTree. + findAllParentContextWithId(eventId); boolean parentsTerminated = false; boolean allParentsActive = false; + //make sure all the parent contexts got terminated or whether all of them are active if (parentContexts != null) { parentsTerminated = allParentTerminated(parentContexts); allParentsActive = allParentActive(parentContexts); } - if (( terminationList.isEmpty() || allDependentTerminated) && + if ((terminationList.isEmpty() || allDependentTerminated) && (parentContexts.isEmpty() || parentsTerminated || allParentsActive)) { //Find the non existent monitor by traversing dependency tree try { @@ -228,8 +278,7 @@ public abstract class ParentComponentMonitor extends Monitor { } } else { StatusChecker.getInstance().onChildStatusChange(eventId, this.id, this.appId); - log.info("" + - "Checking the status of group/application as no dependent found..."); + log.info("Checking the status of group/application as no dependent found..."); } @@ -299,17 +348,17 @@ public abstract class ParentComponentMonitor extends Monitor { } finally { ApplicationHolder.releaseReadLock(); } - } else if(monitor instanceof AbstractClusterMonitor) { - AbstractClusterMonitor monitor1 = (AbstractClusterMonitor)monitor; + } else if (monitor instanceof AbstractClusterMonitor) { + AbstractClusterMonitor monitor1 = (AbstractClusterMonitor) monitor; TopologyManager.acquireReadLockForCluster(monitor1.getServiceId(), - monitor1.getClusterId()); + monitor1.getClusterId()); try { - if(monitor1.getStatus() == ClusterStatus.Active) { + if (monitor1.getStatus() == ClusterStatus.Active) { parentsActive = true; } } finally { TopologyManager.releaseReadLockForCluster(monitor1.getServiceId(), - monitor1.getClusterId()); + monitor1.getClusterId()); } } @@ -318,83 +367,22 @@ public abstract class ParentComponentMonitor extends Monitor { return parentsActive; } - /** - * This will start the parallel dependencies at once from the top level. - * it will get invoked when the monitor starts up only. - * //TODO restarting the whole group - */ - public void startDependency() throws TopologyInConsistentException { - //start the first dependency - List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.getStarAbleDependencies(); - startDependency(applicationContexts); - - } - - /** - * This will start the parallel dependencies at once from the top level - * by traversing to find the terminated dependencies. - * it will get invoked when start a child monitor on termination of a sub tree - */ - public void startDependencyOnTermination() throws TopologyInConsistentException { - //start the first dependency which went to terminated - List<ApplicationChildContext> applicationContexts = this.startupDependencyTree. - getStarAbleDependenciesByTermination(); - startDependency(applicationContexts); - - } + // move to inactive monitors list to use in the Terminated event + protected synchronized void markMonitorAsInactive(String monitorKey) { - /** - * This will get invoked based on the activation event of its one of the child - * - * @param id alias/clusterId of which receive the activated event - */ - public boolean startDependency(String id) throws TopologyInConsistentException { - List<ApplicationChildContext> applicationContexts = this.startupDependencyTree.getStarAbleDependencies(id); - return startDependency(applicationContexts); + if (!this.inactiveMonitorsList.contains(monitorKey)) { + this.inactiveMonitorsList.add(monitorKey); + } } - /** - * To start the dependency of the given application contexts - * - * @param applicationContexts the found applicationContexts to be started - */ - private boolean startDependency(List<ApplicationChildContext> applicationContexts) - throws TopologyInConsistentException { - if (applicationContexts != null && applicationContexts.isEmpty()) { - //all the groups/clusters have been started and waiting for activation - log.info("There is no child found for the [group]: " + this.id); - return false; - - } - for (ApplicationChildContext context : applicationContexts) { - if (log.isDebugEnabled()) { - log.debug("Dependency check for the Group " + context.getId() + " started"); - } - if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) { - //to avoid if it is already started - context.setTerminated(false); - startMonitor(this, context); + // move to inactive monitors list to use in the Terminated event + protected synchronized void markMonitorAsTerminating(String monitorKey) { + if (!this.terminatingMonitorsList.contains(monitorKey)) { + if (this.inactiveMonitorsList.contains(monitorKey)) { + this.inactiveMonitorsList.remove(monitorKey); } + this.terminatingMonitorsList.add(monitorKey); } - - return true; - - } - - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; } protected synchronized void startMonitor(ParentComponentMonitor parent, ApplicationChildContext context) { @@ -481,4 +469,53 @@ public abstract class ParentComponentMonitor extends Monitor { } } + public Map<String, Monitor> getAliasToActiveMonitorsMap() { + return aliasToActiveMonitorsMap; + } + + public void setAliasToActiveMonitorsMap(Map<String, Monitor> aliasToActiveMonitorsMap) { + this.aliasToActiveMonitorsMap = aliasToActiveMonitorsMap; + } + + public boolean hasActiveMonitors() { + boolean hasMonitor = false; + if ((this.aliasToActiveMonitorsMap != null && !this.aliasToActiveMonitorsMap.isEmpty())) { + hasMonitor = true; + } + return hasMonitor; + } + + public boolean hasMonitors() { + + return this.aliasToActiveMonitorsMap != null; + } + + public boolean hasIndependentChild() { + boolean hasInDepChild = false; + for (Monitor monitor : this.aliasToActiveMonitorsMap.values()) { + if (!monitor.hasStartupDependents()) { + hasInDepChild = true; + break; + } + } + return hasInDepChild; + } + + public List<String> getAliasToInActiveMonitorsMap() { + return this.inactiveMonitorsList; + } + + public void setAliasToInActiveMonitorsMap(List<String> inactiveMonitorsList) { + this.inactiveMonitorsList = inactiveMonitorsList; + } + + public List<String> getTerminatingMonitorsList() { + return terminatingMonitorsList; + } + + public void setTerminatingMonitorsList(List<String> terminatingMonitorsList) { + this.terminatingMonitorsList = terminatingMonitorsList; + } + + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/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 f8b463e..f230918 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 @@ -123,8 +123,9 @@ public class ApplicationMonitor extends ParentComponentMonitor { return monitor; } else { // check if this Group has nested sub Groups. If so, traverse them as well - if (monitor.getAliasToActiveMonitorsMap() != null) { - return findGroupMonitor(id, monitor.getAliasToActiveMonitorsMap().values()); + if (monitor instanceof ParentComponentMonitor) { + return findGroupMonitor(id, ((ParentComponentMonitor)monitor). + getAliasToActiveMonitorsMap().values()); } } } @@ -200,11 +201,6 @@ public class ApplicationMonitor extends ParentComponentMonitor { } @Override - public void onEvent(MonitorTerminateAllEvent terminateAllEvent) { - - } - - @Override public void onEvent(MonitorScalingEvent scalingEvent) { } http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java index a201a44..6101082 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java @@ -313,11 +313,6 @@ public abstract class AbstractClusterMonitor extends Monitor implements Runnable } @Override - public void onEvent(MonitorTerminateAllEvent terminateAllEvent) { - - } - - @Override public void onEvent(MonitorScalingEvent scalingEvent) { } http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/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 a0f0c8e..81c5b3c 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 @@ -67,6 +67,28 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler startDependency(); } + /** + * Will set the status of the monitor based on Topology Group status/child status like scaling + * + * @param status status of the group + */ + public void setStatus(GroupStatus status) { + + //if(this.status != status) { + this.status = status; + //notifying the parent + if (status == GroupStatus.Inactive && !this.hasStartupDependents) { + log.info("[Group] " + this.id + "is not notifying the parent, " + + "since it is identified as the independent unit"); + } else { + // notify parent + log.info("[Group] " + this.id + "is notifying the [parent] " + this.parent.getId()); + MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, this.status, this.id); + } + //notify the children about the state change + MonitorStatusEventBuilder.notifyChildren(this, new GroupStatusEvent(status, getId())); + } + @Override public void onChildStatusEvent(MonitorStatusEvent statusEvent) { String id = statusEvent.getId(); @@ -151,63 +173,12 @@ public class GroupMonitor extends ParentComponentMonitor implements EventHandler } @Override - public void onEvent(MonitorTerminateAllEvent terminateAllEvent) { - this.terminateChildren = true; - - } - - @Override public void onEvent(MonitorScalingEvent scalingEvent) { } - public ParentComponentMonitor getParent() { - return parent; - } - - public void setParent(ParentComponentMonitor parent) { - this.parent = parent; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - private boolean isParent(String id) { - if (this.parent.getId().equals(id)) { - return true; - } else { - return false; - } - } - public GroupStatus getStatus() { return status; } - /** - * Will set the status of the monitor based on Topology Group status/child status like scaling - * - * @param status - */ - public void setStatus(GroupStatus status) { - - //if(this.status != status) { - this.status = status; - //notifying the parent - if (status == GroupStatus.Inactive && !this.hasStartupDependents) { - log.info("[Group] " + this.id + "is not notifying the parent, " + - "since it is identified as the independent unit"); - } else { - // notify parent - log.info("[Group] " + this.id + "is notifying the [parent] " + this.parent.getId()); - MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent, this.status, this.id); - } - //notify the children about the state change - MonitorStatusEventBuilder.notifyChildren(this, new GroupStatusEvent(status, getId())); - } } http://git-wip-us.apache.org/repos/asf/stratos/blob/50244935/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 b5729c2..c1dc547 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 @@ -49,7 +49,6 @@ public class StatusChecker { } public static StatusChecker getInstance() { - //TODO synchronized return Holder.INSTANCE; } @@ -110,7 +109,6 @@ public class StatusChecker { cluster = service.getCluster(monitor.getClusterId()); if (cluster != null) { try { - ApplicationHolder.acquireReadLock(); Application application = ApplicationHolder.getApplications().getApplication(appId); //if all members removed from the cluster and cluster is in terminating, @@ -188,6 +186,12 @@ public class StatusChecker { return clusterActive; } + /** + * Find out whether cluster monitor has any non terminated members + * + * @param monitor the cluster monitor + * @return whether has members or not + */ private boolean clusterMonitorHasMembers(VMClusterMonitor monitor) { boolean hasMember = false; for (NetworkPartitionContext networkPartitionContext : monitor.getNetworkPartitionCtxts().values()) { @@ -244,6 +248,14 @@ public class StatusChecker { groupThread.start(); } + /** + * This will calculate whether all the minimum of partition in a cluster satisfy in order + * to decide on the cluster status. + * + * @param monitor Cluster monitor of which the status needs to be calculated + * @param partitionId partition which got the faulty member + * @return whether cluster inActive or not + */ private boolean getClusterInactive(VMClusterMonitor monitor, String partitionId) { boolean clusterInActive = false; for (NetworkPartitionContext networkPartitionContext : monitor.getNetworkPartitionCtxts().values()) { @@ -260,85 +272,52 @@ public class StatusChecker { } /** - * @param idOfChild - * @param groupId - * @param appId + * This will use to calculate whether all children of a particular component is active by traversing Top + * + * @param appId application id + * @param idOfComponent id of the component to which calculate the status + * @param idOfChild children of the component as groups */ - public void onChildStatusChange(final String idOfChild, final String groupId, - final String appId) { - updateChild(idOfChild, groupId, appId); - } - - private void updateChild(final String idOfChild, final String groupId, final String appId) { - Runnable group = new Runnable() { - public void run() { - try { - ApplicationHolder.acquireWriteLock(); - ParentComponent component; - if (groupId.equals(appId)) { - //it is an application - component = ApplicationHolder.getApplications(). - getApplication(appId); - } else { - //it is a group - component = ApplicationHolder.getApplications(). - getApplication(appId).getGroupRecursively(groupId); - } - Map<String, ClusterDataHolder> clusterIds = component.getClusterDataMap(); - Map<String, Group> groups = component.getAliasToGroupMap(); - updateChildStatus(appId, idOfChild, groups, clusterIds, component); - } finally { - ApplicationHolder.releaseWriteLock(); + public void onChildStatusChange(String idOfChild, String idOfComponent, String appId) { + ParentComponent component; + Map<String, Group> groups; + Map<String, ClusterDataHolder> clusterData; - } + if (log.isInfoEnabled()) { + log.info("StatusChecker calculating the status for the group [ " + idOfChild + " ]"); + } + try { + ApplicationHolder.acquireWriteLock(); + if (idOfComponent.equals(appId)) { + //it is an application + component = ApplicationHolder.getApplications(). + getApplication(appId); + } else { + //it is a group + component = ApplicationHolder.getApplications(). + getApplication(appId).getGroupRecursively(idOfComponent); } - }; - Thread groupThread = new Thread(group); - groupThread.start(); - } + clusterData = component.getClusterDataMap(); + groups = component.getAliasToGroupMap(); - /** - * This will use to calculate whether all children of a particular component is active by travesing Top - * - * @param appId - * @param id - * @param groups - * @param clusterData - * @param parent - * @return - */ - private boolean updateChildStatus(String appId, String id, Map<String, Group> groups, - Map<String, ClusterDataHolder> clusterData, ParentComponent parent) { - boolean childFound = false; - boolean clusterFound = false; - - for (ClusterDataHolder clusterDataHolder : clusterData.values()) { - if (clusterDataHolder.getClusterId().equals(id)) { - clusterFound = true; - } - } - log.info("StatusChecker calculating the status for the group [ " + id + " ]"); - if (clusterFound || groups.containsKey(id)) { - childFound = true; - Application application = ApplicationHolder.getApplications().getApplication(appId); if (groups.isEmpty() && getAllClusterInSameState(clusterData, ClusterStatus.Active) || clusterData.isEmpty() && getAllGroupInSameState(groups, GroupStatus.Active) || getAllClusterInSameState(clusterData, ClusterStatus.Active) && getAllGroupInSameState(groups, GroupStatus.Active)) { //send activation event - if (parent instanceof Application) { + if (component instanceof Application) { //send application activated event - if (((Application) parent).getStatus() != ApplicationStatus.Active) { + if (((Application) component).getStatus() != ApplicationStatus.Active) { log.info("sending app activate: " + appId); ApplicationBuilder.handleApplicationActivatedEvent(appId); } - } else if (parent instanceof Group) { + } else if (component instanceof Group) { //send activation to the parent - if (((Group) parent).getStatus() != GroupStatus.Active) { - log.info("sending group activate: " + parent.getUniqueIdentifier()); - ApplicationBuilder.handleGroupActivatedEvent(appId, parent.getUniqueIdentifier()); + if (((Group) component).getStatus() != GroupStatus.Active) { + log.info("sending group activate: " + component.getUniqueIdentifier()); + ApplicationBuilder.handleGroupActivatedEvent(appId, component.getUniqueIdentifier()); } } } else if (groups.isEmpty() && getAllClusterInSameState(clusterData, ClusterStatus.Terminated) || @@ -346,73 +325,70 @@ public class StatusChecker { getAllClusterInSameState(clusterData, ClusterStatus.Terminated) && getAllGroupInSameState(groups, GroupStatus.Terminated)) { //send the terminated event - if (parent instanceof Application) { - //validating the life cycle - //if (application.getStatus() != ApplicationStatus.Terminated) { - log.info("sending app terminated: " + appId); - ApplicationBuilder.handleApplicationTerminatedEvent(appId); -// } else { -// log.info("[Application] " + appId + " is in the [status] " + -// application.getStatus().toString() + ". Hence not sending terminated event"); -// } - //StatusEventPublisher.sendApp(appId); - } else if (parent instanceof Group) { + if (component instanceof Application) { + log.info("sending app terminated: " + appId); + ApplicationBuilder.handleApplicationTerminatedEvent(appId); + } else if (component instanceof Group) { //send activation to the parent - if (((Group) parent).getStatus() != GroupStatus.Terminated) { - log.info("sending group terminated : " + parent.getUniqueIdentifier()); - ApplicationBuilder.handleGroupTerminatedEvent(appId, parent.getUniqueIdentifier()); + if (((Group) component).getStatus() != GroupStatus.Terminated) { + log.info("sending group terminated : " + component.getUniqueIdentifier()); + ApplicationBuilder.handleGroupTerminatedEvent(appId, component.getUniqueIdentifier()); } } } else if (groups.isEmpty() && getAllClusterInSameState(clusterData, ClusterStatus.Created) || clusterData.isEmpty() && getAllGroupInSameState(groups, GroupStatus.Created) || getAllClusterInSameState(clusterData, ClusterStatus.Created) && getAllGroupInSameState(groups, GroupStatus.Created)) { - if (parent instanceof Application) { + if (component instanceof Application) { log.info("[Application] " + appId + "couldn't change to Created, since it is" + - "already in " + application.getStatus().toString()); - } else if (parent instanceof Group) { + "already in " + ((Application) component).getStatus().toString()); + } else if (component instanceof Group) { //send activation to the parent - if (((Group) parent).getStatus() != GroupStatus.Created) { - log.info("sending group created : " + parent.getUniqueIdentifier()); - ApplicationBuilder.handleGroupCreatedEvent(appId, parent.getUniqueIdentifier()); + if (((Group) component).getStatus() != GroupStatus.Created) { + log.info("sending group created : " + component.getUniqueIdentifier()); + ApplicationBuilder.handleGroupCreatedEvent(appId, component.getUniqueIdentifier()); } } } else if (groups.isEmpty() && getAllClusterInactive(clusterData) || clusterData.isEmpty() && getAllGroupInActive(groups) || getAllClusterInactive(clusterData) || getAllGroupInActive(groups)) { //send the in activation event - if (parent instanceof Application) { + if (component instanceof Application) { //send application activated event log.warn("Application can't be in in-active : " + appId); //StatusEventPublisher.sendApplicationInactivatedEvent(appId); - } else if (parent instanceof Group) { + } else if (component instanceof Group) { //send activation to the parent - if (((Group) parent).getStatus() != GroupStatus.Inactive) { - log.info("sending group in-active: " + parent.getUniqueIdentifier()); - ApplicationBuilder.handleGroupInActivateEvent(appId, parent.getUniqueIdentifier()); + if (((Group) component).getStatus() != GroupStatus.Inactive) { + log.info("sending group in-active: " + component.getUniqueIdentifier()); + ApplicationBuilder.handleGroupInActivateEvent(appId, component.getUniqueIdentifier()); } } } else { - if (parent instanceof Application) { + if (component instanceof Application) { //send application activated event log.warn("Application can't be in in-active : " + appId); //StatusEventPublisher.sendApplicationInactivatedEvent(appId); - } else if (parent instanceof Group) { + } else if (component instanceof Group) { //send activation to the parent - if (((Group) parent).getStatus() != GroupStatus.Inactive) { - log.info("sending group in-active: " + parent.getUniqueIdentifier()); - ApplicationBuilder.handleGroupInActivateEvent(appId, parent.getUniqueIdentifier()); + if (((Group) component).getStatus() != GroupStatus.Inactive) { + log.info("sending group in-active: " + component.getUniqueIdentifier()); + ApplicationBuilder.handleGroupInActivateEvent(appId, component.getUniqueIdentifier()); } } } - return childFound; - } else { - log.warn("There is no child found in the [group/cluster] " + id + " found in the " + - "[component]" + parent.getUniqueIdentifier()); + } finally { + ApplicationHolder.releaseWriteLock(); + } - return childFound; } + /** + * Find out whether all the any group is inActive + * + * @param groups groups of a group/application + * @return whether inActive or not + */ private boolean getAllGroupInActive(Map<String, Group> groups) { boolean groupStat = false; for (Group group : groups.values()) { @@ -426,6 +402,13 @@ public class StatusChecker { return groupStat; } + /** + * Find out whether all the groups of a group in the same state or not + * + * @param groups groups of a group/application + * @param status the state to check in all groups + * @return whether groups in the given state or not + */ private boolean getAllGroupInSameState(Map<String, Group> groups, GroupStatus status) { boolean groupStat = false; for (Group group : groups.values()) { @@ -440,6 +423,12 @@ public class StatusChecker { } + /** + * Find out whether any of the clusters of a group in the InActive state + * + * @param clusterData clusters of the group + * @return whether inActive or not + */ private boolean getAllClusterInactive(Map<String, ClusterDataHolder> clusterData) { boolean clusterStat = false; for (Map.Entry<String, ClusterDataHolder> clusterDataHolderEntry : clusterData.entrySet()) { @@ -456,6 +445,13 @@ public class StatusChecker { return clusterStat; } + /** + * Find out whether all the clusters of a group are in the same state + * + * @param clusterData clusters of the group + * @param status the status to check of the group + * @return whether all groups in the same state or not + */ private boolean getAllClusterInSameState(Map<String, ClusterDataHolder> clusterData, ClusterStatus status) { boolean clusterStat = false; @@ -480,96 +476,6 @@ public class StatusChecker { return clusterStat; } - /*private GroupStatus getGroupStatus(Map<String, Group> groups) { - GroupStatus status = null; - boolean groupActive = true; - boolean groupTerminated = true; - boolean groupCreated = true; - - for (Group group : groups.values()) { - if (group.getStatus() == GroupStatus.Active) { - groupActive = groupActive && true; - groupTerminated = false; - groupCreated = false; - } else if (group.getStatus() == GroupStatus.Inactive) { - status = GroupStatus.Inactive; - groupActive = false; - groupTerminated = false; - groupCreated = false; - break; - } else if (group.getStatus() == GroupStatus.Terminated) { - groupActive = false; - groupCreated = false; - groupTerminated = groupTerminated && true; - } else if (group.getStatus() == GroupStatus.Created) { - groupActive = false; - groupTerminated = false; - groupCreated = groupCreated && true; - } - } - - if (groups == null || groups != null && groups.isEmpty()) { - groupActive = false; - groupTerminated = false; - groupCreated = false; - } - - if (groupActive) { - status = GroupStatus.Active; - } else if (groupTerminated) { - status = GroupStatus.Terminated; - } else if (groupCreated) { - status = GroupStatus.Created; - } - return status; - - } - - private ClusterStatus getClusterStatus(Map<String, ClusterDataHolder> clusterData) { - ClusterStatus status = null; - boolean clusterActive = true; - boolean clusterTerminated = true; - boolean clusterCreated = true; - for (Map.Entry<String, ClusterDataHolder> clusterDataHolderEntry : clusterData.entrySet()) { - Service service = TopologyManager.getTopology().getService(clusterDataHolderEntry.getValue().getServiceType()); - Cluster cluster = service.getCluster(clusterDataHolderEntry.getValue().getClusterId()); - if (cluster.getStatus() == ClusterStatus.Active) { - clusterActive = clusterActive && true; - clusterTerminated = false; - clusterCreated = false; - } else if (cluster.getStatus() == ClusterStatus.Inactive) { - status = ClusterStatus.Inactive; - clusterActive = false; - clusterTerminated = false; - clusterCreated = false; - break; - } else if (cluster.getStatus() == ClusterStatus.Terminated) { - clusterActive = false; - clusterCreated = false; - clusterTerminated = clusterTerminated && true; - } else if (cluster.getStatus() == ClusterStatus.Created) { - clusterActive = false; - clusterTerminated = false; - clusterCreated = clusterCreated && true; - } - } - - if (clusterData == null || clusterData != null && clusterData.isEmpty()) { - clusterActive = false; - clusterTerminated = false; - clusterCreated = false; - } - - if (clusterActive) { - status = ClusterStatus.Active; - } else if (clusterTerminated) { - status = ClusterStatus.Terminated; - } else if (clusterCreated) { - status = ClusterStatus.Created; - } - return status; - }*/ - private static class Holder { private static final StatusChecker INSTANCE = new StatusChecker(); }
