use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AbstractSortTestCase method init.
@BeforeClass
public static void init() throws IOException {
Path genericConfigFolder = createTempDir();
Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder).build();
Environment environment = new Environment(baseSettings);
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngineService()));
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
scriptService = new ScriptService(baseSettings, environment, new ResourceWatcherService(baseSettings, null), scriptEngineRegistry, scriptContextRegistry, scriptSettings) {
@Override
public CompiledScript compile(Script script, ScriptContext scriptContext) {
return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);
}
};
SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class URLRepositoryTests method testWhiteListingRepoURL.
public void testWhiteListingRepoURL() throws IOException {
String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.ALLOWED_URLS_SETTING.getKey(), repoPath).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).build();
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("url", URLRepository.TYPE, baseSettings);
new URLRepository(repositoryMetaData, new Environment(baseSettings), new NamedXContentRegistry(Collections.emptyList()));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class URLRepositoryTests method testIfNotWhiteListedMustSetRepoURL.
public void testIfNotWhiteListedMustSetRepoURL() throws IOException {
String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).build();
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("url", URLRepository.TYPE, baseSettings);
try {
new URLRepository(repositoryMetaData, new Environment(baseSettings), new NamedXContentRegistry(Collections.emptyList()));
fail("RepositoryException should have been thrown.");
} catch (RepositoryException e) {
String msg = "[url] file url [" + repoPath + "] doesn't match any of the locations specified by path.repo or repositories.url.allowed_urls";
assertEquals(msg, e.getMessage());
}
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class AnalysisPolishFactoryTests method testThreadSafety.
public void testThreadSafety() throws IOException {
// TODO: is this the right boilerplate? I forked this out of TransportAnalyzeAction.java:
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
Environment environment = new Environment(settings);
IndexMetaData metaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(settings).build();
IndexSettings indexSettings = new IndexSettings(metaData, Settings.EMPTY);
testThreadSafety(new PolishStemTokenFilterFactory(indexSettings, environment, "stempelpolishstem", settings));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InstallPluginCommandTests method testPlatformBinPermissions.
public void testPlatformBinPermissions() throws Exception {
assumeTrue("posix filesystem", isPosix);
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
Path platformDir = pluginDir.resolve("platform");
Path platformNameDir = platformDir.resolve("linux-x86_64");
Path platformBinDir = platformNameDir.resolve("bin");
Files.createDirectories(platformBinDir);
Path programFile = Files.createFile(platformBinDir.resolve("someprogram"));
// a file created with Files.createFile() should not have execute permissions
Set<PosixFilePermission> sourcePerms = Files.getPosixFilePermissions(programFile);
assertFalse(sourcePerms.contains(PosixFilePermission.OWNER_EXECUTE));
assertFalse(sourcePerms.contains(PosixFilePermission.GROUP_EXECUTE));
assertFalse(sourcePerms.contains(PosixFilePermission.OTHERS_EXECUTE));
String pluginZip = createPlugin("fake", pluginDir);
installPlugin(pluginZip, env.v1());
assertPlugin("fake", pluginDir, env.v2());
// check that the installed program has execute permissions, even though the one added to the plugin didn't
Path installedPlatformBinDir = env.v2().pluginsFile().resolve("fake").resolve("platform").resolve("linux-x86_64").resolve("bin");
assertTrue(Files.isDirectory(installedPlatformBinDir));
Path installedProgramFile = installedPlatformBinDir.resolve("someprogram");
assertTrue(Files.isRegularFile(installedProgramFile));
Set<PosixFilePermission> installedPerms = Files.getPosixFilePermissions(installedProgramFile);
assertTrue(installedPerms.contains(PosixFilePermission.OWNER_EXECUTE));
assertTrue(installedPerms.contains(PosixFilePermission.GROUP_EXECUTE));
assertTrue(installedPerms.contains(PosixFilePermission.OTHERS_EXECUTE));
}
Aggregations