Search in sources :

Example 1 with JobExecutionState

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

the class TestJobLifecycleListenersList method testHappyPath.

@Test
public void testHappyPath() {
    Logger log = LoggerFactory.getLogger("testHappyPath");
    JobCatalogListenersContainer jobCatalog = mock(JobCatalogListenersContainer.class);
    JobSpecSchedulerListenersContainer jobScheduler = mock(JobSpecSchedulerListenersContainer.class);
    JobExecutionDriver mockDriver = mock(JobExecutionDriver.class);
    JobExecutionState mockState = mock(JobExecutionState.class);
    JobLifecycleListener listener1 = mock(JobLifecycleListener.class);
    JobLifecycleListener listener2 = mock(JobLifecycleListener.class);
    JobLifecycleListenersList disp = new JobLifecycleListenersList(jobCatalog, jobScheduler, log);
    disp.registerJobLifecycleListener(listener1);
    disp.onJobLaunch(mockDriver);
    disp.registerWeakJobLifecycleListener(listener2);
    disp.onMetadataChange(mockState, "key", "oldValue", "newValue");
    verify(jobCatalog).addListener(eq(listener1));
    verify(jobScheduler).registerJobSpecSchedulerListener(eq(listener1));
    verify(listener1).onJobLaunch(eq(mockDriver));
    verify(listener2, never()).onJobLaunch(eq(mockDriver));
    verify(jobCatalog).registerWeakJobCatalogListener(eq(listener2));
    verify(jobScheduler).registerWeakJobSpecSchedulerListener(eq(listener2));
    verify(listener1).onMetadataChange(eq(mockState), eq("key"), eq("oldValue"), eq("newValue"));
    verify(listener2).onMetadataChange(eq(mockState), eq("key"), eq("oldValue"), eq("newValue"));
}
Also used : JobCatalogListenersContainer(org.apache.gobblin.runtime.api.JobCatalogListenersContainer) JobExecutionState(org.apache.gobblin.runtime.api.JobExecutionState) JobLifecycleListener(org.apache.gobblin.runtime.api.JobLifecycleListener) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver) Logger(org.slf4j.Logger) JobSpecSchedulerListenersContainer(org.apache.gobblin.runtime.api.JobSpecSchedulerListenersContainer) Test(org.testng.annotations.Test)

Example 2 with JobExecutionState

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

the class TestFilteredJobLifecycleListener method testSimple.

@Test
public void testSimple() {
    Config config = ConfigFactory.empty().withValue(ConfigurationKeys.JOB_NAME_KEY, ConfigValueFactory.fromAnyRef("myJob"));
    JobSpec js1_1 = JobSpec.builder("gobblin:/testSimple/job1").withVersion("1").withConfig(config).build();
    JobSpec js1_2 = JobSpec.builder("gobblin:/testSimple/job1").withVersion("2").withConfig(config).build();
    JobLifecycleListener mockListener = mock(JobLifecycleListener.class);
    FilteredJobLifecycleListener testListener = new FilteredJobLifecycleListener(JobSpecFilter.builder().eqURI("gobblin:/testSimple/job1").eqVersion("2").build(), mockListener);
    JobExecutionState jss1_1 = new JobExecutionState(js1_1, JobExecutionUpdatable.createFromJobSpec(js1_1), Optional.<JobExecutionStateListener>absent());
    JobExecutionState jss1_2 = new JobExecutionState(js1_2, JobExecutionUpdatable.createFromJobSpec(js1_2), Optional.<JobExecutionStateListener>absent());
    testListener.onAddJob(js1_1);
    testListener.onDeleteJob(js1_1.getUri(), js1_1.getVersion());
    testListener.onUpdateJob(js1_1);
    ;
    testListener.onStatusChange(jss1_1, RunningState.PENDING, RunningState.RUNNING);
    testListener.onStageTransition(jss1_1, "Stage1", "Stage2");
    testListener.onMetadataChange(jss1_1, "metaKey", "value1", "value2");
    testListener.onAddJob(js1_2);
    testListener.onDeleteJob(js1_2.getUri(), js1_2.getVersion());
    testListener.onUpdateJob(js1_2);
    testListener.onStatusChange(jss1_2, RunningState.RUNNING, RunningState.SUCCESSFUL);
    testListener.onStageTransition(jss1_2, "Stage1", "Stage2");
    testListener.onMetadataChange(jss1_2, "metaKey", "value1", "value2");
    verify(mockListener).onAddJob(eq(js1_2));
    verify(mockListener).onDeleteJob(eq(js1_2.getUri()), eq(js1_2.getVersion()));
    verify(mockListener).onUpdateJob(eq(js1_2));
    verify(mockListener).onStatusChange(eq(jss1_2), eq(RunningState.RUNNING), eq(RunningState.SUCCESSFUL));
    verify(mockListener).onStageTransition(eq(jss1_2), eq("Stage1"), eq("Stage2"));
    verify(mockListener).onMetadataChange(eq(jss1_2), eq("metaKey"), eq("value1"), eq("value2"));
    verify(mockListener, never()).onAddJob(eq(js1_1));
    verify(mockListener, never()).onDeleteJob(eq(js1_1.getUri()), eq(js1_1.getVersion()));
    verify(mockListener, never()).onUpdateJob(eq(js1_1));
    verify(mockListener, never()).onStatusChange(eq(jss1_1), eq(RunningState.RUNNING), eq(RunningState.SUCCESSFUL));
    verify(mockListener, never()).onStatusChange(eq(jss1_1), eq(RunningState.PENDING), eq(RunningState.RUNNING));
    verify(mockListener, never()).onStageTransition(eq(jss1_1), eq("Stage1"), eq("Stage2"));
    verify(mockListener, never()).onMetadataChange(eq(jss1_1), eq("metaKey"), eq("value1"), eq("value2"));
}
Also used : Config(com.typesafe.config.Config) JobExecutionState(org.apache.gobblin.runtime.api.JobExecutionState) JobLifecycleListener(org.apache.gobblin.runtime.api.JobLifecycleListener) JobSpec(org.apache.gobblin.runtime.api.JobSpec) Test(org.testng.annotations.Test)

Example 3 with JobExecutionState

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

the class TestJobExecutionStateListeners method testHappyPath.

@Test
public void testHappyPath() {
    final Logger log = LoggerFactory.getLogger(getClass() + ".testHappyPath");
    JobExecutionStateListeners listeners = new JobExecutionStateListeners(log);
    JobSpec js1 = JobSpec.builder("gobblin:test/job").withConfig(ConfigFactory.empty().withValue(ConfigurationKeys.JOB_NAME_KEY, ConfigValueFactory.fromAnyRef("myJob"))).build();
    JobExecutionUpdatable je1 = JobExecutionUpdatable.createFromJobSpec(js1);
    JobExecutionStateListener l1 = Mockito.mock(JobExecutionStateListener.class);
    JobExecutionStateListener l2 = Mockito.mock(JobExecutionStateListener.class);
    JobExecutionStateListener l3 = Mockito.mock(JobExecutionStateListener.class);
    listeners.registerStateListener(l1);
    JobExecutionState state = new JobExecutionState(js1, je1, Optional.<JobExecutionStateListener>of(listeners));
    state.setRunningState(RunningState.PENDING);
    state.setRunningState(RunningState.RUNNING);
    listeners.registerStateListener(l2);
    listeners.registerStateListener(l3);
    state.setStage("Stage1");
    listeners.unregisterStateListener(l2);
    listeners.onMetadataChange(state, "key", "oldValue", "newValue");
    Mockito.verify(l1).onStatusChange(Mockito.eq(state), Mockito.eq((RunningState) null), Mockito.eq(RunningState.PENDING));
    Mockito.verify(l1).onStatusChange(Mockito.eq(state), Mockito.eq(RunningState.PENDING), Mockito.eq(RunningState.RUNNING));
    Mockito.verify(l1).onStageTransition(Mockito.eq(state), Mockito.eq(JobExecutionState.UKNOWN_STAGE), Mockito.eq("Stage1"));
    Mockito.verify(l1).onMetadataChange(Mockito.eq(state), Mockito.eq("key"), Mockito.eq("oldValue"), Mockito.eq("newValue"));
    Mockito.verify(l2).onStageTransition(Mockito.eq(state), Mockito.eq(JobExecutionState.UKNOWN_STAGE), Mockito.eq("Stage1"));
    Mockito.verify(l3).onStageTransition(Mockito.eq(state), Mockito.eq(JobExecutionState.UKNOWN_STAGE), Mockito.eq("Stage1"));
    Mockito.verify(l3).onMetadataChange(Mockito.eq(state), Mockito.eq("key"), Mockito.eq("oldValue"), Mockito.eq("newValue"));
    Mockito.verifyNoMoreInteractions(l1);
    Mockito.verifyNoMoreInteractions(l2);
    Mockito.verifyNoMoreInteractions(l3);
}
Also used : RunningState(org.apache.gobblin.runtime.JobState.RunningState) JobExecutionState(org.apache.gobblin.runtime.api.JobExecutionState) JobSpec(org.apache.gobblin.runtime.api.JobSpec) Logger(org.slf4j.Logger) JobExecutionStateListener(org.apache.gobblin.runtime.api.JobExecutionStateListener) Test(org.testng.annotations.Test)

Example 4 with JobExecutionState

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

the class JobLauncherExecutionDriver method create.

/**
 * Creates a new JobExecutionDriver which acts as an adapter to the legacy {@link JobLauncher} API.
 * @param sysConfig             the system/environment config
 * @param jobSpec               the JobSpec to be executed
 * @param jobLauncherType       an optional jobLauncher type; the value follows the convention of
 *        {@link JobLauncherFactory#newJobLauncher(java.util.Properties, java.util.Properties, String).
 *        If absent, {@link JobLauncherFactory#newJobLauncher(java.util.Properties, java.util.Properties)}
 *        will be used which looks for the {@link ConfigurationKeys#JOB_LAUNCHER_TYPE_KEY}
 *        in the system configuration.
 * @param jobExecStateListener  an optional listener to listen for state changes in the execution.
 * @param log                   an optional logger to be used; if none is specified, a default one
 *                              will be instantiated.
 */
public static JobLauncherExecutionDriver create(Configurable sysConfig, JobSpec jobSpec, Optional<JobLauncherFactory.JobLauncherType> jobLauncherType, Optional<Logger> log, boolean instrumentationEnabled, JobExecutionLauncher.StandardMetrics launcherMetrics, SharedResourcesBroker<GobblinScopeTypes> instanceBroker) {
    Logger actualLog = log.isPresent() ? log.get() : LoggerFactory.getLogger(JobLauncherExecutionDriver.class);
    JobExecutionStateListeners callbackDispatcher = new JobExecutionStateListeners(actualLog);
    JobExecutionUpdatable jobExec = JobExecutionUpdatable.createFromJobSpec(jobSpec);
    JobExecutionState jobState = new JobExecutionState(jobSpec, jobExec, Optional.<JobExecutionStateListener>of(callbackDispatcher));
    JobLauncher jobLauncher = createLauncher(sysConfig, jobSpec, actualLog, jobLauncherType.isPresent() ? Optional.of(jobLauncherType.get().toString()) : Optional.<String>absent(), instanceBroker);
    JobListenerToJobStateBridge bridge = new JobListenerToJobStateBridge(actualLog, jobState, instrumentationEnabled, launcherMetrics);
    DriverRunnable runnable = new DriverRunnable(jobLauncher, bridge, jobState, callbackDispatcher, jobExec);
    return new JobLauncherExecutionDriver(jobSpec, actualLog, runnable);
}
Also used : JobLauncher(org.apache.gobblin.runtime.JobLauncher) JobExecutionState(org.apache.gobblin.runtime.api.JobExecutionState) Logger(org.slf4j.Logger) JobExecutionUpdatable(org.apache.gobblin.runtime.std.JobExecutionUpdatable) JobExecutionStateListeners(org.apache.gobblin.runtime.std.JobExecutionStateListeners)

Aggregations

JobExecutionState (org.apache.gobblin.runtime.api.JobExecutionState)4 Logger (org.slf4j.Logger)3 Test (org.testng.annotations.Test)3 JobLifecycleListener (org.apache.gobblin.runtime.api.JobLifecycleListener)2 JobSpec (org.apache.gobblin.runtime.api.JobSpec)2 Config (com.typesafe.config.Config)1 JobLauncher (org.apache.gobblin.runtime.JobLauncher)1 RunningState (org.apache.gobblin.runtime.JobState.RunningState)1 JobCatalogListenersContainer (org.apache.gobblin.runtime.api.JobCatalogListenersContainer)1 JobExecutionDriver (org.apache.gobblin.runtime.api.JobExecutionDriver)1 JobExecutionStateListener (org.apache.gobblin.runtime.api.JobExecutionStateListener)1 JobSpecSchedulerListenersContainer (org.apache.gobblin.runtime.api.JobSpecSchedulerListenersContainer)1 JobExecutionStateListeners (org.apache.gobblin.runtime.std.JobExecutionStateListeners)1 JobExecutionUpdatable (org.apache.gobblin.runtime.std.JobExecutionUpdatable)1