Search in sources :

Example 11 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.

the class JsonSettingsLoaderTests method testDuplicateKeysThrowsException.

public void testDuplicateKeysThrowsException() {
    assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled());
    final String json = "{\"foo\":\"bar\",\"foo\":\"baz\"}";
    final SettingsException e = expectThrows(SettingsException.class, () -> Settings.builder().loadFromSource(json, XContentType.JSON).build());
    assertEquals(e.getCause().getClass(), ElasticsearchParseException.class);
    assertThat(e.toString(), containsString("duplicate settings key [foo] " + "found at line number [1], " + "column number [20], " + "previous value [bar], " + "current value [baz]"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SettingsException(org.elasticsearch.common.settings.SettingsException)

Example 12 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.

the class AzureSettingsParserTests method testParseTwoSettingsTooManyDefaultSet.

public void testParseTwoSettingsTooManyDefaultSet() {
    Settings settings = Settings.builder().put("cloud.azure.storage.azure1.account", "myaccount1").put("cloud.azure.storage.azure1.key", "mykey1").put("cloud.azure.storage.azure1.default", true).put("cloud.azure.storage.azure2.account", "myaccount2").put("cloud.azure.storage.azure2.key", "mykey2").put("cloud.azure.storage.azure2.default", true).build();
    try {
        AzureStorageSettings.parse(settings);
        fail("Should have failed with a SettingsException (multiple default data stores)");
    } catch (SettingsException ex) {
        assertEquals(ex.getMessage(), "Multiple default Azure data stores configured: [azure1] and [azure2]");
    }
}
Also used : SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings) AzureStorageSettings(org.elasticsearch.cloud.azure.storage.AzureStorageSettings)

Example 13 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project graylog2-server by Graylog2.

the class EsNodeProvider method readNodeSettings.

public static Settings readNodeSettings(ElasticsearchConfiguration conf, NodeId nodeId) {
    final Settings.Builder settings = Settings.builder();
    // Standard Configuration.
    settings.put("cluster.name", conf.getClusterName());
    settings.put("node.name", conf.getNodeNamePrefix() + nodeId);
    settings.put("node.master", conf.isMasterNode());
    settings.put("node.data", conf.isDataNode());
    settings.put("node.client", true);
    settings.put("path.home", conf.getPathHome());
    if (!isNullOrEmpty(conf.getPathData())) {
        settings.put("path.data", conf.getPathData());
    }
    settings.put("action.auto_create_index", false);
    settings.put("http.enabled", conf.isHttpEnabled());
    settings.put("transport.tcp.port", conf.getTransportTcpPort());
    settings.put("discovery.initial_state_timeout", conf.getInitialStateTimeout());
    final List<String> unicastHosts = conf.getUnicastHosts();
    if (unicastHosts != null && !unicastHosts.isEmpty()) {
        final String[] trimmedHosts = new String[unicastHosts.size()];
        for (int i = 0; i < unicastHosts.size(); i++) {
            final String host = unicastHosts.get(i);
            trimmedHosts[i] = host.trim();
        }
        settings.putArray("discovery.zen.ping.unicast.hosts", trimmedHosts);
    }
    if (!isNullOrEmpty(conf.getNetworkHost())) {
        settings.put("network.host", conf.getNetworkHost());
    }
    if (!isNullOrEmpty(conf.getNetworkBindHost())) {
        settings.put("network.bind_host", conf.getNetworkBindHost());
    }
    if (!isNullOrEmpty(conf.getNetworkPublishHost())) {
        settings.put("network.publish_host", conf.getNetworkPublishHost());
    }
    // Overwrite from a custom ElasticSearch config file.
    final Path esConfigFile = conf.getConfigFile();
    if (esConfigFile != null) {
        try {
            settings.loadFromPath(esConfigFile);
        } catch (SettingsException e) {
            LOG.warn("Cannot read Elasticsearch configuration from " + esConfigFile, e);
        }
    }
    return settings.build();
}
Also used : Path(java.nio.file.Path) SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings)

Example 14 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project crate by crate.

the class AzureStorageServiceTests method testProxyNoHost.

public void testProxyNoHost() {
    final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_port", 8080).put("proxy_type", randomFrom("socks", "http")).build();
    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure Proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
Also used : SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings)

Example 15 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project crate by crate.

the class Ec2ClientSettings method loadCredentials.

static AWSCredentials loadCredentials(Settings settings) {
    try (SecureString key = ACCESS_KEY_SETTING.get(settings);
        SecureString secret = SECRET_KEY_SETTING.get(settings);
        SecureString sessionToken = SESSION_TOKEN_SETTING.get(settings)) {
        if (key.length() == 0 && secret.length() == 0) {
            if (sessionToken.length() > 0) {
                throw new SettingsException("Setting [{}] is set but [{}] and [{}] are not", SESSION_TOKEN_SETTING.getKey(), ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
            }
            LOGGER.debug("Using either environment variables, system properties or instance profile credentials");
            return null;
        } else {
            if (key.length() == 0) {
                DEPRECATION_LOGGER.deprecated("Setting [{}] is set but [{}] is not, which will be unsupported in future", SECRET_KEY_SETTING.getKey(), ACCESS_KEY_SETTING.getKey());
            }
            if (secret.length() == 0) {
                DEPRECATION_LOGGER.deprecated("Setting [{}] is set but [{}] is not, which will be unsupported in future", ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
            }
            final AWSCredentials credentials;
            if (sessionToken.length() == 0) {
                LOGGER.debug("Using basic key/secret credentials");
                credentials = new BasicAWSCredentials(key.toString(), secret.toString());
            } else {
                LOGGER.debug("Using basic session credentials");
                credentials = new BasicSessionCredentials(key.toString(), secret.toString(), sessionToken.toString());
            }
            return credentials;
        }
    }
}
Also used : BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) SettingsException(org.elasticsearch.common.settings.SettingsException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) SecureString(org.elasticsearch.common.settings.SecureString) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

SettingsException (org.elasticsearch.common.settings.SettingsException)16 Settings (org.elasticsearch.common.settings.Settings)10 Path (java.nio.file.Path)5 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AzureStorageSettings (org.elasticsearch.cloud.azure.storage.AzureStorageSettings)2 Environment (org.elasticsearch.env.Environment)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 HashSet (java.util.HashSet)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Strings.cleanPath (org.elasticsearch.common.Strings.cleanPath)1 SecureString (org.elasticsearch.common.settings.SecureString)1 Netty4CorsConfigBuilder (org.elasticsearch.http.netty4.cors.Netty4CorsConfigBuilder)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1