Search in sources :

Example 96 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class JobState method getTaskStatesAsWorkUnitStates.

/**
 * Get task states of {@link Task}s of this job as {@link WorkUnitState}s.
 *
 * @return a list of {@link WorkUnitState}s
 */
public List<WorkUnitState> getTaskStatesAsWorkUnitStates() {
    ImmutableList.Builder<WorkUnitState> builder = ImmutableList.builder();
    for (TaskState taskState : this.taskStates.values()) {
        WorkUnitState workUnitState = new WorkUnitState(taskState.getWorkunit(), taskState.getJobState());
        workUnitState.setId(taskState.getId());
        workUnitState.addAll(taskState);
        builder.add(workUnitState);
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) WorkUnitState(org.apache.gobblin.configuration.WorkUnitState)

Example 97 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class TaskContinuousTest method getStreamingTaskState.

private TaskState getStreamingTaskState() {
    WorkUnitState workUnitState = new WorkUnitState(WorkUnit.create(new Extract(Extract.TableType.SNAPSHOT_ONLY, this.getClass().getName(), this.getClass().getSimpleName())));
    workUnitState.setProp(ConfigurationKeys.TASK_KEY_KEY, "1234");
    TaskState taskState = new TaskState(workUnitState);
    taskState.setProp(ConfigurationKeys.METRICS_ENABLED_KEY, Boolean.toString(false));
    taskState.setProp(TaskConfigurationKeys.TASK_EXECUTION_MODE, ExecutionModel.STREAMING.name());
    taskState.setJobId("1234");
    taskState.setTaskId("testContinuousTaskId");
    return taskState;
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Extract(org.apache.gobblin.source.workunit.Extract)

Example 98 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class TaskStateTest method setUp.

@BeforeClass
public void setUp() {
    WorkUnitState workUnitState = new WorkUnitState();
    workUnitState.setProp(ConfigurationKeys.JOB_ID_KEY, "Job-1");
    workUnitState.setProp(ConfigurationKeys.TASK_ID_KEY, "Task-1");
    this.taskState = new TaskState(workUnitState);
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) BeforeClass(org.testng.annotations.BeforeClass)

Example 99 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class MultiConverterTest method testConversionWithMultiplicityAndOneOrEmpty.

/**
 * Combines {@link MultiIdentityConverter()} with {@link OneOrEmptyConverter()}
 * @throws Exception
 */
@Test
public void testConversionWithMultiplicityAndOneOrEmpty() throws Exception {
    MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(20), new OneOrEmptyConverter(1), new TestConverter()));
    WorkUnitState workUnitState = new WorkUnitState();
    Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    Iterable<Object> convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
    Assert.assertEquals(Iterables.size(convertedRecordIterable), 20);
    for (Object record : convertedRecordIterable) {
        checkConvertedAvroData(schema, (GenericRecord) record);
    }
    multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(20), new OneOrEmptyConverter(10), new TestConverter()));
    workUnitState = new WorkUnitState();
    schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
    Assert.assertEquals(Iterables.size(convertedRecordIterable), 2);
    for (Object record : convertedRecordIterable) {
        checkConvertedAvroData(schema, (GenericRecord) record);
    }
    multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(20), new OneOrEmptyConverter(10), new MultiIdentityConverter(10), new TestConverter()));
    workUnitState = new WorkUnitState();
    schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
    Assert.assertEquals(Iterables.size(convertedRecordIterable), 20);
    for (Object record : convertedRecordIterable) {
        checkConvertedAvroData(schema, (GenericRecord) record);
    }
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) JsonObject(com.google.gson.JsonObject) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Example 100 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class MultiConverterTest method testConversionWithEmptyConverter.

@Test
public void testConversionWithEmptyConverter() throws Exception {
    WorkUnitState workUnitState = new WorkUnitState();
    MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new EmptyConverter(), new SchemaSimplificationConverter(), new TestConverter()));
    Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
    multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new EmptyConverter(), new TestConverter()));
    schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
    multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new TestConverter(), new EmptyConverter()));
    schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
    multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(5), new TestConverter(), new EmptyConverter()));
    schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
    multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new EmptyConverter(), new MultiIdentityConverter(5), new TestConverter()));
    schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
    Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Aggregations

WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)222 Test (org.testng.annotations.Test)143 State (org.apache.gobblin.configuration.State)48 SourceState (org.apache.gobblin.configuration.SourceState)39 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)39 Schema (org.apache.avro.Schema)29 Path (org.apache.hadoop.fs.Path)26 GenericRecord (org.apache.avro.generic.GenericRecord)19 JsonObject (com.google.gson.JsonObject)17 ArrayList (java.util.ArrayList)16 File (java.io.File)14 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)12 List (java.util.List)11 Configuration (org.apache.hadoop.conf.Configuration)11 IOException (java.io.IOException)10 LongWatermark (org.apache.gobblin.source.extractor.extract.LongWatermark)10 Extract (org.apache.gobblin.source.workunit.Extract)10 FileSystem (org.apache.hadoop.fs.FileSystem)10 Closer (com.google.common.io.Closer)8 JsonParser (com.google.gson.JsonParser)8