Search in sources :

Example 1 with Server

use of com.twitter.finagle.builder.Server 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();
}
Also used : MalformedURLException(java.net.MalformedURLException) Server(com.twitter.finagle.builder.Server) ServerConfiguration(com.twitter.distributedlog.service.config.ServerConfiguration) URI(java.net.URI) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) IdentityStreamPartitionConverter(com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter) StreamPartitionConverter(com.twitter.distributedlog.service.streamset.StreamPartitionConverter) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) ServerSetAnnouncer(com.twitter.distributedlog.service.announcer.ServerSetAnnouncer) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IdentityStreamPartitionConverter(com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) NOPAnnouncer(com.twitter.distributedlog.service.announcer.NOPAnnouncer) DefaultStreamConfigProvider(com.twitter.distributedlog.service.config.DefaultStreamConfigProvider) ServiceStreamConfigProvider(com.twitter.distributedlog.service.config.ServiceStreamConfigProvider) NullStreamConfigProvider(com.twitter.distributedlog.service.config.NullStreamConfigProvider) StreamConfigProvider(com.twitter.distributedlog.service.config.StreamConfigProvider) File(java.io.File)

Example 2 with Server

use of com.twitter.finagle.builder.Server in project distributedlog by twitter.

the class DistributedLogServer method runServer.

static Pair<DistributedLogServiceImpl, Server> runServer(ServerConfiguration serverConf, DistributedLogConfiguration dlConf, DynamicDistributedLogConfiguration dynDlConf, URI dlUri, StreamPartitionConverter partitionConverter, StatsProvider provider, int port, CountDownLatch keepAliveLatch, StatsReceiver statsReceiver, boolean thriftmux, StreamConfigProvider streamConfProvider) throws IOException {
    logger.info("Running server @ uri {}.", dlUri);
    boolean perStreamStatsEnabled = serverConf.isPerStreamStatEnabled();
    StatsLogger perStreamStatsLogger;
    if (perStreamStatsEnabled) {
        perStreamStatsLogger = provider.getStatsLogger("stream");
    } else {
        perStreamStatsLogger = NullStatsLogger.INSTANCE;
    }
    // dl service
    DistributedLogServiceImpl dlService = new DistributedLogServiceImpl(serverConf, dlConf, dynDlConf, streamConfProvider, dlUri, partitionConverter, provider.getStatsLogger(""), perStreamStatsLogger, keepAliveLatch);
    StatsReceiver serviceStatsReceiver = statsReceiver.scope("service");
    StatsLogger serviceStatsLogger = provider.getStatsLogger("service");
    ServerBuilder serverBuilder = ServerBuilder.get().name("DistributedLogServer").codec(ThriftServerFramedCodec.get()).reportTo(statsReceiver).keepAlive(true).bindTo(new InetSocketAddress(port));
    if (thriftmux) {
        logger.info("Using thriftmux.");
        Tuple2<Transport.Liveness, Stack.Param<Transport.Liveness>> livenessParam = new Transport.Liveness(Duration.Top(), Duration.Top(), Option.apply((Object) Boolean.valueOf(true))).mk();
        serverBuilder = serverBuilder.stack(ThriftMuxServer$.MODULE$.configured(livenessParam._1(), livenessParam._2()));
    }
    logger.info("DistributedLogServer running with the following configuration : \n{}", dlConf.getPropsAsString());
    // starts dl server
    Server server = ServerBuilder.safeBuild(new ClientIdRequiredFilter<byte[], byte[]>(serviceStatsReceiver).andThen(new StatsFilter<byte[], byte[]>(serviceStatsLogger).andThen(new DistributedLogService.Service(dlService, new TBinaryProtocol.Factory()))), serverBuilder);
    logger.info("Started DistributedLog Server.");
    return Pair.of(dlService, server);
}
Also used : DistributedLogService(com.twitter.distributedlog.thrift.service.DistributedLogService) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) NullStatsReceiver(com.twitter.finagle.stats.NullStatsReceiver) StatsReceiver(com.twitter.finagle.stats.StatsReceiver) Server(com.twitter.finagle.builder.Server) InetSocketAddress(java.net.InetSocketAddress) LoggerFactory(org.slf4j.LoggerFactory) DynamicConfigurationFactory(com.twitter.distributedlog.config.DynamicConfigurationFactory) ClientIdRequiredFilter(com.twitter.finagle.thrift.ClientIdRequiredFilter) Transport(com.twitter.finagle.transport.Transport) ServerBuilder(com.twitter.finagle.builder.ServerBuilder)

Aggregations

Server (com.twitter.finagle.builder.Server)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)1 DynamicConfigurationFactory (com.twitter.distributedlog.config.DynamicConfigurationFactory)1 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 NOPAnnouncer (com.twitter.distributedlog.service.announcer.NOPAnnouncer)1 ServerSetAnnouncer (com.twitter.distributedlog.service.announcer.ServerSetAnnouncer)1 DefaultStreamConfigProvider (com.twitter.distributedlog.service.config.DefaultStreamConfigProvider)1 NullStreamConfigProvider (com.twitter.distributedlog.service.config.NullStreamConfigProvider)1 ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)1 ServiceStreamConfigProvider (com.twitter.distributedlog.service.config.ServiceStreamConfigProvider)1 StreamConfigProvider (com.twitter.distributedlog.service.config.StreamConfigProvider)1 IdentityStreamPartitionConverter (com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter)1 StreamPartitionConverter (com.twitter.distributedlog.service.streamset.StreamPartitionConverter)1 DistributedLogService (com.twitter.distributedlog.thrift.service.DistributedLogService)1 ServerBuilder (com.twitter.finagle.builder.ServerBuilder)1 NullStatsReceiver (com.twitter.finagle.stats.NullStatsReceiver)1 StatsReceiver (com.twitter.finagle.stats.StatsReceiver)1 ClientIdRequiredFilter (com.twitter.finagle.thrift.ClientIdRequiredFilter)1 Transport (com.twitter.finagle.transport.Transport)1