Search in sources :

Example 16 with JobExecutionInfo

use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.

the class DatabaseJobHistoryStoreV101 method getJobExecutionInfos.

private Map<String, JobExecutionInfo> getJobExecutionInfos(Connection connection, List<String> jobIds) throws SQLException {
    Map<String, JobExecutionInfo> jobExecutionInfos = Maps.newLinkedHashMap();
    if (jobIds != null && jobIds.size() > 0) {
        String template = String.format(JOB_EXECUTION_QUERY_BY_JOB_ID_STATEMENT_TEMPLATE, getInPredicate(jobIds.size()));
        int index = 1;
        try (PreparedStatement jobExecutionQueryStatement = connection.prepareStatement(template)) {
            for (String jobId : jobIds) {
                jobExecutionQueryStatement.setString(index++, jobId);
            }
            try (ResultSet jobRs = jobExecutionQueryStatement.executeQuery()) {
                while (jobRs.next()) {
                    JobExecutionInfo jobExecutionInfo = resultSetToJobExecutionInfo(jobRs);
                    jobExecutionInfos.put(jobExecutionInfo.getJobId(), jobExecutionInfo);
                }
            }
        }
    }
    return jobExecutionInfos;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo)

Example 17 with JobExecutionInfo

use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.

the class DatabaseJobHistoryStoreTest method testQueryByJobName.

@Test(dependsOnMethods = { "testUpdate" })
public void testQueryByJobName() throws IOException {
    JobExecutionQuery queryByJobName = new JobExecutionQuery();
    queryByJobName.setIdType(QueryIdTypeEnum.JOB_NAME);
    queryByJobName.setId(JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(0).getJobName()));
    List<JobExecutionInfo> result = this.jobHistoryStore.get(queryByJobName);
    Assert.assertEquals(result.size(), 1);
    JobExecutionInfo actual = result.get(0);
    JobExecutionInfo expected = this.expectedJobExecutionInfos.get(0);
    assertJobExecution(actual, expected);
}
Also used : JobExecutionQuery(org.apache.gobblin.rest.JobExecutionQuery) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo) Test(org.testng.annotations.Test)

Example 18 with JobExecutionInfo

use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.

the class DatabaseJobHistoryStoreTest method testUpdate.

@Test(dependsOnMethods = { "testInsert" })
public void testUpdate() throws IOException {
    for (JobExecutionInfo jobExecutionInfo : this.expectedJobExecutionInfos) {
        jobExecutionInfo.setEndTime(System.currentTimeMillis());
        jobExecutionInfo.setDuration(jobExecutionInfo.getEndTime() - jobExecutionInfo.getStartTime());
        jobExecutionInfo.setState(JobStateEnum.COMMITTED);
        jobExecutionInfo.setCompletedTasks(jobExecutionInfo.getLaunchedTasks());
        for (TaskExecutionInfo taskExecutionInfo : jobExecutionInfo.getTaskExecutions()) {
            taskExecutionInfo.setEndTime(jobExecutionInfo.getEndTime());
            taskExecutionInfo.setDuration(taskExecutionInfo.getEndTime() - taskExecutionInfo.getStartTime());
            taskExecutionInfo.setState(TaskStateEnum.COMMITTED);
        }
        this.jobHistoryStore.put(jobExecutionInfo);
    }
}
Also used : TaskExecutionInfo(org.apache.gobblin.rest.TaskExecutionInfo) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo) Test(org.testng.annotations.Test)

Example 19 with JobExecutionInfo

use of org.apache.gobblin.rest.JobExecutionInfo in project incubator-gobblin by apache.

the class DatabaseJobHistoryStoreTest method testQueryByTable.

@Test(dependsOnMethods = { "testUpdate" })
public void testQueryByTable() throws IOException {
    JobExecutionQuery queryByTable = new JobExecutionQuery();
    queryByTable.setIdType(QueryIdTypeEnum.TABLE);
    queryByTable.setId(JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(0).getTaskExecutions().get(0).getTable()));
    List<JobExecutionInfo> result = this.jobHistoryStore.get(queryByTable);
    Assert.assertEquals(result.size(), 2);
    JobExecutionInfo actual = result.get(0);
    Assert.assertEquals(actual.getJobName(), this.expectedJobExecutionInfos.get(0).getJobName());
    Assert.assertEquals(actual.getJobId(), this.expectedJobExecutionInfos.get(0).getJobId());
    Assert.assertEquals(actual.getTaskExecutions().size(), 1);
    Assert.assertEquals(actual.getTaskExecutions().get(0).getTable(), this.expectedJobExecutionInfos.get(0).getTaskExecutions().get(0).getTable());
    actual = result.get(1);
    Assert.assertEquals(actual.getJobName(), this.expectedJobExecutionInfos.get(1).getJobName());
    Assert.assertEquals(actual.getJobId(), this.expectedJobExecutionInfos.get(1).getJobId());
    Assert.assertEquals(actual.getTaskExecutions().size(), 1);
    Assert.assertEquals(actual.getTaskExecutions().get(0).getTable(), this.expectedJobExecutionInfos.get(1).getTaskExecutions().get(0).getTable());
    queryByTable.setId(JobExecutionQuery.Id.create(this.expectedJobExecutionInfos.get(1).getTaskExecutions().get(1).getTable()));
    result = this.jobHistoryStore.get(queryByTable);
    Assert.assertEquals(result.size(), 1);
    actual = result.get(0);
    Assert.assertEquals(actual.getJobName(), this.expectedJobExecutionInfos.get(1).getJobName());
    Assert.assertEquals(actual.getJobId(), this.expectedJobExecutionInfos.get(1).getJobId());
    Assert.assertEquals(result.size(), 1);
    Assert.assertEquals(actual.getTaskExecutions().size(), 1);
    Assert.assertEquals(actual.getTaskExecutions().get(0).getTable(), this.expectedJobExecutionInfos.get(1).getTaskExecutions().get(1).getTable());
}
Also used : JobExecutionQuery(org.apache.gobblin.rest.JobExecutionQuery) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo) Test(org.testng.annotations.Test)

Aggregations

JobExecutionInfo (org.apache.gobblin.rest.JobExecutionInfo)19 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 StringMap (com.linkedin.data.template.StringMap)5 SQLException (java.sql.SQLException)5 TaskExecutionInfo (org.apache.gobblin.rest.TaskExecutionInfo)5 Test (org.testng.annotations.Test)5 Map (java.util.Map)4 MetricArray (org.apache.gobblin.rest.MetricArray)4 TaskExecutionInfoArray (org.apache.gobblin.rest.TaskExecutionInfoArray)4 AbstractMap (java.util.AbstractMap)3 JobExecutionQuery (org.apache.gobblin.rest.JobExecutionQuery)3 ParseException (java.text.ParseException)2 Metric (org.apache.gobblin.rest.Metric)2 Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Meter (com.codahale.metrics.Meter)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1