@Override
  public Node stop() {
    if (!lifecycle.moveToStopped()) {
      return this;
    }
    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("{{}}[{}]: stopping ...", Version.full(), JvmInfo.jvmInfo().pid());

    if (settings.getAsBoolean("http.enabled", true)) {
      injector.getInstance(HttpServer.class).stop();
    }
    injector.getInstance(RoutingService.class).stop();
    injector.getInstance(ClusterService.class).stop();
    injector.getInstance(DiscoveryService.class).stop();
    injector.getInstance(MonitorService.class).stop();
    injector.getInstance(GatewayService.class).stop();
    injector.getInstance(SearchService.class).stop();
    injector.getInstance(RiversManager.class).stop();
    injector.getInstance(IndicesClusterStateService.class).stop();
    injector.getInstance(IndicesService.class).stop();
    injector.getInstance(RestController.class).stop();
    injector.getInstance(TransportService.class).stop();
    injector.getInstance(JmxService.class).close();

    for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
      injector.getInstance(plugin).stop();
    }

    logger.info("{{}}[{}]: stopped", Version.full(), JvmInfo.jvmInfo().pid());

    return this;
  }
 private void maybeLogHeapDetails() {
   JvmInfo jvmInfo = JvmInfo.jvmInfo();
   ByteSizeValue maxHeapSize = jvmInfo.getMem().getHeapMax();
   String useCompressedOops = jvmInfo.useCompressedOops();
   logger.info(
       "heap size [{}], compressed ordinary object pointers [{}]", maxHeapSize, useCompressedOops);
 }
 private void maybeLogHeapDetails() {
   ByteSizeValue maxHeapSize = JvmInfo.jvmInfo().getMem().getHeapMax();
   Boolean usingCompressedOops = JvmInfo.jvmInfo().usingCompressedOops();
   String usingCompressedOopsStatus =
       usingCompressedOops == null ? "unknown" : Boolean.toString(usingCompressedOops);
   logger.info(
       "heap size [{}], compressed ordinary object pointers [{}]",
       maxHeapSize,
       usingCompressedOopsStatus);
 }
  public InternalNode(Settings pSettings, boolean loadConfigSettings)
      throws ElasticSearchException {
    Tuple<Settings, Environment> tuple =
        InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);

    ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
    logger.info("{{}}[{}]: initializing ...", Version.full(), JvmInfo.jvmInfo().pid());

    this.pluginsService = new PluginsService(tuple.v1(), tuple.v2());
    this.settings = pluginsService.updatedSettings();
    this.environment = tuple.v2();

    ModulesBuilder modules = new ModulesBuilder();
    modules.add(new PluginsModule(settings, pluginsService));
    modules.add(new SettingsModule(settings));
    modules.add(new NodeModule(this));
    modules.add(new NetworkModule());
    modules.add(new NodeCacheModule(settings));
    modules.add(new ScriptModule());
    modules.add(new JmxModule(settings));
    modules.add(new EnvironmentModule(environment));
    modules.add(new NodeEnvironmentModule());
    modules.add(new ClusterNameModule(settings));
    modules.add(new ThreadPoolModule(settings));
    modules.add(new TimerModule());
    modules.add(new DiscoveryModule(settings));
    modules.add(new ClusterModule(settings));
    modules.add(new RestModule(settings));
    modules.add(new TransportModule(settings));
    if (settings.getAsBoolean("http.enabled", true)) {
      modules.add(new HttpServerModule(settings));
    }
    modules.add(new RiversModule(settings));
    modules.add(new IndicesModule(settings));
    modules.add(new SearchModule());
    modules.add(new TransportActionModule());
    modules.add(new MonitorModule(settings));
    modules.add(new GatewayModule(settings));
    modules.add(new NodeClientModule());

    injector = modules.createInjector();

    client = injector.getInstance(Client.class);

    logger.info("{{}}[{}]: initialized", Version.full(), JvmInfo.jvmInfo().pid());
  }
Beispiel #5
0
 public static void main(String[] args) {
   System.out.println(
       "Version: "
           + Version.CURRENT
           + ", Build: "
           + Build.CURRENT.hashShort()
           + "/"
           + Build.CURRENT.timestamp()
           + ", JVM: "
           + JvmInfo.jvmInfo().version());
 }
  @Override
  public Node stop() {
    if (!lifecycle.moveToStopped()) {
      return this;
    }
    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("{{}}[{}]: stopping ...", Version.full(), JvmInfo.jvmInfo().pid());

    if (settings.getAsBoolean("http.enabled", true)) {
      injector.getInstance(HttpServer.class).stop();
    }
    // stop any changes happening as a result of cluster state changes
    injector.getInstance(IndicesClusterStateService.class).stop();
    // we close indices first, so operations won't be allowed on it
    injector.getInstance(IndexingMemoryBufferController.class).stop();
    injector.getInstance(IndicesService.class).stop();
    // sleep a bit to let operations finish with indices service
    //        try {
    //            Thread.sleep(500);
    //        } catch (InterruptedException e) {
    //            // ignore
    //        }
    injector.getInstance(RoutingService.class).stop();
    injector.getInstance(ClusterService.class).stop();
    injector.getInstance(DiscoveryService.class).stop();
    injector.getInstance(MonitorService.class).stop();
    injector.getInstance(GatewayService.class).stop();
    injector.getInstance(SearchService.class).stop();
    injector.getInstance(RiversManager.class).stop();
    injector.getInstance(RestController.class).stop();
    injector.getInstance(TransportService.class).stop();
    injector.getInstance(JmxService.class).close();

    for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
      injector.getInstance(plugin).stop();
    }

    logger.info("{{}}[{}]: stopped", Version.full(), JvmInfo.jvmInfo().pid());

    return this;
  }
  public Node start() {
    if (!lifecycle.moveToStarted()) {
      return this;
    }

    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("{{}}[{}]: starting ...", Version.full(), JvmInfo.jvmInfo().pid());

    for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
      injector.getInstance(plugin).start();
    }

    injector.getInstance(IndicesService.class).start();
    injector.getInstance(IndexingMemoryBufferController.class).start();
    injector.getInstance(IndicesClusterStateService.class).start();
    injector.getInstance(RiversManager.class).start();
    injector.getInstance(ClusterService.class).start();
    injector.getInstance(RoutingService.class).start();
    injector.getInstance(SearchService.class).start();
    injector.getInstance(MonitorService.class).start();
    injector.getInstance(RestController.class).start();
    injector.getInstance(TransportService.class).start();
    DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start();

    // gateway should start after disco, so it can try and recovery from gateway on "start"
    injector.getInstance(GatewayService.class).start();

    if (settings.getAsBoolean("http.enabled", true)) {
      injector.getInstance(HttpServer.class).start();
    }
    injector
        .getInstance(JmxService.class)
        .connectAndRegister(
            discoService.nodeDescription(), injector.getInstance(NetworkService.class));

    logger.info("{{}}[{}]: started", Version.full(), JvmInfo.jvmInfo().pid());

    return this;
  }
  private Table buildTable(
      RestRequest req,
      ClusterStateResponse state,
      NodesInfoResponse nodesInfo,
      NodesStatsResponse nodesStats) {
    boolean fullId = req.paramAsBoolean("full_id", false);

    DiscoveryNodes nodes = state.getState().nodes();
    String masterId = nodes.masterNodeId();
    Table table = getTableWithHeader(req);

    for (DiscoveryNode node : nodes) {
      NodeInfo info = nodesInfo.getNodesMap().get(node.id());
      NodeStats stats = nodesStats.getNodesMap().get(node.id());

      JvmInfo jvmInfo = info == null ? null : info.getJvm();
      JvmStats jvmStats = stats == null ? null : stats.getJvm();
      FsInfo fsInfo = stats == null ? null : stats.getFs();
      OsStats osStats = stats == null ? null : stats.getOs();
      ProcessStats processStats = stats == null ? null : stats.getProcess();
      NodeIndicesStats indicesStats = stats == null ? null : stats.getIndices();

      table.startRow();

      table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
      table.addCell(info == null ? null : info.getProcess().getId());
      table.addCell(node.getHostName());
      table.addCell(node.getHostAddress());
      if (node.address() instanceof InetSocketTransportAddress) {
        table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
      } else {
        table.addCell("-");
      }

      table.addCell(node.getVersion().number());
      table.addCell(info == null ? null : info.getBuild().shortHash());
      table.addCell(jvmInfo == null ? null : jvmInfo.version());
      table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable());
      table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed());
      table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsedPercent());
      table.addCell(jvmInfo == null ? null : jvmInfo.getMem().getHeapMax());
      table.addCell(
          osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsed());
      table.addCell(
          osStats == null
              ? null
              : osStats.getMem() == null ? null : osStats.getMem().getUsedPercent());
      table.addCell(
          osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getTotal());
      table.addCell(processStats == null ? null : processStats.getOpenFileDescriptors());
      table.addCell(
          processStats == null
              ? null
              : calculatePercentage(
                  processStats.getOpenFileDescriptors(), processStats.getMaxFileDescriptors()));
      table.addCell(processStats == null ? null : processStats.getMaxFileDescriptors());

      table.addCell(
          osStats == null ? null : String.format(Locale.ROOT, "%.2f", osStats.getLoadAverage()));
      table.addCell(jvmStats == null ? null : jvmStats.getUptime());
      table.addCell(node.clientNode() ? "c" : node.dataNode() ? "d" : "-");
      table.addCell(
          masterId == null
              ? "x"
              : masterId.equals(node.id()) ? "*" : node.masterNode() ? "m" : "-");
      table.addCell(node.name());

      CompletionStats completionStats =
          indicesStats == null ? null : stats.getIndices().getCompletion();
      table.addCell(completionStats == null ? null : completionStats.getSize());

      FieldDataStats fdStats = indicesStats == null ? null : stats.getIndices().getFieldData();
      table.addCell(fdStats == null ? null : fdStats.getMemorySize());
      table.addCell(fdStats == null ? null : fdStats.getEvictions());

      QueryCacheStats fcStats = indicesStats == null ? null : indicesStats.getQueryCache();
      table.addCell(fcStats == null ? null : fcStats.getMemorySize());
      table.addCell(fcStats == null ? null : fcStats.getEvictions());

      RequestCacheStats qcStats = indicesStats == null ? null : indicesStats.getRequestCache();
      table.addCell(qcStats == null ? null : qcStats.getMemorySize());
      table.addCell(qcStats == null ? null : qcStats.getEvictions());
      table.addCell(qcStats == null ? null : qcStats.getHitCount());
      table.addCell(qcStats == null ? null : qcStats.getMissCount());

      FlushStats flushStats = indicesStats == null ? null : indicesStats.getFlush();
      table.addCell(flushStats == null ? null : flushStats.getTotal());
      table.addCell(flushStats == null ? null : flushStats.getTotalTime());

      GetStats getStats = indicesStats == null ? null : indicesStats.getGet();
      table.addCell(getStats == null ? null : getStats.current());
      table.addCell(getStats == null ? null : getStats.getTime());
      table.addCell(getStats == null ? null : getStats.getCount());
      table.addCell(getStats == null ? null : getStats.getExistsTime());
      table.addCell(getStats == null ? null : getStats.getExistsCount());
      table.addCell(getStats == null ? null : getStats.getMissingTime());
      table.addCell(getStats == null ? null : getStats.getMissingCount());

      IndexingStats indexingStats = indicesStats == null ? null : indicesStats.getIndexing();
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCurrent());
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteTime());
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCount());
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCurrent());
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexTime());
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCount());
      table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexFailedCount());

      MergeStats mergeStats = indicesStats == null ? null : indicesStats.getMerge();
      table.addCell(mergeStats == null ? null : mergeStats.getCurrent());
      table.addCell(mergeStats == null ? null : mergeStats.getCurrentNumDocs());
      table.addCell(mergeStats == null ? null : mergeStats.getCurrentSize());
      table.addCell(mergeStats == null ? null : mergeStats.getTotal());
      table.addCell(mergeStats == null ? null : mergeStats.getTotalNumDocs());
      table.addCell(mergeStats == null ? null : mergeStats.getTotalSize());
      table.addCell(mergeStats == null ? null : mergeStats.getTotalTime());

      PercolateStats percolateStats = indicesStats == null ? null : indicesStats.getPercolate();
      table.addCell(percolateStats == null ? null : percolateStats.getCurrent());
      table.addCell(percolateStats == null ? null : percolateStats.getMemorySize());
      table.addCell(percolateStats == null ? null : percolateStats.getNumQueries());
      table.addCell(percolateStats == null ? null : percolateStats.getTime());
      table.addCell(percolateStats == null ? null : percolateStats.getCount());

      RefreshStats refreshStats = indicesStats == null ? null : indicesStats.getRefresh();
      table.addCell(refreshStats == null ? null : refreshStats.getTotal());
      table.addCell(refreshStats == null ? null : refreshStats.getTotalTime());

      ScriptStats scriptStats = stats == null ? null : stats.getScriptStats();
      table.addCell(scriptStats == null ? null : scriptStats.getCompilations());
      table.addCell(scriptStats == null ? null : scriptStats.getCacheEvictions());

      SearchStats searchStats = indicesStats == null ? null : indicesStats.getSearch();
      table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCurrent());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchTime());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCount());
      table.addCell(searchStats == null ? null : searchStats.getOpenContexts());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCurrent());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryTime());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCount());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCurrent());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollTime());
      table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCount());

      SegmentsStats segmentsStats = indicesStats == null ? null : indicesStats.getSegments();
      table.addCell(segmentsStats == null ? null : segmentsStats.getCount());
      table.addCell(segmentsStats == null ? null : segmentsStats.getMemory());
      table.addCell(segmentsStats == null ? null : segmentsStats.getIndexWriterMemory());
      table.addCell(segmentsStats == null ? null : segmentsStats.getIndexWriterMaxMemory());
      table.addCell(segmentsStats == null ? null : segmentsStats.getVersionMapMemory());
      table.addCell(segmentsStats == null ? null : segmentsStats.getBitsetMemory());

      SuggestStats suggestStats = indicesStats == null ? null : indicesStats.getSuggest();
      table.addCell(suggestStats == null ? null : suggestStats.getCurrent());
      table.addCell(suggestStats == null ? null : suggestStats.getTime());
      table.addCell(suggestStats == null ? null : suggestStats.getCount());

      table.endRow();
    }

    return table;
  }
 JvmVersion(JvmInfo jvmInfo) {
   version = jvmInfo.version();
   vmName = jvmInfo.vmName();
   vmVersion = jvmInfo.vmVersion();
   vmVendor = jvmInfo.vmVendor();
 }
Beispiel #10
0
 @Override
 public boolean check() {
   return JvmInfo.jvmInfo().useG1GC().equals("true");
 }
Beispiel #11
0
  static {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();

    // returns the <process id>@<host>
    long pid;
    String xPid = runtimeMXBean.getName();
    try {
      xPid = xPid.split("@")[0];
      pid = Long.parseLong(xPid);
    } catch (Exception e) {
      pid = -1;
    }
    JvmInfo info = new JvmInfo();
    info.pid = pid;
    info.startTime = runtimeMXBean.getStartTime();
    info.version = System.getProperty("java.version");
    info.vmName = runtimeMXBean.getVmName();
    info.vmVendor = runtimeMXBean.getVmVendor();
    info.vmVersion = runtimeMXBean.getVmVersion();
    info.mem = new Mem();
    info.mem.heapInit =
        memoryMXBean.getHeapMemoryUsage().getInit() < 0
            ? 0
            : memoryMXBean.getHeapMemoryUsage().getInit();
    info.mem.heapMax =
        memoryMXBean.getHeapMemoryUsage().getMax() < 0
            ? 0
            : memoryMXBean.getHeapMemoryUsage().getMax();
    info.mem.nonHeapInit =
        memoryMXBean.getNonHeapMemoryUsage().getInit() < 0
            ? 0
            : memoryMXBean.getNonHeapMemoryUsage().getInit();
    info.mem.nonHeapMax =
        memoryMXBean.getNonHeapMemoryUsage().getMax() < 0
            ? 0
            : memoryMXBean.getNonHeapMemoryUsage().getMax();
    try {
      Class<?> vmClass = Class.forName("sun.misc.VM");
      info.mem.directMemoryMax = (Long) vmClass.getMethod("maxDirectMemory").invoke(null);
    } catch (Exception t) {
      // ignore
    }
    info.inputArguments =
        runtimeMXBean
            .getInputArguments()
            .toArray(new String[runtimeMXBean.getInputArguments().size()]);
    try {
      info.bootClassPath = runtimeMXBean.getBootClassPath();
    } catch (UnsupportedOperationException e) {
      // oracle java 9
      info.bootClassPath = System.getProperty("sun.boot.class.path");
      if (info.bootClassPath == null) {
        // something else
        info.bootClassPath = "<unknown>";
      }
    }
    info.classPath = runtimeMXBean.getClassPath();
    info.systemProperties = Collections.unmodifiableMap(runtimeMXBean.getSystemProperties());

    List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    info.gcCollectors = new String[gcMxBeans.size()];
    for (int i = 0; i < gcMxBeans.size(); i++) {
      GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
      info.gcCollectors[i] = gcMxBean.getName();
    }

    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    info.memoryPools = new String[memoryPoolMXBeans.size()];
    for (int i = 0; i < memoryPoolMXBeans.size(); i++) {
      MemoryPoolMXBean memoryPoolMXBean = memoryPoolMXBeans.get(i);
      info.memoryPools[i] = memoryPoolMXBean.getName();
    }

    try {
      @SuppressWarnings("unchecked")
      Class<? extends PlatformManagedObject> clazz =
          (Class<? extends PlatformManagedObject>)
              Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
      Class<?> vmOptionClazz = Class.forName("com.sun.management.VMOption");
      PlatformManagedObject hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(clazz);
      Method vmOptionMethod = clazz.getMethod("getVMOption", String.class);
      Method valueMethod = vmOptionClazz.getMethod("getValue");

      try {
        Object onError = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "OnError");
        info.onError = (String) valueMethod.invoke(onError);
      } catch (Exception ignored) {
      }

      try {
        Object onOutOfMemoryError =
            vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "OnOutOfMemoryError");
        info.onOutOfMemoryError = (String) valueMethod.invoke(onOutOfMemoryError);
      } catch (Exception ignored) {
      }

      try {
        Object useCompressedOopsVmOption =
            vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseCompressedOops");
        info.useCompressedOops = (String) valueMethod.invoke(useCompressedOopsVmOption);
      } catch (Exception ignored) {
      }

      try {
        Object useG1GCVmOption = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseG1GC");
        info.useG1GC = (String) valueMethod.invoke(useG1GCVmOption);
      } catch (Exception ignored) {
      }

      try {
        Object initialHeapSizeVmOption =
            vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "InitialHeapSize");
        info.configuredInitialHeapSize =
            Long.parseLong((String) valueMethod.invoke(initialHeapSizeVmOption));
      } catch (Exception ignored) {
      }

      try {
        Object maxHeapSizeVmOption = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "MaxHeapSize");
        info.configuredMaxHeapSize =
            Long.parseLong((String) valueMethod.invoke(maxHeapSizeVmOption));
      } catch (Exception ignored) {
      }
    } catch (Exception ignored) {

    }

    INSTANCE = info;
  }
Beispiel #12
0
  public InternalNode(Settings preparedSettings, boolean loadConfigSettings)
      throws ElasticsearchException {
    final Settings pSettings =
        settingsBuilder()
            .put(preparedSettings)
            .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();
    Tuple<Settings, Environment> tuple =
        InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings);
    tuple = new Tuple<>(TribeService.processSettings(tuple.v1()), tuple.v2());

    // The only place we can actually fake the version a node is running on:
    Version version = pSettings.getAsVersion("tests.mock.version", Version.CURRENT);

    ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
    logger.info(
        "version[{}], pid[{}], build[{}/{}]",
        version,
        JvmInfo.jvmInfo().pid(),
        Build.CURRENT.hashShort(),
        Build.CURRENT.timestamp());

    logger.info("initializing ...");

    if (logger.isDebugEnabled()) {
      Environment env = tuple.v2();
      logger.debug(
          "using home [{}], config [{}], data [{}], logs [{}], work [{}], plugins [{}]",
          env.homeFile(),
          env.configFile(),
          Arrays.toString(env.dataFiles()),
          env.logsFile(),
          env.workFile(),
          env.pluginsFile());
    }

    this.pluginsService = new PluginsService(tuple.v1(), tuple.v2());
    this.settings = pluginsService.updatedSettings();
    // create the environment based on the finalized (processed) view of the settings
    this.environment = new Environment(this.settings());

    CompressorFactory.configure(settings);
    final NodeEnvironment nodeEnvironment;
    try {
      nodeEnvironment = new NodeEnvironment(this.settings, this.environment);
    } catch (IOException ex) {
      throw new ElasticsearchIllegalStateException("Failed to created node environment", ex);
    }

    boolean success = false;
    try {
      ModulesBuilder modules = new ModulesBuilder();
      modules.add(new Version.Module(version));
      modules.add(new PageCacheRecyclerModule(settings));
      modules.add(new CircuitBreakerModule(settings));
      modules.add(new BigArraysModule(settings));
      modules.add(new PluginsModule(settings, pluginsService));
      modules.add(new SettingsModule(settings));
      modules.add(new NodeModule(this));
      modules.add(new NetworkModule());
      modules.add(new ScriptModule(settings));
      modules.add(new EnvironmentModule(environment));
      modules.add(new NodeEnvironmentModule(nodeEnvironment));
      modules.add(new ClusterNameModule(settings));
      modules.add(new ThreadPoolModule(settings));
      modules.add(new DiscoveryModule(settings));
      modules.add(new ClusterModule(settings));
      modules.add(new RestModule(settings));
      modules.add(new TransportModule(settings));
      if (settings.getAsBoolean(HTTP_ENABLED, true)) {
        modules.add(new HttpServerModule(settings));
      }
      modules.add(new RiversModule(settings));
      modules.add(new IndicesModule(settings));
      modules.add(new SearchModule());
      modules.add(new ActionModule(false));
      modules.add(new MonitorModule(settings));
      modules.add(new GatewayModule(settings));
      modules.add(new NodeClientModule());
      modules.add(new ShapeModule());
      modules.add(new PercolatorModule());
      modules.add(new ResourceWatcherModule());
      modules.add(new RepositoriesModule());
      modules.add(new TribeModule());
      modules.add(new BenchmarkModule(settings));

      injector = modules.createInjector();

      client = injector.getInstance(Client.class);
      success = true;
    } finally {
      if (!success) {
        nodeEnvironment.close();
      }
    }

    logger.info("initialized");
  }
Beispiel #13
0
 public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
   JvmInfo jvmInfo = new JvmInfo();
   jvmInfo.readFrom(in);
   return jvmInfo;
 }
  /** This method is invoked by {@link Elasticsearch#main(String[])} to startup elasticsearch. */
  static void init(String[] args) throws Throwable {
    // Set the system property before anything has a chance to trigger its use
    initLoggerPrefix();

    BootstrapCLIParser bootstrapCLIParser = new BootstrapCLIParser();
    CliTool.ExitStatus status = bootstrapCLIParser.execute(args);

    if (CliTool.ExitStatus.OK != status) {
      exit(status.status());
    }

    INSTANCE = new Bootstrap();

    boolean foreground =
        !"false".equals(System.getProperty("es.foreground", System.getProperty("es-foreground")));

    Environment environment = initialSettings(foreground);
    Settings settings = environment.settings();
    setupLogging(settings, environment);
    checkForCustomConfFile();

    if (environment.pidFile() != null) {
      PidFile.create(environment.pidFile(), true);
    }

    if (System.getProperty("es.max-open-files", "false").equals("true")) {
      ESLogger logger = Loggers.getLogger(Bootstrap.class);
      logger.info("max_open_files [{}]", ProcessProbe.getInstance().getMaxFileDescriptorCount());
    }

    // warn if running using the client VM
    if (JvmInfo.jvmInfo().getVmName().toLowerCase(Locale.ROOT).contains("client")) {
      ESLogger logger = Loggers.getLogger(Bootstrap.class);
      logger.warn(
          "jvm uses the client vm, make sure to run `java` with the server vm for best performance by adding `-server` to the command line");
    }

    try {
      if (!foreground) {
        Loggers.disableConsoleLogging();
        closeSystOut();
      }

      // fail if using broken version
      JVMCheck.check();

      // fail if somebody replaced the lucene jars
      checkLucene();

      INSTANCE.setup(true, settings, environment);

      INSTANCE.start();

      if (!foreground) {
        closeSysError();
      }
    } catch (Throwable e) {
      // disable console logging, so user does not see the exception twice (jvm will show it
      // already)
      if (foreground) {
        Loggers.disableConsoleLogging();
      }
      ESLogger logger = Loggers.getLogger(Bootstrap.class);
      if (INSTANCE.node != null) {
        logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("node.name"));
      }
      // HACK, it sucks to do this, but we will run users out of disk space otherwise
      if (e instanceof CreationException) {
        // guice: log the shortened exc to the log file
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(os, false, "UTF-8");
        new StartupError(e).printStackTrace(ps);
        ps.flush();
        logger.error("Guice Exception: {}", os.toString("UTF-8"));
      } else {
        // full exception
        logger.error("Exception", e);
      }
      // re-enable it if appropriate, so they can see any logging during the shutdown process
      if (foreground) {
        Loggers.enableConsoleLogging();
      }

      throw e;
    }
  }
 static void initializeProbes() {
   // Force probes to be loaded
   ProcessProbe.getInstance();
   OsProbe.getInstance();
   JvmInfo.jvmInfo();
 }
  @Inject
  public NettyHttpServerTransport(
      Settings settings, NetworkService networkService, BigArrays bigArrays) {
    super(settings);
    this.networkService = networkService;
    this.bigArrays = bigArrays;

    if (settings.getAsBoolean("netty.epollBugWorkaround", false)) {
      System.setProperty("org.jboss.netty.epollBugWorkaround", "true");
    }

    ByteSizeValue maxContentLength =
        settings.getAsBytesSize(
            "http.netty.max_content_length",
            settings.getAsBytesSize(
                "http.max_content_length", new ByteSizeValue(100, ByteSizeUnit.MB)));
    this.maxChunkSize =
        settings.getAsBytesSize(
            "http.netty.max_chunk_size",
            settings.getAsBytesSize("http.max_chunk_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
    this.maxHeaderSize =
        settings.getAsBytesSize(
            "http.netty.max_header_size",
            settings.getAsBytesSize("http.max_header_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
    this.maxInitialLineLength =
        settings.getAsBytesSize(
            "http.netty.max_initial_line_length",
            settings.getAsBytesSize(
                "http.max_initial_line_length", new ByteSizeValue(4, ByteSizeUnit.KB)));
    // don't reset cookies by default, since I don't think we really need to
    // note, parsing cookies was fixed in netty 3.5.1 regarding stack allocation, but still,
    // currently, we don't need cookies
    this.resetCookies =
        settings.getAsBoolean(
            "http.netty.reset_cookies", settings.getAsBoolean("http.reset_cookies", false));
    this.maxCumulationBufferCapacity =
        settings.getAsBytesSize("http.netty.max_cumulation_buffer_capacity", null);
    this.maxCompositeBufferComponents =
        settings.getAsInt("http.netty.max_composite_buffer_components", -1);
    this.workerCount =
        settings.getAsInt(
            "http.netty.worker_count", EsExecutors.boundedNumberOfProcessors(settings) * 2);
    this.blockingServer =
        settings.getAsBoolean(
            "http.netty.http.blocking_server",
            settings.getAsBoolean(TCP_BLOCKING_SERVER, settings.getAsBoolean(TCP_BLOCKING, false)));
    this.port = settings.get("http.netty.port", settings.get("http.port", "9200-9300"));
    this.bindHost =
        settings.get(
            "http.netty.bind_host", settings.get("http.bind_host", settings.get("http.host")));
    this.publishHost =
        settings.get(
            "http.netty.publish_host",
            settings.get("http.publish_host", settings.get("http.host")));
    this.publishPort =
        settings.getAsInt("http.netty.publish_port", settings.getAsInt("http.publish_port", 0));
    this.tcpNoDelay = settings.get("http.netty.tcp_no_delay", settings.get(TCP_NO_DELAY, "true"));
    this.tcpKeepAlive =
        settings.get("http.netty.tcp_keep_alive", settings.get(TCP_KEEP_ALIVE, "true"));
    this.reuseAddress =
        settings.getAsBoolean(
            "http.netty.reuse_address",
            settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
    this.tcpSendBufferSize =
        settings.getAsBytesSize(
            "http.netty.tcp_send_buffer_size",
            settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
    this.tcpReceiveBufferSize =
        settings.getAsBytesSize(
            "http.netty.tcp_receive_buffer_size",
            settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
    this.detailedErrorsEnabled = settings.getAsBoolean(SETTING_HTTP_DETAILED_ERRORS_ENABLED, true);

    long defaultReceiverPredictor = 512 * 1024;
    if (JvmInfo.jvmInfo().getMem().getDirectMemoryMax().bytes() > 0) {
      // we can guess a better default...
      long l =
          (long) ((0.3 * JvmInfo.jvmInfo().getMem().getDirectMemoryMax().bytes()) / workerCount);
      defaultReceiverPredictor = Math.min(defaultReceiverPredictor, Math.max(l, 64 * 1024));
    }

    // See AdaptiveReceiveBufferSizePredictor#DEFAULT_XXX for default values in netty..., we can use
    // higher ones for us, even fixed one
    ByteSizeValue receivePredictorMin =
        settings.getAsBytesSize(
            "http.netty.receive_predictor_min",
            settings.getAsBytesSize(
                "http.netty.receive_predictor_size", new ByteSizeValue(defaultReceiverPredictor)));
    ByteSizeValue receivePredictorMax =
        settings.getAsBytesSize(
            "http.netty.receive_predictor_max",
            settings.getAsBytesSize(
                "http.netty.receive_predictor_size", new ByteSizeValue(defaultReceiverPredictor)));
    if (receivePredictorMax.bytes() == receivePredictorMin.bytes()) {
      receiveBufferSizePredictorFactory =
          new FixedReceiveBufferSizePredictorFactory((int) receivePredictorMax.bytes());
    } else {
      receiveBufferSizePredictorFactory =
          new AdaptiveReceiveBufferSizePredictorFactory(
              (int) receivePredictorMin.bytes(),
              (int) receivePredictorMin.bytes(),
              (int) receivePredictorMax.bytes());
    }

    this.compression = settings.getAsBoolean(SETTING_HTTP_COMPRESSION, false);
    this.compressionLevel = settings.getAsInt(SETTING_HTTP_COMPRESSION_LEVEL, 6);
    this.pipelining = settings.getAsBoolean(SETTING_PIPELINING, DEFAULT_SETTING_PIPELINING);
    this.pipeliningMaxEvents =
        settings.getAsInt(SETTING_PIPELINING_MAX_EVENTS, DEFAULT_SETTING_PIPELINING_MAX_EVENTS);

    // validate max content length
    if (maxContentLength.bytes() > Integer.MAX_VALUE) {
      logger.warn(
          "maxContentLength[" + maxContentLength + "] set to high value, resetting it to [100mb]");
      maxContentLength = new ByteSizeValue(100, ByteSizeUnit.MB);
    }
    this.maxContentLength = maxContentLength;

    logger.debug(
        "using max_chunk_size[{}], max_header_size[{}], max_initial_line_length[{}], max_content_length[{}], receive_predictor[{}->{}], pipelining[{}], pipelining_max_events[{}]",
        maxChunkSize,
        maxHeaderSize,
        maxInitialLineLength,
        this.maxContentLength,
        receivePredictorMin,
        receivePredictorMax,
        pipelining,
        pipeliningMaxEvents);
  }
Beispiel #17
0
  public void close() {
    if (lifecycle.started()) {
      stop();
    }
    if (!lifecycle.moveToClosed()) {
      return;
    }

    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("{{}}[{}]: closing ...", Version.full(), JvmInfo.jvmInfo().pid());

    StopWatch stopWatch = new StopWatch("node_close");
    stopWatch.start("http");
    if (settings.getAsBoolean("http.enabled", true)) {
      injector.getInstance(HttpServer.class).close();
    }
    stopWatch.stop().start("client");
    injector.getInstance(Client.class).close();
    stopWatch.stop().start("routing");
    injector.getInstance(RoutingService.class).close();
    stopWatch.stop().start("cluster");
    injector.getInstance(ClusterService.class).close();
    stopWatch.stop().start("discovery");
    injector.getInstance(DiscoveryService.class).close();
    stopWatch.stop().start("monitor");
    injector.getInstance(MonitorService.class).close();
    stopWatch.stop().start("gateway");
    injector.getInstance(GatewayService.class).close();
    stopWatch.stop().start("search");
    injector.getInstance(SearchService.class).close();
    stopWatch.stop().start("indexers");
    injector.getInstance(RiversManager.class).close();
    stopWatch.stop().start("indices_cluster");
    injector.getInstance(IndicesClusterStateService.class).close();
    stopWatch.stop().start("indices");
    injector.getInstance(IndicesService.class).close();
    stopWatch.stop().start("rest");
    injector.getInstance(RestController.class).close();
    stopWatch.stop().start("transport");
    injector.getInstance(TransportService.class).close();

    for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
      stopWatch.stop().start("plugin(" + plugin.getName() + ")");
      injector.getInstance(plugin).close();
    }

    stopWatch.stop().start("node_cache");
    injector.getInstance(NodeCache.class).close();

    stopWatch.stop().start("script");
    injector.getInstance(ScriptService.class).close();

    stopWatch.stop().start("timer");
    injector.getInstance(TimerService.class).close();
    stopWatch.stop().start("thread_pool");
    injector.getInstance(ThreadPool.class).shutdown();
    try {
      injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      // ignore
    }
    stopWatch.stop().start("thread_pool_force_shutdown");
    try {
      injector.getInstance(ThreadPool.class).shutdownNow();
    } catch (Exception e) {
      // ignore
    }
    stopWatch.stop();

    ThreadLocals.clearReferencesThreadLocals();

    if (logger.isTraceEnabled()) {
      logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint());
    }

    injector.getInstance(NodeEnvironment.class).close();
    Injectors.close(injector);

    logger.info("{{}}[{}]: closed", Version.full(), JvmInfo.jvmInfo().pid());
  }