You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/05/01 07:08:37 UTC
stratos git commit: Adding try catch block to MonitorAdder.run()
method to cover its full scope
Repository: stratos
Updated Branches:
refs/heads/master aa4d9d773 -> 9ec061f44
Adding try catch block to MonitorAdder.run() method to cover its full scope
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/9ec061f4
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/9ec061f4
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/9ec061f4
Branch: refs/heads/master
Commit: 9ec061f44a3189ccd8b509ef4da980687dfbcf62
Parents: aa4d9d7
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri May 1 10:38:13 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri May 1 10:38:31 2015 +0530
----------------------------------------------------------------------
.../component/ParentComponentMonitor.java | 107 ++++++++++---------
1 file changed, 56 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ec061f4/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 d5831ba..ce3159f 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
@@ -826,62 +826,67 @@ public abstract class ParentComponentMonitor extends Monitor implements Runnable
}
public void run() {
- long startTime = System.currentTimeMillis();
- long endTime = startTime;
- int retries = 5;
- Monitor monitor = null;
- boolean success = false;
- while (!success && retries != 0) {
-
- startTime = System.currentTimeMillis();
- if (log.isInfoEnabled()) {
- log.info(String.format("Starting monitor: [type] %s [component] %s",
- monitorTypeStr, context.getId()));
- }
+ try {
+ long startTime = System.currentTimeMillis();
+ long endTime = startTime;
+ int retries = 5;
+ Monitor monitor = null;
+ boolean success = false;
+ while (!success && retries != 0) {
+
+ startTime = System.currentTimeMillis();
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Starting monitor: [type] %s [component] %s",
+ monitorTypeStr, context.getId()));
+ }
- try {
- monitor = MonitorFactory.getMonitor(parent, context, appId, parentInstanceIds);
- } catch (DependencyBuilderException e) {
- String msg = String.format("Monitor creation failed: [type] %s [component] %s",
- monitorTypeStr, context.getId());
- log.warn(msg, e);
- retries--;
- } catch (TopologyInConsistentException e) {
- String msg = String.format("Monitor creation failed: [type] %s [component] %s",
- monitorTypeStr, context.getId());
- log.warn(msg, e);
- retries--;
- } catch (PolicyValidationException e) {
- String msg = String.format("Monitor creation failed: [type] %s [component] %s",
- monitorTypeStr, context.getId());
- log.warn(msg, e);
- retries--;
- } catch (PartitionValidationException e) {
- String msg = String.format("Monitor creation failed: [type] %s [component] %s",
- monitorTypeStr, context.getId());
- log.warn(msg, e);
- retries--;
+ try {
+ monitor = MonitorFactory.getMonitor(parent, context, appId, parentInstanceIds);
+ } catch (DependencyBuilderException e) {
+ String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+ monitorTypeStr, context.getId());
+ log.warn(msg, e);
+ retries--;
+ } catch (TopologyInConsistentException e) {
+ String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+ monitorTypeStr, context.getId());
+ log.warn(msg, e);
+ retries--;
+ } catch (PolicyValidationException e) {
+ String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+ monitorTypeStr, context.getId());
+ log.warn(msg, e);
+ retries--;
+ } catch (PartitionValidationException e) {
+ String msg = String.format("Monitor creation failed: [type] %s [component] %s",
+ monitorTypeStr, context.getId());
+ log.warn(msg, e);
+ retries--;
+ }
+ success = true;
+ endTime = System.currentTimeMillis();
}
- success = true;
- endTime = System.currentTimeMillis();
- }
- if (monitor == null) {
- String msg = String.format("Monitor creation failed even after retrying for 5 times: "
- + "[type] %s [component] ", monitorTypeStr, context.getId());
- log.error(msg);
- //TODO parent.notify();
- throw new RuntimeException(msg);
- }
+ if (monitor == null) {
+ String msg = String.format("Monitor creation failed even after retrying for 5 times: "
+ + "[type] %s [component] ", monitorTypeStr, context.getId());
+ log.error(msg);
+ //TODO parent.notify();
+ throw new RuntimeException(msg);
+ }
- aliasToActiveMonitorsMap.put(context.getId(), monitor);
- pendingMonitorsList.remove(context.getId());
+ aliasToActiveMonitorsMap.put(context.getId(), monitor);
+ pendingMonitorsList.remove(context.getId());
- if (log.isInfoEnabled()) {
- long startupTime = (endTime - startTime) / 1000;
- log.info(String.format("Monitor started successfully: [type] %s [component] %s [dependents] %s " +
- "[startup-time] %d seconds", monitorTypeStr, context.getId(),
- getIdList(context.getApplicationChildContextList()), startupTime));
+ if (log.isInfoEnabled()) {
+ long startupTime = (endTime - startTime) / 1000;
+ log.info(String.format("Monitor started successfully: [type] %s [component] %s [dependents] %s " +
+ "[startup-time] %d seconds", monitorTypeStr, context.getId(),
+ getIdList(context.getApplicationChildContextList()), startupTime));
+ }
+ } catch (Exception e) {
+ log.error(String.format("An error occurred while starting monitor: [type] %s [component] %s",
+ monitorTypeStr, context.getId()), e);
}
}