Search in sources :

Example 6 with TaskScopeInstance

use of org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance in project incubator-gobblin by apache.

the class DefaultGobblinBrokerTest method testLifecycle.

@Test
public void testLifecycle() throws Exception {
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> taskBroker = jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskabc")).withAdditionalParentBroker(containerBroker).build();
    // create a shared resource
    TestFactory.SharedResource jobResource = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.JOB);
    TestFactory.SharedResource taskResource = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.TASK);
    Assert.assertFalse(jobResource.isClosed());
    Assert.assertFalse(taskResource.isClosed());
    taskBroker.close();
    // only resources at lower scopes than task should be closed
    Assert.assertFalse(jobResource.isClosed());
    Assert.assertTrue(taskResource.isClosed());
    // since taskResource has been closed, broker should return a new instance of the object
    TestFactory.SharedResource taskResource2 = taskBroker.getSharedResourceAtScope(new TestFactory<GobblinScopeTypes>(), new TestResourceKey("myKey"), GobblinScopeTypes.TASK);
    Assert.assertNotEquals(taskResource, taskResource2);
    topBroker.close();
    Assert.assertTrue(jobResource.isClosed());
    Assert.assertTrue(taskResource.isClosed());
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Example 7 with TaskScopeInstance

use of org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance in project incubator-gobblin by apache.

the class GobblinBrokerCreationTest method testFailIfDifferentAncestors.

@Test
public void testFailIfDifferentAncestors() throws Exception {
    // Correct creation behavior
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker2 = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker2.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    try {
        jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskxyz")).withAdditionalParentBroker(containerBroker).build();
        Assert.fail();
    } catch (IllegalArgumentException iae) {
    // expected
    }
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Example 8 with TaskScopeInstance

use of org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance in project incubator-gobblin by apache.

the class GobblinBrokerCreationTest method testCreationOfBrokers.

@Test
public void testCreationOfBrokers() throws Exception {
    // Correct creation behavior
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, new SimpleScope<GobblinScopeTypes>(GobblinScopeTypes.GLOBAL, "myGlobalScope"));
    SharedResourcesBrokerImpl<GobblinScopeTypes> jobBroker = topBroker.newSubscopedBuilder(new JobScopeInstance("myJob", "job123")).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> containerBroker = topBroker.newSubscopedBuilder(GobblinScopeTypes.CONTAINER.defaultScopeInstance()).build();
    SharedResourcesBrokerImpl<GobblinScopeTypes> taskBroker = jobBroker.newSubscopedBuilder(new TaskScopeInstance("taskabc")).withAdditionalParentBroker(containerBroker).build();
    Assert.assertEquals(taskBroker.selfScope().getType(), GobblinScopeTypes.TASK);
    Assert.assertEquals(((TaskScopeInstance) taskBroker.selfScope()).getTaskId(), "taskabc");
    Assert.assertEquals(taskBroker.getScope(GobblinScopeTypes.CONTAINER).getType(), GobblinScopeTypes.CONTAINER);
    Assert.assertEquals(((GobblinScopeInstance) taskBroker.getScope(GobblinScopeTypes.CONTAINER)).getScopeId(), "container");
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) JobScopeInstance(org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Example 9 with TaskScopeInstance

use of org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance in project incubator-gobblin by apache.

the class GobblinBrokerCreationTest method testFailIfIntermediateScopeHasNoDefault.

@Test
public void testFailIfIntermediateScopeHasNoDefault() throws Exception {
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<GobblinScopeTypes> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, GobblinScopeTypes.GLOBAL.defaultScopeInstance());
    // should trow error if an intermediate scope does not have a default
    try {
        topBroker.newSubscopedBuilder(new TaskScopeInstance("taskxyz")).build();
        Assert.fail();
    } catch (IllegalArgumentException iae) {
    // expected
    }
}
Also used : GobblinScopeTypes(org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes) Config(com.typesafe.config.Config) TaskScopeInstance(org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance) Test(org.testng.annotations.Test)

Aggregations

GobblinScopeTypes (org.apache.gobblin.broker.gobblin_scopes.GobblinScopeTypes)9 TaskScopeInstance (org.apache.gobblin.broker.gobblin_scopes.TaskScopeInstance)9 Config (com.typesafe.config.Config)7 JobScopeInstance (org.apache.gobblin.broker.gobblin_scopes.JobScopeInstance)7 Test (org.testng.annotations.Test)7 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)2 SubscopedBrokerBuilder (org.apache.gobblin.broker.iface.SubscopedBrokerBuilder)1 State (org.apache.gobblin.configuration.State)1 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)1 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)1