@Test public void schedulerHasBeenStarted() throws Exception { List<ScheduleSecHubJob> jobsRunningButStartedBefore = new ArrayList<>(); ScheduleSecHubJob job1 = mock(ScheduleSecHubJob.class); UUID uuid1 = UUID.randomUUID(); when(job1.getUUID()).thenReturn(uuid1); jobsRunningButStartedBefore.add(job1); when(repository.findAllRunningJobsStartedBefore(any())).thenReturn(jobsRunningButStartedBefore); handlerToTest.schedulerHasBeenStarted().run(); ArgumentCaptor<DomainMessage> argument = ArgumentCaptor.forClass(DomainMessage.class); verify(eventBus).sendAsynchron(argument.capture()); DomainMessage domainMessage = argument.getValue(); assertEquals(BASE_URL1, domainMessage.get(MessageDataKeys.ENVIRONMENT_BASE_URL)); ClusterMemberMessage status = domainMessage.get(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS); assertNotNull(status); assertEquals(HOSTNAME_1,status.getHostName()); }
@Bean @Order(Ordered.HIGHEST_PRECEDENCE) @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) public CommandLineRunner schedulerHasBeenStarted() { return args -> { LOG.info("scheduler has been started - inspect zombie job status and send event"); List<ScheduleSecHubJob> jobsRunningButStartedBefore = repository.findAllRunningJobsStartedBefore(LocalDateTime.now()); String information = buildZombieInformation(jobsRunningButStartedBefore); DomainMessage request = new DomainMessage(MessageID.SCHEDULER_STARTED); ClusterMemberMessage status = new ClusterMemberMessage(); status.setHostName(hostnameBuilder.buildHostname()); status.setServiceName("scheduler"); status.setServiceStatus("starting"); status.setInformation(information); request.set(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS, status); request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, environment.getServerBaseUrl()); eventBus.sendAsynchron(request); }; }
SchedulerStartHandler { @Bean @Order(Ordered.HIGHEST_PRECEDENCE) @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) public CommandLineRunner schedulerHasBeenStarted() { return args -> { LOG.info("scheduler has been started - inspect zombie job status and send event"); List<ScheduleSecHubJob> jobsRunningButStartedBefore = repository.findAllRunningJobsStartedBefore(LocalDateTime.now()); String information = buildZombieInformation(jobsRunningButStartedBefore); DomainMessage request = new DomainMessage(MessageID.SCHEDULER_STARTED); ClusterMemberMessage status = new ClusterMemberMessage(); status.setHostName(hostnameBuilder.buildHostname()); status.setServiceName("scheduler"); status.setServiceStatus("starting"); status.setInformation(information); request.set(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS, status); request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, environment.getServerBaseUrl()); eventBus.sendAsynchron(request); }; } }
SchedulerStartHandler { @Bean @Order(Ordered.HIGHEST_PRECEDENCE) @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) public CommandLineRunner schedulerHasBeenStarted() { return args -> { LOG.info("scheduler has been started - inspect zombie job status and send event"); List<ScheduleSecHubJob> jobsRunningButStartedBefore = repository.findAllRunningJobsStartedBefore(LocalDateTime.now()); String information = buildZombieInformation(jobsRunningButStartedBefore); DomainMessage request = new DomainMessage(MessageID.SCHEDULER_STARTED); ClusterMemberMessage status = new ClusterMemberMessage(); status.setHostName(hostnameBuilder.buildHostname()); status.setServiceName("scheduler"); status.setServiceStatus("starting"); status.setInformation(information); request.set(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS, status); request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, environment.getServerBaseUrl()); eventBus.sendAsynchron(request); }; }  }
SchedulerStartHandler { @Bean @Order(Ordered.HIGHEST_PRECEDENCE) @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) public CommandLineRunner schedulerHasBeenStarted() { return args -> { LOG.info("scheduler has been started - inspect zombie job status and send event"); List<ScheduleSecHubJob> jobsRunningButStartedBefore = repository.findAllRunningJobsStartedBefore(LocalDateTime.now()); String information = buildZombieInformation(jobsRunningButStartedBefore); DomainMessage request = new DomainMessage(MessageID.SCHEDULER_STARTED); ClusterMemberMessage status = new ClusterMemberMessage(); status.setHostName(hostnameBuilder.buildHostname()); status.setServiceName("scheduler"); status.setServiceStatus("starting"); status.setInformation(information); request.set(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS, status); request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, environment.getServerBaseUrl()); eventBus.sendAsynchron(request); }; }  @Bean @Order(Ordered.HIGHEST_PRECEDENCE) // want this at the very beginning of scheduler start @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) CommandLineRunner schedulerHasBeenStarted(); }
SchedulerStartHandler { @Bean @Order(Ordered.HIGHEST_PRECEDENCE) @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) public CommandLineRunner schedulerHasBeenStarted() { return args -> { LOG.info("scheduler has been started - inspect zombie job status and send event"); List<ScheduleSecHubJob> jobsRunningButStartedBefore = repository.findAllRunningJobsStartedBefore(LocalDateTime.now()); String information = buildZombieInformation(jobsRunningButStartedBefore); DomainMessage request = new DomainMessage(MessageID.SCHEDULER_STARTED); ClusterMemberMessage status = new ClusterMemberMessage(); status.setHostName(hostnameBuilder.buildHostname()); status.setServiceName("scheduler"); status.setServiceStatus("starting"); status.setInformation(information); request.set(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS, status); request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, environment.getServerBaseUrl()); eventBus.sendAsynchron(request); }; }  @Bean @Order(Ordered.HIGHEST_PRECEDENCE) // want this at the very beginning of scheduler start @IsSendingAsyncMessage(MessageID.SCHEDULER_STARTED) @UseCaseAdministratorReceivesNotificationAboutNewchedulerInstanceStart(@Step(number = 1, name = "send domain message that new scheduler instance has been started and information about potential zombie jobs")) CommandLineRunner schedulerHasBeenStarted();  }