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/15 10:14:04 UTC
[3/3] stratos git commit: speed up termination process and refactoring
speed up termination process and refactoring
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/15cd21fb
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/15cd21fb
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/15cd21fb
Branch: refs/heads/4.1.0-test
Commit: 15cd21fb4371ce2a951419c817172d9d0e9a9e13
Parents: bbc838a
Author: reka <rt...@gmail.com>
Authored: Mon Dec 15 11:58:39 2014 +0530
Committer: reka <rt...@gmail.com>
Committed: Mon Dec 15 13:57:02 2014 +0530
----------------------------------------------------------------------
.../AutoscalerTopologyEventReceiver.java | 1 +
.../autoscaler/monitor/MonitorFactory.java | 49 +++++-------------
.../monitor/cluster/VMClusterMonitor.java | 52 ++++++++------------
.../monitor/component/GroupMonitor.java | 3 +-
4 files changed, 34 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/15cd21fb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
index 87a9c91..08f5ca5 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -469,6 +469,7 @@ public class AutoscalerTopologyEventReceiver {
log.info("Monitoring task for Cluster Monitor with cluster id "
+ clusterInstanceCreatedEvent.getClusterId() + " started successfully");
} else {
+ //monitor already started. Invoking it directly to speed up the process
((VMClusterMonitor)clusterMonitor).monitor();
}
} catch (PolicyValidationException e) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/15cd21fb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
index 6c26ad8..d4414af 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
@@ -35,7 +35,6 @@ import org.apache.stratos.autoscaler.monitor.cluster.VMClusterMonitor;
import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
import org.apache.stratos.autoscaler.monitor.component.GroupMonitor;
import org.apache.stratos.autoscaler.monitor.component.ParentComponentMonitor;
-import org.apache.stratos.common.constants.StratosConstants;
import org.apache.stratos.messaging.domain.applications.Application;
import org.apache.stratos.messaging.domain.applications.Group;
import org.apache.stratos.messaging.domain.applications.ScalingDependentList;
@@ -83,7 +82,6 @@ public class MonitorFactory {
}
-
/**
* This will create the GroupMonitor based on given groupId by going thr Topology
*
@@ -107,17 +105,15 @@ public class MonitorFactory {
Group group = ApplicationHolder.getApplications().
getApplication(appId).getGroupRecursively(context.getId());
-
boolean hasScalingDependents = false;
- if(parentMonitor.getScalingDependencies() != null) {
- for (ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()){
-
- if(scalingDependentList.getScalingDependentListComponents().contains(context.getId())){
-
+ if (parentMonitor.getScalingDependencies() != null) {
+ for (ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()) {
+ if (scalingDependentList.getScalingDependentListComponents().contains(context.getId())) {
hasScalingDependents = true;
}
}
}
+
groupMonitor = new GroupMonitor(group, appId, instanceIds, hasScalingDependents);
groupMonitor.setAppId(appId);
if (parentMonitor != null) {
@@ -130,15 +126,6 @@ public class MonitorFactory {
groupMonitor.setHasStartupDependents(false);
}
}
-
-
- if (group.isGroupScalingEnabled()) {
- groupMonitor.setGroupScalingEnabled(true);
- } else if (parentMonitor instanceof GroupMonitor) {
- /*if (parentMonitor.hasScalingDependents() || parentMonitor.getList --> not empty) {
- groupMonitor.setHasScalingDependents(true);
- }*/
- }
} finally {
ApplicationHolder.releaseReadLock();
@@ -147,7 +134,7 @@ public class MonitorFactory {
Group group = ApplicationHolder.getApplications().
getApplication(appId).getGroupRecursively(context.getId());
//Starting the minimum dependencies
- initialStartup = groupMonitor.createInstanceAndStartDependencyAtStartup(group, instanceIds);
+ groupMonitor.createInstanceAndStartDependencyAtStartup(group, instanceIds);
/**
* If not first app deployment, acquiring read lock to check current the status of the group,
@@ -200,7 +187,7 @@ public class MonitorFactory {
}
- initialStartup = applicationMonitor.startMinimumDependencies(application);
+ applicationMonitor.startMinimumDependencies(application);
/*//If not first app deployment, then calculate the current status of the app instance.
if (!initialStartup) {
@@ -257,16 +244,15 @@ public class MonitorFactory {
}
boolean hasScalingDependents = false;
- for (ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()){
-
- if(scalingDependentList.getScalingDependentListComponents().contains("cartridge." + clusterId.substring(0, clusterId.indexOf('.')))){
-
+ for (ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()) {
+ if (scalingDependentList.getScalingDependentListComponents().
+ contains("cartridge." + clusterId.substring(0, clusterId.indexOf('.')))) {
hasScalingDependents = true;
}
}
boolean groupScalingEnabledSubtree = false;
- if(parentMonitor instanceof GroupMonitor){
+ if (parentMonitor instanceof GroupMonitor) {
GroupMonitor groupMonitor = (GroupMonitor) parentMonitor;
groupScalingEnabledSubtree = findIfChildIsInGroupScalingEnabledSubTree(groupMonitor);
@@ -285,35 +271,24 @@ public class MonitorFactory {
clusterMonitor.setHasStartupDependents(false);
}
- //setting the scaling dependent behaviour of the cluster monitor
-// if (parentMonitor.hasScalingDependents() || (context.isGroupScalingEnabled())) {
-// clusterMonitor.setHasScalingDependents(true);
-// } else {
-// clusterMonitor.setHasScalingDependents(false);
-// }
//Creating the instance of the cluster
- ((VMClusterMonitor)clusterMonitor).createClusterInstance(parentInstanceIds, cluster);
+ ((VMClusterMonitor) clusterMonitor).createClusterInstance(parentInstanceIds, cluster);
//add it to autoscaler context
AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
-
return clusterMonitor;
-
} finally {
TopologyManager.releaseReadLockForCluster(serviceName, clusterId);
}
}
private static boolean findIfChildIsInGroupScalingEnabledSubTree(GroupMonitor groupMonitor) {
-
boolean groupScalingEnabledSubtree = false;
ParentComponentMonitor parentComponentMonitor = groupMonitor.getParent();
- if(parentComponentMonitor != null && parentComponentMonitor instanceof GroupMonitor){
-
+ if (parentComponentMonitor != null && parentComponentMonitor instanceof GroupMonitor) {
findIfChildIsInGroupScalingEnabledSubTree((GroupMonitor) parentComponentMonitor);
} else {
-
return groupMonitor.isGroupScalingEnabled();
}
return groupScalingEnabledSubtree;
http://git-wip-us.apache.org/repos/asf/stratos/blob/15cd21fb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
index 653499f..7d8f2b4 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java
@@ -34,8 +34,8 @@ import org.apache.stratos.autoscaler.exception.InvalidArgumentException;
import org.apache.stratos.autoscaler.exception.cartridge.TerminationException;
import org.apache.stratos.autoscaler.exception.partition.PartitionValidationException;
import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
-import org.apache.stratos.autoscaler.monitor.events.ScalingEvent;
import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent;
+import org.apache.stratos.autoscaler.monitor.events.ScalingEvent;
import org.apache.stratos.autoscaler.monitor.events.ScalingOverMaxEvent;
import org.apache.stratos.autoscaler.monitor.events.builder.MonitorStatusEventBuilder;
import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
@@ -243,7 +243,7 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
if (log.isDebugEnabled()) {
log.debug(String.format("Running minimum check for cluster instance %s ",
- instanceContext.getId() + " for the cluster: " + clusterId));
+ instanceContext.getId() + " for the cluster: " + clusterId));
}
minCheckFactHandle = AutoscalerRuleEvaluator.evaluate(getMinCheckKnowledgeSession(),
@@ -331,14 +331,6 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
}
}
-// public String getLbReferenceType() {
-// return lbReferenceType;
-// }
-//
-// public void setLbReferenceType(String lbReferenceType) {
-// this.lbReferenceType = lbReferenceType;
-// }
-
@Override
public void destroy() {
getMinCheckKnowledgeSession().dispose();
@@ -354,7 +346,6 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
@Override
public String toString() {
return "VMClusterMonitor [clusterId=" + getClusterId() +
-// ", lbReferenceType=" + lbReferenceType +
", hasPrimary=" + hasPrimary + " ]";
}
@@ -915,20 +906,9 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
String memberId = memberReadyToShutdownEvent.getMemberId();
String partitionId = getPartitionOfMember(memberId);
ClusterLevelPartitionContext partitionCtxt = nwPartitionCtxt.getPartitionCtxt(partitionId);
- // terminate the shutdown ready member
- //CloudControllerClient ccClient = CloudControllerClient.getInstance();
try {
- //NetworkPartitionContext nwPartitionCtxt;
- //String networkPartitionId = memberReadyToShutdownEvent.getNetworkPartitionId();
- //nwPartitionCtxt = getNetworkPartitionCtxt(networkPartitionId);
-
- // start a new member in the same Partition
- //String memberId = memberReadyToShutdownEvent.getMemberId();
String clusterId = memberReadyToShutdownEvent.getClusterId();
- //String partitionId = getPartitionOfMember(memberId);
- //PartitionContext partitionCtxt = nwPartitionCtxt.getPartitionCtxt(partitionId);
-
//move member to pending termination list
if (partitionCtxt.getPendingTerminationMember(memberId) != null) {
partitionCtxt.movePendingTerminationMemberToObsoleteMembers(memberId);
@@ -937,14 +917,16 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
"and moved to obsolete list: [member] %s " +
"[partition] %s [cluster] %s ", memberId, partitionId, clusterId));
}
- } else if(partitionCtxt.getObsoleteMember(memberId) != null) {
+ } else if (partitionCtxt.getObsoleteMember(memberId) != null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Member is in obsolete list: [member] %s " +
"[partition] %s [cluster] %s ", memberId, partitionId, clusterId));
}
} //TODO else part
- if(partitionCtxt.getTotalMemberCount() == 0) {
+ //when no more members are there to terminate Invoking it monitor directly
+ // to speed up the termination process
+ if (partitionCtxt.getTotalMemberCount() == 0) {
this.monitor();
}
@@ -1051,13 +1033,13 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
@Override
public void terminateAllMembers(final String instanceId, final String networkPartitionId) {
-
+ final VMClusterMonitor monitor = this;
Thread memberTerminator = new Thread(new Runnable() {
public void run() {
ClusterInstanceContext instanceContext = getAllNetworkPartitionCtxts().get(networkPartitionId)
.getClusterInstanceContext(instanceId);
-
+ boolean allMovedToObsolete = true;
for (ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
if (log.isInfoEnabled()) {
log.info("Starting to terminate all members in cluster [" + getClusterId() + "] " +
@@ -1092,14 +1074,20 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
MemberContext pendingMemberCtxt = pendingIterator.next();
// pending members
String memeberId = pendingMemberCtxt.getMemberId();
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug("Moving pending member [member id] " + memeberId + " to obsolete list");
}
partitionContext.movePendingMemberToObsoleteMembers(memeberId);
}
+ if(partitionContext.getTotalMemberCount() == 0) {
+ allMovedToObsolete = allMovedToObsolete && true;
+ } else {
+ allMovedToObsolete = false;
+ }
+ }
-// terminateAllFactHandle = AutoscalerRuleEvaluator.evaluateTerminateAll
-// (terminateAllKnowledgeSession, terminateAllFactHandle, partitionContext);
+ if(allMovedToObsolete) {
+ monitor.monitor();
}
}
}, "Member Terminator - [cluster id] " + getClusterId());
@@ -1160,10 +1148,10 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
// Cluster instance is already there. No need to create one.
VMClusterContext clusterContext = (VMClusterContext) this.getClusterContext();
- if(clusterContext == null) {
+ if (clusterContext == null) {
clusterContext = ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(), cluster,
- hasScalingDependents());
+ hasScalingDependents());
this.setClusterContext(clusterContext);
}
@@ -1233,7 +1221,7 @@ public class VMClusterMonitor extends AbstractClusterMonitor {
}
for (String memberId : members) {
// pending members
- if(log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) {
log.debug("Moving pending member [member id] " + memberId + " the obsolete list");
}
partitionContext.movePendingMemberToObsoleteMembers(memberId);
http://git-wip-us.apache.org/repos/asf/stratos/blob/15cd21fb/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 7c02da2..4e5bc76 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
@@ -176,8 +176,7 @@ public class GroupMonitor extends ParentComponentMonitor implements Runnable {
String instanceId = statusEvent.getInstanceId();
LifeCycleState status1 = statusEvent.getStatus();
String id = this.id;
-
- //Events coming from parent are In_Active(in faulty detection), Scaling events, termination
+ //Events coming from parent are In_Active(in faulty detection), Scaling events, termination
if (status1 == ClusterStatus.Active || status1 == GroupStatus.Active) {
onChildActivatedEvent(childId, instanceId);