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]"));
}
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]");
}
}
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();
}
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());
}
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;
}
}
}
Aggregations