Search in sources :

Example 11 with TaskContext

use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.

the class ProducerManagerTest method assertUpdateExisted.

@Test
public void assertUpdateExisted() {
    when(configService.load("transient_test_job")).thenReturn(Optional.of(transientJobConfig));
    List<TaskContext> taskContexts = Arrays.asList(TaskContext.from("transient_test_job@-@0@-@READY@-@SLAVE-S0@-@UUID"), TaskContext.from("transient_test_job@-@1@-@READY@-@SLAVE-S0@-@UUID"));
    when(runningService.getRunningTasks("transient_test_job")).thenReturn(taskContexts);
    producerManager.update(transientJobConfig);
    verify(configService).update(transientJobConfig);
    for (TaskContext each : taskContexts) {
        verify(schedulerDriver).killTask(Protos.TaskID.newBuilder().setValue(each.getId()).build());
    }
    verify(runningService).remove("transient_test_job");
    verify(readyService).remove(Lists.newArrayList("transient_test_job"));
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) Test(org.junit.Test)

Example 12 with TaskContext

use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.

the class CloudJobRestfulApiTest method assertFindAllRunningTasks.

@Test
public void assertFindAllRunningTasks() throws Exception {
    RunningService runningService = new RunningService(getRegCenter());
    TaskContext actualTaskContext = TaskContext.from(TaskNode.builder().build().getTaskNodeValue());
    when(getRegCenter().get("/config/job/" + actualTaskContext.getMetaInfo().getJobName())).thenReturn(CloudJsonConstants.getJobJson());
    runningService.add(actualTaskContext);
    assertThat(sentGetRequest("http://127.0.0.1:19000/job/tasks/running"), is(GsonFactory.getGson().toJson(Lists.newArrayList(actualTaskContext))));
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) RunningService(com.dangdang.ddframe.job.cloud.scheduler.state.running.RunningService) Test(org.junit.Test)

Example 13 with TaskContext

use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.

the class FacadeServiceTest method assertRemoveRunning.

@Test
public void assertRemoveRunning() {
    String taskNodeValue = TaskNode.builder().build().getTaskNodeValue();
    TaskContext taskContext = TaskContext.from(taskNodeValue);
    facadeService.removeRunning(taskContext);
    verify(runningService).remove(taskContext);
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) Test(org.junit.Test)

Example 14 with TaskContext

use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.

the class JobRunningStatisticJobTest method assertExecute.

@Test
public void assertExecute() throws SchedulerException {
    Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.of(new JobRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3)));
    Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.of(new TaskRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3)));
    when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics);
    when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics);
    when(repository.add(any(JobRunningStatistics.class))).thenReturn(true);
    when(repository.add(any(TaskRunningStatistics.class))).thenReturn(true);
    Map<String, Set<TaskContext>> jobMap = new HashMap<>(1);
    Set<TaskContext> jobSet = new HashSet<>(1);
    jobSet.add(TaskContext.from(TaskNode.builder().jobName("test_job").build().getTaskNodeValue()));
    jobMap.put("test_job", jobSet);
    when(runningService.getAllRunningTasks()).thenReturn(jobMap);
    jobRunningStatisticJob.execute(null);
    verify(repository).findLatestJobRunningStatistics();
    verify(repository).findLatestTaskRunningStatistics();
    verify(repository, times(3)).add(any(JobRunningStatistics.class));
    verify(repository, times(3)).add(any(TaskRunningStatistics.class));
    verify(runningService).getAllRunningTasks();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TaskContext(com.dangdang.ddframe.job.context.TaskContext) HashMap(java.util.HashMap) JobRunningStatistics(com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics) TaskRunningStatistics(com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with TaskContext

use of com.dangdang.ddframe.job.context.TaskContext in project elastic-job by dangdangdotcom.

the class FacadeService method removeLaunchTasksFromQueue.

/**
     * 从队列中删除已运行的作业.
     * 
     * @param taskContexts 任务上下文集合
     */
public void removeLaunchTasksFromQueue(final List<TaskContext> taskContexts) {
    List<TaskContext> failoverTaskContexts = new ArrayList<>(taskContexts.size());
    Collection<String> readyJobNames = new HashSet<>(taskContexts.size(), 1);
    for (TaskContext each : taskContexts) {
        switch(each.getType()) {
            case FAILOVER:
                failoverTaskContexts.add(each);
                break;
            case READY:
                readyJobNames.add(each.getMetaInfo().getJobName());
                break;
            default:
                break;
        }
    }
    failoverService.remove(Lists.transform(failoverTaskContexts, new Function<TaskContext, TaskContext.MetaInfo>() {

        @Override
        public TaskContext.MetaInfo apply(final TaskContext input) {
            return input.getMetaInfo();
        }
    }));
    readyService.remove(readyJobNames);
}
Also used : Function(com.google.common.base.Function) TaskContext(com.dangdang.ddframe.job.context.TaskContext) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

TaskContext (com.dangdang.ddframe.job.context.TaskContext)19 Test (org.junit.Test)9 JobStatusTraceEvent (com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)4 ArrayList (java.util.ArrayList)3 Protos (org.apache.mesos.Protos)3 TaskNode (com.dangdang.ddframe.job.cloud.scheduler.fixture.TaskNode)2 ByteString (com.google.protobuf.ByteString)2 TaskAssignmentResult (com.netflix.fenzo.TaskAssignmentResult)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 TaskInfo (org.apache.mesos.Protos.TaskInfo)2 CloudAppConfiguration (com.dangdang.ddframe.job.cloud.scheduler.config.app.CloudAppConfiguration)1 CloudJobConfiguration (com.dangdang.ddframe.job.cloud.scheduler.config.job.CloudJobConfiguration)1 RunningService (com.dangdang.ddframe.job.cloud.scheduler.state.running.RunningService)1 ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)1 JobRunningStatistics (com.dangdang.ddframe.job.statistics.type.job.JobRunningStatistics)1 TaskRunningStatistics (com.dangdang.ddframe.job.statistics.type.task.TaskRunningStatistics)1 Function (com.google.common.base.Function)1 TaskRequest (com.netflix.fenzo.TaskRequest)1 VMAssignmentResult (com.netflix.fenzo.VMAssignmentResult)1