@After
 public void tearDown() throws SchedulerException, NoSuchFieldException {
   ProcessCountStatistics.reset(jobName);
   JobScheduler jobScheduler = JobRegistry.getInstance().getJob(jobName);
   if (null != jobScheduler) {
     JobRegistry.getInstance().getJob(jobName).shutdown();
   }
   ReflectionUtils.setFieldValue(JobRegistry.getInstance(), "instance", null);
 }
Exemplo n.º 2
0
 /** 停止作业. */
 public void stopJob() {
   try {
     JobRegistry.getInstance().getJobInstance(jobConfiguration.getJobName()).stop();
     scheduler.pauseAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
 }
Exemplo n.º 3
0
 /** 恢复手工停止的作业. */
 public void resumeManualStopedJob() {
   try {
     if (scheduler.isShutdown()) {
       return;
     }
     JobRegistry.getInstance().getJobInstance(jobConfiguration.getJobName()).resume();
     scheduler.resumeAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
   serverService.clearJobStopedStatus();
 }
Exemplo n.º 4
0
 /** 初始化作业. */
 public void init() {
   log.debug("Elastic job: job controller init, job name is: {}.", jobConfiguration.getJobName());
   coordinatorRegistryCenter.addCacheData("/" + jobConfiguration.getJobName());
   registerElasticEnv();
   jobDetail = createJobDetail();
   try {
     scheduler = initializeScheduler(jobDetail.getKey().toString());
     scheduleJob(createTrigger(configService.getCron()));
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
   JobRegistry.getInstance().addJob(jobConfiguration.getJobName(), this);
 }
Exemplo n.º 5
0
 /**
  * 恢复因服务器崩溃而停止的作业.
  *
  * <p>不会恢复手工设置停止运行的作业.
  */
 public void resumeCrashedJob() {
   serverService.persistServerOnline();
   executionService.clearRunningInfo(shardingService.getLocalHostShardingItems());
   if (serverService.isJobStopedManually()) {
     return;
   }
   JobRegistry.getInstance().getJobInstance(jobConfiguration.getJobName()).resume();
   try {
     scheduler.resumeAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
 }
Exemplo n.º 6
0
 @Test
 public void assertFailoverLeaderExecutionCallbackIfNecessary() {
   when(jobNodeStorage.isJobNodeExisted("leader/failover/items")).thenReturn(true);
   when(jobNodeStorage.getJobNodeChildrenKeys("leader/failover/items"))
       .thenReturn(Arrays.asList("0", "1", "2"));
   when(serverService.isLocalhostServerReady()).thenReturn(true);
   JobRegistry.getInstance().addJobScheduleController("testJob", jobScheduleController);
   failoverService.new FailoverLeaderExecutionCallback().execute();
   verify(jobNodeStorage).isJobNodeExisted("leader/failover/items");
   verify(jobNodeStorage, times(2)).getJobNodeChildrenKeys("leader/failover/items");
   verify(serverService).isLocalhostServerReady();
   verify(jobNodeStorage).fillEphemeralJobNode("execution/0/failover", "mockedIP");
   verify(jobNodeStorage).removeJobNodeIfExisted("leader/failover/items/0");
   verify(jobScheduleController).triggerJob();
 }
Exemplo n.º 7
0
 /**
  * 注册作业启动信息.
  *
  * @param jobExecutionShardingContext 作业运行时分片上下文
  */
 public void registerJobBegin(
     final JobExecutionMultipleShardingContext jobExecutionShardingContext) {
   if (!jobExecutionShardingContext.getShardingItems().isEmpty()
       && configService.isMonitorExecution()) {
     serverService.updateServerStatus(ServerStatus.RUNNING);
     for (int each : jobExecutionShardingContext.getShardingItems()) {
       jobNodeStorage.fillEphemeralJobNode(ExecutionNode.getRunningNode(each), "");
       jobNodeStorage.replaceJobNode(
           ExecutionNode.getLastBeginTimeNode(each), System.currentTimeMillis());
       Date nextFireTime =
           JobRegistry.getInstance().getJob(jobConfiguration.getJobName()).getNextFireTime();
       if (null != nextFireTime) {
         jobNodeStorage.replaceJobNode(
             ExecutionNode.getNextFireTimeNode(each), nextFireTime.getTime());
       }
     }
   }
 }