@Inject
  public MockFSDirectoryService(
      IndexSettings idxSettings,
      IndexStore indexStore,
      final IndicesService service,
      final ShardPath path) {
    super(idxSettings, indexStore, path);
    Settings indexSettings = idxSettings.getSettings();
    final long seed = indexSettings.getAsLong(ESIntegTestCase.SETTING_INDEX_SEED, 0l);
    this.random = new Random(seed);

    randomIOExceptionRate = indexSettings.getAsDouble(RANDOM_IO_EXCEPTION_RATE, 0.0d);
    randomIOExceptionRateOnOpen = indexSettings.getAsDouble(RANDOM_IO_EXCEPTION_RATE_ON_OPEN, 0.0d);
    preventDoubleWrite =
        indexSettings.getAsBoolean(RANDOM_PREVENT_DOUBLE_WRITE, true); // true is default in MDW
    noDeleteOpenFile =
        indexSettings.getAsBoolean(
            RANDOM_NO_DELETE_OPEN_FILE, random.nextBoolean()); // true is default in MDW
    random.nextInt(shardId.getId() + 1); // some randomness per shard
    throttle = MockDirectoryWrapper.Throttling.NEVER;
    crashIndex = indexSettings.getAsBoolean(CRASH_INDEX, true);

    if (logger.isDebugEnabled()) {
      logger.debug(
          "Using MockDirWrapper with seed [{}] throttle: [{}] crashIndex: [{}]",
          SeedUtils.formatSeed(seed),
          throttle,
          crashIndex);
    }
    this.indexSettings = indexSettings;
    delegateService = randomDirectorService(indexStore, path);
  }
 @SuppressForbidden(reason = "do not know what this method does")
 public static ESLogger getLogger(String loggerName, Settings settings, String... prefixes) {
   List<String> prefixesList = new ArrayList<>();
   if (settings.getAsBoolean("logger.logHostAddress", false)) {
     final InetAddress addr = getHostAddress();
     if (addr != null) {
       prefixesList.add(addr.getHostAddress());
     }
   }
   if (settings.getAsBoolean("logger.logHostName", false)) {
     final InetAddress addr = getHostAddress();
     if (addr != null) {
       prefixesList.add(addr.getHostName());
     }
   }
   String name = settings.get("node.name");
   if (name != null) {
     prefixesList.add(name);
   }
   if (prefixes != null && prefixes.length > 0) {
     prefixesList.addAll(asList(prefixes));
   }
   return getLogger(
       getLoggerName(loggerName), prefixesList.toArray(new String[prefixesList.size()]));
 }
  @Inject
  public DiskThresholdDecider(
      Settings settings,
      NodeSettingsService nodeSettingsService,
      ClusterInfoService infoService,
      Client client) {
    super(settings);
    String lowWatermark = settings.get(CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK, "85%");
    String highWatermark = settings.get(CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK, "90%");

    if (!validWatermarkSetting(lowWatermark, CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK)) {
      throw new ElasticsearchParseException("unable to parse low watermark [{}]", lowWatermark);
    }
    if (!validWatermarkSetting(highWatermark, CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK)) {
      throw new ElasticsearchParseException("unable to parse high watermark [{}]", highWatermark);
    }
    // Watermark is expressed in terms of used data, but we need "free" data watermark
    this.freeDiskThresholdLow = 100.0 - thresholdPercentageFromWatermark(lowWatermark);
    this.freeDiskThresholdHigh = 100.0 - thresholdPercentageFromWatermark(highWatermark);

    this.freeBytesThresholdLow =
        thresholdBytesFromWatermark(lowWatermark, CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK);
    this.freeBytesThresholdHigh =
        thresholdBytesFromWatermark(highWatermark, CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK);
    this.includeRelocations =
        settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS, true);
    this.rerouteInterval =
        settings.getAsTime(
            CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL, TimeValue.timeValueSeconds(60));

    this.enabled = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED, true);
    nodeSettingsService.addListener(new ApplySettings());
    infoService.addListener(new DiskListener(client));
  }
  @Inject
  public TribeService(
      Settings settings, ClusterService clusterService, DiscoveryService discoveryService) {
    super(settings);
    this.clusterService = clusterService;
    Map<String, Settings> nodesSettings = new HashMap<>(settings.getGroups("tribe", true));
    nodesSettings.remove("blocks"); // remove prefix settings that don't indicate a client
    nodesSettings.remove("on_conflict"); // remove prefix settings that don't indicate a client
    for (Map.Entry<String, Settings> entry : nodesSettings.entrySet()) {
      Settings.Builder sb = Settings.builder().put(entry.getValue());
      sb.put("name", settings.get("name") + "/" + entry.getKey());
      sb.put(
          Environment.PATH_HOME_SETTING.getKey(),
          Environment.PATH_HOME_SETTING.get(settings)); // pass through ES home dir
      sb.put(TRIBE_NAME, entry.getKey());
      if (sb.get("http.enabled") == null) {
        sb.put("http.enabled", false);
      }
      sb.put(Node.NODE_CLIENT_SETTING.getKey(), true);
      nodes.add(new TribeClientNode(sb.build()));
    }

    String[] blockIndicesWrite = Strings.EMPTY_ARRAY;
    String[] blockIndicesRead = Strings.EMPTY_ARRAY;
    String[] blockIndicesMetadata = Strings.EMPTY_ARRAY;
    if (!nodes.isEmpty()) {
      // remove the initial election / recovery blocks since we are not going to have a
      // master elected in this single tribe  node local "cluster"
      clusterService.removeInitialStateBlock(discoveryService.getNoMasterBlock());
      clusterService.removeInitialStateBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK);
      if (settings.getAsBoolean("tribe.blocks.write", false)) {
        clusterService.addInitialStateBlock(TRIBE_WRITE_BLOCK);
      }
      blockIndicesWrite = settings.getAsArray("tribe.blocks.write.indices", Strings.EMPTY_ARRAY);
      if (settings.getAsBoolean("tribe.blocks.metadata", false)) {
        clusterService.addInitialStateBlock(TRIBE_METADATA_BLOCK);
      }
      blockIndicesMetadata =
          settings.getAsArray("tribe.blocks.metadata.indices", Strings.EMPTY_ARRAY);
      blockIndicesRead = settings.getAsArray("tribe.blocks.read.indices", Strings.EMPTY_ARRAY);
      for (Node node : nodes) {
        node.injector().getInstance(ClusterService.class).add(new TribeClusterStateListener(node));
      }
    }
    this.blockIndicesMetadata = blockIndicesMetadata;
    this.blockIndicesRead = blockIndicesRead;
    this.blockIndicesWrite = blockIndicesWrite;

    this.onConflict = settings.get("tribe.on_conflict", ON_CONFLICT_ANY);
  }
 /** Creates a new {@link org.elasticsearch.index.engine.EngineConfig} */
 public EngineConfig(
     ShardId shardId,
     boolean optimizeAutoGenerateId,
     ThreadPool threadPool,
     ShardIndexingService indexingService,
     IndexSettingsService indexSettingsService,
     IndicesWarmer warmer,
     Store store,
     SnapshotDeletionPolicy deletionPolicy,
     Translog translog,
     MergePolicyProvider mergePolicyProvider,
     MergeSchedulerProvider mergeScheduler,
     Analyzer analyzer,
     Similarity similarity,
     CodecService codecService,
     Engine.FailedEngineListener failedEngineListener) {
   this.shardId = shardId;
   this.optimizeAutoGenerateId = optimizeAutoGenerateId;
   this.threadPool = threadPool;
   this.indexingService = indexingService;
   this.indexSettingsService = indexSettingsService;
   this.warmer = warmer;
   this.store = store;
   this.deletionPolicy = deletionPolicy;
   this.translog = translog;
   this.mergePolicyProvider = mergePolicyProvider;
   this.mergeScheduler = mergeScheduler;
   this.analyzer = analyzer;
   this.similarity = similarity;
   this.codecService = codecService;
   this.failedEngineListener = failedEngineListener;
   Settings indexSettings = indexSettingsService.getSettings();
   this.compoundOnFlush =
       indexSettings.getAsBoolean(EngineConfig.INDEX_COMPOUND_ON_FLUSH, compoundOnFlush);
   this.indexConcurrency =
       indexSettings.getAsInt(
           EngineConfig.INDEX_CONCURRENCY_SETTING,
           Math.max(
               IndexWriterConfig.DEFAULT_MAX_THREAD_STATES,
               (int) (EsExecutors.boundedNumberOfProcessors(indexSettings) * 0.65)));
   codecName =
       indexSettings.get(EngineConfig.INDEX_CODEC_SETTING, EngineConfig.DEFAULT_CODEC_NAME);
   indexingBufferSize =
       indexSettings.getAsBytesSize(INDEX_BUFFER_SIZE_SETTING, DEFAUTL_INDEX_BUFFER_SIZE);
   failEngineOnCorruption = indexSettings.getAsBoolean(INDEX_FAIL_ON_CORRUPTION_SETTING, true);
   failOnMergeFailure = indexSettings.getAsBoolean(INDEX_FAIL_ON_MERGE_FAILURE_SETTING, true);
   gcDeletesInMillis =
       indexSettings.getAsTime(INDEX_GC_DELETES_SETTING, EngineConfig.DEFAULT_GC_DELETES).millis();
 }
 @Inject
 public TransportShardBulkAction(
     Settings settings,
     TransportService transportService,
     ClusterService clusterService,
     IndicesService indicesService,
     ThreadPool threadPool,
     ShardStateAction shardStateAction,
     MappingUpdatedAction mappingUpdatedAction,
     UpdateHelper updateHelper,
     ActionFilters actionFilters,
     IndexNameExpressionResolver indexNameExpressionResolver) {
   super(
       settings,
       ACTION_NAME,
       transportService,
       clusterService,
       indicesService,
       threadPool,
       shardStateAction,
       mappingUpdatedAction,
       actionFilters,
       indexNameExpressionResolver,
       BulkShardRequest::new,
       BulkShardRequest::new,
       ThreadPool.Names.BULK);
   this.updateHelper = updateHelper;
   this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true);
 }
 public Plugin(Settings settings) {
   String priorPath = settings.get(PRIOR_PATH_KEY);
   enabled =
       settings.getAsBoolean(PRIOR_STORE_ENABLED_KEY, true)
           && null != priorPath
           && Files.isDirectory(Paths.get(priorPath));
 }
 public static CharArraySet getWordSet(Environment env, Settings settings, String settingsPrefix) {
   List<String> wordList = getWordList(env, settings, settingsPrefix);
   if (wordList == null) {
     return null;
   }
   return new CharArraySet(wordList, settings.getAsBoolean(settingsPrefix + "_case", false));
 }
  @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;
  }
 @Inject
 public TransportIndexAction(
     Settings settings,
     TransportService transportService,
     ClusterService clusterService,
     IndicesService indicesService,
     ThreadPool threadPool,
     ShardStateAction shardStateAction,
     TransportCreateIndexAction createIndexAction,
     MappingUpdatedAction mappingUpdatedAction,
     ActionFilters actionFilters) {
   super(
       settings,
       IndexAction.NAME,
       transportService,
       clusterService,
       indicesService,
       threadPool,
       shardStateAction,
       actionFilters);
   this.createIndexAction = createIndexAction;
   this.mappingUpdatedAction = mappingUpdatedAction;
   this.autoCreateIndex = new AutoCreateIndex(settings);
   this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true);
 }
 @Inject
 public TransportIndexAction(
     Settings settings,
     TransportService transportService,
     ClusterService clusterService,
     IndicesService indicesService,
     ThreadPool threadPool,
     ShardStateAction shardStateAction,
     TransportCreateIndexAction createIndexAction,
     MappingUpdatedAction mappingUpdatedAction,
     ActionFilters actionFilters,
     IndexNameExpressionResolver indexNameExpressionResolver,
     AutoCreateIndex autoCreateIndex) {
   super(
       settings,
       IndexAction.NAME,
       transportService,
       clusterService,
       indicesService,
       threadPool,
       shardStateAction,
       mappingUpdatedAction,
       actionFilters,
       indexNameExpressionResolver,
       IndexRequest::new,
       IndexRequest::new,
       ThreadPool.Names.INDEX);
   this.createIndexAction = createIndexAction;
   this.autoCreateIndex = autoCreateIndex;
   this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true);
   this.clusterService = clusterService;
 }
 @Override
 public Collection<Class<? extends LifecycleComponent>> nodeServices() {
   Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
   if (settings.getAsBoolean("plugins.langdetect.enabled", true)) {
     services.add(LangdetectService.class);
   }
   return services;
 }
 MergeSchedulerConfig(Settings settings) {
   maxThreadCount =
       settings.getAsInt(
           MAX_THREAD_COUNT,
           Math.max(1, Math.min(4, EsExecutors.boundedNumberOfProcessors(settings) / 2)));
   maxMergeCount = settings.getAsInt(MAX_MERGE_COUNT, maxThreadCount + 5);
   this.autoThrottle = settings.getAsBoolean(AUTO_THROTTLE, true);
 }
 @Override
 public Collection<Module> indexModules(Settings indexSettings) {
   Collection<Module> modules = new ArrayList<>();
   if (settings.getAsBoolean("plugins.langdetect.enabled", true)) {
     modules.add(new LangdetectModule());
   }
   if (settings.getAsBoolean("plugins.reference.enabled", true)) {
     modules.add(new ReferenceModule());
   }
   if (settings.getAsBoolean("plugins.standardnumber.enabled", true)) {
     modules.add(new StandardnumberIndexModule());
   }
   if (settings.getAsBoolean("plugins.crypt.enabled", true)) {
     modules.add(new CryptModule());
   }
   return modules;
 }
 private static FieldType idFieldType(Settings indexSettings) {
   FieldType fieldType = new FieldType(Defaults.FIELD_TYPE);
   boolean pre2x = Version.indexCreated(indexSettings).before(Version.V_2_0_0);
   if (pre2x && indexSettings.getAsBoolean("index.mapping._id.indexed", true) == false) {
     fieldType.setTokenized(false);
   }
   return fieldType;
 }
  @Inject
  public MapperService(
      Index index,
      @IndexSettings Settings indexSettings,
      AnalysisService analysisService,
      SimilarityLookupService similarityLookupService,
      ScriptService scriptService) {
    super(index, indexSettings);
    this.analysisService = analysisService;
    this.fieldTypes = new FieldTypeLookup();
    this.documentParser =
        new DocumentMapperParser(
            indexSettings, this, analysisService, similarityLookupService, scriptService);
    this.indexAnalyzer =
        new MapperAnalyzerWrapper(analysisService.defaultIndexAnalyzer(), INDEX_ANALYZER_EXTRACTOR);
    this.searchAnalyzer =
        new MapperAnalyzerWrapper(
            analysisService.defaultSearchAnalyzer(), SEARCH_ANALYZER_EXTRACTOR);
    this.searchQuoteAnalyzer =
        new MapperAnalyzerWrapper(
            analysisService.defaultSearchQuoteAnalyzer(), SEARCH_QUOTE_ANALYZER_EXTRACTOR);

    this.dynamic = indexSettings.getAsBoolean("index.mapper.dynamic", true);
    defaultPercolatorMappingSource =
        "{\n"
            + "\"_default_\":{\n"
            + "\"properties\" : {\n"
            + "\"query\" : {\n"
            + "\"type\" : \"object\",\n"
            + "\"enabled\" : false\n"
            + "}\n"
            + "}\n"
            + "}\n"
            + "}";
    if (index.getName().equals(ScriptService.SCRIPT_INDEX)) {
      defaultMappingSource =
          "{"
              + "\"_default_\": {"
              + "\"properties\": {"
              + "\"script\": { \"enabled\": false },"
              + "\"template\": { \"enabled\": false }"
              + "}"
              + "}"
              + "}";
    } else {
      defaultMappingSource = "{\"_default_\":{}}";
    }

    if (logger.isTraceEnabled()) {
      logger.trace(
          "using dynamic[{}], default mapping source[{}], default percolator mapping source[{}]",
          dynamic,
          defaultMappingSource,
          defaultPercolatorMappingSource);
    } else if (logger.isDebugEnabled()) {
      logger.debug("using dynamic[{}]", dynamic);
    }
  }
 private boolean isCacheEnabled(Settings settings, boolean defaultEnable) {
   Boolean enable = settings.getAsBoolean(INDEX_CACHE_REQUEST_ENABLED, null);
   if (enable == null) {
     enable = settings.getAsBoolean(DEPRECATED_INDEX_CACHE_REQUEST_ENABLED, null);
     if (enable != null) {
       deprecationLogger.deprecated(
           "The ["
               + DEPRECATED_INDEX_CACHE_REQUEST_ENABLED
               + "] settings is now deprecated, use ["
               + INDEX_CACHE_REQUEST_ENABLED
               + "] instead");
     }
   }
   if (enable == null) {
     enable = defaultEnable;
   }
   return enable;
 }
  private void loadSettings() {
    settings =
        settingsBuilder()
            .loadFromStream("settings.yml", ClassLoader.getSystemResourceAsStream("settings.yml"))
            .build();

    this.useDynamicPorts = settings.getAsBoolean("mongodb.use_dynamic_ports", Boolean.FALSE);
    this.mongoVersion = settings.get("mongodb.version");
  }
 private static MappedFieldType idFieldType(Settings indexSettings, MappedFieldType existing) {
   if (existing != null) {
     return existing.clone();
   }
   MappedFieldType fieldType = Defaults.FIELD_TYPE.clone();
   boolean pre2x = Version.indexCreated(indexSettings).before(Version.V_2_0_0_beta1);
   if (pre2x && indexSettings.getAsBoolean("index.mapping._id.indexed", true) == false) {
     fieldType.setTokenized(false);
   }
   return fieldType;
 }
  @Inject
  public TransportGetAction(
      Settings settings,
      ClusterService clusterService,
      TransportService transportService,
      IndicesService indicesService,
      ThreadPool threadPool) {
    super(settings, threadPool, clusterService, transportService);
    this.indicesService = indicesService;

    this.realtime = settings.getAsBoolean("action.get.realtime", true);
  }
  @Inject
  public RestMultiSearchAction(Settings settings, Client client, RestController controller) {
    super(settings, client);

    controller.registerHandler(GET, "/_msearch", this);
    controller.registerHandler(POST, "/_msearch", this);
    controller.registerHandler(GET, "/{index}/_msearch", this);
    controller.registerHandler(POST, "/{index}/_msearch", this);
    controller.registerHandler(GET, "/{index}/{type}/_msearch", this);
    controller.registerHandler(POST, "/{index}/{type}/_msearch", this);

    this.allowExplicitIndex = settings.getAsBoolean("rest.action.multi.allow_explicit_index", true);
  }
  /**
   * Loads the hunspell dictionary for the given local.
   *
   * @param locale The locale of the hunspell dictionary to be loaded.
   * @param nodeSettings The node level settings
   * @param env The node environment (from which the conf path will be resolved)
   * @return The loaded Hunspell dictionary
   * @throws Exception when loading fails (due to IO errors or malformed dictionary files)
   */
  private Dictionary loadDictionary(String locale, Settings nodeSettings, Environment env)
      throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Loading hunspell dictionary [{}]...", locale);
    }
    Path dicDir = hunspellDir.resolve(locale);
    if (FileSystemUtils.isAccessibleDirectory(dicDir, logger) == false) {
      throw new ElasticsearchException(
          String.format(Locale.ROOT, "Could not find hunspell dictionary [%s]", locale));
    }

    // merging node settings with hunspell dictionary specific settings
    Settings dictSettings = HUNSPELL_DICTIONARY_OPTIONS.get(nodeSettings);
    nodeSettings = loadDictionarySettings(dicDir, dictSettings.getByPrefix(locale));

    boolean ignoreCase = nodeSettings.getAsBoolean("ignore_case", defaultIgnoreCase);

    Path[] affixFiles = FileSystemUtils.files(dicDir, "*.aff");
    if (affixFiles.length == 0) {
      throw new ElasticsearchException(
          String.format(Locale.ROOT, "Missing affix file for hunspell dictionary [%s]", locale));
    }
    if (affixFiles.length != 1) {
      throw new ElasticsearchException(
          String.format(
              Locale.ROOT, "Too many affix files exist for hunspell dictionary [%s]", locale));
    }
    InputStream affixStream = null;

    Path[] dicFiles = FileSystemUtils.files(dicDir, "*.dic");
    List<InputStream> dicStreams = new ArrayList<>(dicFiles.length);
    try {

      for (int i = 0; i < dicFiles.length; i++) {
        dicStreams.add(Files.newInputStream(dicFiles[i]));
      }

      affixStream = Files.newInputStream(affixFiles[0]);

      try (Directory tmp = new SimpleFSDirectory(env.tmpFile())) {
        return new Dictionary(tmp, "hunspell", affixStream, dicStreams, ignoreCase);
      }

    } catch (Exception e) {
      logger.error("Could not load hunspell dictionary [{}]", e, locale);
      throw e;
    } finally {
      IOUtils.close(affixStream);
      IOUtils.close(dicStreams);
    }
  }
 @Inject
 public GroovyScriptEngineService(Settings settings) {
   super(settings);
   ImportCustomizer imports = new ImportCustomizer();
   imports.addStarImports("org.joda.time");
   imports.addStaticStars("java.lang.Math");
   CompilerConfiguration config = new CompilerConfiguration();
   config.addCompilationCustomizers(imports);
   this.sandboxed = settings.getAsBoolean(GROOVY_SCRIPT_SANDBOX_ENABLED, true);
   if (this.sandboxed) {
     config.addCompilationCustomizers(
         GroovySandboxExpressionChecker.getSecureASTCustomizer(settings));
   }
   this.loader = new GroovyClassLoader(settings.getClassLoader(), config);
 }
  @Override
  public Node stop() {
    if (!lifecycle.moveToStopped()) {
      return this;
    }
    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("stopping ...");

    injector.getInstance(TribeService.class).stop();
    injector.getInstance(ResourceWatcherService.class).stop();
    if (settings.getAsBoolean("http.enabled", true)) {
      injector.getInstance(HttpServer.class).stop();
    }

    injector.getInstance(MappingUpdatedAction.class).stop();
    injector.getInstance(RiversManager.class).stop();

    injector.getInstance(SnapshotsService.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(IndexingMemoryController.class).stop();
    injector.getInstance(IndicesTTLService.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(RestController.class).stop();
    injector.getInstance(TransportService.class).stop();

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

    logger.info("stopped");

    return this;
  }
  @Inject
  public TransportIndexAction(
      Settings settings,
      ThreadPool threadPool,
      TransportService transportService,
      ClusterService clusterService,
      TransportLeaderShardIndexAction transportLeaderShardIndexAction,
      TransportReplicaShardIndexAction transportReplicaShardIndexAction,
      ActionFilters actionFilters) {
    super(settings, IndexAction.NAME, threadPool, actionFilters);
    this.clusterService = clusterService;
    this.transportLeaderShardIndexAction = transportLeaderShardIndexAction;
    this.transportReplicaShardIndexAction = transportReplicaShardIndexAction;
    this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true);

    transportService.registerHandler(IndexAction.NAME, new IndexTransportHandler());
  }
  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());
  }
 @Inject
 public LengthTokenFilterFactory(
     IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) {
   super(indexSettings, name, settings);
   min = settings.getAsInt("min", 0);
   max = settings.getAsInt("max", Integer.MAX_VALUE);
   if (version.onOrAfter(Version.LUCENE_4_4) && settings.get(ENABLE_POS_INC_KEY) != null) {
     throw new IllegalArgumentException(
         ENABLE_POS_INC_KEY
             + " is not supported anymore. Please fix your analysis chain or use"
             + " an older compatibility version (<=4.3) but beware that it might cause highlighting bugs.");
   }
   enablePositionIncrements =
       version.onOrAfter(Version.LUCENE_4_4)
           ? true
           : settings.getAsBoolean(ENABLE_POS_INC_KEY, true);
 }
  public Node start() {
    if (!lifecycle.moveToStarted()) {
      return this;
    }

    ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
    logger.info("starting ...");

    // hack around dependency injection problem (for now...)
    injector
        .getInstance(Discovery.class)
        .setAllocationService(injector.getInstance(AllocationService.class));

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

    injector.getInstance(MappingUpdatedAction.class).start();
    injector.getInstance(IndicesService.class).start();
    injector.getInstance(IndexingMemoryController.class).start();
    injector.getInstance(IndicesClusterStateService.class).start();
    injector.getInstance(IndicesTTLService.class).start();
    injector.getInstance(RiversManager.class).start();
    injector.getInstance(SnapshotsService.class).start();
    injector.getInstance(TransportService.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();
    DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start();
    discoService.waitForInitialState();

    // 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(ResourceWatcherService.class).start();
    injector.getInstance(TribeService.class).start();

    logger.info("started");

    return this;
  }
  @Inject
  public TransportBulkAction(
      Settings settings,
      ThreadPool threadPool,
      TransportService transportService,
      ClusterService clusterService,
      TransportShardBulkAction shardBulkAction,
      TransportCreateIndexAction createIndexAction) {
    super(settings, threadPool);
    this.clusterService = clusterService;
    this.shardBulkAction = shardBulkAction;
    this.createIndexAction = createIndexAction;

    this.autoCreateIndex = settings.getAsBoolean("action.auto_create_index", true);
    this.allowIdGeneration = componentSettings.getAsBoolean("action.allow_id_generation", true);

    transportService.registerHandler(TransportActions.BULK, new TransportHandler());
  }
    @Override
    public void onRefreshSettings(Settings settings) {
      String newLowWatermark = settings.get(CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK, null);
      String newHighWatermark = settings.get(CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK, null);
      Boolean newEnableSetting =
          settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED, null);

      if (newEnableSetting != null) {
        logger.info(
            "updating [{}] from [{}] to [{}]",
            CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED,
            DiskThresholdDecider.this.enabled,
            newEnableSetting);
        DiskThresholdDecider.this.enabled = newEnableSetting;
      }
      if (newLowWatermark != null) {
        if (!validWatermarkSetting(newLowWatermark)) {
          throw new ElasticsearchParseException(
              "Unable to parse low watermark: [" + newLowWatermark + "]");
        }
        logger.info(
            "updating [{}] to [{}]",
            CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK,
            newLowWatermark);
        DiskThresholdDecider.this.freeDiskThresholdLow =
            100.0 - thresholdPercentageFromWatermark(newLowWatermark);
        DiskThresholdDecider.this.freeBytesThresholdLow =
            thresholdBytesFromWatermark(newLowWatermark);
      }
      if (newHighWatermark != null) {
        if (!validWatermarkSetting(newHighWatermark)) {
          throw new ElasticsearchParseException(
              "Unable to parse high watermark: [" + newHighWatermark + "]");
        }
        logger.info(
            "updating [{}] to [{}]",
            CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK,
            newHighWatermark);
        DiskThresholdDecider.this.freeDiskThresholdHigh =
            100.0 - thresholdPercentageFromWatermark(newHighWatermark);
        DiskThresholdDecider.this.freeBytesThresholdHigh =
            thresholdBytesFromWatermark(newHighWatermark);
      }
    }