@Test
  public void testRepositoryWithCustomCredentials() {
    Client client = client();
    Settings bucketSettings =
        internalCluster()
            .getInstance(Settings.class)
            .getByPrefix("repositories.s3.private-bucket.");
    logger.info(
        "-->  creating s3 repository with bucket[{}] and path [{}]",
        bucketSettings.get("bucket"),
        basePath);
    PutRepositoryResponse putRepositoryResponse =
        client
            .admin()
            .cluster()
            .preparePutRepository("test-repo")
            .setType("s3")
            .setSettings(
                Settings.settingsBuilder()
                    .put("base_path", basePath)
                    .put("region", bucketSettings.get("region"))
                    .put("access_key", bucketSettings.get("access_key"))
                    .put("secret_key", bucketSettings.get("secret_key"))
                    .put("bucket", bucketSettings.get("bucket")))
            .get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

    assertRepositoryIsOperational(client, "test-repo");
  }
  @Test
  @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch-cloud-aws/issues/211")
  public void testRepositoryInRemoteRegion() {
    Client client = client();
    Settings settings = internalCluster().getInstance(Settings.class);
    Settings bucketSettings = settings.getByPrefix("repositories.s3.remote-bucket.");
    logger.info(
        "-->  creating s3 repository with bucket[{}] and path [{}]",
        bucketSettings.get("bucket"),
        basePath);
    PutRepositoryResponse putRepositoryResponse =
        client
            .admin()
            .cluster()
            .preparePutRepository("test-repo")
            .setType("s3")
            .setSettings(
                Settings.settingsBuilder()
                    .put("base_path", basePath)
                    .put("bucket", bucketSettings.get("bucket"))
                    .put("region", bucketSettings.get("region")))
            .get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

    assertRepositoryIsOperational(client, "test-repo");
  }
  protected TransportShardReplicationOperationAction(
      Settings settings,
      TransportService transportService,
      ClusterService clusterService,
      IndicesService indicesService,
      ThreadPool threadPool,
      ShardStateAction shardStateAction) {
    super(settings, threadPool);
    this.transportService = transportService;
    this.clusterService = clusterService;
    this.indicesService = indicesService;
    this.shardStateAction = shardStateAction;

    this.transportAction = transportAction();
    this.transportReplicaAction = transportReplicaAction();
    this.executor = executor();
    this.checkWriteConsistency = checkWriteConsistency();

    transportService.registerHandler(transportAction, new OperationTransportHandler());
    transportService.registerHandler(
        transportReplicaAction, new ReplicaOperationTransportHandler());

    this.transportOptions = transportOptions();

    this.defaultReplicationType =
        ReplicationType.fromString(settings.get("action.replication_type", "sync"));
    this.defaultWriteConsistencyLevel =
        WriteConsistencyLevel.fromString(settings.get("action.write_consistency", "quorum"));
  }
  @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));
  }
  /**
   * This test verifies that the test configuration is set up in a manner that does not make the
   * test {@link #testRepositoryInRemoteRegion()} pointless.
   */
  @Test(expected = RepositoryVerificationException.class)
  public void assertRepositoryInRemoteRegionIsRemote() {
    Client client = client();
    Settings bucketSettings =
        internalCluster().getInstance(Settings.class).getByPrefix("repositories.s3.remote-bucket.");
    logger.info(
        "-->  creating s3 repository with bucket[{}] and path [{}]",
        bucketSettings.get("bucket"),
        basePath);
    client
        .admin()
        .cluster()
        .preparePutRepository("test-repo")
        .setType("s3")
        .setSettings(
            Settings.settingsBuilder()
                .put("base_path", basePath)
                .put("bucket", bucketSettings.get("bucket"))
            // Below setting intentionally omitted to assert bucket is not available in default
            // region.
            //                        .put("region", privateBucketSettings.get("region"))
            )
        .get();

    fail("repository verification should have raise an exception!");
  }
Пример #6
0
  static void addBindPermissions(Permissions policy, Settings settings) throws IOException {
    // http is simple
    String httpRange = HttpTransportSettings.SETTING_HTTP_PORT.get(settings).getPortRangeString();
    // listen is always called with 'localhost' but use wildcard to be sure, no name service is
    // consulted.
    // see SocketPermission implies() code
    policy.add(new SocketPermission("*:" + httpRange, "listen,resolve"));
    // transport is waaaay overengineered
    Map<String, Settings> profiles =
        TransportSettings.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups();
    if (!profiles.containsKey(TransportSettings.DEFAULT_PROFILE)) {
      profiles = new HashMap<>(profiles);
      profiles.put(TransportSettings.DEFAULT_PROFILE, Settings.EMPTY);
    }

    // loop through all profiles and add permissions for each one, if its valid.
    // (otherwise NettyTransport is lenient and ignores it)
    for (Map.Entry<String, Settings> entry : profiles.entrySet()) {
      Settings profileSettings = entry.getValue();
      String name = entry.getKey();
      String transportRange = profileSettings.get("port", TransportSettings.PORT.get(settings));

      // a profile is only valid if its the default profile, or if it has an actual name and
      // specifies a port
      boolean valid =
          TransportSettings.DEFAULT_PROFILE.equals(name)
              || (Strings.hasLength(name) && profileSettings.get("port") != null);
      if (valid) {
        // listen is always called with 'localhost' but use wildcard to be sure, no name service is
        // consulted.
        // see SocketPermission implies() code
        policy.add(new SocketPermission("*:" + transportRange, "listen,resolve"));
      }
    }
  }
  @Inject
  public LocalGatewayMetaState(
      Settings settings,
      ThreadPool threadPool,
      NodeEnvironment nodeEnv,
      TransportNodesListGatewayMetaState nodesListGatewayMetaState,
      LocalAllocateDangledIndices allocateDangledIndices,
      NodeIndexDeletedAction nodeIndexDeletedAction)
      throws Exception {
    super(settings);
    this.nodeEnv = nodeEnv;
    this.threadPool = threadPool;
    this.format = XContentType.fromRestContentType(settings.get("format", "smile"));
    this.allocateDangledIndices = allocateDangledIndices;
    this.nodeIndexDeletedAction = nodeIndexDeletedAction;
    nodesListGatewayMetaState.init(this);

    if (this.format == XContentType.SMILE) {
      Map<String, String> params = Maps.newHashMap();
      params.put("binary", "true");
      formatParams = new ToXContent.MapParams(params);
      Map<String, String> globalOnlyParams = Maps.newHashMap();
      globalOnlyParams.put("binary", "true");
      globalOnlyParams.put(MetaData.PERSISTENT_ONLY_PARAM, "true");
      globalOnlyParams.put(MetaData.GLOBAL_ONLY_PARAM, "true");
      globalOnlyFormatParams = new ToXContent.MapParams(globalOnlyParams);
    } else {
      formatParams = ToXContent.EMPTY_PARAMS;
      Map<String, String> globalOnlyParams = Maps.newHashMap();
      globalOnlyParams.put(MetaData.PERSISTENT_ONLY_PARAM, "true");
      globalOnlyParams.put(MetaData.GLOBAL_ONLY_PARAM, "true");
      globalOnlyFormatParams = new ToXContent.MapParams(globalOnlyParams);
    }

    this.autoImportDangled =
        AutoImportDangledState.fromString(
            settings.get(
                "gateway.local.auto_import_dangled", AutoImportDangledState.YES.toString()));
    this.danglingTimeout =
        settings.getAsTime("gateway.local.dangling_timeout", TimeValue.timeValueHours(2));

    logger.debug(
        "using gateway.local.auto_import_dangled [{}], with gateway.local.dangling_timeout [{}]",
        this.autoImportDangled,
        this.danglingTimeout);

    if (DiscoveryNode.masterNode(settings)) {
      try {
        pre019Upgrade();
        long start = System.currentTimeMillis();
        loadState();
        logger.debug(
            "took {} to load state", TimeValue.timeValueMillis(System.currentTimeMillis() - start));
      } catch (Exception e) {
        logger.error("failed to read local state, exiting...", e);
        throw e;
      }
    }
  }
 public IcuTransformTokenFilterFactory(
     IndexSettings indexSettings, Environment environment, String name, Settings settings) {
   super(indexSettings, name, settings);
   this.id = settings.get("id", "Null");
   String s = settings.get("dir", "forward");
   this.dir = "forward".equals(s) ? Transliterator.FORWARD : Transliterator.REVERSE;
   this.transliterator = Transliterator.getInstance(id, dir);
 }
 @Inject
 public StemmerTokenFilterFactory(
     Index index,
     @IndexSettings Settings indexSettings,
     @Assisted String name,
     @Assisted Settings settings) {
   super(index, indexSettings, name, settings);
   this.language = Strings.capitalize(settings.get("language", settings.get("name", "porter")));
 }
  @Inject
  public IndexAuthenticator(
      final Settings settings, final Client client, final AuthService authService) {
    super(settings);
    this.client = client;
    this.authService = authService;

    authIndex = settings.get("auth.authenticator.index.index", "auth");
    userType = settings.get("auth.authenticator.index.type", "user");
    usernameKey = settings.get("auth.authenticator.index.username", "username");
    passwordKey = settings.get("auth.authenticator.index.password", "password");
  }
  @Inject
  public PatternReplaceCharFilterFactory(
      IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) {
    super(indexSettings, name);

    if (!Strings.hasLength(settings.get("pattern"))) {
      throw new IllegalArgumentException(
          "pattern is missing for [" + name + "] char filter of type 'pattern_replace'");
    }
    pattern = Pattern.compile(settings.get("pattern"));
    replacement = settings.get("replacement", ""); // when not set or set to "", use "".
  }
Пример #12
0
  @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);
  }
  @Inject
  public PatternTokenizerFactory(
      IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) {
    super(indexSettings, name, settings);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
      throw new IllegalArgumentException(
          "pattern is missing for [" + name + "] tokenizer of type 'pattern'");
    }

    this.pattern = Regex.compile(sPattern, settings.get("flags"));
    this.group = settings.getAsInt("group", -1);
  }
Пример #14
0
 public static Version parseAnalysisVersion(
     @IndexSettings Settings indexSettings, Settings settings, ESLogger logger) {
   // check for explicit version on the specific analyzer component
   String sVersion = settings.get("version");
   if (sVersion != null) {
     return Lucene.parseVersion(sVersion, Lucene.ANALYZER_VERSION, logger);
   }
   // check for explicit version on the index itself as default for all analysis components
   sVersion = indexSettings.get("index.analysis.version");
   if (sVersion != null) {
     return Lucene.parseVersion(sVersion, Lucene.ANALYZER_VERSION, logger);
   }
   // resolve the analysis version based on the version the index was created with
   return org.elasticsearch.Version.indexCreated(indexSettings).luceneVersion;
 }
Пример #15
0
  @Inject
  public GatewayAllocator(
      Settings settings,
      TransportNodesListGatewayStartedShards startedAction,
      TransportNodesListShardStoreMetaData storeAction) {
    super(settings);
    this.startedAction = startedAction;
    this.storeAction = storeAction;

    this.initialShards =
        settings.get(
            "gateway.initial_shards", settings.get("gateway.local.initial_shards", "quorum"));

    logger.debug("using initial_shards [{}]", initialShards);
  }
  @Test
  public void testLoadFromDelimitedString() {
    Settings settings =
        settingsBuilder().loadFromDelimitedString("key1=value1;key2=value2", ';').build();
    assertThat(settings.get("key1"), equalTo("value1"));
    assertThat(settings.get("key2"), equalTo("value2"));
    assertThat(settings.getAsMap().size(), equalTo(2));
    assertThat(settings.toDelimitedString(';'), equalTo("key1=value1;key2=value2;"));

    settings = settingsBuilder().loadFromDelimitedString("key1=value1;key2=value2;", ';').build();
    assertThat(settings.get("key1"), equalTo("value1"));
    assertThat(settings.get("key2"), equalTo("value2"));
    assertThat(settings.getAsMap().size(), equalTo(2));
    assertThat(settings.toDelimitedString(';'), equalTo("key1=value1;key2=value2;"));
  }
Пример #17
0
 public Builder(
     String index, @Nullable Settings indexSettings, RootObjectMapper.Builder builder) {
   this.index = index;
   this.indexSettings = indexSettings;
   this.builderContext = new Mapper.BuilderContext(indexSettings, new ContentPath(1));
   this.rootObjectMapper = builder.build(builderContext);
   IdFieldMapper idFieldMapper = new IdFieldMapper();
   if (indexSettings != null) {
     String idIndexed = indexSettings.get("index.mapping._id.indexed");
     if (idIndexed != null && Booleans.parseBoolean(idIndexed, false)) {
       FieldType fieldType = new FieldType(IdFieldMapper.Defaults.FIELD_TYPE);
       fieldType.setTokenized(false);
       idFieldMapper = new IdFieldMapper(fieldType);
     }
   }
   this.rootMappers.put(IdFieldMapper.class, idFieldMapper);
   // add default mappers, order is important (for example analyzer should come before the rest
   // to set context.analyzer)
   this.rootMappers.put(SizeFieldMapper.class, new SizeFieldMapper());
   this.rootMappers.put(IndexFieldMapper.class, new IndexFieldMapper());
   this.rootMappers.put(SourceFieldMapper.class, new SourceFieldMapper());
   this.rootMappers.put(TypeFieldMapper.class, new TypeFieldMapper());
   this.rootMappers.put(AnalyzerMapper.class, new AnalyzerMapper());
   this.rootMappers.put(AllFieldMapper.class, new AllFieldMapper());
   this.rootMappers.put(BoostFieldMapper.class, new BoostFieldMapper());
   this.rootMappers.put(RoutingFieldMapper.class, new RoutingFieldMapper());
   this.rootMappers.put(TimestampFieldMapper.class, new TimestampFieldMapper());
   this.rootMappers.put(TTLFieldMapper.class, new TTLFieldMapper());
   this.rootMappers.put(UidFieldMapper.class, new UidFieldMapper());
   // don't add parent field, by default its "null"
 }
Пример #18
0
 public static Settings processSettings(Settings settings) {
   if (settings.get(TRIBE_NAME) != null) {
     // if its a node client started by this service as tribe, remove any tribe group setting
     // to avoid recursive configuration
     Settings.Builder sb = Settings.builder().put(settings);
     for (String s : settings.getAsMap().keySet()) {
       if (s.startsWith("tribe.") && !s.equals(TRIBE_NAME)) {
         sb.remove(s);
       }
     }
     return sb.build();
   }
   Map<String, Settings> nodesSettings = settings.getGroups("tribe", true);
   if (nodesSettings.isEmpty()) {
     return settings;
   }
   // its a tribe configured node..., force settings
   Settings.Builder sb = Settings.builder().put(settings);
   sb.put(Node.NODE_CLIENT_SETTING.getKey(), true); // this node should just act as a node client
   sb.put(
       DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(),
       "local"); // a tribe node should not use zen discovery
   sb.put(
       DiscoveryService.INITIAL_STATE_TIMEOUT_SETTING.getKey(),
       0); // nothing is going to be discovered, since no master will be elected
   if (sb.get("cluster.name") == null) {
     sb.put(
         "cluster.name",
         "tribe_"
             + Strings
                 .randomBase64UUID()); // make sure it won't join other tribe nodes in the same JVM
   }
   sb.put(TransportMasterNodeReadAction.FORCE_LOCAL_SETTING, true);
   return sb.build();
 }
Пример #19
0
 public static boolean masterNode(Settings settings) {
   String master = settings.get("node.master");
   if (master == null) {
     return !clientNode(settings);
   }
   return master.equals("true");
 }
Пример #20
0
  /**
   * Fetches a list of words from the specified settings file. The list should either be available
   * at the key specified by settingsPrefix or in a file specified by settingsPrefix + _path.
   *
   * @throws IllegalArgumentException If the word list cannot be found at either key.
   */
  public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
    String wordListPath = settings.get(settingPrefix + "_path", null);

    if (wordListPath == null) {
      String[] explicitWordList = settings.getAsArray(settingPrefix, null);
      if (explicitWordList == null) {
        return null;
      } else {
        return Arrays.asList(explicitWordList);
      }
    }

    final Path wordListFile = env.configFile().resolve(wordListPath);

    try (BufferedReader reader =
        FileSystemUtils.newBufferedReader(wordListFile.toUri().toURL(), StandardCharsets.UTF_8)) {
      return loadWordList(reader, "#");
    } catch (IOException ioe) {
      String message =
          String.format(
              Locale.ROOT,
              "IOException while reading %s_path: %s",
              settingPrefix,
              ioe.getMessage());
      throw new IllegalArgumentException(message);
    }
  }
Пример #21
0
 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));
 }
Пример #22
0
 @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()]));
 }
Пример #23
0
 public static boolean dataNode(Settings settings) {
   String data = settings.get("data");
   if (data == null) {
     return !clientNode(settings);
   }
   return data.equals("true");
 }
  private void assertMMNinClusterSetting(InternalTestCluster cluster, int masterNodes) {
    final int minMasterNodes = masterNodes / 2 + 1;
    for (final String node : cluster.getNodeNames()) {
      Settings stateSettings =
          cluster
              .client(node)
              .admin()
              .cluster()
              .prepareState()
              .setLocal(true)
              .get()
              .getState()
              .getMetaData()
              .settings();

      assertThat(
          "dynamic setting for node ["
              + node
              + "] has the wrong min_master_node setting : ["
              + stateSettings.get(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey())
              + "]",
          stateSettings.getAsMap(),
          hasEntry(
              DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(),
              Integer.toString(minMasterNodes)));
    }
  }
Пример #25
0
  /**
   * Creates a new TranslogConfig instance
   *
   * @param shardId the shard ID this translog belongs to
   * @param translogPath the path to use for the transaction log files
   * @param indexSettings the index settings used to set internal variables
   * @param durabilty the default durability setting for the translog
   * @param bigArrays a bigArrays instance used for temporarily allocating write operations
   * @param threadPool a {@link ThreadPool} to schedule async sync durability
   */
  public TranslogConfig(
      ShardId shardId,
      Path translogPath,
      Settings indexSettings,
      Translog.Durabilty durabilty,
      BigArrays bigArrays,
      @Nullable ThreadPool threadPool) {
    this.indexSettings = indexSettings;
    this.shardId = shardId;
    this.translogPath = translogPath;
    this.durabilty = durabilty;
    this.threadPool = threadPool;
    this.bigArrays = bigArrays;
    this.type =
        TranslogWriter.Type.fromString(
            indexSettings.get(INDEX_TRANSLOG_FS_TYPE, TranslogWriter.Type.BUFFERED.name()));
    this.bufferSize =
        (int)
            indexSettings
                .getAsBytesSize(
                    INDEX_TRANSLOG_BUFFER_SIZE,
                    IndexingMemoryController.INACTIVE_SHARD_TRANSLOG_BUFFER)
                .bytes(); // Not really interesting, updated by IndexingMemoryController...

    syncInterval =
        indexSettings.getAsTime(INDEX_TRANSLOG_SYNC_INTERVAL, TimeValue.timeValueSeconds(5));
    if (syncInterval.millis() > 0 && threadPool != null) {
      syncOnEachOperation = false;
    } else if (syncInterval.millis() == 0) {
      syncOnEachOperation = true;
    } else {
      syncOnEachOperation = false;
    }
  }
Пример #26
0
  @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;
  }
Пример #27
0
 public static String generateNodeId(Settings settings) {
   String seed = settings.get("discovery.id.seed");
   if (seed != null) {
     Strings.randomBase64UUID(new Random(Long.parseLong(seed)));
   }
   return Strings.randomBase64UUID();
 }
  @Inject
  public HyphenationCompoundWordTokenFilterFactory(
      Index index,
      @IndexSettings Settings indexSettings,
      Environment env,
      @Assisted String name,
      @Assisted Settings settings) {
    super(index, indexSettings, env, name, settings);

    String hyphenationPatternsPath = settings.get("hyphenation_patterns_path", null);
    if (hyphenationPatternsPath == null) {
      throw new ElasticsearchIllegalArgumentException(
          "hyphenation_patterns_path is a required setting.");
    }

    URL hyphenationPatternsFile = env.resolveConfig(hyphenationPatternsPath);

    try {
      hyphenationTree =
          HyphenationCompoundWordTokenFilter.getHyphenationTree(
              new InputSource(hyphenationPatternsFile.toExternalForm()));
    } catch (Exception e) {
      throw new ElasticsearchIllegalArgumentException(
          "Exception while reading hyphenation_patterns_path: " + e.getMessage());
    }
  }
Пример #29
0
 private final String getNodeUUID(Settings settings) {
   String seed = settings.get("discovery.id.seed");
   if (seed != null) {
     logger.trace("using stable discover node UUIDs with seed: [{}]", seed);
     Strings.randomBase64UUID(new Random(Long.parseLong(seed)));
   }
   return Strings.randomBase64UUID();
 }
 @Inject
 public JiebaTokenFilterFactory(
     IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) {
   super(indexSettings, name, settings);
   type = settings.get("seg_mode", "index");
   Environment env = new Environment(indexSettings.getSettings());
   WordDictionary.getInstance().init(env.pluginsFile().resolve("jieba/dic"));
 }