You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2015/05/19 12:01:09 UTC
[2/6] stratos git commit: Cover instance creation logic with try
catch block for catching all the exceptions
Cover instance creation logic with try catch block for catching all the exceptions
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2a9f21d8
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2a9f21d8
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2a9f21d8
Branch: refs/heads/master
Commit: 2a9f21d8fcb4f568ebb702e957f6e46a21f5578f
Parents: 080614c
Author: Lahiru Sandaruwan <la...@apache.org>
Authored: Tue May 19 14:11:26 2015 +0530
Committer: Lahiru Sandaruwan <la...@apache.org>
Committed: Tue May 19 15:30:57 2015 +0530
----------------------------------------------------------------------
.../monitor/component/ApplicationMonitor.java | 121 ++++++++++---------
1 file changed, 64 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/2a9f21d8/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 2d5ef12..122a6a7 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
@@ -399,74 +399,81 @@ public class ApplicationMonitor extends ParentComponentMonitor {
*/
private boolean createInstanceAndStartDependency(Application application)
throws TopologyInConsistentException, PolicyValidationException {
+
boolean initialStartup = true;
- List<String> instanceIds = new ArrayList<String>();
- String instanceId;
+ try {
+ List<String> instanceIds = new ArrayList<String>();
+ String instanceId;
- ApplicationPolicy applicationPolicy = PolicyManager.getInstance().
- getApplicationPolicy(application.getApplicationPolicyId());
- if (applicationPolicy == null) {
- String msg = String.format("Application policy not found in registry or " +
- "in-memory [application-id] %s", appId);
- log.error(msg);
- throw new RuntimeException(msg);
- }
+ ApplicationPolicy applicationPolicy = PolicyManager.getInstance().
+ getApplicationPolicy(application.getApplicationPolicyId());
+ if (applicationPolicy == null) {
+ String msg = String.format("Application policy not found in registry or " +
+ "in-memory [application-id] %s", appId);
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
- NetworkPartitionAlgorithmContext algorithmContext = AutoscalerContext.getInstance().
- getNetworkPartitionAlgorithmContext(appId);
- if (algorithmContext == null) {
- String msg = String.format("Network partition algorithm context not found " +
- "in registry or in-memory [application-id] %s", appId);
- log.error(msg);
- throw new RuntimeException(msg);
- }
+ NetworkPartitionAlgorithmContext algorithmContext = AutoscalerContext.getInstance().
+ getNetworkPartitionAlgorithmContext(appId);
+ if (algorithmContext == null) {
+ String msg = String.format("Network partition algorithm context not found " +
+ "in registry or in-memory [application-id] %s", appId);
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
- String networkPartitionAlgorithmName = applicationPolicy.getAlgorithm();
- if (log.isDebugEnabled()) {
- String msg = String.format("Network partition algorithm is %s [application-id] %s",
- networkPartitionAlgorithmName, appId);
- log.debug(msg);
- }
+ 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);
- }
+ 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);
+ }
- List<String> nextNetworkPartitions = algorithm.getNextNetworkPartitions(algorithmContext);
- if (nextNetworkPartitions == null || nextNetworkPartitions.isEmpty()) {
- String msg = String.format("No network partitions available for application bursting " +
- "[application-id] %s", appId);
- log.warn(msg);
- return false;
- }
+ List<String> nextNetworkPartitions = algorithm.getNextNetworkPartitions(algorithmContext);
+ if (nextNetworkPartitions == null || nextNetworkPartitions.isEmpty()) {
+ String msg = String.format("No network partitions available for application bursting " +
+ "[application-id] %s", appId);
+ log.warn(msg);
+ return false;
+ }
- for (String networkPartitionIds : nextNetworkPartitions) {
- ApplicationLevelNetworkPartitionContext context =
- new ApplicationLevelNetworkPartitionContext(networkPartitionIds);
- //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) {
- //use the existing instance in the Topology to create the data
- instanceId = handleApplicationInstanceCreation(application, context, appInstance);
- initialStartup = false;
- } else {
- //create new app instance as it doesn't exist in the Topology
- instanceId = handleApplicationInstanceCreation(application, context, null);
+ for (String networkPartitionIds : nextNetworkPartitions) {
+ ApplicationLevelNetworkPartitionContext context =
+ new ApplicationLevelNetworkPartitionContext(networkPartitionIds);
+ //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) {
+ //use the existing instance in the Topology to create the data
+ instanceId = handleApplicationInstanceCreation(application, context, appInstance);
+ initialStartup = false;
+ } else {
+ //create new app instance as it doesn't exist in the Topology
+ instanceId = handleApplicationInstanceCreation(application, context, null);
+ }
+ instanceIds.add(instanceId);
+ log.info("Application instance has been added for the [network partition] " +
+ networkPartitionIds + " [appInstanceId] " + instanceId);
}
- instanceIds.add(instanceId);
- log.info("Application instance has been added for the [network partition] " +
- networkPartitionIds + " [appInstanceId] " + instanceId);
+
+ startDependency(application, instanceIds);
+
+ } catch (Exception e){
+ log.error(String.format("Application instance creation failed [applcaition-id] %s", appId), e);
}
- startDependency(application, instanceIds);
return initialStartup;
}