use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AnalysisModuleTests method testRegisterHunspellDictionary.
public void testRegisterHunspellDictionary() throws Exception {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
Environment environment = new Environment(settings);
InputStream aff = getClass().getResourceAsStream("/indices/analyze/conf_dir/hunspell/en_US/en_US.aff");
InputStream dic = getClass().getResourceAsStream("/indices/analyze/conf_dir/hunspell/en_US/en_US.dic");
Dictionary dictionary;
try (Directory tmp = new SimpleFSDirectory(environment.tmpFile())) {
dictionary = new Dictionary(tmp, "hunspell", aff, dic);
}
AnalysisModule module = new AnalysisModule(environment, singletonList(new AnalysisPlugin() {
@Override
public Map<String, Dictionary> getHunspellDictionaries() {
return singletonMap("foo", dictionary);
}
}));
assertSame(dictionary, module.getHunspellService().getDictionary("foo"));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testSecureSettings.
public void testSecureSettings() {
MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("foo", "secret");
Settings input = Settings.builder().put(baseEnvSettings).setSecureSettings(secureSettings).build();
Environment env = InternalSettingsPreparer.prepareEnvironment(input, null);
Setting<SecureString> fakeSetting = SecureSetting.secureString("foo", null, false);
assertEquals("secret", fakeSetting.get(env.settings()).toString());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testEmptySettings.
public void testEmptySettings() {
Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY);
// a name was not set
assertNull(settings.get("node.name"));
// a cluster name was set
assertNotNull(settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()));
int size = settings.names().size();
Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null);
settings = env.settings();
// a name was not set
assertNull(settings.get("node.name"));
// a cluster name was set
assertNotNull(settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()));
assertEquals(settings.toString(), size + 1, /* path.home is in the base settings */
settings.names().size());
String home = Environment.PATH_HOME_SETTING.get(baseEnvSettings);
String configDir = env.configFile().toString();
assertTrue(configDir, configDir.startsWith(home));
}
use of org.elasticsearch.env.Environment in project crate by crate.
the class CrateSettingsPreparer method prepareEnvironment.
/**
* ES_COPY_OF: core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java
* This is a copy of {@link InternalSettingsPreparer#prepareEnvironment(Settings, Terminal)}
* <p>
* with the addition of the "applyCrateDefaults" call.
*/
public static Environment prepareEnvironment(Settings input, Terminal terminal) {
// just create enough settings to build the environment, to get the config dir
Settings.Builder output = settingsBuilder();
InternalSettingsPreparer.initializeSettings(output, input, true);
Environment environment = new Environment(output.build());
Path path = environment.configFile().resolve("crate.yml");
if (Files.exists(path)) {
output.loadFromPath(path);
}
// re-initialize settings now that the config file has been loaded
// TODO: only re-initialize if a config file was actually loaded
InternalSettingsPreparer.initializeSettings(output, input, false);
InternalSettingsPreparer.finalizeSettings(output, terminal, environment.configFile());
validateKnownSettings(output);
applyCrateDefaults(output);
environment = new Environment(output.build());
// we put back the path.logs so we can use it in the logging configuration file
output.put("path.logs", cleanPath(environment.logsFile().toAbsolutePath().toString()));
return new Environment(output.build());
}
use of org.elasticsearch.env.Environment in project crate by crate.
the class NodeSettingsTest method doSetup.
private void doSetup() throws IOException {
// mute log4j warning by configuring a dummy logger
if (!loggingConfigured) {
Logger root = Logger.getRootLogger();
root.removeAllAppenders();
root.setLevel(Level.OFF);
root.addAppender(new NullAppender());
loggingConfigured = true;
}
tmp.create();
Settings.Builder builder = Settings.settingsBuilder().put("node.name", "node-test").put("node.data", true).put("index.store.type", "default").put("index.store.fs.memory.enabled", "true").put("gateway.type", "default").put("path.home", createConfigPath()).put("index.number_of_shards", "1").put("index.number_of_replicas", "0").put("cluster.routing.schedule", "50ms").put("node.local", true);
Terminal terminal = Terminal.DEFAULT;
Environment environment = CrateSettingsPreparer.prepareEnvironment(builder.build(), terminal);
node = new CrateNode(environment);
node.start();
client = node.client();
client.admin().indices().prepareCreate("test").execute().actionGet();
}
Aggregations