Java Code Examples for org.elasticsearch.common.settings.Settings#Builder

The following examples show how to use org.elasticsearch.common.settings.Settings#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginsService.java    From Elasticsearch with Apache License 2.0 7 votes vote down vote up
public Settings updatedSettings() {
    Map<String, String> foundSettings = new HashMap<>();
    final Settings.Builder builder = Settings.settingsBuilder();
    for (Tuple<PluginInfo, Plugin> plugin : plugins) {
        Settings settings = plugin.v2().additionalSettings();
        for (String setting : settings.getAsMap().keySet()) {
            String oldPlugin = foundSettings.put(setting, plugin.v1().getName());
            if (oldPlugin != null) {
                throw new IllegalArgumentException("Cannot have additional setting [" + setting + "] " +
                    "in plugin [" + plugin.v1().getName() + "], already added in plugin [" + oldPlugin + "]");
            }
        }
        builder.put(settings);
    }
    return builder.put(this.settings).build();
}
 
Example 2
Source File: JKSCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void paramsArePassedToConfiguredObject() {

    // given
    JKSCertInfo certInfo = createTestCertInfoBuilder()
            .withKeystorePath(TEST_KEYSTORE_PATH)
            .withKeystorePassword(TEST_KEYSTORE_PASSWORD)
            .withTruststorePath(TEST_TRUSTSTORE_PATH)
            .withTruststorePassword(TEST_TRUSTSTORE_PASSWORD)
            .build();

    Settings.Builder settings = Settings.builder();

    // when
    certInfo.applyTo(settings);

    // then
    Assert.assertEquals(TEST_KEYSTORE_PATH, settings.get(JKSCertInfo.SHIELD_SSL_KEYSTORE_PATH));
    Assert.assertEquals(TEST_KEYSTORE_PASSWORD, settings.get(JKSCertInfo.SHIELD_SSL_KEYSTORE_PASSWORD));
    Assert.assertEquals(TEST_TRUSTSTORE_PATH, settings.get(JKSCertInfo.SHIELD_SSL_TRUSTSTORE_PATH));
    Assert.assertEquals(TEST_TRUSTSTORE_PASSWORD, settings.get(JKSCertInfo.SHIELD_SSL_TRUSTSTORE_PASSWORD));
}
 
Example 3
Source File: ESIntegTestCase.java    From crate with Apache License 2.0 6 votes vote down vote up
private static Settings.Builder setRandomIndexTranslogSettings(Random random, Settings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
                new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 300), ByteSizeUnit.MB));
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(),
                new ByteSizeValue(1, ByteSizeUnit.PB)); // just don't flush
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(),
                RandomPicks.randomFrom(random, Translog.Durability.values()));
    }

    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(),
                RandomNumbers.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
    }

    return builder;
}
 
Example 4
Source File: ESIntegTestCase.java    From crate with Apache License 2.0 6 votes vote down vote up
private static Settings.Builder setRandomIndexMergeSettings(Random random, Settings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(MergePolicyConfig.INDEX_COMPOUND_FORMAT_SETTING.getKey(),
            (random.nextBoolean() ? random.nextDouble() : random.nextBoolean()).toString());
    }
    switch (random.nextInt(4)) {
        case 3:
            final int maxThreadCount = RandomNumbers.randomIntBetween(random, 1, 4);
            final int maxMergeCount = RandomNumbers.randomIntBetween(random, maxThreadCount, maxThreadCount + 4);
            builder.put(MergeSchedulerConfig.MAX_MERGE_COUNT_SETTING.getKey(), maxMergeCount);
            builder.put(MergeSchedulerConfig.MAX_THREAD_COUNT_SETTING.getKey(), maxThreadCount);
            break;
    }

    return builder;
}
 
Example 5
Source File: PreBuiltTransportClientFactory.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Settings createSettings(String clusterName, Map<String, String> settings) {
  if (clusterName == null) {
    throw new NullPointerException("clusterName cannot be null");
  }

  Settings.Builder builder = Settings.builder();
  builder.put("cluster.name", clusterName);
  if (settings != null) {
    builder.put(settings);
  }
  return builder.build();
}
 
Example 6
Source File: ReadOnlyNodeIntegrationTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected Settings nodeSettings(int nodeOrdinal) {
    Settings.Builder builder = Settings.builder();
    builder.put(super.nodeSettings(nodeOrdinal));
    builder.put("path.repo", folder.getRoot().getParent());
    if ((nodeOrdinal + 1) % 2 == 0) {
        builder.put(SQLOperations.NODE_READ_ONLY_SETTING.getKey(), true);
    }
    return builder.build();
}
 
Example 7
Source File: SecureClientProviderTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void providedAuthIsUsedToCustomizeClient() {

    // given
    Auth<Settings.Builder> auth = mock(Auth.class);
    ClientProvider<TransportClient> clientProvider = new SecureClientProvider(auth);

    // when
    clientProvider.createClient();

    // then
    Mockito.verify(auth).configure(any());
}
 
Example 8
Source File: PluginLoader.java    From crate with Apache License 2.0 5 votes vote down vote up
Settings additionalSettings() {
    Settings.Builder builder = Settings.builder();
    for (Plugin plugin : plugins) {
        builder.put(plugin.additionalSettings());
    }
    return builder.build();
}
 
Example 9
Source File: InternalSettingsPreparer.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares settings for the transport client by gathering all
 * elasticsearch system properties and setting defaults.
 */
public static Settings prepareSettings(Settings input) {
    Settings.Builder output = Settings.builder();
    initializeSettings(output, input, Collections.emptyMap());
    finalizeSettings(output, () -> null);
    return output.build();
}
 
Example 10
Source File: PluginLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Settings additionalSettings() {
    Settings.Builder builder = Settings.settingsBuilder();
    for (Plugin plugin : plugins) {
        builder.put(plugin.additionalSettings());
    }
    return builder.build();
}
 
Example 11
Source File: NettyTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Settings createFallbackSettings() {
    Settings.Builder fallbackSettingsBuilder = settingsBuilder();

    String fallbackBindHost = settings.get("transport.netty.bind_host", settings.get("transport.bind_host", settings.get("transport.host")));
    if (fallbackBindHost != null) {
        fallbackSettingsBuilder.put("bind_host", fallbackBindHost);
    }

    String fallbackPublishHost = settings.get("transport.netty.publish_host", settings.get("transport.publish_host", settings.get("transport.host")));
    if (fallbackPublishHost != null) {
        fallbackSettingsBuilder.put("publish_host", fallbackPublishHost);
    }

    String fallbackTcpNoDelay = settings.get("transport.netty.tcp_no_delay", settings.get(TCP_NO_DELAY, "true"));
    if (fallbackTcpNoDelay != null) {
        fallbackSettingsBuilder.put("tcp_no_delay", fallbackTcpNoDelay);
    }

    String fallbackTcpKeepAlive = settings.get("transport.netty.tcp_keep_alive", settings.get(TCP_KEEP_ALIVE, "true"));
    if (fallbackTcpKeepAlive != null) {
        fallbackSettingsBuilder.put("tcp_keep_alive", fallbackTcpKeepAlive);
    }

    boolean fallbackReuseAddress = settings.getAsBoolean("transport.netty.reuse_address", settings.getAsBoolean(TCP_REUSE_ADDRESS, NetworkUtils.defaultReuseAddress()));
    fallbackSettingsBuilder.put("reuse_address", fallbackReuseAddress);

    ByteSizeValue fallbackTcpSendBufferSize = settings.getAsBytesSize("transport.netty.tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
    if (fallbackTcpSendBufferSize != null) {
        fallbackSettingsBuilder.put("tcp_send_buffer_size", fallbackTcpSendBufferSize);
    }

    ByteSizeValue fallbackTcpBufferSize = settings.getAsBytesSize("transport.netty.tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
    if (fallbackTcpBufferSize != null) {
        fallbackSettingsBuilder.put("tcp_receive_buffer_size", fallbackTcpBufferSize);
    }

    return fallbackSettingsBuilder.build();
}
 
Example 12
Source File: Elasticsearch7SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private static Client createTransportClient(ElasticsearchSearchIndexConfiguration config) {
    Settings settings = tryReadSettingsFromFile(config);
    if (settings == null) {
        Settings.Builder settingsBuilder = Settings.builder();
        if (config.getClusterName() != null) {
            settingsBuilder.put("cluster.name", config.getClusterName());
        }
        for (Map.Entry<String, String> esSetting : config.getEsSettings().entrySet()) {
            settingsBuilder.put(esSetting.getKey(), esSetting.getValue());
        }
        settings = settingsBuilder.build();
    }
    Collection<Class<? extends Plugin>> plugins = loadTransportClientPlugins(config);
    Client transportClient = config.getXpackEnabled() ?
        new org.elasticsearch.xpack.client.PreBuiltXPackTransportClient(settings, plugins) :
        new org.elasticsearch.transport.client.PreBuiltTransportClient(settings, plugins);
    for (String esLocation : config.getEsLocations()) {
        String[] locationSocket = esLocation.split(":");
        String hostname;
        int port;
        if (locationSocket.length == 2) {
            hostname = locationSocket[0];
            port = Integer.parseInt(locationSocket[1]);
        } else if (locationSocket.length == 1) {
            hostname = locationSocket[0];
            port = config.getPort();
        } else {
            throw new VertexiumException("Invalid elastic search location: " + esLocation);
        }
        InetAddress host;
        try {
            host = InetAddress.getByName(hostname);
        } catch (UnknownHostException ex) {
            throw new VertexiumException("Could not resolve host: " + hostname, ex);
        }
        ((org.elasticsearch.client.transport.TransportClient) transportClient).addTransportAddress(new TransportAddress(new InetSocketAddress(host, port)));
    }
    return transportClient;
}
 
Example 13
Source File: BlobAdminClient.java    From crate with Apache License 2.0 5 votes vote down vote up
public CompletableFuture<Long> createBlobTable(String tableName, Settings indexSettings) {
    Settings.Builder builder = Settings.builder();
    builder.put(indexSettings);
    builder.put(SETTING_INDEX_BLOBS_ENABLED.getKey(), true);

    FutureActionListener<CreateIndexResponse, Long> listener = new FutureActionListener<>(r -> 1L);
    CreateIndexRequest createIndexRequest = new CreateIndexRequest(fullIndexName(tableName), builder.build());
    createIndexAction.execute(createIndexRequest, listener);
    return listener;
}
 
Example 14
Source File: Ec2DiscoveryPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Settings additionalSettings() {
    final Settings.Builder builder = Settings.builder();

    // Adds a node attribute for the ec2 availability zone
    final String azMetadataUrl = AwsEc2ServiceImpl.EC2_METADATA_URL + "placement/availability-zone";
    builder.put(getAvailabilityZoneNodeAttributes(settings, azMetadataUrl));
    return builder.build();
}
 
Example 15
Source File: TablePropertiesAnalyzer.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void applyValue(Settings.Builder settingsBuilder, Object value) {
    throw new UnsupportedOperationException("Not supported");
}
 
Example 16
Source File: BasicCredentials.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void applyTo(Settings.Builder clientSettings) {
    clientSettings.put(XPACK_SECURITY_USER, username + ":" + password);
}
 
Example 17
Source File: BasicCredentials.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void applyTo(Settings.Builder clientSettings) {
    clientSettings.put(XPACK_SECURITY_USER, username + ":" + password);
}
 
Example 18
Source File: ClientSettings.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
public void applyTo(Settings.Builder settings) {
    for (ClientSetting clientSetting : clientSettings) {
        settings.put(clientSetting.getName(), clientSetting.getValue());
    }
}
 
Example 19
Source File: ClusterUpdateSettingsRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the transient settings to be updated. They will not survive a full cluster restart
 */
public ClusterUpdateSettingsRequest transientSettings(Settings.Builder settings) {
    this.transientSettings = settings.build();
    return this;
}
 
Example 20
Source File: BaseElasticSearchMapping.java    From ElasticUtils with MIT License 3 votes vote down vote up
private Settings.Builder getSettingsBuilder() {

        Settings.Builder settingsBuilder = Settings.builder()
                .put(IndexMetaData.SETTING_VERSION_CREATED, version)
                .put(IndexMetaData.SETTING_CREATION_DATE, System.currentTimeMillis());

        configureSettingsBuilder(settingsBuilder);

        return settingsBuilder;
    }