Search in sources :

Example 1 with StatsReceiver

use of com.twitter.finagle.stats.StatsReceiver in project distributedlog by twitter.

the class MonitorServiceApp method runCmd.

void runCmd(CommandLine cmdline) throws IOException {
    StatsProvider statsProvider = new NullStatsProvider();
    if (cmdline.hasOption("p")) {
        String providerClass = cmdline.getOptionValue("p");
        statsProvider = ReflectionUtils.newInstance(providerClass, StatsProvider.class);
    }
    StatsReceiver statsReceiver = NullStatsReceiver.get();
    final MonitorService monitorService = new MonitorService(getOptionalStringArg(cmdline, "u"), getOptionalStringArg(cmdline, "c"), getOptionalStringArg(cmdline, "s"), getOptionalIntegerArg(cmdline, "i"), getOptionalIntegerArg(cmdline, "d"), getOptionalStringArg(cmdline, "f"), getOptionalIntegerArg(cmdline, "n"), getOptionalIntegerArg(cmdline, "t"), getOptionalIntegerArg(cmdline, "hck"), getOptionalBooleanArg(cmdline, "hsci"), getOptionalBooleanArg(cmdline, "w"), statsReceiver, statsProvider);
    monitorService.runServer();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            logger.info("Closing monitor service.");
            monitorService.close();
            logger.info("Closed monitor service.");
        }
    });
    try {
        monitorService.join();
    } catch (InterruptedException ie) {
        logger.warn("Interrupted when waiting monitor service to be finished : ", ie);
    }
}
Also used : StatsReceiver(com.twitter.finagle.stats.StatsReceiver) NullStatsReceiver(com.twitter.finagle.stats.NullStatsReceiver) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) StatsProvider(org.apache.bookkeeper.stats.StatsProvider) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider)

Example 2 with StatsReceiver

use of com.twitter.finagle.stats.StatsReceiver 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)

Example 3 with StatsReceiver

use of com.twitter.finagle.stats.StatsReceiver in project distributedlog by twitter.

the class DistributedLogServerApp method runCmd.

private void runCmd(CommandLine cmdline) throws IllegalArgumentException, IOException, ConfigurationException {
    final StatsReceiver statsReceiver = NullStatsReceiver.get();
    Optional<String> confOptional = getOptionalStringArg(cmdline, "c");
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    if (confOptional.isPresent()) {
        String configFile = confOptional.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 + ".");
        }
    }
    // load the stats provider
    final StatsProvider statsProvider = getOptionalStringArg(cmdline, "pd").transform(new Function<String, StatsProvider>() {

        @Nullable
        @Override
        public StatsProvider apply(@Nullable String name) {
            return ReflectionUtils.newInstance(name, StatsProvider.class);
        }
    }).or(new NullStatsProvider());
    final DistributedLogServer server = DistributedLogServer.runServer(getOptionalStringArg(cmdline, "u"), confOptional, getOptionalStringArg(cmdline, "sc"), getOptionalIntegerArg(cmdline, "p"), getOptionalIntegerArg(cmdline, "sp"), getOptionalIntegerArg(cmdline, "si"), getOptionalBooleanArg(cmdline, "a"), getOptionalBooleanArg(cmdline, "mx"), statsReceiver, statsProvider);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            logger.info("Closing DistributedLog Server.");
            server.close();
            logger.info("Closed DistributedLog Server.");
            statsProvider.stop();
        }
    });
    try {
        server.join();
    } catch (InterruptedException e) {
        logger.warn("Interrupted when waiting distributedlog server to be finished : ", e);
    }
    logger.info("DistributedLog Service Interrupted.");
    server.close();
    logger.info("Closed DistributedLog Server.");
    statsProvider.stop();
}
Also used : MalformedURLException(java.net.MalformedURLException) StatsReceiver(com.twitter.finagle.stats.StatsReceiver) NullStatsReceiver(com.twitter.finagle.stats.NullStatsReceiver) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) Function(com.google.common.base.Function) ConfigurationException(org.apache.commons.configuration.ConfigurationException) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) StatsProvider(org.apache.bookkeeper.stats.StatsProvider) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

NullStatsReceiver (com.twitter.finagle.stats.NullStatsReceiver)3 StatsReceiver (com.twitter.finagle.stats.StatsReceiver)3 NullStatsProvider (org.apache.bookkeeper.stats.NullStatsProvider)2 StatsProvider (org.apache.bookkeeper.stats.StatsProvider)2 Function (com.google.common.base.Function)1 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)1 DynamicConfigurationFactory (com.twitter.distributedlog.config.DynamicConfigurationFactory)1 DistributedLogService (com.twitter.distributedlog.thrift.service.DistributedLogService)1 Server (com.twitter.finagle.builder.Server)1 ServerBuilder (com.twitter.finagle.builder.ServerBuilder)1 ClientIdRequiredFilter (com.twitter.finagle.thrift.ClientIdRequiredFilter)1 Transport (com.twitter.finagle.transport.Transport)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 MalformedURLException (java.net.MalformedURLException)1 Nullable (javax.annotation.Nullable)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 LoggerFactory (org.slf4j.LoggerFactory)1