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();
}
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;
}
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));
}
Aggregations