org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateAnalyzerAnalyzerTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateAnalyzerExtendingBuiltin() throws Exception {
    ClusterUpdateSettingsRequest request = analyze(
        "CREATE ANALYZER a4 EXTENDS " +
        "german WITH (" +
        "   \"stop_words\"=['der', 'die', 'das']" +
        ")");

    assertThat(
        extractAnalyzerSettings("a4", request.persistentSettings()),
        allOf(
            hasEntry("index.analysis.analyzer.a4.stop_words", "[der, die, das]"),
            hasEntry("index.analysis.analyzer.a4.type", "german")
        )
    );
}
 
Example #2
Source File: ESClusterUpdateSettingsTask.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public ESClusterUpdateSettingsTask(UUID jobId,
                                   TransportClusterUpdateSettingsAction transport,
                                   ESClusterUpdateSettingsNode node) {
    super(jobId);
    this.transport = transport;

    final SettableFuture<TaskResult> result = SettableFuture.create();
    results = Collections.<ListenableFuture<TaskResult>>singletonList(result);

    request = new ClusterUpdateSettingsRequest();
    request.persistentSettings(node.persistentSettings());
    request.transientSettings(node.transientSettings());
    if (node.persistentSettingsToRemove() != null) {
        request.persistentSettingsToRemove(node.persistentSettingsToRemove());
    }
    if (node.transientSettingsToRemove() != null) {
        request.transientSettingsToRemove(node.transientSettingsToRemove());
    }
    listener = ActionListeners.wrap(result, Functions.constant(TaskResult.ONE_ROW));
}
 
Example #3
Source File: CaseController.java    From skywalking with Apache License 2.0 6 votes vote down vote up
private void putSettings() throws IOException {
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
    String transientSettingKey =
        RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    int transientSettingValue = 10;
    Settings transientSettings = Settings.builder()
            .put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES)
            .build();
    request.transientSettings(transientSettings);
    ClusterUpdateSettingsResponse response = client.cluster().putSettings(request, RequestOptions.DEFAULT);
    if (response == null) {
        String message = "elasticsearch put settings fail.";
        logger.error(message);
        throw new RuntimeException(message);
    }
}
 
Example #4
Source File: DecommissioningService.java    From crate with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<ClusterUpdateSettingsResponse> clusterSetDecommissionNodeSetting() {
    if (dataAvailability == DataAvailability.NONE) {
        return CompletableFuture.completedFuture(null);
    }

    /*
     * setting this setting will cause the {@link DecommissionAllocationDecider} to prevent allocations onto this node
     *
     * nodeIds are part of the key to prevent conflicts if other nodes are being decommissioned in parallel
     */
    Settings settings = Settings.builder().put(
        DECOMMISSION_PREFIX + clusterService.localNode().getId(), true).build();
    FutureActionListener<ClusterUpdateSettingsResponse, ClusterUpdateSettingsResponse> settingsResponseFutureListener
        = FutureActionListener.newInstance();
    updateSettingsAction.execute(
        new ClusterUpdateSettingsRequest().transientSettings(settings), settingsResponseFutureListener);
    return settingsResponseFutureListener;
}
 
Example #5
Source File: CreateAnalyzerPlan.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    ClusterUpdateSettingsRequest request = createRequest(
        createAnalyzer,
        plannerContext.transactionContext(),
        plannerContext.functions(),
        params,
        subQueryResults,
        dependencies.fulltextAnalyzerResolver());

    dependencies
        .transportActionProvider()
        .transportClusterUpdateSettingsAction()
        .execute(request, new OneRowActionListener<>(consumer, r -> new Row1(1L)));
}
 
Example #6
Source File: UpdateSettingsPlan.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {

    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(),
                                                                          plannerContext.functions(),
                                                                          x,
                                                                          params,
                                                                          subQueryResults);
    ClusterUpdateSettingsRequest request = isPersistent
        ? new ClusterUpdateSettingsRequest().persistentSettings(buildSettingsFrom(settings, eval))
        : new ClusterUpdateSettingsRequest().transientSettings(buildSettingsFrom(settings, eval));

    OneRowActionListener<ClusterUpdateSettingsResponse> actionListener = new OneRowActionListener<>(
        consumer,
        r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));
    dependencies.transportActionProvider().transportClusterUpdateSettingsAction().execute(request, actionListener);
}
 
Example #7
Source File: ResetSettingsPlan.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {

    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(),
                                                                          plannerContext.functions(),
                                                                          x,
                                                                          params,
                                                                          subQueryResults);

    Settings settings = buildSettingsFrom(resetAnalyzedStatement.settingsToRemove(), eval);

    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest()
        .persistentSettings(settings)
        .transientSettings(settings);
    OneRowActionListener<ClusterUpdateSettingsResponse> actionListener = new OneRowActionListener<>(
        consumer,
        r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));
    dependencies.transportActionProvider().transportClusterUpdateSettingsAction().execute(request, actionListener);
}
 
Example #8
Source File: DropAnalyzerPlan.java    From crate with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static ClusterUpdateSettingsRequest createRequest(String analyzerName,
                                                         FulltextAnalyzerResolver ftResolver) {
    Settings.Builder builder = Settings.builder();
    builder.putNull(ANALYZER.buildSettingName(analyzerName));

    Settings settings = ftResolver.getCustomAnalyzer(analyzerName);

    String tokenizerName = settings.get(ANALYZER.buildSettingChildName(analyzerName, TOKENIZER.getName()));
    if (tokenizerName != null
        && ftResolver.hasCustomThingy(tokenizerName, FulltextAnalyzerResolver.CustomType.TOKENIZER)) {
        builder.putNull(TOKENIZER.buildSettingName(tokenizerName));
    }

    for (String tokenFilterName : settings
        .getAsList(ANALYZER.buildSettingChildName(analyzerName, TOKEN_FILTER.getName()))) {
        if (ftResolver.hasCustomThingy(tokenFilterName, FulltextAnalyzerResolver.CustomType.TOKEN_FILTER)) {
            builder.putNull(TOKEN_FILTER.buildSettingName(tokenFilterName));
        }
    }

    for (String charFilterName : settings
        .getAsList(ANALYZER.buildSettingChildName(analyzerName, CHAR_FILTER.getName()))) {
        if (ftResolver.hasCustomThingy(charFilterName, FulltextAnalyzerResolver.CustomType.CHAR_FILTER)) {
            builder.putNull(CHAR_FILTER.buildSettingName(charFilterName));
        }
    }

    return new ClusterUpdateSettingsRequest()
        .persistentSettings(builder.build());
}
 
Example #9
Source File: CreateAnalyzerAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAnalyzerWithTokenFilters() throws Exception {
    ClusterUpdateSettingsRequest request = analyze(
        "CREATE ANALYZER a11 (" +
        "  TOKENIZER standard," +
        "  TOKEN_FILTERS (" +
        "    lowercase," +
        "    mystop WITH (" +
        "      type='stop'," +
        "      stopword=['the', 'over']" +
        "    )" +
        "  )" +
        ")");

    assertThat(
        extractAnalyzerSettings("a11", request.persistentSettings()),
        allOf(
            hasEntry("index.analysis.analyzer.a11.tokenizer", "standard"),
            hasEntry("index.analysis.analyzer.a11.filter", "[lowercase, a11_mystop]")
        )
    );

    var tokenFiltersSettings = FulltextAnalyzerResolver.decodeSettings(
        request.persistentSettings().get(TOKEN_FILTER.buildSettingName("a11_mystop")));
    assertThat(
        tokenFiltersSettings,
        allOf(
            hasEntry("index.analysis.filter.a11_mystop.type", "stop"),
            hasEntry("index.analysis.filter.a11_mystop.stopword", "[the, over]")
        )
    );
}
 
Example #10
Source File: CreateAnalyzerAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAnalyzerWithCharFilters() throws Exception {
    ClusterUpdateSettingsRequest request = analyze(
        "CREATE ANALYZER a3 (" +
        "   TOKENIZER lowercase," +
        "   CHAR_FILTERS (" +
        "       \"html_strip\"," +
        "       my_mapping WITH (" +
        "           type='mapping'," +
        "           mappings=['ph=>f', 'ß=>ss', 'ö=>oe']" +
        "       )" +
        "   )" +
        ")");

    assertThat(
        extractAnalyzerSettings("a3", request.persistentSettings()),
        allOf(
            hasEntry("index.analysis.analyzer.a3.tokenizer", "lowercase"),
            hasEntry("index.analysis.analyzer.a3.char_filter", "[html_strip, a3_my_mapping]")
        )
    );

    var charFiltersSettings = FulltextAnalyzerResolver.decodeSettings(
        request.persistentSettings().get(CHAR_FILTER.buildSettingName("a3_my_mapping")));
    assertThat(
        charFiltersSettings,
        allOf(
            hasEntry("index.analysis.char_filter.a3_my_mapping.mappings", "[ph=>f, ß=>ss, ö=>oe]"),
            hasEntry("index.analysis.char_filter.a3_my_mapping.type", "mapping")
        )
    );
}
 
Example #11
Source File: CreateAnalyzerAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAnalyzerWithCustomTokenizer() throws Exception {
    ClusterUpdateSettingsRequest request = analyze(
        "CREATE ANALYZER a2 (" +
        "   TOKENIZER tok2 with (" +
        "       type='ngram'," +
        "       \"min_ngram\"=2," +
        "       \"token_chars\"=['letter', 'digits']" +
        "   )" +
        ")");
    assertThat(
        extractAnalyzerSettings("a2", request.persistentSettings()),
        allOf(
            hasEntry("index.analysis.analyzer.a2.tokenizer", "a2_tok2"),
            hasEntry("index.analysis.analyzer.a2.type", "custom")
        )
    );

    var tokenizerSettings = FulltextAnalyzerResolver.decodeSettings(
        request.persistentSettings().get(TOKENIZER.buildSettingName("a2_tok2")));
    assertThat(
        tokenizerSettings,
        allOf(
            hasEntry("index.analysis.tokenizer.a2_tok2.min_ngram", "2"),
            hasEntry("index.analysis.tokenizer.a2_tok2.type", "ngram"),
            hasEntry("index.analysis.tokenizer.a2_tok2.token_chars", "[letter, digits]")
        )
    );
}
 
Example #12
Source File: CreateAnalyzerAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAnalyzerSimple() throws Exception {
    ClusterUpdateSettingsRequest request = analyze(
        "CREATE ANALYZER a1 (TOKENIZER lowercase)");
    assertThat(
        extractAnalyzerSettings("a1", request.persistentSettings()),
        allOf(
            hasEntry("index.analysis.analyzer.a1.tokenizer", "lowercase"),
            hasEntry("index.analysis.analyzer.a1.type", "custom")
        )
    );
}
 
Example #13
Source File: CreateAnalyzerAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
private ClusterUpdateSettingsRequest analyze(String stmt, Object... arguments) {
    AnalyzedCreateAnalyzer analyzedStatement = e.analyze(stmt);
    return CreateAnalyzerPlan.createRequest(
        analyzedStatement,
        plannerContext.transactionContext(),
        plannerContext.functions(),
        new RowN(arguments),
        SubQueryResults.EMPTY,
        e.fulltextAnalyzerResolver());
}
 
Example #14
Source File: DecommissioningService.java    From crate with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected void removeDecommissioningSetting() {
    if (dataAvailability == DataAvailability.NONE) {
        return;
    }

    Map<String, Object> settingsToRemove = MapBuilder.<String, Object>newMapBuilder()
        .put(DECOMMISSION_PREFIX + clusterService.localNode().getId(), null)
        .map();
    updateSettingsAction.execute(new ClusterUpdateSettingsRequest().transientSettings(settingsToRemove));
}
 
Example #15
Source File: DecommissioningService.java    From crate with Apache License 2.0 5 votes vote down vote up
private void removeRemovedNodes(ClusterChangedEvent event) {
    if (!event.localNodeMaster() || !event.nodesRemoved()) {
        return;
    }
    Map<String, Object> removedDecommissionedNodes = getRemovedDecommissionedNodes(
        event.nodesDelta(), event.state().metaData().transientSettings());
    if (removedDecommissionedNodes != null) {
        updateSettingsAction.execute(new ClusterUpdateSettingsRequest().transientSettings(removedDecommissionedNodes));
    }
}
 
Example #16
Source File: DecommissioningService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void removeRemovedNodes(ClusterChangedEvent event) {
    if (!event.localNodeMaster() || !event.nodesRemoved()) {
        return;
    }
    Set<String> removedDecommissionedNodes = getRemovedDecommissionedNodes(
        event.nodesDelta(), event.state().metaData().transientSettings());
    if (removedDecommissionedNodes != null) {
        updateSettingsAction.execute(new ClusterUpdateSettingsRequest().transientSettingsToRemove(removedDecommissionedNodes));
    }
}
 
Example #17
Source File: DropAnalyzerPlan.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    ClusterUpdateSettingsRequest request = createRequest(
        dropAnalyzer.name(),
        dependencies.fulltextAnalyzerResolver());

    dependencies
        .transportActionProvider()
        .transportClusterUpdateSettingsAction()
        .execute(request, new OneRowActionListener<>(consumer, r -> new Row1(1L)));
}
 
Example #18
Source File: ClusterClientPutSettingsMethodsInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    ClusterUpdateSettingsRequest updateSettingsRequest = (ClusterUpdateSettingsRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    if (restClientEnhanceInfo != null) {
        AbstractSpan span = ContextManager
            .createExitSpan(Constants.CLUSTER_PUT_SETTINGS_NAME, restClientEnhanceInfo.getPeers());
        span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

        Tags.DB_TYPE.set(span, DB_TYPE);
        if (TRACE_DSL) {
            StringBuilder sb = new StringBuilder("persistent:[");
            Settings persist = updateSettingsRequest.persistentSettings();
            if (persist != null) {
                sb.append(persist.toString());
            }
            sb.append("]---transient:[");
            Settings transi = updateSettingsRequest.transientSettings();
            if (transi != null) {
                sb.append(transi.toString());
            }
            sb.append("]");
            Tags.DB_STATEMENT.set(span, sb.toString());
        }
        SpanLayer.asDB(span);
    }
}
 
Example #19
Source File: CreateAnalyzerPlan.java    From crate with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static ClusterUpdateSettingsRequest createRequest(AnalyzedCreateAnalyzer createAnalyzer,
                                                         CoordinatorTxnCtx txnCtx,
                                                         Functions functions,
                                                         Row parameters,
                                                         SubQueryResults subQueryResults,
                                                         FulltextAnalyzerResolver ftResolver) {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(
        txnCtx,
        functions,
        x,
        parameters,
        subQueryResults
    );

    var analyzerIdent = createAnalyzer.ident();

    var tokenizer = bindTokenizer(
        createAnalyzer.tokenizer(),
        analyzerIdent,
        eval,
        ftResolver);

    var tokenFilters = bindTokenFilters(
        createAnalyzer.tokenFilters(),
        analyzerIdent,
        eval,
        ftResolver);

    var charFilters = bindCharFilters(
        createAnalyzer.charFilters(),
        analyzerIdent,
        eval,
        ftResolver);

    var genericAnalyzerSettings = bindGenericAnalyzerProperties(
        createAnalyzer.genericAnalyzerProperties(),
        analyzerIdent,
        eval);

    var analyzerSettings = buildAnalyzerSettings(
        analyzerIdent,
        createAnalyzer.extendedAnalyzerName(),
        tokenizer,
        tokenFilters,
        charFilters,
        genericAnalyzerSettings,
        ftResolver);

    Settings.Builder encodedSettingsBuilder = Settings.builder();
    encodedSettingsBuilder.put(
        ANALYZER.buildSettingName(analyzerIdent),
        encodeSettings(analyzerSettings).utf8ToString()
    );
    if (tokenizer != null && !tokenizer.v2().isEmpty()) {
        encodedSettingsBuilder.put(
            TOKENIZER.buildSettingName(tokenizer.v1()),
            encodeSettings(tokenizer.v2()).utf8ToString()
        );
    }
    for (Map.Entry<String, Settings> tokenFilter : tokenFilters.entrySet()) {
        if (!tokenFilter.getValue().isEmpty()) {
            encodedSettingsBuilder.put(
                TOKEN_FILTER.buildSettingName(tokenFilter.getKey()),
                encodeSettings(tokenFilter.getValue()).utf8ToString()
            );
        }
    }
    for (Map.Entry<String, Settings> charFilter : charFilters.entrySet()) {
        if (!charFilter.getValue().isEmpty()) {
            encodedSettingsBuilder.put(
                CHAR_FILTER.buildSettingName(charFilter.getKey()),
                encodeSettings(charFilter.getValue()).utf8ToString()
            );
        }
    }

    return new ClusterUpdateSettingsRequest()
        .persistentSettings(encodedSettingsBuilder.build());
}
 
Example #20
Source File: UpdateClusterSettingsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<ClusterUpdateSettingsResponse> doExecute(ClusterUpdateSettingsRequest request) {
    return client.admin().cluster().updateSettings(request);
}
 
Example #21
Source File: UpdateClusterSettingsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public UpdateClusterSettingsRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new ClusterUpdateSettingsRequest(), jsonToString, stringToJson);
}
 
Example #22
Source File: DropAnalyzerTest.java    From crate with Apache License 2.0 4 votes vote down vote up
private ClusterUpdateSettingsRequest analyze(String stmt) {
    AnalyzedDropAnalyzer analyzedStatement = e.analyze(stmt);
    return DropAnalyzerPlan.createRequest(
        analyzedStatement.name(),
        e.fulltextAnalyzerResolver());
}
 
Example #23
Source File: DropAnalyzerTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testDropAnalyzer() {
    ClusterUpdateSettingsRequest request = analyze("DROP ANALYZER a1");
    assertIsMarkedToBeRemove(request.persistentSettings(), ANALYZER.buildSettingName("a1"));
}
 
Example #24
Source File: DropAnalyzerTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testDropAnalyzerWithCustomTokenizer() {
    ClusterUpdateSettingsRequest request = analyze("DROP ANALYZER a2");
    assertIsMarkedToBeRemove(request.persistentSettings(), ANALYZER.buildSettingName("a2"));
    assertIsMarkedToBeRemove(request.persistentSettings(), TOKENIZER.buildSettingName("a2_mypattern"));
}
 
Example #25
Source File: DropAnalyzerTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testDropAnalyzerWithCustomTokenFilter() {
    ClusterUpdateSettingsRequest request = analyze("DROP ANALYZER a3");
    assertIsMarkedToBeRemove(request.persistentSettings(), ANALYZER.buildSettingName("a3"));
    assertIsMarkedToBeRemove(request.persistentSettings(), TOKEN_FILTER.buildSettingName("a3_lowercase_german"));
}
 
Example #26
Source File: DropAnalyzerTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testDropAnalyzerWithCustomCharFilter() {
    ClusterUpdateSettingsRequest request = analyze("DROP ANALYZER a4");
    assertIsMarkedToBeRemove(request.persistentSettings(), ANALYZER.buildSettingName("a4"));
    assertIsMarkedToBeRemove(request.persistentSettings(), CHAR_FILTER.buildSettingName("a4_mymapping"));
}
 
Example #27
Source File: Requests.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static ClusterUpdateSettingsRequest clusterUpdateSettingsRequest() {
    return new ClusterUpdateSettingsRequest();
}
 
Example #28
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void updateSettings(final ClusterUpdateSettingsRequest request, final ActionListener<ClusterUpdateSettingsResponse> listener) {
    execute(ClusterUpdateSettingsAction.INSTANCE, request, listener);
}
 
Example #29
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<ClusterUpdateSettingsResponse> updateSettings(final ClusterUpdateSettingsRequest request) {
    return execute(ClusterUpdateSettingsAction.INSTANCE, request);
}
 
Example #30
Source File: DecommissioningService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private void removeDecommissioningSetting() {
    HashSet<String> settingsToRemove = Sets.newHashSet(DECOMMISSION_PREFIX + clusterService.localNode().id());
    updateSettingsAction.execute(new ClusterUpdateSettingsRequest().transientSettingsToRemove(settingsToRemove));
}