@Override protected final String keyOf(final JobInfo value) { return value.getJobId(); }
@Override protected final String keyOf(final JobInfo value) { return value.getJobId(); }
@Override public JobInfo createOrUpdate(final JobInfo job) { jobs.put(job.getJobId(), job); return job; }
/** * Execute the cleanup of the given repository. */ @Scheduled(fixedRate = KEEP_LAST_JOBS_CLEANUP_INTERVAL) public void doCleanUp() { final List<JobInfo> jobs = jobRepository.findAllJobInfoWithoutMessages(); findJobsToDelete(jobs) .forEach(jobInfo -> jobRepository.removeIfStopped(jobInfo.getJobId())); }
/** * Execute the cleanup of the given repository. */ @Scheduled(fixedRate = KEEP_LAST_JOBS_CLEANUP_INTERVAL) public void doCleanUp() { final List<JobInfo> jobs = jobRepository.findAllJobInfoWithoutMessages(); findJobsToDelete(jobs) .forEach(jobInfo -> jobRepository.removeIfStopped(jobInfo.getJobId())); }
public List<Link> getLinks() { final String jobUri = String.format("%s%s/jobs/%s", baseUri, edisonManagementBasePath, job.getJobId()); return asList( link("self", jobUri, "Self"), link("http://github.com/otto-de/edison/link-relations/job/definition", String.format("%s%s/jobdefinitions/%s", baseUri, edisonManagementBasePath, job.getJobType()), "Job Definition"), link("collection", jobUri.substring(0, jobUri.lastIndexOf("/")), "All Jobs"), link("collection/" + getJobType(), jobUri.substring(0, jobUri.lastIndexOf("/")) + "?type=" + getJobType(), "All " + getJobType() + " Jobs") ); }
public void killJobsDeadSince(final int seconds) { final OffsetDateTime timeToMarkJobAsStopped = now(clock).minusSeconds(seconds); LOG.info(format("JobCleanup: Looking for jobs older than %s ", timeToMarkJobAsStopped)); final List<JobInfo> deadJobs = jobRepository.findRunningWithoutUpdateSince(timeToMarkJobAsStopped); deadJobs.forEach(deadJob -> killJob(deadJob.getJobId())); clearRunLocks(); }
private JobInfo someRunningJob(final JobInfo.JobStatus jobStatus, int startedSecondsAgo) { OffsetDateTime now = now(); JobInfo someJob = mock(JobInfo.class); when(someJob.getJobType()).thenReturn("someJobType"); when(someJob.getJobId()).thenReturn("someJobId"); when(someJob.getStarted()).thenReturn(now.minusSeconds(startedSecondsAgo)); when(someJob.getStopped()).thenReturn(empty()); when(someJob.getStatus()).thenReturn(jobStatus); return someJob; } }
@Test public void shouldFindAll() { // given repository.createOrUpdate(newJobInfo("oldest", "FOO", fixed(Instant.now().minusSeconds(1), systemDefault()), "localhost")); repository.createOrUpdate(newJobInfo("youngest", "FOO", fixed(Instant.now(), systemDefault()), "localhost")); // when final List<JobInfo> jobInfos = repository.findAll(); // then assertThat(jobInfos.size(), is(2)); assertThat(jobInfos.get(0).getJobId(), is("youngest")); assertThat(jobInfos.get(1).getJobId(), is("oldest")); }
private JobInfo someStoppedJob(final JobInfo.JobStatus jobStatus, int startedSecondsAgo) { OffsetDateTime now = now(); JobInfo someJob = mock(JobInfo.class); when(someJob.getJobType()).thenReturn("someJobType"); when(someJob.getJobId()).thenReturn("someId"); when(someJob.getStarted()).thenReturn(now.minusSeconds(startedSecondsAgo)); when(someJob.getStopped()).thenReturn(of(now.minusSeconds(startedSecondsAgo-1))); when(someJob.getStatus()).thenReturn(jobStatus); return someJob; }
@Test public void shouldKillDeadJobsSince() { JobInfo someJobInfo = defaultJobInfo().setJobType("jobType").build(); when(jobRepository.findRunningWithoutUpdateSince(any())).thenReturn(singletonList(someJobInfo)); when(jobRepository.findOne(someJobInfo.getJobId())).thenReturn(Optional.of(someJobInfo)); jobService.killJobsDeadSince(60); verify(jobMetaService).releaseRunLock("jobType"); }
@Test public void shouldRunJob() { // given: String jobType = "bar"; when(jobRunnable.getJobDefinition()).thenReturn(someJobDefinition(jobType)); // when: Optional<String> optionalJobId = jobService.startAsyncJob(jobType); // then: final JobInfo expectedJobInfo = JobInfo.newJobInfo(optionalJobId.get(), jobType, clock, systemInfo.hostname); verify(executorService).execute(any(Runnable.class)); verify(jobRepository).createOrUpdate(expectedJobInfo); verify(jobRunnable).execute(); verify(jobMetaService).aquireRunLock(expectedJobInfo.getJobId(), expectedJobInfo.getJobType()); }
@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)); }
@Test public void shouldUpdateJobLastUpdateTime() { //Given final JobInfo foo = jobInfo("http://localhost/foo", "T_FOO"); repo.createOrUpdate(foo); final OffsetDateTime myTestTime = OffsetDateTime.of(1979, 2, 5, 1, 2, 3, 4, ZoneOffset.UTC); //When repo.setLastUpdate(foo.getJobId(), myTestTime); final Optional<JobInfo> jobInfo = repo.findOne(foo.getJobId()); //Then assertThat(jobInfo, OptionalMatchers.isPresent()); assertThat(Date.from(jobInfo.get().getLastUpdated().toInstant()), is(Date.from(myTestTime.toInstant()))); }
@Test public void shouldFindRunningJobsWithoutUpdatedSinceSpecificDate() throws Exception { // given repository.createOrUpdate(newJobInfo("deadJob", "FOO", fixed(Instant.now().minusSeconds(10), systemDefault()), "localhost")); repository.createOrUpdate(newJobInfo("running", "FOO", fixed(Instant.now(), systemDefault()), "localhost")); // when final List<JobInfo> jobInfos = repository.findRunningWithoutUpdateSince(now().minus(5, ChronoUnit.SECONDS)); // then assertThat(jobInfos, IsCollectionWithSize.hasSize(1)); assertThat(jobInfos.get(0).getJobId(), is("deadJob")); }
@Test public void shouldFindJobInfoByUri() { // given InMemJobRepository repository = new InMemJobRepository(); // when JobInfo job = newJobInfo(randomUUID().toString(), "MYJOB", clock, "localhost"); repository.createOrUpdate(job); // then assertThat(repository.findOne(job.getJobId()), isPresent()); }
@Test public void shouldUpdateJobStatus() { //Given final JobInfo foo = jobInfo("http://localhost/foo", "T_FOO"); //default jobStatus is 'OK' repository.createOrUpdate(foo); //When repository.setJobStatus(foo.getJobId(), ERROR); JobStatus status = repository.findStatus("http://localhost/foo"); //Then assertThat(status, is(ERROR)); }
@Test public void shouldUpdateJobStatus() { //Given final JobInfo foo = jobInfo("http://localhost/foo", "T_FOO"); //default jobStatus is 'OK' repo.createOrUpdate(foo); //When repo.setJobStatus(foo.getJobId(), ERROR); final JobStatus status = repo.findStatus("http://localhost/foo"); //Then assertThat(status, is(ERROR)); }