Search in sources :

Example 26 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class InternalSettingsPreparer method prepareEnvironment.

/**
     * Prepares the settings by gathering all elasticsearch system properties, optionally loading the configuration settings,
     * and then replacing all property placeholders. If a {@link Terminal} is provided and configuration settings are loaded,
     * settings with a value of <code>${prompt.text}</code> or <code>${prompt.secret}</code> will result in a prompt for
     * the setting to the user.
     * @param input The custom settings to use. These are not overwritten by settings in the configuration file.
     * @param terminal the Terminal to use for input/output
     * @param properties Map of properties key/value pairs (usually from the command-line)
     * @return the {@link Settings} and {@link Environment} as a {@link Tuple}
     */
public static Environment prepareEnvironment(Settings input, Terminal terminal, Map<String, String> properties) {
    // 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());
    // start with a fresh output
    output = Settings.builder();
    boolean settingsFileFound = false;
    Set<String> foundSuffixes = new HashSet<>();
    for (String allowedSuffix : ALLOWED_SUFFIXES) {
        Path path = environment.configFile().resolve("elasticsearch" + allowedSuffix);
        if (Files.exists(path)) {
            if (!settingsFileFound) {
                try {
                    output.loadFromPath(path);
                } catch (IOException e) {
                    throw new SettingsException("Failed to load settings from " + path.toString(), e);
                }
            }
            settingsFileFound = true;
            foundSuffixes.add(allowedSuffix);
        }
    }
    if (foundSuffixes.size() > 1) {
        throw new SettingsException("multiple settings files found with suffixes: " + Strings.collectionToDelimitedString(foundSuffixes, ","));
    }
    // re-initialize settings now that the config file has been loaded
    initializeSettings(output, input, properties);
    finalizeSettings(output, terminal);
    environment = new Environment(output.build());
    // we put back the path.logs so we can use it in the logging configuration file
    output.put(Environment.PATH_LOGS_SETTING.getKey(), cleanPath(environment.logsFile().toAbsolutePath().toString()));
    return new Environment(output.build());
}
Also used : Path(java.nio.file.Path) Strings.cleanPath(org.elasticsearch.common.Strings.cleanPath) Environment(org.elasticsearch.env.Environment) IOException(java.io.IOException) SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings) HashSet(java.util.HashSet)

Example 27 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class PluginsService method updatedSettings.

public Settings updatedSettings() {
    Map<String, String> foundSettings = new HashMap<>();
    final Settings.Builder builder = Settings.builder();
    for (Tuple<PluginInfo, Plugin> plugin : plugins) {
        Settings settings = plugin.v2().additionalSettings();
        for (String setting : settings.getAsMap().keySet()) {
            String oldPlugin = foundSettings.put(setting, plugin.v1().getName());
            if (oldPlugin != null) {
                throw new IllegalArgumentException("Cannot have additional setting [" + setting + "] " + "in plugin [" + plugin.v1().getName() + "], already added in plugin [" + oldPlugin + "]");
            }
        }
        builder.put(settings);
    }
    return builder.put(this.settings).build();
}
Also used : HashMap(java.util.HashMap) Settings(org.elasticsearch.common.settings.Settings)

Example 28 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class TransportTasksActionTests method testFailedTasksCount.

public void testFailedTasksCount() throws ExecutionException, InterruptedException, IOException {
    Settings settings = Settings.builder().put(MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING.getKey(), true).build();
    setupTestNodes(settings);
    connectNodes(testNodes);
    TestNodesAction[] actions = new TestNodesAction[nodesCount];
    RecordingTaskManagerListener[] listeners = setupListeners(testNodes, "testAction*");
    for (int i = 0; i < testNodes.length; i++) {
        final int node = i;
        actions[i] = new TestNodesAction(CLUSTER_SETTINGS, "testAction", threadPool, testNodes[i].clusterService, testNodes[i].transportService) {

            @Override
            protected NodeResponse nodeOperation(NodeRequest request) {
                logger.info("Action on node {}", node);
                throw new RuntimeException("Test exception");
            }
        };
    }
    for (TestNode testNode : testNodes) {
        assertEquals(0, testNode.transportService.getTaskManager().getTasks().size());
    }
    NodesRequest request = new NodesRequest("Test Request");
    NodesResponse responses = actions[0].execute(request).get();
    assertEquals(nodesCount, responses.failureCount());
    // Make sure that actions are still registered in the task manager on all nodes
    // Twice on the coordinating node and once on all other nodes.
    assertEquals(4, listeners[0].getEvents().size());
    assertEquals(2, listeners[0].getRegistrationEvents().size());
    assertEquals(2, listeners[0].getUnregistrationEvents().size());
    for (int i = 1; i < listeners.length; i++) {
        assertEquals(2, listeners[i].getEvents().size());
        assertEquals(1, listeners[i].getRegistrationEvents().size());
        assertEquals(1, listeners[i].getUnregistrationEvents().size());
    }
}
Also used : BaseNodeRequest(org.elasticsearch.action.support.nodes.BaseNodeRequest) BaseNodesRequest(org.elasticsearch.action.support.nodes.BaseNodesRequest) Settings(org.elasticsearch.common.settings.Settings)

Example 29 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class GetTermVectorsIT method testArtificialDocWithPreference.

public void testArtificialDocWithPreference() throws ExecutionException, InterruptedException, IOException {
    // setup indices
    Settings.Builder settings = Settings.builder().put(indexSettings()).put("index.analysis.analyzer", "standard");
    assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", "field1", "type=text,term_vector=with_positions_offsets"));
    ensureGreen();
    // index document
    indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "random permutation"));
    // Get search shards
    ClusterSearchShardsResponse searchShardsResponse = client().admin().cluster().prepareSearchShards("test").get();
    List<Integer> shardIds = Arrays.stream(searchShardsResponse.getGroups()).map(s -> s.getShardId().id()).collect(Collectors.toList());
    // request termvectors of artificial document from each shard
    int sumTotalTermFreq = 0;
    int sumDocFreq = 0;
    for (Integer shardId : shardIds) {
        TermVectorsResponse tvResponse = client().prepareTermVectors().setIndex("test").setType("type1").setPreference("_shards:" + shardId).setDoc(jsonBuilder().startObject().field("field1", "random permutation").endObject()).setFieldStatistics(true).setTermStatistics(true).get();
        Fields fields = tvResponse.getFields();
        Terms terms = fields.terms("field1");
        assertNotNull(terms);
        TermsEnum termsEnum = terms.iterator();
        while (termsEnum.next() != null) {
            sumTotalTermFreq += termsEnum.totalTermFreq();
            sumDocFreq += termsEnum.docFreq();
        }
    }
    assertEquals("expected to find term statistics in exactly one shard!", 2, sumTotalTermFreq);
    assertEquals("expected to find term statistics in exactly one shard!", 2, sumDocFreq);
}
Also used : ClusterSearchShardsResponse(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) Versions(org.elasticsearch.common.lucene.uid.Versions) Arrays(java.util.Arrays) FieldType(org.apache.lucene.document.FieldType) Alias(org.elasticsearch.action.admin.indices.alias.Alias) Fields(org.apache.lucene.index.Fields) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) PayloadHelper(org.apache.lucene.analysis.payloads.PayloadHelper) ActionFuture(org.elasticsearch.action.ActionFuture) Strings(org.elasticsearch.common.Strings) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Settings(org.elasticsearch.common.settings.Settings) ObjectIntHashMap(com.carrotsearch.hppc.ObjectIntHashMap) TermsEnum(org.apache.lucene.index.TermsEnum) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) XContentFactory.jsonBuilder(org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder) VersionConflictEngineException(org.elasticsearch.index.engine.VersionConflictEngineException) ElasticsearchAssertions.assertThrows(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) PostingsEnum(org.apache.lucene.index.PostingsEnum) Terms(org.apache.lucene.index.Terms) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) BytesRef(org.apache.lucene.util.BytesRef) DirectoryReader(org.apache.lucene.index.DirectoryReader) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ClusterSearchShardsResponse(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) Fields(org.apache.lucene.index.Fields) Terms(org.apache.lucene.index.Terms) Settings(org.elasticsearch.common.settings.Settings) TermsEnum(org.apache.lucene.index.TermsEnum)

Example 30 with Settings

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.

the class GetTermVectorsIT method testPerFieldAnalyzer.

public void testPerFieldAnalyzer() throws IOException {
    int numFields = 25;
    // setup mapping and document source
    Set<String> withTermVectors = new HashSet<>();
    XContentBuilder mapping = jsonBuilder().startObject().startObject("type1").startObject("properties");
    XContentBuilder source = jsonBuilder().startObject();
    for (int i = 0; i < numFields; i++) {
        String fieldName = "field" + i;
        if (randomBoolean()) {
            withTermVectors.add(fieldName);
        }
        mapping.startObject(fieldName).field("type", "text").field("term_vector", withTermVectors.contains(fieldName) ? "yes" : "no").endObject();
        source.field(fieldName, "some text here");
    }
    source.endObject();
    mapping.endObject().endObject().endObject();
    // setup indices with mapping
    Settings.Builder settings = Settings.builder().put(indexSettings()).put("index.analysis.analyzer", "standard");
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSettings(settings).addMapping("type1", mapping));
    ensureGreen();
    // index a single document with prepared source
    client().prepareIndex("test", "type1", "0").setSource(source).get();
    refresh();
    // create random per_field_analyzer and selected fields
    Map<String, String> perFieldAnalyzer = new HashMap<>();
    Set<String> selectedFields = new HashSet<>();
    for (int i = 0; i < numFields; i++) {
        if (randomBoolean()) {
            perFieldAnalyzer.put("field" + i, "keyword");
        }
        if (randomBoolean()) {
            perFieldAnalyzer.put("non_existing" + i, "keyword");
        }
        if (randomBoolean()) {
            selectedFields.add("field" + i);
        }
        if (randomBoolean()) {
            selectedFields.add("non_existing" + i);
        }
    }
    // selected fields not specified
    TermVectorsResponse response = client().prepareTermVectors(indexOrAlias(), "type1", "0").setPerFieldAnalyzer(perFieldAnalyzer).get();
    // should return all fields that have terms vectors, some with overridden analyzer
    checkAnalyzedFields(response.getFields(), withTermVectors, perFieldAnalyzer);
    // selected fields specified including some not in the mapping
    response = client().prepareTermVectors(indexOrAlias(), "type1", "0").setSelectedFields(selectedFields.toArray(Strings.EMPTY_ARRAY)).setPerFieldAnalyzer(perFieldAnalyzer).get();
    // should return only the specified valid fields, with some with overridden analyzer
    checkAnalyzedFields(response.getFields(), selectedFields, perFieldAnalyzer);
}
Also used : HashMap(java.util.HashMap) ObjectIntHashMap(com.carrotsearch.hppc.ObjectIntHashMap) Alias(org.elasticsearch.action.admin.indices.alias.Alias) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Settings(org.elasticsearch.common.settings.Settings) HashSet(java.util.HashSet)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)1248 Test (org.junit.Test)197 IndexSettings (org.elasticsearch.index.IndexSettings)167 IOException (java.io.IOException)133 Path (java.nio.file.Path)121 ClusterState (org.elasticsearch.cluster.ClusterState)120 ArrayList (java.util.ArrayList)108 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)106 HashMap (java.util.HashMap)105 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)98 Version (org.elasticsearch.Version)91 Matchers.containsString (org.hamcrest.Matchers.containsString)91 Environment (org.elasticsearch.env.Environment)87 Map (java.util.Map)85 List (java.util.List)79 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 Index (org.elasticsearch.index.Index)70 HashSet (java.util.HashSet)58 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)54 ThreadPool (org.elasticsearch.threadpool.ThreadPool)54