Search in sources :

Example 16 with JobStatusTraceEvent

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

the class JobEventRdbStorageTest method assertAddJobStatusTraceEventWhenFailoverWithTaskFailedState.

@Test
public void assertAddJobStatusTraceEventWhenFailoverWithTaskFailedState() throws SQLException {
    JobStatusTraceEvent stagingJobStatusTraceEvent = new JobStatusTraceEvent("test_job", "fake_failed_failover_task_id", "fake_slave_id", Source.LITE_EXECUTOR, ExecutionType.FAILOVER, "0", State.TASK_STAGING, "message is empty.");
    stagingJobStatusTraceEvent.setOriginalTaskId("original_fake_failed_failover_task_id");
    storage.addJobStatusTraceEvent(stagingJobStatusTraceEvent);
    JobStatusTraceEvent failedJobStatusTraceEvent = new JobStatusTraceEvent("test_job", "fake_failed_failover_task_id", "fake_slave_id", Source.LITE_EXECUTOR, ExecutionType.FAILOVER, "0", State.TASK_FAILED, "message is empty.");
    storage.addJobStatusTraceEvent(failedJobStatusTraceEvent);
    List<JobStatusTraceEvent> jobStatusTraceEvents = storage.getJobStatusTraceEvents("fake_failed_failover_task_id");
    assertThat(jobStatusTraceEvents.size(), is(2));
    for (JobStatusTraceEvent jobStatusTraceEvent : jobStatusTraceEvents) {
        assertThat(jobStatusTraceEvent.getOriginalTaskId(), is("original_fake_failed_failover_task_id"));
    }
}
Also used : JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Test(org.junit.Test)

Example 17 with JobStatusTraceEvent

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

the class JobEventRdbStorage method getJobStatusTraceEvents.

List<JobStatusTraceEvent> getJobStatusTraceEvents(final String taskId) {
    String sql = String.format("SELECT * FROM %s WHERE task_id = '%s'", TABLE_JOB_STATUS_TRACE_LOG, taskId);
    List<JobStatusTraceEvent> result = new ArrayList<>();
    try (Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery()) {
        while (resultSet.next()) {
            JobStatusTraceEvent jobStatusTraceEvent = new JobStatusTraceEvent(resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5), Source.valueOf(resultSet.getString(6)), ExecutionType.valueOf(resultSet.getString(7)), resultSet.getString(8), State.valueOf(resultSet.getString(9)), resultSet.getString(10), new SimpleDateFormat("yyyy-mm-dd HH:MM:SS").parse(resultSet.getString(11)));
            result.add(jobStatusTraceEvent);
        }
    } catch (final SQLException | ParseException ex) {
        // TODO 记录失败直接输出日志,未来可考虑配置化
        log.error(ex.getMessage());
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with JobStatusTraceEvent

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

the class TaskLaunchScheduledService method createJobStatusTraceEvent.

private JobStatusTraceEvent createJobStatusTraceEvent(final TaskContext taskContext) {
    TaskContext.MetaInfo metaInfo = taskContext.getMetaInfo();
    JobStatusTraceEvent result = new JobStatusTraceEvent(metaInfo.getJobName(), taskContext.getId(), taskContext.getSlaveId(), Source.CLOUD_SCHEDULER, taskContext.getType(), String.valueOf(metaInfo.getShardingItems()), JobStatusTraceEvent.State.TASK_STAGING, "");
    if (ExecutionType.FAILOVER == taskContext.getType()) {
        Optional<String> taskContextOptional = facadeService.getFailoverTaskId(metaInfo);
        if (taskContextOptional.isPresent()) {
            result.setOriginalTaskId(taskContextOptional.get());
        }
    }
    return result;
}
Also used : TaskContext(com.dangdang.ddframe.job.context.TaskContext) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) ByteString(com.google.protobuf.ByteString)

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