public String getState() { return job.isStopped() ? "Stopped" : "Running"; }
@Override public void removeIfStopped(final String id) { final JobInfo jobInfo = jobs.get(id); if (jobInfo != null && jobInfo.isStopped()) { jobs.remove(id); } }
private List<JobInfo> findJobsToDelete(final List<JobInfo> jobs) { List<JobInfo> jobsToDelete = new ArrayList<>(); jobs.stream() .sorted(comparing(JobInfo::getStarted, reverseOrder())) .collect(groupingBy(JobInfo::getJobType)) .forEach((jobType, jobExecutions) -> { jobExecutions.stream() .filter(j -> j.isStopped() && Objects.equals(j.getStatus(), SKIPPED)) .skip(numberOfJobsToKeep) .forEach(jobsToDelete::add); }); return jobsToDelete; } }
@Override public List<JobInfo> findRunningWithoutUpdateSince(OffsetDateTime timeOffset) { return jobs.values().stream() .filter(jobInfo -> !jobInfo.isStopped() && jobInfo.getLastUpdated().isBefore(timeOffset)) .collect(toList()); }
private List<JobInfo> findJobsToDelete(final List<JobInfo> jobs) { List<JobInfo> jobsToDelete = new ArrayList<>(); jobs.stream() .sorted(comparing(JobInfo::getStarted, reverseOrder())) .collect(groupingBy(JobInfo::getJobType)) .forEach((jobType, jobExecutions) -> { Optional<JobInfo> lastOkExecution = jobExecutions.stream() .filter(j -> j.isStopped() && j.getStatus() == OK) .findFirst(); jobExecutions.stream() .filter(JobInfo::isStopped) .skip(numberOfJobsToKeep) .filter(j -> !(lastOkExecution.isPresent() && lastOkExecution.get().equals(j))) .forEach(jobsToDelete::add); }); return jobsToDelete; }
public String getStopped() { return job.isStopped() ? formatTime(job.getStopped().get()) : ""; }
/** * Checks all run locks and releases the lock, if the job is stopped. * * TODO: This method should never do something, otherwise the is a bug in the lock handling. * TODO: Check Log files + Remove */ private void clearRunLocks() { jobMetaService.runningJobs().forEach((RunningJob runningJob) -> { final Optional<JobInfo> jobInfoOptional = jobRepository.findOne(runningJob.jobId); if (jobInfoOptional.isPresent() && jobInfoOptional.get().isStopped()) { jobMetaService.releaseRunLock(runningJob.jobType); LOG.error("Clear Lock of Job {}. Job stopped already.", runningJob.jobType); } else if (!jobInfoOptional.isPresent()){ jobMetaService.releaseRunLock(runningJob.jobType); LOG.error("Clear Lock of Job {}. JobID does not exist", runningJob.jobType); } }); }
@Override public void removeIfStopped(final String id) { findOne(id).ifPresent(jobInfo -> { if (jobInfo.isStopped()) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).deleteOne(eq(ID, id)); } }); }
@Override public void removeIfStopped(final String id) { findOne(id).ifPresent(jobInfo -> { if (jobInfo.isStopped()) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).deleteOne(eq(ID, id)); } }); }
public String getRuntime() { return job.isStopped() ? formatRuntime(job.getStarted(), job.getStopped().get()) : formatRuntime(job.getStarted(), OffsetDateTime.now()); }
@Test public void shouldKillJobsWithoutUpdateSince() { JobInfo toBeKilled = defaultJobInfo("toBeKilled", 75); jobRepository.createOrUpdate(toBeKilled); jobService.killJobsDeadSince(60); Optional<JobInfo> expectedKilledJob = jobRepository.findOne(toBeKilled.getJobId()); assertThat(expectedKilledJob.get().isStopped(), is(true)); assertThat(expectedKilledJob.get().getStatus(), is(DEAD)); }
@Test public void shouldNotKillJobsThatHaveRecentlyBeenUpdated() { JobInfo notToBeKilled = defaultJobInfo("notToBeKilled", 45); jobRepository.createOrUpdate(notToBeKilled); jobService.killJobsDeadSince(60); Optional<JobInfo> expectedRunningJob = jobRepository.findOne(notToBeKilled.getJobId()); assertThat(expectedRunningJob.get().isStopped(), is(false)); assertThat(expectedRunningJob.get().getStatus(), is(OK)); }
@Override protected final Document encode(final JobInfo job) { final Document document = new Document() .append(JobStructure.ID.key(), job.getJobId()) .append(JobStructure.JOB_TYPE.key(), job.getJobType()) .append(JobStructure.STARTED.key(), Date.from(job.getStarted().toInstant())) .append(JobStructure.LAST_UPDATED.key(), Date.from(job.getLastUpdated().toInstant())) .append(JobStructure.MESSAGES.key(), job.getMessages().stream() .map(MongoJobRepository::encodeJobMessage) .collect(toList())) .append(JobStructure.STATUS.key(), job.getStatus().name()) .append(JobStructure.HOSTNAME.key(), job.getHostname()); if (job.isStopped()) { document.append(JobStructure.STOPPED.key(), Date.from(job.getStopped().get().toInstant())); } return document; }
@Override protected final Document encode(final JobInfo job) { final Document document = new Document() .append(JobStructure.ID.key(), job.getJobId()) .append(JobStructure.JOB_TYPE.key(), job.getJobType()) .append(JobStructure.STARTED.key(), DateTimeConverters.toDate(job.getStarted())) .append(JobStructure.LAST_UPDATED.key(), DateTimeConverters.toDate(job.getLastUpdated())) .append(JobStructure.MESSAGES.key(), job.getMessages().stream() .map(MongoJobRepository::encodeJobMessage) .collect(toList())) .append(JobStructure.STATUS.key(), job.getStatus().name()) .append(JobStructure.HOSTNAME.key(), job.getHostname()); if (job.isStopped()) { document.append(JobStructure.STOPPED.key(), DateTimeConverters.toDate(job.getStopped().get())); } return document; }