Search in sources :

Example 16 with SettingsException

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

the class InternalSettingsPreparer method prepareEnvironment.

/**
 * Prepares the settings by gathering all elasticsearch system properties, optionally loading the configuration settings.
 *
 * @param input      the custom settings to use; these are not overwritten by settings in the configuration file
 * @param properties map of properties key/value pairs (usually from the command-line)
 * @param configPath path to config directory; (use null to indicate the default)
 * @param defaultNodeName supplier for the default node.name if the setting isn't defined
 * @return the {@link Environment}
 */
public static Environment prepareEnvironment(Settings input, Map<String, String> properties, Path configPath, Supplier<String> defaultNodeName) {
    // just create enough settings to build the environment, to get the config dir
    Settings.Builder output = Settings.builder();
    initializeSettings(output, input, properties);
    Environment environment = new Environment(output.build(), configPath);
    // start with a fresh output
    output = Settings.builder();
    Path path = environment.configFile().resolve("crate.yml");
    if (Files.exists(path)) {
        try {
            output.loadFromPath(path);
        } catch (IOException e) {
            throw new SettingsException("Failed to load settings from " + path.toString(), e);
        }
    }
    // re-initialize settings now that the config file has been loaded
    initializeSettings(output, input, properties);
    finalizeSettings(output, defaultNodeName);
    environment = new Environment(output.build(), configPath);
    // we put back the path.logs so we can use it in the logging configuration file
    output.put(Environment.PATH_LOGS_SETTING.getKey(), environment.logsFile().toAbsolutePath().normalize().toString());
    return new Environment(output.build(), configPath);
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) IOException(java.io.IOException) SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings)

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