Search in sources :

Example 6 with JobState

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

the class HiveMaterializerTest method getTaskContextForRun.

private TaskContext getTaskContextForRun(WorkUnit workUnit) {
    workUnit.setProp(ConfigurationKeys.JOB_ID_KEY, "job123");
    workUnit.setProp(ConfigurationKeys.TASK_ID_KEY, "task123");
    workUnit.setProp(HiveConverterUtils.HIVE_DATASET_DESTINATION_SKIP_SETGROUP, Boolean.toString(true));
    HiveTask.disableHiveWatermarker(workUnit);
    JobState jobState = new JobState("job", "job123");
    return new TaskContext(new WorkUnitState(workUnit, jobState));
}
Also used : TaskContext(org.apache.gobblin.runtime.TaskContext) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) JobState(org.apache.gobblin.runtime.JobState)

Example 7 with JobState

use of org.apache.gobblin.runtime.JobState 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 8 with JobState

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

the class JobMetricsTest method testJobMetricsGet.

@Test
public void testJobMetricsGet() {
    String jobName = "testJob";
    String jobId = "job_123";
    JobState jobState = new JobState(jobName, jobId);
    JobMetrics jobMetrics = JobMetrics.get(jobState);
    Assert.assertNotNull(jobMetrics.getMetricContext());
    List<Tag<?>> tags = jobMetrics.getMetricContext().getTags();
    Map<String, ?> tagMap = jobMetrics.getMetricContext().getTagMap();
    String contextId = tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME).toString();
    String contextName = tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME).toString();
    Assert.assertEquals(tagMap.size(), 4);
    Assert.assertEquals(tagMap.get(JobEvent.METADATA_JOB_ID), jobId);
    Assert.assertEquals(tagMap.get(JobEvent.METADATA_JOB_NAME), jobName);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME), contextId);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME), contextName);
    // should get the original jobMetrics, can check by the id
    JobMetrics jobMetrics1 = JobMetrics.get(jobName + "_", jobId);
    Assert.assertNotNull(jobMetrics1.getMetricContext());
    tagMap = jobMetrics1.getMetricContext().getTagMap();
    Assert.assertEquals(tags.size(), 4);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME), contextId);
    Assert.assertEquals(tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME), contextName);
    // remove original jobMetrics, should create a new one
    GobblinMetricsRegistry.getInstance().remove(jobMetrics.getId());
    JobMetrics jobMetrics2 = JobMetrics.get(jobName + "_", jobId);
    Assert.assertNotNull(jobMetrics2.getMetricContext());
    tagMap = jobMetrics2.getMetricContext().getTagMap();
    Assert.assertEquals(tags.size(), 4);
    Assert.assertNotEquals(tagMap.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME), contextId);
    Assert.assertNotEquals(tagMap.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME), contextName);
}
Also used : JobState(org.apache.gobblin.runtime.JobState) Tag(org.apache.gobblin.metrics.Tag) Test(org.testng.annotations.Test)

Example 9 with JobState

use of org.apache.gobblin.runtime.JobState 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)

Example 10 with JobState

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

the class JobStateToJsonConverter method writeJobStates.

/**
 * Write a list of {@link JobState}s to json document.
 *
 * @param jsonWriter {@link com.google.gson.stream.JsonWriter}
 * @param jobStates list of {@link JobState}s to write to json document
 * @throws IOException
 */
private void writeJobStates(JsonWriter jsonWriter, List<? extends JobState> jobStates) throws IOException {
    jsonWriter.beginArray();
    for (JobState jobState : jobStates) {
        writeJobState(jsonWriter, jobState);
    }
    jsonWriter.endArray();
}
Also used : JobState(org.apache.gobblin.runtime.JobState)

Aggregations

JobState (org.apache.gobblin.runtime.JobState)15 Test (org.testng.annotations.Test)5 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)4 TaskState (org.apache.gobblin.runtime.TaskState)3 File (java.io.File)2 EmailException (org.apache.commons.mail.EmailException)2 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)2 TimingEvent (org.apache.gobblin.metrics.event.TimingEvent)2 JobContext (org.apache.gobblin.runtime.JobContext)2 Path (org.apache.hadoop.fs.Path)2 Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 GobblinScopeTypes (org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes)1 SourceState (org.apache.gobblin.configuration.SourceState)1 State (org.apache.gobblin.configuration.State)1 FsStateStore (org.apache.gobblin.metastore.FsStateStore)1 Tag (org.apache.gobblin.metrics.Tag)1 TaskContext (org.apache.gobblin.runtime.TaskContext)1 MultiWorkUnitUnpackingIterator (org.apache.gobblin.runtime.util.MultiWorkUnitUnpackingIterator)1 MultiWorkUnit (org.apache.gobblin.source.workunit.MultiWorkUnit)1