Ejemplo n.º 1
0
  public void init() throws Exception {
    initializeEmitter();
    initializeMonitors();
    initializeMergerConfig();
    initializeTaskToolbox();
    initializeJacksonInjections();
    initializeJacksonSubtypes();
    initializeCuratorFramework();
    initializeCuratorCoordinator();
    initializeTaskMonitor();
    initializeServer();

    final ScheduledExecutorFactory scheduledExecutorFactory =
        ScheduledExecutors.createFactory(lifecycle);
    final ScheduledExecutorService globalScheduledExec =
        scheduledExecutorFactory.create(1, "Global--%d");
    final MonitorScheduler monitorScheduler =
        new MonitorScheduler(
            configFactory.build(MonitorSchedulerConfig.class),
            globalScheduledExec,
            emitter,
            monitors);
    lifecycle.addManagedInstance(monitorScheduler);

    final Context root = new Context(server, "/", Context.SESSIONS);

    root.addServlet(new ServletHolder(new StatusServlet()), "/status");
    root.addServlet(new ServletHolder(new DefaultServlet()), "/mmx/*");
    root.addFilter(GuiceFilter.class, "/mmx/indexer/worker/v1/*", 0);
  }
Ejemplo n.º 2
0
  public static void main(String[] args) throws Exception {
    LogLevelAdjuster.register();

    Lifecycle lifecycle = new Lifecycle();

    lifecycle.addManagedInstance(WorkerNode.builder().build());

    try {
      lifecycle.start();
    } catch (Throwable t) {
      log.info(t, "Throwable caught at startup, committing seppuku");
      System.exit(2);
    }

    lifecycle.join();
  }
  public static PrioritizedExecutorService create(
      Lifecycle lifecycle, ExecutorServiceConfig config) {
    final PrioritizedExecutorService service =
        new PrioritizedExecutorService(
            new ThreadPoolExecutor(
                config.getNumThreads(),
                config.getNumThreads(),
                0L,
                TimeUnit.MILLISECONDS,
                new PriorityBlockingQueue<Runnable>(),
                new ThreadFactoryBuilder()
                    .setDaemon(true)
                    .setNameFormat(config.getFormatString())
                    .build()));

    lifecycle.addHandler(
        new Lifecycle.Handler() {
          @Override
          public void start() throws Exception {}

          @Override
          public void stop() {
            service.shutdownNow();
          }
        });

    return service;
  }
Ejemplo n.º 4
0
  @LifecycleStart
  public synchronized void start() throws Exception {
    if (!initialized) {
      init();
    }

    lifecycle.start();
  }
Ejemplo n.º 5
0
 public void initializeCuratorCoordinator() {
   if (workerCuratorCoordinator == null) {
     workerCuratorCoordinator =
         new WorkerCuratorCoordinator(
             jsonMapper,
             configFactory.build(IndexerZkConfig.class),
             curatorFramework,
             new Worker(workerConfig));
     lifecycle.addManagedInstance(workerCuratorCoordinator);
   }
 }
Ejemplo n.º 6
0
 public void initializeTaskMonitor() {
   if (taskMonitor == null) {
     final ExecutorService workerExec = Executors.newFixedThreadPool(workerConfig.getNumThreads());
     final PathChildrenCache pathChildrenCache =
         new PathChildrenCache(
             curatorFramework, workerCuratorCoordinator.getTaskPathForWorker(), false);
     taskMonitor =
         new TaskMonitor(
             pathChildrenCache,
             curatorFramework,
             workerCuratorCoordinator,
             taskToolbox,
             workerExec);
     lifecycle.addManagedInstance(taskMonitor);
   }
 }
  @Inject
  public OffHeapNamespaceExtractionCacheManager(
      Lifecycle lifecycle,
      @Named("namespaceExtractionFunctionCache")
          ConcurrentMap<String, Function<String, String>> fnCache,
      @Named("namespaceReverseExtractionFunctionCache")
          ConcurrentMap<String, Function<String, List<String>>> reverseFnCache,
      ServiceEmitter emitter,
      final Map<Class<? extends ExtractionNamespace>, ExtractionNamespaceFunctionFactory<?>>
          namespaceFunctionFactoryMap) {
    super(lifecycle, fnCache, reverseFnCache, emitter, namespaceFunctionFactoryMap);
    try {
      tmpFile = File.createTempFile("druidMapDB", getClass().getCanonicalName());
      log.info("Using file [%s] for mapDB off heap namespace cache", tmpFile.getAbsolutePath());
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
    mmapDB =
        DBMaker.newFileDB(tmpFile)
            .closeOnJvmShutdown()
            .transactionDisable()
            .deleteFilesAfterClose()
            .strictDBGet()
            .asyncWriteEnable()
            .mmapFileEnable()
            .commitFileSyncDisable()
            .cacheSize(10_000_000)
            .make();
    lifecycle.addHandler(
        new Lifecycle.Handler() {
          @Override
          public void start() throws Exception {
            // NOOP
          }

          @Override
          public void stop() {
            if (!mmapDB.isClosed()) {
              mmapDB.close();
              if (!tmpFile.delete()) {
                log.warn("Unable to delete file at [%s]", tmpFile.getAbsolutePath());
              }
            }
          }
        });
  }
Ejemplo n.º 8
0
  private void initializeServer() {
    if (server == null) {
      server = Initialization.makeJettyServer(configFactory.build(ServerConfig.class));

      lifecycle.addHandler(
          new Lifecycle.Handler() {
            @Override
            public void start() throws Exception {
              log.info("Starting Jetty");
              server.start();
            }

            @Override
            public void stop() {
              log.info("Stopping Jetty");
              try {
                server.stop();
              } catch (Exception e) {
                log.error(e, "Exception thrown while stopping Jetty");
              }
            }
          });
    }
  }
Ejemplo n.º 9
0
 @LifecycleStop
 public synchronized void stop() {
   lifecycle.stop();
 }