Search in sources :

Example 6 with JobStatusTraceEvent

use of com.dangdang.ddframe.job.event.type.JobStatusTraceEvent in project elastic-job by dangdangdotcom.

the class JobEventRdbSearchTest method assertFindJobStatusTraceEventsWithSort.

@Test
public void assertFindJobStatusTraceEventsWithSort() {
    Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, "jobName", "ASC", null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
    result = repository.findJobStatusTraceEvents(new Condition(10, 1, "jobName", "DESC", null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    assertThat(result.getRows().get(0).getJobName(), is("test_job_99"));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Test(org.junit.Test)

Example 7 with JobStatusTraceEvent

use of com.dangdang.ddframe.job.event.type.JobStatusTraceEvent in project elastic-job by dangdangdotcom.

the class JobEventRdbSearchTest method assertFindJobStatusTraceEventsWithErrorSort.

@Test
public void assertFindJobStatusTraceEventsWithErrorSort() {
    Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, "jobName", "ERROR_SORT", null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
    result = repository.findJobStatusTraceEvents(new Condition(10, 1, "notExistField", "ASC", null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Test(org.junit.Test)

Example 8 with JobStatusTraceEvent

use of com.dangdang.ddframe.job.event.type.JobStatusTraceEvent in project elastic-job by dangdangdotcom.

the class LiteJobFacade method postJobStatusTraceEvent.

@Override
public void postJobStatusTraceEvent(final String taskId, final State state, final String message) {
    TaskContext taskContext = TaskContext.from(taskId);
    jobEventBus.post(new JobStatusTraceEvent(taskContext.getMetaInfo().getJobName(), taskContext.getId(), taskContext.getSlaveId(), Source.LITE_EXECUTOR, taskContext.getType(), taskContext.getMetaInfo().getShardingItems().toString(), state, message));
    if (!Strings.isNullOrEmpty(message)) {
        log.trace(message);
    }
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)

Example 9 with JobStatusTraceEvent

use of com.dangdang.ddframe.job.event.type.JobStatusTraceEvent in project elastic-job by dangdangdotcom.

the class SchedulerEngine method statusUpdate.

@Override
public void statusUpdate(final SchedulerDriver schedulerDriver, final Protos.TaskStatus taskStatus) {
    String taskId = taskStatus.getTaskId().getValue();
    TaskContext taskContext = TaskContext.from(taskId);
    String jobName = taskContext.getMetaInfo().getJobName();
    log.trace("call statusUpdate task state is: {}, task id is: {}", taskStatus.getState(), taskId);
    jobEventBus.post(new JobStatusTraceEvent(jobName, taskContext.getId(), taskContext.getSlaveId(), Source.CLOUD_SCHEDULER, taskContext.getType(), String.valueOf(taskContext.getMetaInfo().getShardingItems()), State.valueOf(taskStatus.getState().name()), taskStatus.getMessage()));
    switch(taskStatus.getState()) {
        case TASK_RUNNING:
            if (!facadeService.load(jobName).isPresent()) {
                schedulerDriver.killTask(Protos.TaskID.newBuilder().setValue(taskId).build());
            }
            if ("BEGIN".equals(taskStatus.getMessage())) {
                facadeService.updateDaemonStatus(taskContext, false);
            } else if ("COMPLETE".equals(taskStatus.getMessage())) {
                facadeService.updateDaemonStatus(taskContext, true);
            }
            break;
        case TASK_FINISHED:
            facadeService.removeRunning(taskContext);
            unAssignTask(taskId);
            statisticManager.taskRunSuccessfully();
            break;
        case TASK_KILLED:
            log.warn("task id is: {}, status is: {}, message is: {}, source is: {}", taskId, taskStatus.getState(), taskStatus.getMessage(), taskStatus.getSource());
            facadeService.removeRunning(taskContext);
            facadeService.addDaemonJobToReadyQueue(jobName);
            unAssignTask(taskId);
            break;
        case TASK_LOST:
        case TASK_FAILED:
        case TASK_ERROR:
            log.warn("task id is: {}, status is: {}, message is: {}, source is: {}", taskId, taskStatus.getState(), taskStatus.getMessage(), taskStatus.getSource());
            facadeService.removeRunning(taskContext);
            facadeService.recordFailoverTask(taskContext);
            unAssignTask(taskId);
            statisticManager.taskRunFailed();
            break;
        default:
            break;
    }
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)

Example 10 with JobStatusTraceEvent

use of com.dangdang.ddframe.job.event.type.JobStatusTraceEvent in project elastic-job by dangdangdotcom.

the class CloudJobRestfulApiTest method assertFindJobStatusTraceEvent.

@Test
public void assertFindJobStatusTraceEvent() throws Exception {
    ReflectionUtils.setFieldValue(CloudJobRestfulApi.class, CloudJobRestfulApi.class.getDeclaredField("jobEventRdbSearch"), getJobEventRdbSearch());
    JobStatusTraceEvent jobStatusTraceEvent = new JobStatusTraceEvent("test-job", "fake_task_id", "fake_slave_id", Source.LITE_EXECUTOR, ExecutionType.READY, "0", State.TASK_RUNNING, "message is empty.");
    when(getJobEventRdbSearch().findJobStatusTraceEvents(any(Condition.class))).thenReturn(new Result<>(0, Lists.newArrayList(jobStatusTraceEvent)));
    assertThat(sentGetRequest("http://127.0.0.1:19000/job/events/statusTraces?" + buildFindJobEventsQueryParameter()), is(GsonFactory.getGson().toJson(new Result<>(0, Lists.newArrayList(jobStatusTraceEvent)))));
    verify(getJobEventRdbSearch()).findJobStatusTraceEvents(any(Condition.class));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Test(org.junit.Test)

Aggregations

JobStatusTraceEvent (com.dangdang.ddframe.job.event.type.JobStatusTraceEvent)18 Test (org.junit.Test)11 Condition (com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition)8 TaskContext (com.dangdang.ddframe.job.context.TaskContext)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 JobExecutionEvent (com.dangdang.ddframe.job.event.type.JobExecutionEvent)1 ByteString (com.google.protobuf.ByteString)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1