You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2014/12/11 06:02:17 UTC
[1/2] stratos git commit: adding a map to keep track of inactive and
terminating instances
Repository: stratos
Updated Branches:
refs/heads/4.1.0-test 65e6c0ea5 -> 58800b3d2
adding a map to keep track of inactive and terminating instances
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c920d2e0
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c920d2e0
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c920d2e0
Branch: refs/heads/4.1.0-test
Commit: c920d2e03617f58316184fee6e25768177259b96
Parents: 65e6c0e
Author: reka <rt...@gmail.com>
Authored: Wed Dec 10 20:27:48 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Thu Dec 11 10:30:51 2014 +0530
----------------------------------------------------------------------
.../monitor/component/ApplicationMonitor.java | 23 ++--
.../monitor/component/GroupMonitor.java | 42 +++----
.../component/ParentComponentMonitor.java | 117 ++++++++++++-------
3 files changed, 103 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/c920d2e0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
index 9026966..f8f2e82 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java
@@ -129,36 +129,33 @@ public class ApplicationMonitor extends ParentComponentMonitor {
@Override
public void onChildStatusEvent(MonitorStatusEvent statusEvent) {
- String id = statusEvent.getId();
+ String childId = statusEvent.getId();
String instanceId = statusEvent.getInstanceId();
LifeCycleState status1 = statusEvent.getStatus();
//Events coming from parent are In_Active(in faulty detection), Scaling events, termination
if (status1 == ClusterStatus.Active || status1 == GroupStatus.Active) {
- onChildActivatedEvent(id, instanceId);
+ onChildActivatedEvent(childId, instanceId);
} else if (status1 == ClusterStatus.Inactive || status1 == GroupStatus.Inactive) {
- this.markMonitorAsInactive(id);
- onChildInactiveEvent(id, instanceId);
+ this.markInstanceAsInactive(childId, instanceId);
+ onChildInactiveEvent(childId, instanceId);
} else if (status1 == ClusterStatus.Terminating || status1 == GroupStatus.Terminating) {
- //mark the child monitor as inactive in the map
- this.markMonitorAsTerminating(id);
+ //mark the child monitor as inActive in the map
+ markInstanceAsTerminating(childId, instanceId);
} else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated) {
//Check whether all dependent goes Terminated and then start them in parallel.
- if (this.terminatingMonitorsList.contains(id)) {
- this.terminatingMonitorsList.remove(id);
- this.aliasToActiveMonitorsMap.remove(id);
- } else {
- log.warn("[monitor] " + id + " cannot be found in the inactive monitors list");
- }
+ removeInstanceFromFromInactiveMap(childId, instanceId);
+ removeInstanceFromFromTerminatingMap(childId, instanceId);
+
ApplicationInstance instance = (ApplicationInstance) instanceIdToInstanceMap.get(instanceId);
if (instance != null) {
if (instance.getStatus() == ApplicationStatus.Terminating) {
ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().process(this.id,
appId, instanceId);
} else {
- onChildTerminatedEvent(id, instanceId);
+ onChildTerminatedEvent(childId, instanceId);
}
} else {
log.warn("The required instance cannot be found in the the [GroupMonitor] " +
http://git-wip-us.apache.org/repos/asf/stratos/blob/c920d2e0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
index 8ba999b..c139ff5 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
@@ -125,10 +125,10 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
*/
public void setStatus(GroupStatus status, String instanceId) {
GroupInstance groupInstance = (GroupInstance) this.instanceIdToInstanceMap.get(instanceId);
- if(groupInstance == null) {
+ if (groupInstance == null) {
log.warn("The required group [instance] " + instanceId + " not found in the GroupMonitor");
} else {
- if(groupInstance.getStatus() != status) {
+ if (groupInstance.getStatus() != status) {
groupInstance.setStatus(status);
}
}
@@ -173,49 +173,45 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
@Override
public void onChildStatusEvent(MonitorStatusEvent statusEvent) {
- String id = statusEvent.getId();
+ String childId = statusEvent.getId();
String instanceId = statusEvent.getInstanceId();
LifeCycleState status1 = statusEvent.getStatus();
//Events coming from parent are In_Active(in faulty detection), Scaling events, termination
if (status1 == ClusterStatus.Active || status1 == GroupStatus.Active) {
- onChildActivatedEvent(id, instanceId);
+ onChildActivatedEvent(childId, instanceId);
} else if (status1 == ClusterStatus.Inactive || status1 == GroupStatus.Inactive) {
//handling restart of stratos
- if (!this.aliasToActiveMonitorsMap.get(id).hasStartupDependents()) {
- onChildActivatedEvent(id, instanceId);
+ if (!this.aliasToActiveMonitorsMap.get(childId).hasStartupDependents()) {
+ onChildActivatedEvent(childId, instanceId);
} else {
- this.markMonitorAsInactive(instanceId);
- onChildInactiveEvent(id, instanceId);
+ this.markInstanceAsInactive(childId, instanceId);
+ onChildInactiveEvent(childId, instanceId);
}
-
} else if (status1 == ClusterStatus.Terminating || status1 == GroupStatus.Terminating) {
- //mark the child monitor as inactive in the map
- this.markMonitorAsTerminating(instanceId);
+ //mark the child monitor as inActive in the map
+ markInstanceAsTerminating(childId, instanceId);
} else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated) {
//Check whether all dependent goes Terminated and then start them in parallel.
- if (this.terminatingMonitorsList.contains(id)) {
- this.terminatingMonitorsList.remove(id);
- this.aliasToActiveMonitorsMap.remove(id);
- } else {
- log.warn("[monitor] " + id + " cannot be found in the inactive monitors list");
- }
+ removeInstanceFromFromInactiveMap(childId, instanceId);
+ removeInstanceFromFromTerminatingMap(childId, instanceId);
GroupInstance instance = (GroupInstance) this.instanceIdToInstanceMap.get(instanceId);
if (instance != null) {
if (instance.getStatus() == GroupStatus.Terminating || instance.getStatus() == GroupStatus.Terminated) {
ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().process(this.id,
appId, instanceId);
} else {
- onChildTerminatedEvent(id, instanceId);
+ onChildTerminatedEvent(childId, instanceId);
}
} else {
log.warn("The required instance cannot be found in the the [GroupMonitor] " +
this.id);
}
}
+
}
@Override
@@ -388,7 +384,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
if (parentPartitionId != null &&
networkPartitionContext.getPartitionCtxt(parentPartitionId) == null) {
partitionContext = new GroupLevelPartitionContext(parentPartitionId,
- networkPartitionId);
+ networkPartitionId);
networkPartitionContext.addPartitionContext((GroupLevelPartitionContext) partitionContext);
if (log.isInfoEnabled()) {
log.info("[Partition] " + parentPartitionId + "has been added for the " +
@@ -627,14 +623,14 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
return networkPartitionCtxts;
}
- public GroupLevelNetworkPartitionContext getNetworkPartitionContext(String networkPartitionId) {
- return this.networkPartitionCtxts.get(networkPartitionId);
- }
-
public void setNetworkPartitionCtxts(Map<String, GroupLevelNetworkPartitionContext> networkPartitionCtxts) {
this.networkPartitionCtxts = networkPartitionCtxts;
}
+ public GroupLevelNetworkPartitionContext getNetworkPartitionContext(String networkPartitionId) {
+ return this.networkPartitionCtxts.get(networkPartitionId);
+ }
+
public void addNetworkPartitionContext(GroupLevelNetworkPartitionContext clusterLevelNetworkPartitionContext) {
this.networkPartitionCtxts.put(clusterLevelNetworkPartitionContext.getId(), clusterLevelNetworkPartitionContext);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c920d2e0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
index a0e552c..050d85d 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
@@ -43,15 +43,14 @@ import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
import org.apache.stratos.autoscaler.monitor.cluster.VMClusterMonitor;
import org.apache.stratos.autoscaler.monitor.events.builder.MonitorStatusEventBuilder;
import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
-import org.apache.stratos.messaging.domain.applications.Group;
import org.apache.stratos.messaging.domain.applications.GroupStatus;
import org.apache.stratos.messaging.domain.applications.ParentComponent;
import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.instance.Instance;
import org.apache.stratos.messaging.domain.topology.ClusterStatus;
import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Monitor is to monitor it's child monitors and
@@ -68,15 +67,15 @@ public abstract class ParentComponentMonitor extends Monitor {
protected Map<String, Monitor> aliasToActiveMonitorsMap;
//Pending monitors list
protected List<String> pendingMonitorsList;
- //instanceIds map, stopped monitors
- protected List<String> inactiveMonitorsList;
- //terminating instances list
- protected List<String> terminatingMonitorsList;
+ //instanceIds map, key=alias, value instanceIds stopped monitors
+ protected Map<String, List<String>> inactiveInstancesMap;
+ //terminating map, key=alias, value instanceIds
+ protected Map<String, List<String>> terminatingInstancesMap;
public ParentComponentMonitor(ParentComponent component) throws DependencyBuilderException {
- aliasToActiveMonitorsMap = new HashMap<String, Monitor>();
- inactiveMonitorsList = new ArrayList<String>();
- terminatingMonitorsList = new ArrayList<String>();
+ aliasToActiveMonitorsMap = new ConcurrentHashMap<String, Monitor>();
+ inactiveInstancesMap = new ConcurrentHashMap<String, List<String>>();
+ terminatingInstancesMap = new ConcurrentHashMap<String, List<String>>();
pendingMonitorsList = new ArrayList<String>();
//clusterIdToClusterMonitorsMap = new HashMap<String, AbstractClusterMonitor>();
this.id = component.getUniqueIdentifier();
@@ -235,24 +234,18 @@ public abstract class ParentComponentMonitor extends Monitor {
/**
* 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
+ * @param childId parent id of the event which received
*/
- protected void onChildActivatedEvent(String eventId, String instanceId) {
+ protected void onChildActivatedEvent(String childId, String instanceId) {
try {
- //if the activated monitor is in in_active map move it to active map
- if (this.inactiveMonitorsList.contains(eventId)) {
- this.inactiveMonitorsList.remove(eventId);
- }
-
- if (this.terminatingMonitorsList.contains(eventId)) {
- this.terminatingMonitorsList.remove(eventId);
- }
+ removeInstanceFromFromInactiveMap(childId, instanceId);
+ removeInstanceFromFromTerminatingMap(childId, instanceId);
boolean startDep;
- if (!aliasToActiveMonitorsMap.containsKey(eventId) || !pendingMonitorsList.contains(eventId)) {
- startDep = startDependency(eventId, instanceId);
+ if (!aliasToActiveMonitorsMap.containsKey(childId) || !pendingMonitorsList.contains(childId)) {
+ startDep = startDependency(childId, instanceId);
} else {
- startDep = startDependencyByInstanceCreation(eventId, instanceId);
+ startDep = startDependencyByInstanceCreation(childId, instanceId);
}
//Checking whether all the monitors got created
@@ -260,7 +253,7 @@ public abstract class ParentComponentMonitor extends Monitor {
ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().
process(this.id, this.appId, instanceId);
} else {
- log.info("started a child: " + startDep + " by the group/cluster: " + eventId);
+ log.info("started a child: " + startDep + " by the group/cluster: " + childId);
}
} catch (MonitorNotFoundException e) {
//TODO revert the siblings and notify parent, change a flag for reverting/un-subscription
@@ -399,7 +392,7 @@ public abstract class ParentComponentMonitor extends Monitor {
log.warn("Dependent [monitor] " + context1.getId() + " not in the correct state");
allDependentTerminated = false;
return allDependentTerminated;
- } else if (this.inactiveMonitorsList.contains(context1.getId())) {
+ } else if (this.inactiveInstancesMap.containsKey(context1.getId())) {
log.info("Waiting for the [dependent] " + context1.getId() + " to be terminated...");
allDependentTerminated = false;
return allDependentTerminated;
@@ -415,7 +408,8 @@ public abstract class ParentComponentMonitor extends Monitor {
String instanceId) {
boolean parentsTerminated = false;
for (ApplicationChildContext context1 : parentContexts) {
- if (this.inactiveMonitorsList.contains(context1.getId())) {
+ if (this.inactiveInstancesMap.containsKey(context1.getId()) &&
+ this.inactiveInstancesMap.get(context1.getId()).contains(instanceId)) {
log.info("Waiting for the [Parent Monitor] " + context1.getId()
+ " to be terminated");
parentsTerminated = false;
@@ -437,8 +431,10 @@ public abstract class ParentComponentMonitor extends Monitor {
private boolean allParentActive(List<ApplicationChildContext> parentContexts, String instanceId) {
boolean parentsActive = false;
for (ApplicationChildContext context1 : parentContexts) {
- if (this.inactiveMonitorsList.contains(instanceId) ||
- this.terminatingMonitorsList.contains(instanceId)) {
+ if (this.inactiveInstancesMap.containsKey(context1.getId()) &&
+ this.inactiveInstancesMap.get(context1.getId()).contains(instanceId) ||
+ this.terminatingInstancesMap.containsKey(context1.getId()) &&
+ this.terminatingInstancesMap.get(context1.getId()).contains(instanceId)) {
parentsActive = false;
log.info("Dependent [Monitor] " + context1.getId()
+ " is not yet active");
@@ -478,20 +474,55 @@ public abstract class ParentComponentMonitor extends Monitor {
}
// move to inactive monitors list to use in the Terminated event
- protected synchronized void markMonitorAsInactive(String monitorKey) {
+ protected synchronized void markInstanceAsInactive(String childId, String instanceId) {
+
+ if (!this.inactiveInstancesMap.containsKey(childId)) {
+ this.inactiveInstancesMap.get(childId).add(instanceId);
+ } else {
+ List<String> instanceIds = new ArrayList<String>();
+ instanceIds.add(instanceId);
+ this.inactiveInstancesMap.put(childId, instanceIds);
+ }
+ }
+
+ // move to inactive monitors list to use in the Terminated event
+ protected synchronized void removeInstanceFromFromInactiveMap(String childId, String instanceId) {
+ if (this.inactiveInstancesMap.containsKey(childId) &&
+ this.inactiveInstancesMap.get(childId).contains(instanceId)) {
+ this.inactiveInstancesMap.get(childId).remove(instanceId);
+ if(this.inactiveInstancesMap.get(childId).isEmpty()) {
+ this.inactiveInstancesMap.remove(childId);
+ }
+ }
+ }
- if (!this.inactiveMonitorsList.contains(monitorKey)) {
- this.inactiveMonitorsList.add(monitorKey);
+ // move to inactive monitors list to use in the Terminated event
+ protected synchronized void removeInstanceFromFromTerminatingMap(String childId, String instanceId) {
+ if (this.terminatingInstancesMap.containsKey(childId) &&
+ this.terminatingInstancesMap.get(childId).contains(instanceId)) {
+ this.terminatingInstancesMap.get(childId).remove(instanceId);
+ if(this.terminatingInstancesMap.get(childId).isEmpty()) {
+ this.terminatingInstancesMap.remove(childId);
+ }
}
}
// 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);
+ protected synchronized void markInstanceAsTerminating(String childId, String instanceId) {
+ if (!this.terminatingInstancesMap.containsKey(childId)) {
+ if (this.inactiveInstancesMap.containsKey(childId) &&
+ this.inactiveInstancesMap.get(childId).contains(instanceId)) {
+ this.inactiveInstancesMap.get(childId).remove(instanceId);
+ this.terminatingInstancesMap.get(childId).add(instanceId);
+ } else {
+ if (this.inactiveInstancesMap.containsKey(childId) &&
+ this.inactiveInstancesMap.get(childId).contains(instanceId)) {
+ this.inactiveInstancesMap.get(childId).remove(instanceId);
+ }
+ List<String> instanceIds = new ArrayList<String>();
+ instanceIds.add(instanceId);
+ this.terminatingInstancesMap.put(childId, instanceIds);
}
- this.terminatingMonitorsList.add(monitorKey);
}
}
@@ -552,20 +583,20 @@ public abstract class ParentComponentMonitor extends Monitor {
return hasInDepChild;
}
- public List<String> getAliasToInActiveMonitorsMap() {
- return this.inactiveMonitorsList;
+ public Map<String, List<String>> getAliasToInActiveMonitorsMap() {
+ return this.inactiveInstancesMap;
}
- public void setAliasToInActiveMonitorsMap(List<String> inactiveMonitorsList) {
- this.inactiveMonitorsList = inactiveMonitorsList;
+ public void setAliasToInActiveMonitorsMap(Map<String, List<String>> inactiveMonitorsList) {
+ this.inactiveInstancesMap = inactiveMonitorsList;
}
- public List<String> getTerminatingMonitorsList() {
- return terminatingMonitorsList;
+ public Map<String, List<String>> getTerminatingInstancesMap() {
+ return terminatingInstancesMap;
}
- public void setTerminatingMonitorsList(List<String> terminatingMonitorsList) {
- this.terminatingMonitorsList = terminatingMonitorsList;
+ public void setTerminatingInstancesMap(Map<String, List<String>> terminatingInstancesMap) {
+ this.terminatingInstancesMap = terminatingInstancesMap;
}
public AutoscaleAlgorithm getAutoscaleAlgorithm(String partitionAlgorithm) {
[2/2] stratos git commit: making status checking call async
Posted by re...@apache.org.
making status checking call async
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/58800b3d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/58800b3d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/58800b3d
Branch: refs/heads/4.1.0-test
Commit: 58800b3d2437b373ec69ab5ac70e1543dd63d0b8
Parents: c920d2e
Author: reka <rt...@gmail.com>
Authored: Thu Dec 11 10:26:46 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Thu Dec 11 10:32:04 2014 +0530
----------------------------------------------------------------------
.../monitor/component/GroupMonitor.java | 122 ++++++++++---------
.../component/ParentComponentMonitor.java | 4 +-
.../cluster/ClusterStatusProcessorChain.java | 3 +-
.../group/GroupStatusProcessorChain.java | 29 +++--
4 files changed, 88 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/58800b3d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
index c139ff5..98e04c5 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java
@@ -132,36 +132,36 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
groupInstance.setStatus(status);
}
}
- if (status == GroupStatus.Inactive && !this.hasStartupDependents) {
+ /*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());
- if (this.isGroupScalingEnabled()) {
- ApplicationHolder.acquireReadLock();
- try {
- Application application = ApplicationHolder.getApplications().
- getApplication(this.appId);
- if (application != null) {
- //Notifying the parent using parent's instance Id,
- // as it has group scaling enabled.
- Group group = application.getGroupRecursively(this.id);
- if (group != null) {
- GroupInstance context = group.getInstanceContexts(instanceId);
- MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent,
- status, this.id, context.getParentId());
+ } else {*/
+ // notify parent
+ log.info("[Group] " + this.id + "is notifying the [parent] " + this.parent.getId());
+ if (this.isGroupScalingEnabled()) {
+ ApplicationHolder.acquireReadLock();
+ try {
+ Application application = ApplicationHolder.getApplications().
+ getApplication(this.appId);
+ if (application != null) {
+ //Notifying the parent using parent's instance Id,
+ // as it has group scaling enabled.
+ Group group = application.getGroupRecursively(this.id);
+ if (group != null) {
+ GroupInstance context = group.getInstanceContexts(instanceId);
+ MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent,
+ status, this.id, context.getParentId());
- }
}
- } finally {
- ApplicationHolder.releaseReadLock();
}
- } else {
- MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent,
- status, this.id, instanceId);
+ } finally {
+ ApplicationHolder.releaseReadLock();
}
+ } else {
+ MonitorStatusEventBuilder.handleGroupStatusEvent(this.parent,
+ status, this.id, instanceId);
}
+ //}
//notify the children about the state change
try {
MonitorStatusEventBuilder.notifyChildren(this, new GroupStatusEvent(status, this.id, instanceId));
@@ -173,44 +173,54 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
@Override
public void onChildStatusEvent(MonitorStatusEvent statusEvent) {
- String childId = statusEvent.getId();
- String instanceId = statusEvent.getInstanceId();
- LifeCycleState status1 = statusEvent.getStatus();
- //Events coming from parent are In_Active(in faulty detection), Scaling events, termination
-
- if (status1 == ClusterStatus.Active || status1 == GroupStatus.Active) {
- onChildActivatedEvent(childId, instanceId);
+ final String childId = statusEvent.getId();
+ final String instanceId = statusEvent.getInstanceId();
+ final LifeCycleState status1 = statusEvent.getStatus();
+ final String id = this.id;
+ //TODO get lock when executing this
+ Runnable monitoringRunnable = new Runnable() {
+ @Override
+ public void run() {
+ //Events coming from parent are In_Active(in faulty detection), Scaling events, termination
- } else if (status1 == ClusterStatus.Inactive || status1 == GroupStatus.Inactive) {
- //handling restart of stratos
- if (!this.aliasToActiveMonitorsMap.get(childId).hasStartupDependents()) {
- onChildActivatedEvent(childId, instanceId);
- } else {
- this.markInstanceAsInactive(childId, instanceId);
- onChildInactiveEvent(childId, instanceId);
- }
+ if (status1 == ClusterStatus.Active || status1 == GroupStatus.Active) {
+ onChildActivatedEvent(childId, instanceId);
- } else if (status1 == ClusterStatus.Terminating || status1 == GroupStatus.Terminating) {
- //mark the child monitor as inActive in the map
- markInstanceAsTerminating(childId, instanceId);
+ } else if (status1 == ClusterStatus.Inactive || status1 == GroupStatus.Inactive) {
+ //handling restart of stratos
+ if (!aliasToActiveMonitorsMap.get(childId).hasStartupDependents()) {
+ onChildActivatedEvent(childId, instanceId);
+ } else {
+ markInstanceAsInactive(childId, instanceId);
+ onChildInactiveEvent(childId, instanceId);
+ }
- } else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated) {
- //Check whether all dependent goes Terminated and then start them in parallel.
- removeInstanceFromFromInactiveMap(childId, instanceId);
- removeInstanceFromFromTerminatingMap(childId, instanceId);
- GroupInstance instance = (GroupInstance) this.instanceIdToInstanceMap.get(instanceId);
- if (instance != null) {
- if (instance.getStatus() == GroupStatus.Terminating || instance.getStatus() == GroupStatus.Terminated) {
- ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().process(this.id,
- appId, instanceId);
- } else {
- onChildTerminatedEvent(childId, instanceId);
+ } else if (status1 == ClusterStatus.Terminating || status1 == GroupStatus.Terminating) {
+ //mark the child monitor as inActive in the map
+ markInstanceAsTerminating(childId, instanceId);
+
+ } else if (status1 == ClusterStatus.Terminated || status1 == GroupStatus.Terminated) {
+ //Check whether all dependent goes Terminated and then start them in parallel.
+ removeInstanceFromFromInactiveMap(childId, instanceId);
+ removeInstanceFromFromTerminatingMap(childId, instanceId);
+
+ GroupInstance instance = (GroupInstance) instanceIdToInstanceMap.get(instanceId);
+ if (instance != null) {
+ if (instance.getStatus() == GroupStatus.Terminating || instance.getStatus() == GroupStatus.Terminated) {
+ ServiceReferenceHolder.getInstance().getGroupStatusProcessorChain().process(id,
+ appId, instanceId);
+ } else {
+ onChildTerminatedEvent(childId, instanceId);
+ }
+ } else {
+ log.warn("The required instance cannot be found in the the [GroupMonitor] " +
+ id);
+ }
}
- } else {
- log.warn("The required instance cannot be found in the the [GroupMonitor] " +
- this.id);
}
- }
+ };
+ monitoringRunnable.run();
+
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/58800b3d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
index 050d85d..9f6ca75 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java
@@ -476,7 +476,7 @@ public abstract class ParentComponentMonitor extends Monitor {
// move to inactive monitors list to use in the Terminated event
protected synchronized void markInstanceAsInactive(String childId, String instanceId) {
- if (!this.inactiveInstancesMap.containsKey(childId)) {
+ if (this.inactiveInstancesMap.containsKey(childId)) {
this.inactiveInstancesMap.get(childId).add(instanceId);
} else {
List<String> instanceIds = new ArrayList<String>();
@@ -509,7 +509,7 @@ public abstract class ParentComponentMonitor extends Monitor {
// move to inactive monitors list to use in the Terminated event
protected synchronized void markInstanceAsTerminating(String childId, String instanceId) {
- if (!this.terminatingInstancesMap.containsKey(childId)) {
+ if (this.terminatingInstancesMap.containsKey(childId)) {
if (this.inactiveInstancesMap.containsKey(childId) &&
this.inactiveInstancesMap.get(childId).contains(instanceId)) {
this.inactiveInstancesMap.get(childId).remove(instanceId);
http://git-wip-us.apache.org/repos/asf/stratos/blob/58800b3d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusProcessorChain.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusProcessorChain.java
index 1d5355b..4787a6f 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusProcessorChain.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusProcessorChain.java
@@ -41,12 +41,13 @@ public class ClusterStatusProcessorChain extends StatusProcessorChain {
}
- public boolean process(String type, String clusterId, String instanceId) {
+ public boolean process(final String type, final String clusterId, final String instanceId) {
ClusterStatusProcessor root = (ClusterStatusProcessor) list.getFirst();
if (root == null) {
throw new RuntimeException("Message processor chain is not initialized");
}
return root.process(type, clusterId, instanceId);
+
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/58800b3d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java
index 5724669..9b0631e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessorChain.java
@@ -49,18 +49,25 @@ public class GroupStatusProcessorChain extends StatusProcessorChain {
}
- public boolean process(String idOfComponent, String appId,
- String instanceId) {
- GroupStatusProcessor root = (GroupStatusProcessor) list.getFirst();
- if (root == null) {
- throw new RuntimeException("Message processor chain is not initialized");
- }
- if (log.isInfoEnabled()) {
- log.info("GroupProcessor chain calculating the status for the group " +
- "[ " + idOfComponent + " ]");
- }
+ public void process(final String idOfComponent, final String appId,
+ final String instanceId) {
- return root.process(idOfComponent, appId, instanceId);
+ Runnable monitoringRunnable = new Runnable() {
+ @Override
+ public void run() {
+ GroupStatusProcessor root = (GroupStatusProcessor) list.getFirst();
+ if (root == null) {
+ throw new RuntimeException("Message processor chain is not initialized");
+ }
+ if (log.isInfoEnabled()) {
+ log.info("GroupProcessor chain calculating the status for the group " +
+ "[ " + idOfComponent + " ]");
+ }
+
+ root.process(idOfComponent, appId, instanceId);
+ }
+ };
+ monitoringRunnable.run();
}
}