You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2014/12/12 11:11:07 UTC
[05/50] stratos git commit: making status checking call async
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/master
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();
}
}