JobsConfiguration { @Bean @ConditionalOnProperty(name = "edison.jobs.status.enabled", havingValue = "true", matchIfMissing = true) public StatusDetailIndicator jobStatusDetailIndicator(final JobDefinitionService service, final List<JobStatusCalculator> calculators) { final List<JobDefinition> jobDefinitions = service.getJobDefinitions(); if (jobDefinitions.isEmpty()) { return () -> singletonList(statusDetail("Jobs", Status.OK, "No job definitions configured in application.")); } else { return new CompositeStatusDetailIndicator( jobDefinitions .stream() .map(d -> new JobStatusDetailIndicator(d, findJobStatusCalculator(d.jobType(), calculators))) .collect(toList()) ); } } @Autowired  JobsConfiguration(final JobsProperties jobsProperties,
                             final EdisonApplicationProperties  applicationProperties); @Bean @ConditionalOnMissingBean(ScheduledExecutorService.class) ScheduledExecutorService scheduledExecutorService(); @Bean @ConditionalOnMissingBean(JobMetaRepository.class) JobMetaRepository jobMetaRepository(); @Bean @ConditionalOnMissingBean(JobRepository.class) JobRepository jobRepository(); @Bean @ConditionalOnMissingBean(KeepLastJobs.class) KeepLastJobs keepLastJobsStrategy(final JobRepository jobRepository); @Bean @ConditionalOnMissingBean(StopDeadJobs.class) StopDeadJobs deadJobStrategy(final JobService jobService); @Bean @ConditionalOnMissingBean(DeleteSkippedJobs.class) DeleteSkippedJobs deleteSkippedJobsStrategy(final JobRepository jobRepository); @Bean @ConditionalOnMissingBean(CleanupMessagesOfTooBigJobLogs.class) CleanupMessagesOfTooBigJobLogs cleanupMessagesOfTooBigJobLogs(final JobService jobService); @Bean JobStatusCalculator warningOnLastJobFailed(final JobRepository jobRepository, final JobMetaRepository jobMetaRepository); @Bean JobStatusCalculator errorOnLastJobFailed(final JobRepository jobRepository, final JobMetaRepository jobMetaRepository); @Bean JobStatusCalculator errorOnLastThreeJobsFailed(final JobRepository jobRepository, final JobMetaRepository jobMetaRepository); @Bean JobStatusCalculator errorOnLastTenJobsFailed(final JobRepository jobRepository, final JobMetaRepository jobMetaRepository); @Bean @ConditionalOnProperty(name = "edison.jobs.status.enabled", havingValue = "true", matchIfMissing = true) StatusDetailIndicator jobStatusDetailIndicator(final JobDefinitionService service,
                                                          final List<JobStatusCalculator> calculators); static final Logger LOG; }
@Test public void shouldIndicateOkIfNoJobDefinitionsAvailable() { final JobStatusCalculator defaultCalculator = mock(JobStatusCalculator.class); when(defaultCalculator.getKey()).thenReturn("warningOnLastJobFailed"); final JobDefinitionService noJobDefinitions = mock(JobDefinitionService.class); when(noJobDefinitions.getJobDefinitions()).thenReturn(emptyList()); final StatusDetail statusDetail = testee.jobStatusDetailIndicator( noJobDefinitions, singletonList(defaultCalculator)).statusDetails() .get(0); assertThat(statusDetail.getStatus(), is(OK)); assertThat(statusDetail.getName(), is("Jobs")); assertThat(statusDetail.getMessage(), is("No job definitions configured in application.")); }
@Test public void shouldConstructCompositeStatusDetailIndicator() { final JobStatusCalculator defaultCalculator = mock(JobStatusCalculator.class); when(defaultCalculator.getKey()).thenReturn("warningOnLastJobFailed"); final StatusDetailIndicator indicator = testee.jobStatusDetailIndicator( someJobDefinitionService(), singletonList(defaultCalculator) ); assertThat(indicator, is(instanceOf(CompositeStatusDetailIndicator.class))); }
@Test public void shouldUseDefaultJobStatusDetailIndicator() { final JobStatusCalculator defaultCalculator = mock(JobStatusCalculator.class); when(defaultCalculator.getKey()).thenReturn("warningOnLastJobFailed"); testee.jobStatusDetailIndicator( someJobDefinitionService(), singletonList(defaultCalculator)).statusDetails(); verify(defaultCalculator).statusDetail(any(JobDefinition.class)); }
@Test public void shouldUseConfiguredJobStatusDetailIndicator() { final JobsProperties jobsProperties = new JobsProperties(); jobsProperties.getStatus().setCalculator(new HashMap<String, String>(){{ put("test", "errorOnLastJobFailed"); }}); testee = new JobsConfiguration(jobsProperties, properties); final JobStatusCalculator defaultCalculator = mock(JobStatusCalculator.class); when(defaultCalculator.getKey()).thenReturn("warningOnLastJobFailed"); final JobStatusCalculator testCalculator = mock(JobStatusCalculator.class); when(testCalculator.getKey()).thenReturn("errorOnLastJobFailed"); testee.jobStatusDetailIndicator( someJobDefinitionService(), asList(defaultCalculator, testCalculator)).statusDetails(); verify(testCalculator).statusDetail(any(JobDefinition.class)); }
@Test public void shouldNormalizeJobTypesInConfiguredJobStatusDetailIndicators() { final JobsProperties jobsProperties = new JobsProperties(); jobsProperties.getStatus().setCalculator(new HashMap<String, String>(){{ put("soMe-TeSt job", "errorOnLastJobFailed"); }}); testee = new JobsConfiguration(jobsProperties, properties); final JobStatusCalculator defaultCalculator = mock(JobStatusCalculator.class); when(defaultCalculator.getKey()).thenReturn("warningOnLastJobFailed"); final JobStatusCalculator testCalculator = mock(JobStatusCalculator.class); when(testCalculator.getKey()).thenReturn("errorOnLastJobFailed"); final JobDefinitionService jobDefinitionService = mock(JobDefinitionService.class); when(jobDefinitionService.getJobDefinitions()).thenReturn(singletonList( someJobDefinition("Some Test Job")) ); testee.jobStatusDetailIndicator( jobDefinitionService, asList(defaultCalculator, testCalculator)).statusDetails(); verify(testCalculator).statusDetail(any(JobDefinition.class)); }