/** @param jobEvent */ public void observe(@Observes(notifyObserver = Reception.ALWAYS) JobEvent jobEvent) { if (jobEvent.getEvent() == JobLifecycleEvent.AGENT_STARTED) { JobInstance job = dao.findById(Integer.valueOf(jobEvent.getJobId())); for (EntityVersion version : job.getNotificationVersions()) { JobNotification not = notificationDao.findById(version.getObjectId()); if (not != null && not.getLifecycleEvents() != null && not.getLifecycleEvents().contains(JobLifecycleEvent.AGENT_EXCESSIVE_CPU)) { LOG.info("Adding watches for job " + job.getId()); addWatches(job, not); break; } } } else if (jobEvent.getEvent() == JobLifecycleEvent.JOB_FINISHED) { JobInstance job = dao.findById(Integer.valueOf(jobEvent.getJobId())); for (EntityVersion version : job.getNotificationVersions()) { JobNotification not = notificationDao.findById(version.getObjectId()); if (not != null && not.getLifecycleEvents() != null && not.getLifecycleEvents().contains(JobLifecycleEvent.AGENT_EXCESSIVE_CPU)) { LOG.info("Adding watches for job " + job.getId()); removeWatches(job, not); break; } } } }
private Set<? extends RegionRequest> getRegions(JobInstance job) { Set<JobRegion> ret = new HashSet<JobRegion>(); JobRegionDao dao = new JobRegionDao(); HashSet<VMRegion> regionSet = new HashSet<VMRegion>(); for (EntityVersion version : job.getJobRegionVersions()) { JobRegion jobRegion = null; if (version.getObjectId() > 0 && version.getVersionId() > 0) { try { jobRegion = dao.findRevision(version.getObjectId(), version.getVersionId()); } catch (Exception e) { LOG.error("Error getting region revision: " + e.toString(), e); } } if (jobRegion != null) { ret.add(fixJobRegion(jobRegion, job)); if (regionSet.contains(jobRegion.getRegion())) { LOG.warn("attempt to add multiple regions to job"); } else { regionSet.add(jobRegion.getRegion()); } } else { LOG.warn( "Attempt to add jobRegion version that does not exist. id = " + version.getObjectId() + " : version = " + version.getVersionId()); jobRegion = dao.findById(version.getObjectId()); if (jobRegion != null) { ret.add(fixJobRegion(jobRegion, job)); if (regionSet.contains(jobRegion.getRegion())) { LOG.warn("attempt to add multiple regions to job"); } else { regionSet.add(jobRegion.getRegion()); } } else { LOG.warn( "Cannot find job region with id " + version.getObjectId() + ". Returning current job Regions."); Workload workload = new WorkloadDao().findById(job.getWorkloadId()); ret = workload.getJobConfiguration().getJobRegions(); for (JobRegion region : ret) { fixJobRegion(region, job); } break; // throw new RuntimeException("Cannot find job region with id " + version.getObjectId()); } } } ret = JobRegionDao.cleanRegions(ret); return ret; }
/** * @param job * @return */ private Set<Integer> getDataFileIds(JobInstance job) { DataFileDao dataFileDao = new DataFileDao(); Set<Integer> ret = new HashSet<Integer>(); for (EntityVersion version : job.getDataFileVersions()) { DataFile dataFile = dataFileDao.findRevision(version.getObjectId(), version.getVersionId()); if (dataFile != null) { ret.add(dataFile.getId()); } else { LOG.warn("Attempt to add dataFile that does not exist."); } } return ret; }
/** * @param job * @return */ private Set<? extends Notification> getNotifications(JobInstance job) { HashSet<JobNotification> ret = new HashSet<JobNotification>(); JobNotificationDao dao = new JobNotificationDao(); for (EntityVersion version : job.getNotificationVersions()) { JobNotification notification = dao.findRevision(version.getObjectId(), version.getVersionId()); if (notification != null) { ret.add(notification); } else { LOG.warn("Attempt to add Notification that does not exist."); } } return ret; }