Search in sources :

Example 81 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class URLRepositoryTests method testMustBeSupportedProtocol.

public void testMustBeSupportedProtocol() throws IOException {
    Path directory = createTempDir();
    String repoPath = directory.resolve("repository").toUri().toURL().toString();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(Environment.PATH_REPO_SETTING.getKey(), directory.toString()).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).put(URLRepository.SUPPORTED_PROTOCOLS_SETTING.getKey(), "http,https").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) {
        assertEquals("[url] unsupported url protocol [file] from URL [" + repoPath + "]", e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) Environment(org.elasticsearch.env.Environment) RepositoryException(org.elasticsearch.repositories.RepositoryException) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings)

Example 82 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class NewPathForShardTests method testSelectNewPathForShard.

public void testSelectNewPathForShard() throws Exception {
    Path path = PathUtils.get(createTempDir().toString());
    // Use 2 data paths:
    String[] paths = new String[] { path.resolve("a").toString(), path.resolve("b").toString() };
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), path).putArray(Environment.PATH_DATA_SETTING.getKey(), paths).build();
    NodeEnvironment nodeEnv = new NodeEnvironment(settings, new Environment(settings));
    // Make sure all our mocking above actually worked:
    NodePath[] nodePaths = nodeEnv.nodePaths();
    assertEquals(2, nodePaths.length);
    assertEquals("mocka", nodePaths[0].fileStore.name());
    assertEquals("mockb", nodePaths[1].fileStore.name());
    // Path a has lots of free space, but b has little, so new shard should go to a:
    aFileStore.usableSpace = 100000;
    bFileStore.usableSpace = 1000;
    ShardId shardId = new ShardId("index", "_na_", 0);
    ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.<Path, Integer>emptyMap());
    assertTrue(result.getDataPath().toString().contains(aPathPart));
    // Test the reverse: b has lots of free space, but a has little, so new shard should go to b:
    aFileStore.usableSpace = 1000;
    bFileStore.usableSpace = 100000;
    shardId = new ShardId("index", "_na_", 0);
    result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.<Path, Integer>emptyMap());
    assertTrue(result.getDataPath().toString().contains(bPathPart));
    // Now a and be have equal usable space; we allocate two shards to the node, and each should go to different paths:
    aFileStore.usableSpace = 100000;
    bFileStore.usableSpace = 100000;
    Map<Path, Integer> dataPathToShardCount = new HashMap<>();
    ShardPath result1 = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount);
    dataPathToShardCount.put(NodeEnvironment.shardStatePathToDataPath(result1.getDataPath()), 1);
    ShardPath result2 = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount);
    // #11122: this was the original failure: on a node with 2 disks that have nearly equal
    // free space, we would always allocate all N incoming shards to the one path that
    // had the most free space, never using the other drive unless new shards arrive
    // after the first shards started using storage:
    assertNotEquals(result1.getDataPath(), result2.getDataPath());
    nodeEnv.close();
}
Also used : Path(java.nio.file.Path) NodePath(org.elasticsearch.env.NodeEnvironment.NodePath) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) HashMap(java.util.HashMap) NodePath(org.elasticsearch.env.NodeEnvironment.NodePath) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 83 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class IndexShardIT method testIndexDirIsDeletedWhenShardRemoved.

public void testIndexDirIsDeletedWhenShardRemoved() throws Exception {
    Environment env = getInstanceFromNode(Environment.class);
    Path idxPath = env.sharedDataFile().resolve(randomAsciiOfLength(10));
    logger.info("--> idxPath: [{}]", idxPath);
    Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_DATA_PATH, idxPath).build();
    createIndex("test", idxSettings);
    ensureGreen("test");
    client().prepareIndex("test", "bar", "1").setSource("{}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
    SearchResponse response = client().prepareSearch("test").get();
    assertHitCount(response, 1L);
    client().admin().indices().prepareDelete("test").get();
    assertAllIndicesRemovedAndDeletionCompleted(Collections.singleton(getInstanceFromNode(IndicesService.class)));
    assertPathHasBeenCleared(idxPath);
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 84 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class AnalysisModuleTests method testWordListPath.

public void testWordListPath() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    Environment env = new Environment(settings);
    String[] words = new String[] { "donau", "dampf", "schiff", "spargel", "creme", "suppe" };
    Path wordListFile = generateWordList(words);
    settings = Settings.builder().loadFromSource("index: \n  word_list_path: " + wordListFile.toAbsolutePath(), XContentType.YAML).build();
    Set<?> wordList = Analysis.getWordSet(env, Version.CURRENT, settings, "index.word_list");
    MatcherAssert.assertThat(wordList.size(), equalTo(6));
    //        MatcherAssert.assertThat(wordList, hasItems(words));
    Files.delete(wordListFile);
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 85 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class HunspellServiceTests method testDicWithTwoAffs.

public void testDicWithTwoAffs() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/two_aff_conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    IllegalStateException e = expectThrows(IllegalStateException.class, () -> new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US"));
    assertEquals("failed to load hunspell dictionary for locale: en_US", e.getMessage());
    assertThat(e.getCause(), hasToString(containsString("Too many affix files")));
}
Also used : HunspellService(org.elasticsearch.indices.analysis.HunspellService) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Environment (org.elasticsearch.env.Environment)130 Settings (org.elasticsearch.common.settings.Settings)84 Path (java.nio.file.Path)66 Matchers.containsString (org.hamcrest.Matchers.containsString)42 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)26 TestEnvironment (org.elasticsearch.env.TestEnvironment)22 IndexSettings (org.elasticsearch.index.IndexSettings)21 UserException (org.elasticsearch.cli.UserException)17 IOException (java.io.IOException)15 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 MockTerminal (org.elasticsearch.cli.MockTerminal)8 ClusterState (org.elasticsearch.cluster.ClusterState)8 ScriptService (org.elasticsearch.script.ScriptService)8 HashMap (java.util.HashMap)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 ArrayList (java.util.ArrayList)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 Before (org.junit.Before)6