Updated aurora monitor task to sleep after a round of status check
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/c72417e3 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/c72417e3 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/c72417e3 Branch: refs/heads/auroraMesosIntegration Commit: c72417e3d89daee51538bf78c041cb58bc889491 Parents: b3d4c7a Author: Shameera Rathnayaka <[email protected]> Authored: Tue Nov 1 20:47:08 2016 -0400 Committer: Shameera Rathnayaka <[email protected]> Committed: Tue Nov 1 20:47:08 2016 -0400 ---------------------------------------------------------------------- .../gfac/monitor/cloud/AuroraJobMonitor.java | 60 +++++++++++--------- 1 file changed, 34 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/c72417e3/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/cloud/AuroraJobMonitor.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/cloud/AuroraJobMonitor.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/cloud/AuroraJobMonitor.java index 477f1db..9e24597 100644 --- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/cloud/AuroraJobMonitor.java +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/monitor/cloud/AuroraJobMonitor.java @@ -66,7 +66,7 @@ public class AuroraJobMonitor implements JobMonitor, Runnable { private Map<String,TaskContext> jobMonitoringMap; private AuroraJobMonitor(){ jobMonitoringMap = new ConcurrentHashMap<>(); - timer = new Timer("Aurora status poll timer"); + timer = new Timer("Aurora status poll timer", true); } @@ -125,33 +125,41 @@ public class AuroraJobMonitor implements JobMonitor, Runnable { @Override public void run() { - JobKeyBean jobKeyBean = new JobKeyBean(AuroraUtils.ENVIRONMENT, AuroraUtils.ROLE, "dummy"); - Iterator<Map.Entry<String, TaskContext>> iterator = jobMonitoringMap.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry<String, TaskContext> currentEntry = iterator.next(); - try { - jobKeyBean.setName(currentEntry.getKey()); - JobDetailsResponseBean jobDetailsResponseBean = client.getJobDetails(jobKeyBean); - List<ScheduledTask> tasks = jobDetailsResponseBean.getTasks(); - switch (tasks.get(0).getStatus()) { - case FINISHED: - iterator.remove(); - processJob(currentEntry.getKey(), currentEntry.getValue(), JobState.COMPLETE); - break; - case FAILED: - iterator.remove(); - processJob(currentEntry.getKey(), currentEntry.getValue(), JobState.FAILED); - break; - case RUNNING: - updateStatus(currentEntry.getKey(), currentEntry.getValue(), JobState.ACTIVE); - break; - default: - log.info("Job {} is in {} state", currentEntry.getKey(), tasks.get(0).getStatus().name()); - break; + while(true){ + JobKeyBean jobKeyBean = new JobKeyBean(AuroraUtils.ENVIRONMENT, AuroraUtils.ROLE, "dummy"); + Iterator<Map.Entry<String, TaskContext>> iterator = jobMonitoringMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry<String, TaskContext> currentEntry = iterator.next(); + try { + jobKeyBean.setName(currentEntry.getKey()); + JobDetailsResponseBean jobDetailsResponseBean = client.getJobDetails(jobKeyBean); + List<ScheduledTask> tasks = jobDetailsResponseBean.getTasks(); + switch (tasks.get(0).getStatus()) { + case FINISHED: + iterator.remove(); + processJob(currentEntry.getKey(), currentEntry.getValue(), JobState.COMPLETE); + break; + case FAILED: + iterator.remove(); + processJob(currentEntry.getKey(), currentEntry.getValue(), JobState.FAILED); + break; + case RUNNING: + updateStatus(currentEntry.getKey(), currentEntry.getValue(), JobState.ACTIVE); + break; + default: + log.info("Job {} is in {} state", currentEntry.getKey(), tasks.get(0).getStatus().name()); + break; + } + } catch (Exception e) { + log.error("Error while getting response for job : {}", currentEntry.getKey()); + } - } catch (Exception e) { - log.error("Error while getting response for job : {}", currentEntry.getKey()); + } + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + log.warn("Aurora Monitoring task interrupted"); } } }
