Search in sources :

Example 1 with CoordinatorStreamMetadataStoreFactory

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory in project samza by apache.

the class LocalApplicationRunner method getDefaultCoordinatorStreamStoreFactory.

@VisibleForTesting
static Optional<MetadataStoreFactory> getDefaultCoordinatorStreamStoreFactory(Config config) {
    JobConfig jobConfig = new JobConfig(config);
    String coordinatorSystemName = jobConfig.getCoordinatorSystemNameOrNull();
    JobCoordinatorConfig jobCoordinatorConfig = new JobCoordinatorConfig(jobConfig);
    String jobCoordinatorFactoryClassName = jobCoordinatorConfig.getJobCoordinatorFactoryClassName();
    // TODO: Remove restriction to only ZkJobCoordinator after next phase of metadata store abstraction.
    if (StringUtils.isNotBlank(coordinatorSystemName) && ZkJobCoordinatorFactory.class.getName().equals(jobCoordinatorFactoryClassName)) {
        return Optional.of(new CoordinatorStreamMetadataStoreFactory());
    }
    LOG.warn("{} or {} not configured, or {} is not {}. No default coordinator stream metadata store will be created.", JobConfig.JOB_COORDINATOR_SYSTEM, JobConfig.JOB_DEFAULT_SYSTEM, JobCoordinatorConfig.JOB_COORDINATOR_FACTORY, ZkJobCoordinatorFactory.class.getName());
    return Optional.empty();
}
Also used : ZkJobCoordinatorFactory(org.apache.samza.zk.ZkJobCoordinatorFactory) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) JobConfig(org.apache.samza.config.JobConfig) CoordinatorStreamMetadataStoreFactory(org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with CoordinatorStreamMetadataStoreFactory

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory in project samza by apache.

the class LocalApplicationRunner method createCoordinatorStreamStore.

@VisibleForTesting
MetadataStore createCoordinatorStreamStore(Config config) {
    if (metadataStoreFactory.isPresent()) {
        // TODO: Add missing metadata store abstraction for creating the underlying store to address SAMZA-2182
        if (metadataStoreFactory.get() instanceof CoordinatorStreamMetadataStoreFactory) {
            if (createUnderlyingCoordinatorStream(config)) {
                MetadataStore coordinatorStreamStore = metadataStoreFactory.get().getMetadataStore("NoOp", config, new MetricsRegistryMap());
                LOG.info("Created coordinator stream store of type: {}", coordinatorStreamStore.getClass().getSimpleName());
                return coordinatorStreamStore;
            }
        } else {
            MetadataStore otherMetadataStore = metadataStoreFactory.get().getMetadataStore("NoOp", config, new MetricsRegistryMap());
            LOG.info("Created alternative coordinator stream store of type: {}", otherMetadataStore.getClass().getSimpleName());
            return otherMetadataStore;
        }
    }
    LOG.warn("No coordinator stream store created.");
    return null;
}
Also used : MetadataStore(org.apache.samza.metadatastore.MetadataStore) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) CoordinatorStreamMetadataStoreFactory(org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with CoordinatorStreamMetadataStoreFactory

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory in project samza by apache.

the class TestLocalApplicationRunner method testCreateCoordinatorStreamWithCoordinatorFactory.

/**
 * Underlying coordinator stream should be created if using CoordinatorStreamMetadataStoreFactory
 */
@Test
public void testCreateCoordinatorStreamWithCoordinatorFactory() throws Exception {
    CoordinatorStreamStore coordinatorStreamStore = mock(CoordinatorStreamStore.class);
    CoordinatorStreamMetadataStoreFactory coordinatorStreamMetadataStoreFactory = mock(CoordinatorStreamMetadataStoreFactory.class);
    doReturn(coordinatorStreamStore).when(coordinatorStreamMetadataStoreFactory).getMetadataStore(anyString(), any(Config.class), any(MetricsRegistry.class));
    SystemAdmins systemAdmins = mock(SystemAdmins.class);
    PowerMockito.whenNew(SystemAdmins.class).withAnyArguments().thenReturn(systemAdmins);
    LocalApplicationRunner localApplicationRunner = spy(new LocalApplicationRunner(mockApp, config, coordinatorStreamMetadataStoreFactory));
    // create store only if successful in creating the underlying coordinator stream
    doReturn(true).when(localApplicationRunner).createUnderlyingCoordinatorStream(eq(config));
    assertEquals(coordinatorStreamStore, localApplicationRunner.createCoordinatorStreamStore(config));
    verify(localApplicationRunner).createUnderlyingCoordinatorStream(eq(config));
    // do not create store if creating the underlying coordinator stream fails
    doReturn(false).when(localApplicationRunner).createUnderlyingCoordinatorStream(eq(config));
    assertNull(localApplicationRunner.createCoordinatorStreamStore(config));
}
Also used : CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) MetricsRegistry(org.apache.samza.metrics.MetricsRegistry) MapConfig(org.apache.samza.config.MapConfig) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) ApplicationConfig(org.apache.samza.config.ApplicationConfig) SystemAdmins(org.apache.samza.system.SystemAdmins) CoordinatorStreamMetadataStoreFactory(org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

CoordinatorStreamMetadataStoreFactory (org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JobConfig (org.apache.samza.config.JobConfig)2 JobCoordinatorConfig (org.apache.samza.config.JobCoordinatorConfig)2 ApplicationConfig (org.apache.samza.config.ApplicationConfig)1 Config (org.apache.samza.config.Config)1 MapConfig (org.apache.samza.config.MapConfig)1 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)1 MetadataStore (org.apache.samza.metadatastore.MetadataStore)1 MetricsRegistry (org.apache.samza.metrics.MetricsRegistry)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 SystemAdmins (org.apache.samza.system.SystemAdmins)1 ZkJobCoordinatorFactory (org.apache.samza.zk.ZkJobCoordinatorFactory)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1