Search in sources :

Example 1 with SpecCompiler

use of org.apache.gobblin.service.modules.flow.SpecCompiler in project incubator-gobblin by apache.

the class GobblinServiceJobSchedulerTest method testJobSchedulerUnschedule.

/**
 * Test that flowSpecs that throw compilation errors do not block the scheduling of other flowSpecs
 */
@Test
public void testJobSchedulerUnschedule() throws Exception {
    // Mock a FlowCatalog.
    File specDir = Files.createTempDir();
    Properties properties = new Properties();
    properties.setProperty(FLOWSPEC_STORE_DIR_KEY, specDir.getAbsolutePath());
    FlowCatalog flowCatalog = new FlowCatalog(ConfigUtils.propertiesToConfig(properties));
    ServiceBasedAppLauncher serviceLauncher = new ServiceBasedAppLauncher(properties, "GaaSJobSchedulerTest");
    // Assume that the catalog can store corrupted flows
    SpecCatalogListener mockListener = Mockito.mock(SpecCatalogListener.class);
    when(mockListener.getName()).thenReturn(ServiceConfigKeys.GOBBLIN_SERVICE_JOB_SCHEDULER_LISTENER_CLASS);
    when(mockListener.onAddSpec(any())).thenReturn(new AddSpecResponse(""));
    flowCatalog.addListener(mockListener);
    serviceLauncher.addService(flowCatalog);
    serviceLauncher.start();
    FlowSpec flowSpec0 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec0"));
    FlowSpec flowSpec1 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec1"));
    FlowSpec flowSpec2 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec2"));
    // Ensure that these flows are scheduled
    flowCatalog.put(flowSpec0, true);
    flowCatalog.put(flowSpec1, true);
    flowCatalog.put(flowSpec2, true);
    Assert.assertEquals(flowCatalog.getSpecs().size(), 3);
    Orchestrator mockOrchestrator = Mockito.mock(Orchestrator.class);
    SchedulerService schedulerService = new SchedulerService(new Properties());
    // Mock a GaaS scheduler.
    TestGobblinServiceJobScheduler scheduler = new TestGobblinServiceJobScheduler("testscheduler", ConfigFactory.empty(), Optional.of(flowCatalog), null, mockOrchestrator, schedulerService);
    schedulerService.startAsync().awaitRunning();
    scheduler.startUp();
    SpecCompiler mockCompiler = Mockito.mock(SpecCompiler.class);
    Mockito.when(mockOrchestrator.getSpecCompiler()).thenReturn(mockCompiler);
    Mockito.doAnswer((Answer<Void>) a -> {
        scheduler.isCompilerHealthy = true;
        return null;
    }).when(mockCompiler).awaitHealthy();
    scheduler.setActive(true);
    AssertWithBackoff.create().timeoutMs(20000).maxSleepMs(2000).backoffFactor(2).assertTrue(new Predicate<Void>() {

        @Override
        public boolean apply(Void input) {
            Map<String, Spec> scheduledFlowSpecs = scheduler.scheduledFlowSpecs;
            if (scheduledFlowSpecs != null && scheduledFlowSpecs.size() == 3) {
                return scheduler.scheduledFlowSpecs.containsKey("spec0") && scheduler.scheduledFlowSpecs.containsKey("spec1") && scheduler.scheduledFlowSpecs.containsKey("spec2");
            } else {
                return false;
            }
        }
    }, "Waiting all flowSpecs to be scheduled");
    // set scheduler to be inactive and unschedule flows
    scheduler.setActive(false);
    Collection<Invocation> invocations = Mockito.mockingDetails(mockOrchestrator).getInvocations();
    for (Invocation invocation : invocations) {
        // ensure that orchestrator is not calling remove
        Assert.assertFalse(invocation.getMethod().getName().equals("remove"));
    }
    Assert.assertEquals(scheduler.scheduledFlowSpecs.size(), 0);
    Assert.assertEquals(schedulerService.getScheduler().getJobGroupNames().size(), 0);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.testng.annotations.Test) ConfigUtils(org.apache.gobblin.util.ConfigUtils) Answer(org.mockito.stubbing.Answer) Assert(org.testng.Assert) Files(com.google.common.io.Files) Optional(com.google.common.base.Optional) Map(java.util.Map) FlowCatalogTest(org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest) ConfigFactory(com.typesafe.config.ConfigFactory) URI(java.net.URI) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) AddSpecResponse(org.apache.gobblin.runtime.spec_catalog.AddSpecResponse) TopologyCatalog(org.apache.gobblin.runtime.spec_catalog.TopologyCatalog) ServiceConfigKeys(org.apache.gobblin.service.ServiceConfigKeys) AssertWithBackoff(org.apache.gobblin.testing.AssertWithBackoff) Spec(org.apache.gobblin.runtime.api.Spec) Properties(java.util.Properties) SchedulerService(org.apache.gobblin.scheduler.SchedulerService) ServiceBasedAppLauncher(org.apache.gobblin.runtime.app.ServiceBasedAppLauncher) SpecCompiler(org.apache.gobblin.service.modules.flow.SpecCompiler) Config(com.typesafe.config.Config) Collection(java.util.Collection) ConfigurationKeys(org.apache.gobblin.configuration.ConfigurationKeys) File(java.io.File) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Predicate(com.google.common.base.Predicate) Orchestrator(org.apache.gobblin.service.modules.orchestration.Orchestrator) MockedSpecCompiler(org.apache.gobblin.service.modules.flow.MockedSpecCompiler) JobException(org.apache.gobblin.runtime.JobException) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) SpecCatalogListener(org.apache.gobblin.runtime.api.SpecCatalogListener) SchedulerService(org.apache.gobblin.scheduler.SchedulerService) SpecCatalogListener(org.apache.gobblin.runtime.api.SpecCatalogListener) Invocation(org.mockito.invocation.Invocation) Properties(java.util.Properties) AddSpecResponse(org.apache.gobblin.runtime.spec_catalog.AddSpecResponse) Orchestrator(org.apache.gobblin.service.modules.orchestration.Orchestrator) SpecCompiler(org.apache.gobblin.service.modules.flow.SpecCompiler) MockedSpecCompiler(org.apache.gobblin.service.modules.flow.MockedSpecCompiler) ServiceBasedAppLauncher(org.apache.gobblin.runtime.app.ServiceBasedAppLauncher) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) File(java.io.File) Map(java.util.Map) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) Test(org.testng.annotations.Test) FlowCatalogTest(org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest)

Example 2 with SpecCompiler

use of org.apache.gobblin.service.modules.flow.SpecCompiler in project incubator-gobblin by apache.

the class GobblinServiceJobSchedulerTest method testJobSchedulerInitWithFailedSpec.

/**
 * Test that flowSpecs that throw compilation errors do not block the scheduling of other flowSpecs
 */
@Test
public void testJobSchedulerInitWithFailedSpec() throws Exception {
    // Mock a FlowCatalog.
    File specDir = Files.createTempDir();
    Properties properties = new Properties();
    properties.setProperty(FLOWSPEC_STORE_DIR_KEY, specDir.getAbsolutePath());
    FlowCatalog flowCatalog = new FlowCatalog(ConfigUtils.propertiesToConfig(properties));
    ServiceBasedAppLauncher serviceLauncher = new ServiceBasedAppLauncher(properties, "GaaSJobSchedulerTest");
    // Assume that the catalog can store corrupted flows
    SpecCatalogListener mockListener = Mockito.mock(SpecCatalogListener.class);
    when(mockListener.getName()).thenReturn(ServiceConfigKeys.GOBBLIN_SERVICE_JOB_SCHEDULER_LISTENER_CLASS);
    when(mockListener.onAddSpec(any())).thenReturn(new AddSpecResponse(""));
    flowCatalog.addListener(mockListener);
    serviceLauncher.addService(flowCatalog);
    serviceLauncher.start();
    FlowSpec flowSpec0 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec0"), MockedSpecCompiler.UNCOMPILABLE_FLOW);
    FlowSpec flowSpec1 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec1"));
    FlowSpec flowSpec2 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec2"));
    // Ensure that these flows are scheduled
    flowCatalog.put(flowSpec0, true);
    flowCatalog.put(flowSpec1, true);
    flowCatalog.put(flowSpec2, true);
    Assert.assertEquals(flowCatalog.getSpecs().size(), 3);
    Orchestrator mockOrchestrator = Mockito.mock(Orchestrator.class);
    // Mock a GaaS scheduler.
    TestGobblinServiceJobScheduler scheduler = new TestGobblinServiceJobScheduler("testscheduler", ConfigFactory.empty(), Optional.of(flowCatalog), null, mockOrchestrator, null);
    SpecCompiler mockCompiler = Mockito.mock(SpecCompiler.class);
    Mockito.when(mockOrchestrator.getSpecCompiler()).thenReturn(mockCompiler);
    Mockito.doAnswer((Answer<Void>) a -> {
        scheduler.isCompilerHealthy = true;
        return null;
    }).when(mockCompiler).awaitHealthy();
    scheduler.setActive(true);
    AssertWithBackoff.create().timeoutMs(20000).maxSleepMs(2000).backoffFactor(2).assertTrue(new Predicate<Void>() {

        @Override
        public boolean apply(Void input) {
            Map<String, Spec> scheduledFlowSpecs = scheduler.scheduledFlowSpecs;
            if (scheduledFlowSpecs != null && scheduledFlowSpecs.size() == 2) {
                return scheduler.scheduledFlowSpecs.containsKey("spec1") && scheduler.scheduledFlowSpecs.containsKey("spec2");
            } else {
                return false;
            }
        }
    }, "Waiting all flowSpecs to be scheduled");
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.testng.annotations.Test) ConfigUtils(org.apache.gobblin.util.ConfigUtils) Answer(org.mockito.stubbing.Answer) Assert(org.testng.Assert) Files(com.google.common.io.Files) Optional(com.google.common.base.Optional) Map(java.util.Map) FlowCatalogTest(org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest) ConfigFactory(com.typesafe.config.ConfigFactory) URI(java.net.URI) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) AddSpecResponse(org.apache.gobblin.runtime.spec_catalog.AddSpecResponse) TopologyCatalog(org.apache.gobblin.runtime.spec_catalog.TopologyCatalog) ServiceConfigKeys(org.apache.gobblin.service.ServiceConfigKeys) AssertWithBackoff(org.apache.gobblin.testing.AssertWithBackoff) Spec(org.apache.gobblin.runtime.api.Spec) Properties(java.util.Properties) SchedulerService(org.apache.gobblin.scheduler.SchedulerService) ServiceBasedAppLauncher(org.apache.gobblin.runtime.app.ServiceBasedAppLauncher) SpecCompiler(org.apache.gobblin.service.modules.flow.SpecCompiler) Config(com.typesafe.config.Config) Collection(java.util.Collection) ConfigurationKeys(org.apache.gobblin.configuration.ConfigurationKeys) File(java.io.File) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Predicate(com.google.common.base.Predicate) Orchestrator(org.apache.gobblin.service.modules.orchestration.Orchestrator) MockedSpecCompiler(org.apache.gobblin.service.modules.flow.MockedSpecCompiler) JobException(org.apache.gobblin.runtime.JobException) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) SpecCatalogListener(org.apache.gobblin.runtime.api.SpecCatalogListener) SpecCatalogListener(org.apache.gobblin.runtime.api.SpecCatalogListener) Properties(java.util.Properties) AddSpecResponse(org.apache.gobblin.runtime.spec_catalog.AddSpecResponse) Orchestrator(org.apache.gobblin.service.modules.orchestration.Orchestrator) SpecCompiler(org.apache.gobblin.service.modules.flow.SpecCompiler) MockedSpecCompiler(org.apache.gobblin.service.modules.flow.MockedSpecCompiler) ServiceBasedAppLauncher(org.apache.gobblin.runtime.app.ServiceBasedAppLauncher) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) File(java.io.File) Map(java.util.Map) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) Test(org.testng.annotations.Test) FlowCatalogTest(org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest)

Example 3 with SpecCompiler

use of org.apache.gobblin.service.modules.flow.SpecCompiler in project incubator-gobblin by apache.

the class GobblinServiceJobSchedulerTest method testJobSchedulerInit.

/**
 * Test whenever JobScheduler is calling setActive, the FlowSpec is loading into scheduledFlowSpecs (eventually)
 */
@Test
public void testJobSchedulerInit() throws Exception {
    // Mock a FlowCatalog.
    File specDir = Files.createTempDir();
    Properties properties = new Properties();
    properties.setProperty(FLOWSPEC_STORE_DIR_KEY, specDir.getAbsolutePath());
    FlowCatalog flowCatalog = new FlowCatalog(ConfigUtils.propertiesToConfig(properties));
    SpecCatalogListener mockListener = Mockito.mock(SpecCatalogListener.class);
    when(mockListener.getName()).thenReturn(ServiceConfigKeys.GOBBLIN_SERVICE_JOB_SCHEDULER_LISTENER_CLASS);
    when(mockListener.onAddSpec(any())).thenReturn(new AddSpecResponse(""));
    flowCatalog.addListener(mockListener);
    ServiceBasedAppLauncher serviceLauncher = new ServiceBasedAppLauncher(properties, "GaaSJobSchedulerTest");
    serviceLauncher.addService(flowCatalog);
    serviceLauncher.start();
    FlowSpec flowSpec0 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec0"));
    FlowSpec flowSpec1 = FlowCatalogTest.initFlowSpec(specDir.getAbsolutePath(), URI.create("spec1"));
    flowCatalog.put(flowSpec0, true);
    flowCatalog.put(flowSpec1, true);
    Assert.assertEquals(flowCatalog.getSpecs().size(), 2);
    Orchestrator mockOrchestrator = Mockito.mock(Orchestrator.class);
    // Mock a GaaS scheduler.
    TestGobblinServiceJobScheduler scheduler = new TestGobblinServiceJobScheduler("testscheduler", ConfigFactory.empty(), Optional.of(flowCatalog), null, mockOrchestrator, null);
    SpecCompiler mockCompiler = Mockito.mock(SpecCompiler.class);
    Mockito.when(mockOrchestrator.getSpecCompiler()).thenReturn(mockCompiler);
    Mockito.doAnswer((Answer<Void>) a -> {
        scheduler.isCompilerHealthy = true;
        return null;
    }).when(mockCompiler).awaitHealthy();
    scheduler.setActive(true);
    AssertWithBackoff.create().timeoutMs(20000).maxSleepMs(2000).backoffFactor(2).assertTrue(new Predicate<Void>() {

        @Override
        public boolean apply(Void input) {
            Map<String, Spec> scheduledFlowSpecs = scheduler.scheduledFlowSpecs;
            if (scheduledFlowSpecs != null && scheduledFlowSpecs.size() == 2) {
                return scheduler.scheduledFlowSpecs.containsKey("spec0") && scheduler.scheduledFlowSpecs.containsKey("spec1");
            } else {
                return false;
            }
        }
    }, "Waiting all flowSpecs to be scheduled");
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.testng.annotations.Test) ConfigUtils(org.apache.gobblin.util.ConfigUtils) Answer(org.mockito.stubbing.Answer) Assert(org.testng.Assert) Files(com.google.common.io.Files) Optional(com.google.common.base.Optional) Map(java.util.Map) FlowCatalogTest(org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest) ConfigFactory(com.typesafe.config.ConfigFactory) URI(java.net.URI) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) AddSpecResponse(org.apache.gobblin.runtime.spec_catalog.AddSpecResponse) TopologyCatalog(org.apache.gobblin.runtime.spec_catalog.TopologyCatalog) ServiceConfigKeys(org.apache.gobblin.service.ServiceConfigKeys) AssertWithBackoff(org.apache.gobblin.testing.AssertWithBackoff) Spec(org.apache.gobblin.runtime.api.Spec) Properties(java.util.Properties) SchedulerService(org.apache.gobblin.scheduler.SchedulerService) ServiceBasedAppLauncher(org.apache.gobblin.runtime.app.ServiceBasedAppLauncher) SpecCompiler(org.apache.gobblin.service.modules.flow.SpecCompiler) Config(com.typesafe.config.Config) Collection(java.util.Collection) ConfigurationKeys(org.apache.gobblin.configuration.ConfigurationKeys) File(java.io.File) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Predicate(com.google.common.base.Predicate) Orchestrator(org.apache.gobblin.service.modules.orchestration.Orchestrator) MockedSpecCompiler(org.apache.gobblin.service.modules.flow.MockedSpecCompiler) JobException(org.apache.gobblin.runtime.JobException) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) SpecCatalogListener(org.apache.gobblin.runtime.api.SpecCatalogListener) SpecCatalogListener(org.apache.gobblin.runtime.api.SpecCatalogListener) Properties(java.util.Properties) AddSpecResponse(org.apache.gobblin.runtime.spec_catalog.AddSpecResponse) Orchestrator(org.apache.gobblin.service.modules.orchestration.Orchestrator) SpecCompiler(org.apache.gobblin.service.modules.flow.SpecCompiler) MockedSpecCompiler(org.apache.gobblin.service.modules.flow.MockedSpecCompiler) ServiceBasedAppLauncher(org.apache.gobblin.runtime.app.ServiceBasedAppLauncher) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) File(java.io.File) Map(java.util.Map) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) Test(org.testng.annotations.Test) FlowCatalogTest(org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest)

Aggregations

Optional (com.google.common.base.Optional)3 Predicate (com.google.common.base.Predicate)3 Files (com.google.common.io.Files)3 Config (com.typesafe.config.Config)3 ConfigFactory (com.typesafe.config.ConfigFactory)3 File (java.io.File)3 URI (java.net.URI)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Properties (java.util.Properties)3 ConfigurationKeys (org.apache.gobblin.configuration.ConfigurationKeys)3 JobException (org.apache.gobblin.runtime.JobException)3 FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)3 Spec (org.apache.gobblin.runtime.api.Spec)3 SpecCatalogListener (org.apache.gobblin.runtime.api.SpecCatalogListener)3 ServiceBasedAppLauncher (org.apache.gobblin.runtime.app.ServiceBasedAppLauncher)3 AddSpecResponse (org.apache.gobblin.runtime.spec_catalog.AddSpecResponse)3 FlowCatalog (org.apache.gobblin.runtime.spec_catalog.FlowCatalog)3 FlowCatalogTest (org.apache.gobblin.runtime.spec_catalog.FlowCatalogTest)3 TopologyCatalog (org.apache.gobblin.runtime.spec_catalog.TopologyCatalog)3