@Test public void assertGetAllEligibleJobContextsWithRootNodeAndDaemonJob() { when(regCenter.isExisted("/state/ready")).thenReturn(true); when(regCenter.getChildrenKeys("/state/ready")).thenReturn(Arrays.asList("not_existed_job", "running_job")); when(configService.load("not_existed_job")).thenReturn(Optional.empty()); when(configService.load("running_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("running_job", CloudJobExecutionType.DAEMON))); when(runningService.isJobRunning("running_job")).thenReturn(true); assertThat(readyService.getAllEligibleJobContexts(Collections.emptyList()).size(), is(0)); verify(regCenter).isExisted("/state/ready"); verify(regCenter, times(1)).getChildrenKeys("/state/ready"); verify(configService).load("not_existed_job"); verify(configService).load("running_job"); }
public Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts) { if (!regCenter.isExisted(ReadyNode.ROOT)) { return Collections.emptyList(); } Collection<String> ineligibleJobNames = ineligibleJobContexts.stream().map(input -> input.getCloudJobConfig().getJobConfig().getJobName()).collect(Collectors.toList()); List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT); List<JobContext> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { if (ineligibleJobNames.contains(each)) { continue; } Optional<CloudJobConfigurationPOJO> jobConfig = configService.load(each); if (!jobConfig.isPresent()) { regCenter.remove(ReadyNode.getReadyJobNodePath(each)); continue; } if (!runningService.isJobRunning(each)) { result.add(JobContext.from(jobConfig.get().toCloudJobConfiguration(), ExecutionType.READY)); } } return result; }
ReadyService { public Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts) { if (!regCenter.isExisted(ReadyNode.ROOT)) { return Collections.emptyList(); } Collection<String> ineligibleJobNames = ineligibleJobContexts.stream().map(input -> input.getCloudJobConfig().getJobConfig().getJobName()).collect(Collectors.toList()); List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT); List<JobContext> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { if (ineligibleJobNames.contains(each)) { continue; } Optional<CloudJobConfigurationPOJO> jobConfig = configService.load(each); if (!jobConfig.isPresent()) { regCenter.remove(ReadyNode.getReadyJobNodePath(each)); continue; } if (!runningService.isJobRunning(each)) { result.add(JobContext.from(jobConfig.get().toCloudJobConfiguration(), ExecutionType.READY)); } } return result; } }
ReadyService { public Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts) { if (!regCenter.isExisted(ReadyNode.ROOT)) { return Collections.emptyList(); } Collection<String> ineligibleJobNames = ineligibleJobContexts.stream().map(input -> input.getCloudJobConfig().getJobConfig().getJobName()).collect(Collectors.toList()); List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT); List<JobContext> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { if (ineligibleJobNames.contains(each)) { continue; } Optional<CloudJobConfigurationPOJO> jobConfig = configService.load(each); if (!jobConfig.isPresent()) { regCenter.remove(ReadyNode.getReadyJobNodePath(each)); continue; } if (!runningService.isJobRunning(each)) { result.add(JobContext.from(jobConfig.get().toCloudJobConfiguration(), ExecutionType.READY)); } } return result; } ReadyService(final CoordinatorRegistryCenter regCenter); }
ReadyService { public Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts) { if (!regCenter.isExisted(ReadyNode.ROOT)) { return Collections.emptyList(); } Collection<String> ineligibleJobNames = ineligibleJobContexts.stream().map(input -> input.getCloudJobConfig().getJobConfig().getJobName()).collect(Collectors.toList()); List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT); List<JobContext> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { if (ineligibleJobNames.contains(each)) { continue; } Optional<CloudJobConfigurationPOJO> jobConfig = configService.load(each); if (!jobConfig.isPresent()) { regCenter.remove(ReadyNode.getReadyJobNodePath(each)); continue; } if (!runningService.isJobRunning(each)) { result.add(JobContext.from(jobConfig.get().toCloudJobConfiguration(), ExecutionType.READY)); } } return result; } ReadyService(final CoordinatorRegistryCenter regCenter); void addTransient(final String jobName); void addDaemon(final String jobName); void setMisfireDisabled(final String jobName); Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts); void remove(final Collection<String> jobNames); Map<String, Integer> getAllReadyTasks(); }
ReadyService { public Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts) { if (!regCenter.isExisted(ReadyNode.ROOT)) { return Collections.emptyList(); } Collection<String> ineligibleJobNames = ineligibleJobContexts.stream().map(input -> input.getCloudJobConfig().getJobConfig().getJobName()).collect(Collectors.toList()); List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT); List<JobContext> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { if (ineligibleJobNames.contains(each)) { continue; } Optional<CloudJobConfigurationPOJO> jobConfig = configService.load(each); if (!jobConfig.isPresent()) { regCenter.remove(ReadyNode.getReadyJobNodePath(each)); continue; } if (!runningService.isJobRunning(each)) { result.add(JobContext.from(jobConfig.get().toCloudJobConfiguration(), ExecutionType.READY)); } } return result; } ReadyService(final CoordinatorRegistryCenter regCenter); void addTransient(final String jobName); void addDaemon(final String jobName); void setMisfireDisabled(final String jobName); Collection<JobContext> getAllEligibleJobContexts(final Collection<JobContext> ineligibleJobContexts); void remove(final Collection<String> jobNames); Map<String, Integer> getAllReadyTasks();  }