Search in sources :

Example 1 with JobStatusTraceEvent

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

the class JobEventRdbSearch method getJobStatusTraceEvents.

private List<JobStatusTraceEvent> getJobStatusTraceEvents(final Condition condition) {
    List<JobStatusTraceEvent> result = new LinkedList<>();
    try (Connection conn = dataSource.getConnection();
        PreparedStatement preparedStatement = createDataPreparedStatement(conn, TABLE_JOB_STATUS_TRACE_LOG, FIELDS_JOB_STATUS_TRACE_LOG, condition);
        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 Date(resultSet.getTimestamp(11).getTime()));
            result.add(jobStatusTraceEvent);
        }
    } catch (final SQLException ex) {
        // TODO 记录失败直接输出日志,未来可考虑配置化
        log.error("Fetch JobStatusTraceEvent from DB error:", ex);
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 2 with JobStatusTraceEvent

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

the class JobEventRdbSearchTest method assertFindJobStatusTraceEventsWithErrorFields.

@Test
public void assertFindJobStatusTraceEventsWithErrorFields() {
    Map<String, Object> fields = new HashMap<>();
    fields.put("notExistField", "some value");
    Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, null, fields));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
}
Also used : Condition(com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.Condition) HashMap(java.util.HashMap) JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Test(org.junit.Test)

Example 3 with JobStatusTraceEvent

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

the class JobEventRdbStorageTest method assertAddJobStatusTraceEventWhenFailoverWithTaskStagingState.

@Test
public void assertAddJobStatusTraceEventWhenFailoverWithTaskStagingState() throws SQLException {
    JobStatusTraceEvent jobStatusTraceEvent = new JobStatusTraceEvent("test_job", "fake_failover_task_id", "fake_slave_id", Source.LITE_EXECUTOR, ExecutionType.FAILOVER, "0", State.TASK_STAGING, "message is empty.");
    jobStatusTraceEvent.setOriginalTaskId("original_fake_failover_task_id");
    assertThat(storage.getJobStatusTraceEvents("fake_failover_task_id").size(), is(0));
    storage.addJobStatusTraceEvent(jobStatusTraceEvent);
    assertThat(storage.getJobStatusTraceEvents("fake_failover_task_id").size(), is(1));
}
Also used : JobStatusTraceEvent(com.dangdang.ddframe.job.event.type.JobStatusTraceEvent) Test(org.junit.Test)

Example 4 with JobStatusTraceEvent

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

the class JobEventRdbSearchTest method assertFindJobStatusTraceEventsWithErrorPageSizeAndNumber.

@Test
public void assertFindJobStatusTraceEventsWithErrorPageSizeAndNumber() {
    Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(-1, -1, null, null, 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 5 with JobStatusTraceEvent

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

the class JobEventRdbSearchTest method assertFindJobStatusTraceEventsWithPageSizeAndNumber.

@Test
public void assertFindJobStatusTraceEventsWithPageSizeAndNumber() {
    Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(10));
    result = repository.findJobStatusTraceEvents(new Condition(50, 1, null, null, null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(50));
    result = repository.findJobStatusTraceEvents(new Condition(100, 5, null, null, null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(100));
    result = repository.findJobStatusTraceEvents(new Condition(100, 6, null, null, null, null, null));
    assertThat(result.getTotal(), is(500));
    assertThat(result.getRows().size(), is(0));
}
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