Search in sources :

Example 6 with StreamPartitionCountMonitor

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

the class TestStaticResourceJobCoordinator method testNoExistingJobModel.

@Test
public void testNoExistingJobModel() 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.copyOf(Arrays.asList(JobMetadataChange.values())), false);
    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 7 with StreamPartitionCountMonitor

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

the class TestStaticResourceJobCoordinator method testStopAfterStart.

@Test
public void testStopAfterStart() throws InterruptedException {
    Config jobModelConfig = mock(Config.class);
    JobModel jobModel = setupJobModel(jobModelConfig);
    StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
    StreamRegexMonitor streamRegexMonitor = setupStreamRegexMonitor(jobModel, jobModelConfig);
    setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.copyOf(Arrays.asList(JobMetadataChange.values())), false);
    setUpDiagnosticsManager(jobModel);
    metadataResourceUtil(jobModel);
    // call start in order to set up monitors
    this.staticResourceJobCoordinator.start();
    // call stop to check that the expected components get shut down
    this.staticResourceJobCoordinator.stop();
    verify(this.jobCoordinatorListener).onJobModelExpired();
    verify(this.diagnosticsManager).stop();
    verify(streamPartitionCountMonitor).stop();
    verify(streamRegexMonitor).stop();
    verify(this.coordinatorCommunication).stop();
    verify(this.startpointManager).stop();
    verify(this.systemAdmins).stop();
    verify(this.jobCoordinatorListener).onCoordinatorStop();
}
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 8 with StreamPartitionCountMonitor

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

the class TestStaticResourceJobCoordinator method testStartMissingOptionalComponents.

/**
 * Missing {@link StartpointManager}, {@link JobCoordinatorListener}, {@link StreamRegexMonitor}
 */
@Test
public void testStartMissingOptionalComponents() throws IOException {
    this.staticResourceJobCoordinator = spy(new StaticResourceJobCoordinator(PROCESSOR_ID, this.jobModelHelper, this.jobModelServingContext, this.coordinatorCommunication, this.jobCoordinatorMetadataManager, this.streamPartitionCountMonitorFactory, this.streamRegexMonitorFactory, Optional.empty(), this.changelogStreamManager, this.jobRestartSignal, this.metrics, this.systemAdmins, Optional.empty(), Optional.empty(), this.config));
    Config jobModelConfig = mock(Config.class);
    JobModel jobModel = setupJobModel(jobModelConfig);
    StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
    when(this.streamRegexMonitorFactory.build(any(), any(), any())).thenReturn(Optional.empty());
    JobCoordinatorMetadata newMetadata = setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.copyOf(Arrays.asList(JobMetadataChange.values())), false);
    doReturn(Optional.empty()).when(this.staticResourceJobCoordinator).buildDiagnosticsManager(JOB_NAME, JOB_ID, jobModel, CoordinationConstants.JOB_COORDINATOR_CONTAINER_NAME, Optional.empty(), Optional.empty(), this.config);
    MetadataResourceUtil metadataResourceUtil = metadataResourceUtil(jobModel);
    this.staticResourceJobCoordinator.start();
    assertEquals(jobModel, this.staticResourceJobCoordinator.getJobModel());
    verify(this.systemAdmins).start();
    verify(this.staticResourceJobCoordinator).doSetLoggingContextConfig(jobModelConfig);
    verify(this.staticResourceJobCoordinator).buildDiagnosticsManager(JOB_NAME, JOB_ID, jobModel, CoordinationConstants.JOB_COORDINATOR_CONTAINER_NAME, Optional.empty(), Optional.empty(), this.config);
    verifyPrepareWorkerExecutionAndMonitor(jobModel, metadataResourceUtil, streamPartitionCountMonitor, null, newMetadata, null);
    verifyZeroInteractions(this.jobCoordinatorListener, this.startpointManager);
}
Also used : 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 9 with StreamPartitionCountMonitor

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

the class StaticResourceJobCoordinator method jobModelMonitors.

/*
   * Possible race condition: The partition count monitor queries for stream metadata when it is created, so if the
   * partition counts changed between the job model calculation and the creation of the partition count monitor, then
   * the monitor will not trigger an update to the job model. This method should be called right after calculating the
   * job model, in order to reduce the possible time in which a partition count change is missed. This issue also
   * exists in the older ClusterBasedJobCoordinator.
   * TODO This wouldn't be a problem if the partition count monitor used the job model to calculate initial metadata
   */
private JobModelMonitors jobModelMonitors(JobModel jobModel) {
    StreamPartitionCountMonitor streamPartitionCountMonitor = this.streamPartitionCountMonitorFactory.build(jobModel.getConfig(), streamsChanged -> this.jobRestartSignal.restartJob());
    Optional<StreamRegexMonitor> streamRegexMonitor = this.streamRegexMonitorFactory.build(jobModel, jobModel.getConfig(), (initialInputSet, newInputStreams, regexesMonitored) -> this.jobRestartSignal.restartJob());
    return new JobModelMonitors(streamPartitionCountMonitor, streamRegexMonitor.orElse(null));
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) JobModelMonitors(org.apache.samza.coordinator.JobModelMonitors) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor)

Example 10 with StreamPartitionCountMonitor

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

the class TestZkJobCoordinator method testShouldStopPartitionCountMonitorWhenStoppingTheJobCoordinator.

@Test
public void testShouldStopPartitionCountMonitorWhenStoppingTheJobCoordinator() {
    when(zkUtils.getJobModel(TEST_JOB_MODEL_VERSION)).thenReturn(new JobModel(new MapConfig(), new HashMap<>()));
    ScheduleAfterDebounceTime mockDebounceTimer = Mockito.mock(ScheduleAfterDebounceTime.class);
    ZkJobCoordinator zkJobCoordinator = Mockito.spy(new ZkJobCoordinator(PROCESSOR_ID, new MapConfig(), new NoOpMetricsRegistry(), zkUtils, zkMetadataStore, coordinatorStreamStore));
    StreamPartitionCountMonitor monitor = Mockito.mock(StreamPartitionCountMonitor.class);
    zkJobCoordinator.debounceTimer = mockDebounceTimer;
    zkJobCoordinator.streamPartitionCountMonitor = monitor;
    zkJobCoordinator.stop();
    Mockito.verify(monitor).stop();
}
Also used : NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) HashMap(java.util.HashMap) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Aggregations

StreamPartitionCountMonitor (org.apache.samza.coordinator.StreamPartitionCountMonitor)16 MapConfig (org.apache.samza.config.MapConfig)14 Test (org.junit.Test)14 JobModel (org.apache.samza.job.model.JobModel)12 Config (org.apache.samza.config.Config)11 JobConfig (org.apache.samza.config.JobConfig)11 StreamRegexMonitor (org.apache.samza.coordinator.StreamRegexMonitor)8 MetadataResourceUtil (org.apache.samza.coordinator.MetadataResourceUtil)6 JobCoordinatorMetadata (org.apache.samza.job.JobCoordinatorMetadata)5 HashMap (java.util.HashMap)3 NoOpMetricsRegistry (org.apache.samza.util.NoOpMetricsRegistry)3 Partition (org.apache.samza.Partition)2 ApplicationConfig (org.apache.samza.config.ApplicationConfig)2 CoordinatorStreamSystemProducer (org.apache.samza.coordinator.stream.CoordinatorStreamSystemProducer)2 MetricsRegistry (org.apache.samza.metrics.MetricsRegistry)2 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JobModelMonitors (org.apache.samza.coordinator.JobModelMonitors)1 SystemStream (org.apache.samza.system.SystemStream)1 ZkSessionStateChangedListener (org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener)1