Search in sources :

Example 6 with StreamRegexMonitor

use of org.apache.samza.coordinator.StreamRegexMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method testSameDeploymentWithNewJobModel.

@Test
public void testSameDeploymentWithNewJobModel() throws IOException {
    Config jobModelConfig = mock(Config.class);
    JobModel jobModel = setupJobModel(jobModelConfig);
    StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
    StreamRegexMonitor streamRegexMonitor = setupStreamRegexMonitor(jobModel, jobModelConfig);
    setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.JOB_MODEL), true);
    setUpDiagnosticsManager(jobModel);
    this.staticResourceJobCoordinator.start();
    verifyStartLifecycle();
    verify(this.jobRestartSignal).restartJob();
    assertNull(this.staticResourceJobCoordinator.getJobModel());
    verifyNoSideEffects(streamPartitionCountMonitor, streamRegexMonitor);
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) Test(org.junit.Test)

Example 7 with StreamRegexMonitor

use of org.apache.samza.coordinator.StreamRegexMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method setupStreamRegexMonitor.

/**
 * Set up {@link StreamRegexMonitorFactory} to return a mock {@link StreamRegexMonitor}.
 */
private StreamRegexMonitor setupStreamRegexMonitor(JobModel jobModel, Config jobModelConfig) {
    StreamRegexMonitor streamRegexMonitor = mock(StreamRegexMonitor.class);
    when(this.streamRegexMonitorFactory.build(eq(jobModel), eq(jobModelConfig), any())).thenReturn(Optional.of(streamRegexMonitor));
    return streamRegexMonitor;
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor)

Example 8 with StreamRegexMonitor

use of org.apache.samza.coordinator.StreamRegexMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method testStreamRegexChange.

@Test
public void testStreamRegexChange() throws IOException {
    Config jobModelConfig = mock(Config.class);
    JobModel jobModel = setupJobModel(jobModelConfig);
    StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
    StreamRegexMonitor streamRegexMonitor = mock(StreamRegexMonitor.class);
    ArgumentCaptor<StreamRegexMonitor.Callback> callbackArgumentCaptor = ArgumentCaptor.forClass(StreamRegexMonitor.Callback.class);
    when(this.streamRegexMonitorFactory.build(eq(jobModel), eq(jobModelConfig), callbackArgumentCaptor.capture())).thenReturn(Optional.of(streamRegexMonitor));
    JobCoordinatorMetadata newMetadata = setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.NEW_DEPLOYMENT, JobMetadataChange.JOB_MODEL), true);
    setUpDiagnosticsManager(jobModel);
    MetadataResourceUtil metadataResourceUtil = metadataResourceUtil(jobModel);
    this.staticResourceJobCoordinator.start();
    verifyStartLifecycle();
    verify(this.staticResourceJobCoordinator).doSetLoggingContextConfig(jobModelConfig);
    verify(this.diagnosticsManager).start();
    verifyPrepareWorkerExecutionAndMonitor(jobModel, metadataResourceUtil, streamPartitionCountMonitor, streamRegexMonitor, newMetadata, SINGLE_SSP_FANOUT);
    // call the callback from the monitor
    callbackArgumentCaptor.getValue().onInputStreamsChanged(ImmutableSet.of(SYSTEM_STREAM), ImmutableSet.of(SYSTEM_STREAM, new SystemStream("system", "stream1")), ImmutableMap.of("system", Pattern.compile("stream.*")));
    verify(this.jobRestartSignal).restartJob();
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) JobCoordinatorMetadata(org.apache.samza.job.JobCoordinatorMetadata) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) SystemStream(org.apache.samza.system.SystemStream) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) Test(org.junit.Test)

Example 9 with StreamRegexMonitor

use of org.apache.samza.coordinator.StreamRegexMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method testNewDeploymentNewJobModel.

@Test
public void testNewDeploymentNewJobModel() throws IOException {
    Config jobModelConfig = mock(Config.class);
    JobModel jobModel = setupJobModel(jobModelConfig);
    StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
    StreamRegexMonitor streamRegexMonitor = setupStreamRegexMonitor(jobModel, jobModelConfig);
    JobCoordinatorMetadata newMetadata = setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.NEW_DEPLOYMENT, JobMetadataChange.JOB_MODEL), true);
    setUpDiagnosticsManager(jobModel);
    MetadataResourceUtil metadataResourceUtil = metadataResourceUtil(jobModel);
    this.staticResourceJobCoordinator.start();
    assertEquals(jobModel, this.staticResourceJobCoordinator.getJobModel());
    verifyStartLifecycle();
    verify(this.staticResourceJobCoordinator).doSetLoggingContextConfig(jobModelConfig);
    verify(this.diagnosticsManager).start();
    verifyPrepareWorkerExecutionAndMonitor(jobModel, metadataResourceUtil, streamPartitionCountMonitor, streamRegexMonitor, newMetadata, SINGLE_SSP_FANOUT);
    verify(this.jobCoordinatorListener).onNewJobModel(PROCESSOR_ID, jobModel);
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) JobCoordinatorMetadata(org.apache.samza.job.JobCoordinatorMetadata) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) Test(org.junit.Test)

Example 10 with StreamRegexMonitor

use of org.apache.samza.coordinator.StreamRegexMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method testPartitionCountChange.

@Test
public void testPartitionCountChange() throws IOException {
    Config jobModelConfig = mock(Config.class);
    JobModel jobModel = setupJobModel(jobModelConfig);
    StreamPartitionCountMonitor streamPartitionCountMonitor = mock(StreamPartitionCountMonitor.class);
    ArgumentCaptor<StreamPartitionCountMonitor.Callback> callbackArgumentCaptor = ArgumentCaptor.forClass(StreamPartitionCountMonitor.Callback.class);
    when(this.streamPartitionCountMonitorFactory.build(eq(jobModelConfig), callbackArgumentCaptor.capture())).thenReturn(streamPartitionCountMonitor);
    StreamRegexMonitor streamRegexMonitor = setupStreamRegexMonitor(jobModel, jobModelConfig);
    JobCoordinatorMetadata newMetadata = setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.NEW_DEPLOYMENT, JobMetadataChange.JOB_MODEL), true);
    setUpDiagnosticsManager(jobModel);
    MetadataResourceUtil metadataResourceUtil = metadataResourceUtil(jobModel);
    this.staticResourceJobCoordinator.start();
    verifyStartLifecycle();
    verify(this.staticResourceJobCoordinator).doSetLoggingContextConfig(jobModelConfig);
    verify(this.diagnosticsManager).start();
    verifyPrepareWorkerExecutionAndMonitor(jobModel, metadataResourceUtil, streamPartitionCountMonitor, streamRegexMonitor, newMetadata, SINGLE_SSP_FANOUT);
    // call the callback from the monitor
    callbackArgumentCaptor.getValue().onSystemStreamPartitionChange(ImmutableSet.of(SYSTEM_STREAM));
    verify(this.jobRestartSignal).restartJob();
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) JobCoordinatorMetadata(org.apache.samza.job.JobCoordinatorMetadata) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) Test(org.junit.Test)

Aggregations

StreamRegexMonitor (org.apache.samza.coordinator.StreamRegexMonitor)10 JobConfig (org.apache.samza.config.JobConfig)8 StreamPartitionCountMonitor (org.apache.samza.coordinator.StreamPartitionCountMonitor)8 JobModel (org.apache.samza.job.model.JobModel)8 Config (org.apache.samza.config.Config)7 MapConfig (org.apache.samza.config.MapConfig)7 Test (org.junit.Test)7 MetadataResourceUtil (org.apache.samza.coordinator.MetadataResourceUtil)6 JobCoordinatorMetadata (org.apache.samza.job.JobCoordinatorMetadata)4 HashMap (java.util.HashMap)1 SamzaException (org.apache.samza.SamzaException)1 StorageConfig (org.apache.samza.config.StorageConfig)1 TaskName (org.apache.samza.container.TaskName)1 JobModelMonitors (org.apache.samza.coordinator.JobModelMonitors)1 ContainerModel (org.apache.samza.job.model.ContainerModel)1 TaskModel (org.apache.samza.job.model.TaskModel)1 JmxServer (org.apache.samza.metrics.JmxServer)1 StartpointManager (org.apache.samza.startpoint.StartpointManager)1 StateBackendAdmin (org.apache.samza.storage.StateBackendAdmin)1 StateBackendFactory (org.apache.samza.storage.StateBackendFactory)1