Search in sources :

Example 1 with TaskState

use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.

the class ClusterEventMetadataGeneratorTest method testErrorMessage.

@Test
public void testErrorMessage() throws Exception {
    JobContext jobContext = Mockito.mock(JobContext.class);
    JobState jobState = new JobState("jobName", "1234");
    TaskState taskState1 = new TaskState();
    TaskState taskState2 = new TaskState();
    taskState1.setTaskId("1");
    taskState1.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, "exception1");
    taskState2.setTaskId("2");
    taskState2.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, "exception2");
    taskState2.setProp(EventMetadataUtils.TASK_FAILURE_MESSAGE_KEY, "failureMessage2");
    jobState.addTaskState(taskState1);
    jobState.addTaskState(taskState2);
    Mockito.when(jobContext.getJobState()).thenReturn(jobState);
    ClusterEventMetadataGenerator metadataGenerator = new ClusterEventMetadataGenerator();
    Map<String, String> metadata;
    // error message is not in job commit event
    metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_COMMIT);
    Assert.assertEquals(metadata.get("message"), null);
    // error message is in job failed event
    metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_FAILED);
    Assert.assertTrue(metadata.get("message").startsWith("failureMessage"));
    Assert.assertTrue(metadata.get("message").contains("exception1"));
    Assert.assertTrue(metadata.get("message").contains("exception2"));
}
Also used : JobState(org.apache.gobblin.runtime.JobState) JobContext(org.apache.gobblin.runtime.JobContext) TaskState(org.apache.gobblin.runtime.TaskState) Test(org.testng.annotations.Test)

Example 2 with TaskState

use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.

the class TaskMetricsTest method testTaskGetMetrics.

@Test
public void testTaskGetMetrics() {
    String jobId = "job_456";
    String taskId = "task_456";
    String jobName = "jobName";
    JobState jobState = new JobState(jobName, jobId);
    JobMetrics jobMetrics = JobMetrics.get(jobState);
    State props = new State();
    props.setProp(ConfigurationKeys.JOB_ID_KEY, jobId);
    props.setProp(ConfigurationKeys.TASK_ID_KEY, taskId);
    SourceState sourceState = new SourceState(props, new ArrayList<WorkUnitState>());
    WorkUnit workUnit = new WorkUnit(sourceState, null);
    WorkUnitState workUnitState = new WorkUnitState(workUnit);
    TaskState taskState = new TaskState(workUnitState);
    TaskMetrics taskMetrics = new TaskMetrics(taskState);
    Assert.assertNotNull(taskMetrics.getMetricContext());
    Assert.assertTrue(taskMetrics.getMetricContext().getParent().isPresent());
    Assert.assertEquals(taskMetrics.getMetricContext().getParent().get(), jobMetrics.getMetricContext());
}
Also used : SourceState(org.apache.gobblin.configuration.SourceState) JobState(org.apache.gobblin.runtime.JobState) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) SourceState(org.apache.gobblin.configuration.SourceState) State(org.apache.gobblin.configuration.State) TaskState(org.apache.gobblin.runtime.TaskState) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) JobState(org.apache.gobblin.runtime.JobState) WorkUnit(org.apache.gobblin.source.workunit.WorkUnit) TaskState(org.apache.gobblin.runtime.TaskState) Test(org.testng.annotations.Test)

Example 3 with TaskState

use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.

the class TaskIFaceWrapper method getTaskState.

@Override
public TaskState getTaskState() {
    TaskState taskState = this.taskContext.getTaskState();
    taskState.setTaskId(getTaskId());
    taskState.setJobId(getJobId());
    taskState.setWorkingState(getWorkingState());
    taskState.addAll(getExecutionMetadata());
    taskState.addAll(getPersistentState());
    return taskState;
}
Also used : TaskState(org.apache.gobblin.runtime.TaskState)

Example 4 with TaskState

use of org.apache.gobblin.runtime.TaskState in project incubator-gobblin by apache.

the class ClusterEventMetadataGeneratorTest method testProcessedCount.

@Test
public void testProcessedCount() throws Exception {
    JobContext jobContext = Mockito.mock(JobContext.class);
    JobState jobState = new JobState("jobName", "1234");
    TaskState taskState1 = new TaskState();
    TaskState taskState2 = new TaskState();
    taskState1.setTaskId("1");
    taskState1.setProp(ConfigurationKeys.WRITER_RECORDS_WRITTEN, "1");
    taskState2.setTaskId("2");
    taskState2.setProp(ConfigurationKeys.WRITER_RECORDS_WRITTEN, "22");
    jobState.addTaskState(taskState1);
    jobState.addTaskState(taskState2);
    Mockito.when(jobContext.getJobState()).thenReturn(jobState);
    ClusterEventMetadataGenerator metadataGenerator = new ClusterEventMetadataGenerator();
    Map<String, String> metadata;
    // processed count is not in job cancel event
    metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_CANCEL);
    Assert.assertEquals(metadata.get("processedCount"), null);
    // processed count is in job complete event
    metadata = metadataGenerator.getMetadata(jobContext, EventName.getEnumFromEventId("JobCompleteTimer"));
    Assert.assertEquals(metadata.get("processedCount"), "23");
}
Also used : JobState(org.apache.gobblin.runtime.JobState) JobContext(org.apache.gobblin.runtime.JobContext) TaskState(org.apache.gobblin.runtime.TaskState) Test(org.testng.annotations.Test)

Aggregations

TaskState (org.apache.gobblin.runtime.TaskState)4 JobState (org.apache.gobblin.runtime.JobState)3 Test (org.testng.annotations.Test)3 JobContext (org.apache.gobblin.runtime.JobContext)2 SourceState (org.apache.gobblin.configuration.SourceState)1 State (org.apache.gobblin.configuration.State)1 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)1 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)1