예제 #1
0
  /**
   * 从待执行队列中获取所有有资格执行的作业上下文.
   *
   * @param ineligibleJobContexts 无资格执行的作业上下文
   * @return 有资格执行的作业上下文集合
   */
  public Collection<JobContext> getAllEligibleJobContexts(
      final Collection<JobContext> ineligibleJobContexts) {
    if (!regCenter.isExisted(ReadyNode.ROOT)) {
      return Collections.emptyList();
    }
    Collection<String> ineligibleJobNames =
        Collections2.transform(
            ineligibleJobContexts,
            new Function<JobContext, String>() {

              @Override
              public String apply(final JobContext input) {
                return input.getJobConfig().getJobName();
              }
            });
    List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT);
    List<JobContext> result = new ArrayList<>(jobNames.size());
    for (String each : jobNames) {
      if (ineligibleJobNames.contains(each)) {
        continue;
      }
      Optional<CloudJobConfiguration> jobConfig = configService.load(each);
      if (!jobConfig.isPresent()) {
        regCenter.remove(ReadyNode.getReadyJobNodePath(each));
        continue;
      }
      if (!runningService.isJobRunning(each)
          || JobExecutionType.DAEMON == jobConfig.get().getJobExecutionType()) {
        result.add(JobContext.from(jobConfig.get(), ExecutionType.READY));
      }
    }
    return result;
  }
 @Test
 public void assertDeregisterNotExisted() {
   when(configService.load("transient_test_job"))
       .thenReturn(Optional.<CloudJobConfiguration>absent());
   producerManager.deregister("transient_test_job");
   verify(configService, times(0)).remove("transient_test_job");
 }
예제 #3
0
 /**
  * 设置禁用错过重执行.
  *
  * @param jobName 作业名称
  */
 public void setMisfireDisabled(final String jobName) {
   Optional<CloudJobConfiguration> cloudJobConfig = configService.load(jobName);
   if (cloudJobConfig.isPresent()
       && null != regCenter.getDirectly(ReadyNode.getReadyJobNodePath(jobName))) {
     regCenter.persist(ReadyNode.getReadyJobNodePath(jobName), "1");
   }
 }
 @Test
 public void assertRegisterTransientJob() {
   when(configService.load("transient_test_job"))
       .thenReturn(Optional.<CloudJobConfiguration>absent());
   producerManager.register(transientJobConfig);
   verify(configService).add(transientJobConfig);
   verify(transientProducerScheduler).register(transientJobConfig);
 }
 @Test
 public void assertStartup() {
   when(configService.loadAll()).thenReturn(Arrays.asList(transientJobConfig, daemonJobConfig));
   producerManager.startup();
   verify(configService).loadAll();
   verify(transientProducerScheduler).register(transientJobConfig);
   verify(readyService).addDaemon("daemon_test_job");
 }
 @Test
 public void assertRegisterDaemonJob() {
   when(configService.load("daemon_test_job"))
       .thenReturn(Optional.<CloudJobConfiguration>absent());
   producerManager.register(daemonJobConfig);
   verify(configService).add(daemonJobConfig);
   verify(readyService).addDaemon("daemon_test_job");
 }
 @Test
 public void assertDeregisterExisted() {
   when(configService.load("transient_test_job")).thenReturn(Optional.of(transientJobConfig));
   when(runningService.getRunningTasks("transient_test_job"))
       .thenReturn(
           Arrays.asList(
               TaskContext.from("transient_test_job@-@0@-@READY@-@SLAVE-S0@-@UUID"),
               TaskContext.from("transient_test_job@-@1@-@READY@-@SLAVE-S0@-@UUID")));
   producerManager.deregister("transient_test_job");
   verify(configService).remove("transient_test_job");
   verify(lifecycleService).killJob("transient_test_job");
   verify(runningService).remove("transient_test_job");
   verify(readyService).remove(Lists.newArrayList("transient_test_job"));
 }
예제 #8
0
 /**
  * 将常驻作业放入待执行队列.
  *
  * @param jobName 作业名称
  */
 public void addDaemon(final String jobName) {
   if (regCenter.getNumChildren(ReadyNode.ROOT)
       > env.getFrameworkConfiguration().getJobStateQueueSize()) {
     log.warn(
         "Cannot add daemon job, caused by read state queue size is larger than {}.",
         env.getFrameworkConfiguration().getJobStateQueueSize());
     return;
   }
   Optional<CloudJobConfiguration> cloudJobConfig = configService.load(jobName);
   if (!cloudJobConfig.isPresent()
       || JobExecutionType.DAEMON != cloudJobConfig.get().getJobExecutionType()) {
     return;
   }
   regCenter.persist(ReadyNode.getReadyJobNodePath(jobName), "1");
 }
예제 #9
0
 /**
  * 将瞬时作业放入待执行队列.
  *
  * @param jobName 作业名称
  */
 public void addTransient(final String jobName) {
   if (regCenter.getNumChildren(ReadyNode.ROOT)
       > env.getFrameworkConfiguration().getJobStateQueueSize()) {
     log.warn(
         "Cannot add transient job, caused by read state queue size is larger than {}.",
         env.getFrameworkConfiguration().getJobStateQueueSize());
     return;
   }
   Optional<CloudJobConfiguration> cloudJobConfig = configService.load(jobName);
   if (!cloudJobConfig.isPresent()
       || JobExecutionType.TRANSIENT != cloudJobConfig.get().getJobExecutionType()) {
     return;
   }
   String readyJobNode = ReadyNode.getReadyJobNodePath(jobName);
   String times = regCenter.getDirectly(readyJobNode);
   if (cloudJobConfig.get().getTypeConfig().getCoreConfig().isMisfire()) {
     regCenter.persist(
         readyJobNode, Integer.toString(null == times ? 1 : Integer.parseInt(times) + 1));
   } else {
     regCenter.persist(ReadyNode.getReadyJobNodePath(jobName), "1");
   }
 }
 @Test(expected = JobConfigurationException.class)
 public void assertRegisterExisted() {
   when(configService.load("transient_test_job")).thenReturn(Optional.of(transientJobConfig));
   producerManager.register(transientJobConfig);
 }
 @Test(expected = JobConfigurationException.class)
 public void assertUpdateNotExisted() {
   when(configService.load("transient_test_job"))
       .thenReturn(Optional.<CloudJobConfiguration>absent());
   producerManager.update(transientJobConfig);
 }