use of com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter in project distributedlog by twitter.
the class DistributedLogServer method runServer.
public void runServer() throws ConfigurationException, IllegalArgumentException, IOException {
if (!uri.isPresent()) {
throw new IllegalArgumentException("No distributedlog uri provided.");
}
URI dlUri = URI.create(uri.get());
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
if (conf.isPresent()) {
String configFile = conf.get();
try {
dlConf.loadConf(new File(configFile).toURI().toURL());
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Failed to load distributedlog configuration from " + configFile + ".");
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Failed to load distributedlog configuration from malformed " + configFile + ".");
}
}
this.configExecutorService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("DistributedLogService-Dyncfg-%d").setDaemon(true).build());
// server configuration and dynamic configuration
ServerConfiguration serverConf = new ServerConfiguration();
serverConf.loadConf(dlConf);
// overwrite the shard id if it is provided in the args
if (shardId.isPresent()) {
serverConf.setServerShardId(shardId.get());
}
serverConf.validate();
DynamicDistributedLogConfiguration dynDlConf = getServiceDynConf(dlConf);
logger.info("Starting stats provider : {}", statsProvider.getClass());
statsProvider.start(dlConf);
if (announceServerSet.isPresent() && announceServerSet.get()) {
announcer = new ServerSetAnnouncer(dlUri, port.or(0), statsPort.or(0), shardId.or(0));
} else {
announcer = new NOPAnnouncer();
}
// Build the stream partition converter
StreamPartitionConverter converter;
try {
converter = ReflectionUtils.newInstance(serverConf.getStreamPartitionConverterClass());
} catch (ConfigurationException e) {
logger.warn("Failed to load configured stream-to-partition converter. Fallback to use {}", IdentityStreamPartitionConverter.class.getName());
converter = new IdentityStreamPartitionConverter();
}
StreamConfigProvider streamConfProvider = getStreamConfigProvider(dlConf, converter);
// pre-run
preRun(dlConf, serverConf);
Pair<DistributedLogServiceImpl, Server> serverPair = runServer(serverConf, dlConf, dynDlConf, dlUri, converter, statsProvider, port.or(0), keepAliveLatch, statsReceiver, thriftmux.isPresent(), streamConfProvider);
this.dlService = serverPair.getLeft();
this.server = serverPair.getRight();
// announce the service
announcer.announce();
}
use of com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter in project distributedlog by twitter.
the class TestStreamConfigProvider method testServiceProviderWithMissingConfig.
@Test(timeout = 60000)
public void testServiceProviderWithMissingConfig() throws Exception {
StreamConfigProvider provider = getServiceProvider(new IdentityStreamPartitionConverter());
Optional<DynamicDistributedLogConfiguration> config = provider.getDynamicStreamConfig("stream1");
assertTrue(config.isPresent());
}
use of com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter in project distributedlog by twitter.
the class TestStreamConfigProvider method testServiceProviderWithDefaultConfigPath.
@Test(timeout = 60000)
public void testServiceProviderWithDefaultConfigPath() throws Exception {
// Default config with property set.
PropertiesWriter writer1 = new PropertiesWriter();
writer1.setProperty("rpsStreamAcquireServiceLimit", "191919");
writer1.save();
String fallbackConfPath1 = writer1.getFile().getPath();
StreamConfigProvider provider1 = getServiceProvider(new IdentityStreamPartitionConverter(), DEFAULT_CONFIG_DIR, fallbackConfPath1);
Optional<DynamicDistributedLogConfiguration> config1 = provider1.getDynamicStreamConfig("stream1");
// Empty default config.
PropertiesWriter writer2 = new PropertiesWriter();
writer2.save();
String fallbackConfPath2 = writer2.getFile().getPath();
StreamConfigProvider provider2 = getServiceProvider(new IdentityStreamPartitionConverter(), DEFAULT_CONFIG_DIR, fallbackConfPath2);
Optional<DynamicDistributedLogConfiguration> config2 = provider2.getDynamicStreamConfig("stream1");
assertEquals(191919, config1.get().getRpsStreamAcquireServiceLimit());
assertEquals(-1, config2.get().getRpsStreamAcquireServiceLimit());
}
Aggregations