示例#1
0
 private void registerElasticEnv() {
   listenerManager.startAllListeners();
   leaderElectionService.leaderElection();
   configService.persistJobConfiguration();
   serverService.persistServerOnline();
   serverService.clearJobStopedStatus();
   statisticsService.startProcessCountJob();
   shardingService.setReshardingFlag();
   monitorService.listen();
 }
示例#2
0
 /**
  * 恢复因服务器崩溃而停止的作业.
  *
  * <p>不会恢复手工设置停止运行的作业.
  */
 public void resumeCrashedJob() {
   serverService.persistServerOnline();
   executionService.clearRunningInfo(shardingService.getLocalHostShardingItems());
   if (serverService.isJobStopedManually()) {
     return;
   }
   try {
     scheduler.resumeAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
 }
示例#3
0
 /** 恢复手工停止的作业. */
 public void resumeManualStopedJob() {
   try {
     if (scheduler.isShutdown()) {
       return;
     }
     scheduler.resumeAll();
     // TODO 恢复stoped=fasle状态
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
   serverService.clearJobStopedStatus();
 }
 /** 恢复手工停止的作业. */
 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();
 }
示例#5
0
 /**
  * 注册作业完成信息.
  *
  * @param jobExecutionShardingContext 作业运行时分片上下文
  */
 public void registerJobCompleted(
     final JobExecutionMultipleShardingContext jobExecutionShardingContext) {
   if (!configService.isMonitorExecution()) {
     return;
   }
   serverService.updateServerStatus(ServerStatus.READY);
   for (int each : jobExecutionShardingContext.getShardingItems()) {
     jobNodeStorage.createJobNodeIfNeeded(ExecutionNode.getCompletedNode(each));
     jobNodeStorage.removeJobNodeIfExisted(ExecutionNode.getRunningNode(each));
     jobNodeStorage.replaceJobNode(
         ExecutionNode.getLastCompleteTimeNode(each), System.currentTimeMillis());
   }
 }
 @Test
 public void assertFailoverIfNecessary() {
   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);
   failoverService.failoverIfNecessary();
   verify(jobNodeStorage).isJobNodeExisted("leader/failover/items");
   verify(jobNodeStorage).getJobNodeChildrenKeys("leader/failover/items");
   verify(serverService).isLocalhostServerReady();
   verify(jobNodeStorage)
       .executeInLeader(
           eq("leader/failover/latch"), Matchers.<FailoverLeaderExecutionCallback>any());
 }
 @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();
 }
 @Test
 public void
     assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsNotLeaderWithoutAvailableServers() {
   when(leaderElectionService.hasLeader()).thenReturn(false);
   when(serverService.getAvailableServers()).thenReturn(Collections.<String>emptyList());
   electionListenerManager.new LeaderElectionJobListener()
       .dataChanged(
           null,
           new TreeCacheEvent(
               TreeCacheEvent.Type.NODE_REMOVED,
               new ChildData("/testJob/leader/election/host", null, "localhost".getBytes())),
           "/testJob/leader/election/host");
   verify(leaderElectionService).hasLeader();
   verify(serverService).getAvailableServers();
   verify(leaderElectionService, times(0)).leaderElection();
 }
示例#9
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());
       }
     }
   }
 }
 @Test
 public void testIsJobStoppedManually() {
   when(serverService.isJobStoppedManually()).thenReturn(true);
   assertTrue(schedulerFacade.isJobStoppedManually());
 }
 private boolean needFailover() {
   return jobNodeStorage.isJobNodeExisted(FailoverNode.ITEMS_ROOT)
       && !jobNodeStorage.getJobNodeChildrenKeys(FailoverNode.ITEMS_ROOT).isEmpty()
       && serverService.isServerReady();
 }