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 2015/06/30 07:54:22 UTC
[4/5] stratos git commit: Handling application policy upadte in
application monitor
Handling application policy upadte in application monitor
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/ab5d4470
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/ab5d4470
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/ab5d4470
Branch: refs/heads/master
Commit: ab5d447087794d3a176116a3424ac0b6a5df09c5
Parents: d227bb4
Author: reka <rt...@gmail.com>
Authored: Mon Jun 29 15:55:03 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Tue Jun 30 11:23:49 2015 +0530
----------------------------------------------------------------------
.../autoscaler/monitor/MonitorFactory.java | 10 +-
.../monitor/cluster/ClusterMonitor.java | 4 +-
.../monitor/component/ApplicationMonitor.java | 114 ++++++++++++++++++-
.../monitor/component/GroupMonitor.java | 2 +-
.../services/impl/AutoscalerServiceImpl.java | 3 -
5 files changed, 117 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/ab5d4470/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 0ceac21..ed00369 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
@@ -140,7 +140,6 @@ public class MonitorFactory {
} else {
groupMonitor.setHasStartupDependents(false);
}
- groupMonitor.startScheduler();
} finally {
ApplicationHolder.releaseReadLock();
}
@@ -155,9 +154,10 @@ public class MonitorFactory {
instanceIds.add(instance.getInstanceId());
}
}
-
// Starting the minimum dependencies
groupMonitor.createInstanceAndStartDependencyAtStartup(group, instanceIds);
+ //Starting the scheduler for the group monitor
+ groupMonitor.startScheduler();
return groupMonitor;
@@ -188,13 +188,13 @@ public class MonitorFactory {
applicationMonitor = new ApplicationMonitor(application);
applicationMonitor.setHasStartupDependents(false);
- // Starting the scheduler of the application monitor
- applicationMonitor.startScheduler();
} finally {
ApplicationHolder.releaseReadLock();
}
-
+ //Creating the immediate dependencies
applicationMonitor.startMinimumDependencies(application);
+ // Starting the scheduler of the application monitor
+ applicationMonitor.startScheduler();
return applicationMonitor;
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/ab5d4470/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
index 309fe12..a92edde 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java
@@ -520,7 +520,9 @@ public class ClusterMonitor extends Monitor {
@Override
public void destroy() {
//shutting down the scheduler
- schedulerFuture.cancel(true);
+ if(schedulerFuture != null) {
+ schedulerFuture.cancel(true);
+ }
if (log.isDebugEnabled()) {
log.debug("ClusterMonitor task has been stopped " + this.toString());
http://git-wip-us.apache.org/repos/asf/stratos/blob/ab5d4470/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 df972f0..87e035f 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
@@ -48,7 +48,7 @@ import org.apache.stratos.messaging.domain.application.Application;
import org.apache.stratos.messaging.domain.application.ApplicationStatus;
import org.apache.stratos.messaging.domain.application.GroupStatus;
import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
-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.domain.topology.lifecycle.LifeCycleState;
@@ -78,7 +78,7 @@ public class ApplicationMonitor extends ParentComponentMonitor {
TopologyInConsistentException {
super(application);
- int threadPoolSize = Integer.getInteger(AutoscalerConstants.MONITOR_THREAD_POOL_ID, 100);
+ int threadPoolSize = Integer.getInteger(AutoscalerConstants.MONITOR_THREAD_POOL_SIZE, 100);
this.executorService = StratosThreadPool.getExecutorService(
AutoscalerConstants.MONITOR_THREAD_POOL_ID, threadPoolSize);
@@ -146,6 +146,18 @@ public class ApplicationMonitor extends ParentComponentMonitor {
new ConcurrentHashMap<String, ScalingUpBeyondMaxEvent>());
}
}
+
+ Application application = ApplicationHolder.getApplications().getApplication(appId);
+ if (application != null) {
+ List<String> defaultNetworkPartitions = getDefaultNetworkPartitions(application);
+ //Checking for whether minimum application instances are there.
+ checkForMinimumApplicationInstances(application, defaultNetworkPartitions);
+
+ //Checking for whether any application instances need to be terminated.
+ checkForApplicationInstanceTermination(application, defaultNetworkPartitions);
+ }
+
+
}
};
executorService.execute(monitoringRunnable);
@@ -250,6 +262,95 @@ public class ApplicationMonitor extends ParentComponentMonitor {
}
}
+ public List<String> getDefaultNetworkPartitions(Application application) {
+ //Minimum check, Need to get the network partition
+ NetworkPartitionAlgorithmContext algorithmContext = AutoscalerContext.getInstance().
+ getNetworkPartitionAlgorithmContext(appId);
+ ApplicationPolicy applicationPolicy = PolicyManager.getInstance().
+ getApplicationPolicy(application.getApplicationPolicyId());
+ List<String> defaultNetworkPartitions = new ArrayList<String>();
+
+ if (applicationPolicy != null) {
+ String networkPartitionAlgorithmName = applicationPolicy.getAlgorithm();
+ if (log.isDebugEnabled()) {
+ String msg = String.format("Network partition algorithm is %s [application-id] %s",
+ networkPartitionAlgorithmName, appId);
+ log.debug(msg);
+ }
+
+ NetworkPartitionAlgorithm algorithm = getNetworkPartitionAlgorithm(
+ networkPartitionAlgorithmName);
+ if (algorithm == null) {
+ String msg = String.format("Couldn't create network partition algorithm " +
+ "[application-id] %s", appId);
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
+
+
+ // Check whether the network-partition of the application
+ // instance belongs to default set of network-partitions.
+ // If it is default set, then application instance cannot be terminated.
+ defaultNetworkPartitions = algorithm.
+ getDefaultNetworkPartitions(algorithmContext);
+ }
+
+ return defaultNetworkPartitions;
+ }
+
+ private void checkForMinimumApplicationInstances(Application application,
+ List<String> defaultNetworkPartitions) {
+ List<String> instanceIds = new ArrayList<String>();
+ for (String networkPartitionId : defaultNetworkPartitions) {
+ if (!networkPartitionContextsMap.containsKey(networkPartitionId)) {
+ String instanceId;
+ log.info("Detected a newly updated [network-partition] " + networkPartitionId +
+ " for [application] " + appId + ". Hence new application instance " +
+ "creation is going to start now!");
+ ParentLevelNetworkPartitionContext context =
+ new ParentLevelNetworkPartitionContext(networkPartitionId);
+ //If application instances found in the ApplicationsTopology,
+ // then have to add them first before creating new one
+ ApplicationInstance appInstance = (ApplicationInstance) application.
+ getInstanceByNetworkPartitionId(context.getId());
+ if (appInstance != null) {
+ log.warn("The [application] " + appId + " already has the " +
+ "[application-instance] " + appInstance.getInstanceId() + " for the " +
+ "[network-partition] " + networkPartitionId);
+ return;
+ }
+ instanceId = handleApplicationInstanceCreation(application, context, null);
+ instanceIds.add(instanceId);
+
+ }
+ }
+ //Starting the dependencies
+ if(!instanceIds.isEmpty()) {
+ startDependency(application, instanceIds);
+ }
+
+ }
+
+ private void checkForApplicationInstanceTermination(Application application,
+ List<String> defaultNetworkPartitions) {
+
+ for (NetworkPartitionContext networkPartitionContext : networkPartitionContextsMap.values()) {
+ String nPartitionId = networkPartitionContext.getId();
+ if(!defaultNetworkPartitions.contains(nPartitionId)) {
+ log.info("The [application] " + appId + " runtime cannot be in [network-partition] "
+ + nPartitionId + " as it is removed from the [application-policy]...!");
+ for(InstanceContext instanceContext: networkPartitionContext.
+ getInstanceIdToInstanceContextMap().values()) {
+ //Handling application instance termination
+ ApplicationBuilder.handleApplicationInstanceTerminatingEvent(this.appId,
+ instanceContext.getId());
+ }
+
+ }
+ }
+
+ }
+
/**
* Find the group monitor by traversing recursively in the hierarchical monitors.
@@ -479,8 +580,8 @@ public class ApplicationMonitor extends ParentComponentMonitor {
//Find whether any other instances exists in cluster
// which has not been added to in-memory model in the restart
Map<String, ApplicationInstance> instanceMap = application.getInstanceIdToInstanceContextMap();
- for(ApplicationInstance instance : instanceMap.values()) {
- if(!instanceIds.contains(instance.getInstanceId())) {
+ for (ApplicationInstance instance : instanceMap.values()) {
+ if (!instanceIds.contains(instance.getInstanceId())) {
ParentLevelNetworkPartitionContext context =
new ParentLevelNetworkPartitionContext(instance.getNetworkPartitionId());
//If application instances found in the ApplicationsTopology,
@@ -495,8 +596,9 @@ public class ApplicationMonitor extends ParentComponentMonitor {
" [appInstanceId] " + instance.getInstanceId());
}
}
-
- startDependency(application, instanceIds);
+ if(!instanceIds.isEmpty()) {
+ startDependency(application, instanceIds);
+ }
} catch (Exception e) {
log.error(String.format("Application instance creation failed [applcaition-id] %s", appId), e);
http://git-wip-us.apache.org/repos/asf/stratos/blob/ab5d4470/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 7ef8ce4..4f60af9 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
@@ -187,7 +187,7 @@ public class GroupMonitor extends ParentComponentMonitor {
if (log.isDebugEnabled()) {
log.debug("Creating a group instance of [application] "
+ appId + " [group] " + id +
- " as the the minimum required instances not met");
+ " as the the minimum required instances are not met");
}
createInstanceOnDemand(parentInstanceContext.getId());
http://git-wip-us.apache.org/repos/asf/stratos/blob/ab5d4470/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
index 963136f..6d40cf6 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
@@ -887,9 +887,6 @@ public class AutoscalerServiceImpl implements AutoscalerService {
// validating application policy
AutoscalerUtil.validateApplicationPolicy(applicationPolicy);
- //Update application Monitor
-
-
// updating application policy
PolicyManager.getInstance().updateApplicationPolicy(applicationPolicy);
return true;