Search in sources :

Example 76 with Settings

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

the class SettingsUpdater method updateSettings.

synchronized ClusterState updateSettings(final ClusterState currentState, Settings transientToApply, Settings persistentToApply) {
    boolean changed = false;
    Settings.Builder transientSettings = Settings.builder();
    transientSettings.put(currentState.metaData().transientSettings());
    changed |= clusterSettings.updateDynamicSettings(transientToApply, transientSettings, transientUpdates, "transient");
    Settings.Builder persistentSettings = Settings.builder();
    persistentSettings.put(currentState.metaData().persistentSettings());
    changed |= clusterSettings.updateDynamicSettings(persistentToApply, persistentSettings, persistentUpdates, "persistent");
    if (!changed) {
        return currentState;
    }
    MetaData.Builder metaData = MetaData.builder(currentState.metaData()).persistentSettings(persistentSettings.build()).transientSettings(transientSettings.build());
    ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
    boolean updatedReadOnly = MetaData.SETTING_READ_ONLY_SETTING.get(metaData.persistentSettings()) || MetaData.SETTING_READ_ONLY_SETTING.get(metaData.transientSettings());
    if (updatedReadOnly) {
        blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);
    } else {
        blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);
    }
    ClusterState build = builder(currentState).metaData(metaData).blocks(blocks).build();
    Settings settings = build.metaData().settings();
    // now we try to apply things and if they are invalid we fail
    // this dryRun will validate & parse settings but won't actually apply them.
    clusterSettings.validateUpdate(settings);
    return build;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) MetaData(org.elasticsearch.cluster.metadata.MetaData) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 77 with Settings

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

the class EnableAllocationDecider method canRebalance.

@Override
public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "allocation is explicitly ignoring any disabling of relocation");
    }
    Settings indexSettings = allocation.metaData().getIndexSafe(shardRouting.index()).getSettings();
    final Rebalance enable;
    final boolean usedIndexSetting;
    if (INDEX_ROUTING_REBALANCE_ENABLE_SETTING.exists(indexSettings)) {
        enable = INDEX_ROUTING_REBALANCE_ENABLE_SETTING.get(indexSettings);
        usedIndexSetting = true;
    } else {
        enable = this.enableRebalance;
        usedIndexSetting = false;
    }
    switch(enable) {
        case ALL:
            return allocation.decision(Decision.YES, NAME, "all rebalancing is allowed");
        case NONE:
            return allocation.decision(Decision.NO, NAME, "no rebalancing is allowed due to %s", setting(enable, usedIndexSetting));
        case PRIMARIES:
            if (shardRouting.primary()) {
                return allocation.decision(Decision.YES, NAME, "primary rebalancing is allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "replica rebalancing is forbidden due to %s", setting(enable, usedIndexSetting));
            }
        case REPLICAS:
            if (shardRouting.primary() == false) {
                return allocation.decision(Decision.YES, NAME, "replica rebalancing is allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "primary rebalancing is forbidden due to %s", setting(enable, usedIndexSetting));
            }
        default:
            throw new IllegalStateException("Unknown rebalance option");
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 78 with Settings

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

the class RestUpdateSettingsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    UpdateSettingsRequest updateSettingsRequest = updateSettingsRequest(Strings.splitStringByCommaToArray(request.param("index")));
    updateSettingsRequest.timeout(request.paramAsTime("timeout", updateSettingsRequest.timeout()));
    updateSettingsRequest.setPreserveExisting(request.paramAsBoolean("preserve_existing", updateSettingsRequest.isPreserveExisting()));
    updateSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", updateSettingsRequest.masterNodeTimeout()));
    updateSettingsRequest.indicesOptions(IndicesOptions.fromRequest(request, updateSettingsRequest.indicesOptions()));
    Map<String, Object> settings = new HashMap<>();
    if (request.hasContent()) {
        try (XContentParser parser = request.contentParser()) {
            Map<String, Object> bodySettings = parser.map();
            Object innerBodySettings = bodySettings.get("settings");
            // clean up in case the body is wrapped with "settings" : { ... }
            if (innerBodySettings instanceof Map) {
                @SuppressWarnings("unchecked") Map<String, Object> innerBodySettingsMap = (Map<String, Object>) innerBodySettings;
                settings.putAll(innerBodySettingsMap);
            } else {
                settings.putAll(bodySettings);
            }
        }
    }
    updateSettingsRequest.settings(settings);
    return channel -> client.admin().indices().updateSettings(updateSettingsRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) RestController(org.elasticsearch.rest.RestController) Requests.updateSettingsRequest(org.elasticsearch.client.Requests.updateSettingsRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) Strings(org.elasticsearch.common.Strings) XContentParser(org.elasticsearch.common.xcontent.XContentParser) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 79 with Settings

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

the class RestGetSettingsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");
    final boolean renderDefaults = request.paramAsBoolean("include_defaults", false);
    GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(Strings.splitStringByCommaToArray(request.param("index"))).indicesOptions(IndicesOptions.fromRequest(request, IndicesOptions.strictExpandOpen())).humanReadable(request.hasParam("human")).names(names);
    getSettingsRequest.local(request.paramAsBoolean("local", getSettingsRequest.local()));
    return channel -> client.admin().indices().getSettings(getSettingsRequest, new RestBuilderListener<GetSettingsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSettingsResponse getSettingsResponse, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (ObjectObjectCursor<String, Settings> cursor : getSettingsResponse.getIndexToSettings()) {
                if (cursor.value.isEmpty()) {
                    continue;
                }
                builder.startObject(cursor.key);
                builder.startObject("settings");
                cursor.value.toXContent(builder, request);
                builder.endObject();
                if (renderDefaults) {
                    builder.startObject("defaults");
                    settingsFilter.filter(indexScopedSettings.diff(cursor.value, settings)).toXContent(builder, request);
                    builder.endObject();
                }
                builder.endObject();
            }
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) GET(org.elasticsearch.rest.RestRequest.Method.GET) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) IOException(java.io.IOException) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 80 with Settings

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

the class RestNodesInfoAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] nodeIds;
    Set<String> metrics;
    // this means one must differentiate between allowed metrics and arbitrary node ids in the same place
    if (request.hasParam("nodeId") && !request.hasParam("metrics")) {
        Set<String> metricsOrNodeIds = Strings.splitStringByCommaToSet(request.param("nodeId", "_all"));
        boolean isMetricsOnly = ALLOWED_METRICS.containsAll(metricsOrNodeIds);
        if (isMetricsOnly) {
            nodeIds = new String[] { "_all" };
            metrics = metricsOrNodeIds;
        } else {
            nodeIds = metricsOrNodeIds.toArray(new String[] {});
            metrics = Sets.newHashSet("_all");
        }
    } else {
        nodeIds = Strings.splitStringByCommaToArray(request.param("nodeId", "_all"));
        metrics = Strings.splitStringByCommaToSet(request.param("metrics", "_all"));
    }
    final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodeIds);
    nodesInfoRequest.timeout(request.param("timeout"));
    // shortcut, don't do checks if only all is specified
    if (metrics.size() == 1 && metrics.contains("_all")) {
        nodesInfoRequest.all();
    } else {
        nodesInfoRequest.clear();
        nodesInfoRequest.settings(metrics.contains("settings"));
        nodesInfoRequest.os(metrics.contains("os"));
        nodesInfoRequest.process(metrics.contains("process"));
        nodesInfoRequest.jvm(metrics.contains("jvm"));
        nodesInfoRequest.threadPool(metrics.contains("thread_pool"));
        nodesInfoRequest.transport(metrics.contains("transport"));
        nodesInfoRequest.http(metrics.contains("http"));
        nodesInfoRequest.plugins(metrics.contains("plugins"));
        nodesInfoRequest.ingest(metrics.contains("ingest"));
        nodesInfoRequest.indices(metrics.contains("indices"));
    }
    settingsFilter.addFilterSettingParams(request);
    return channel -> client.admin().cluster().nodesInfo(nodesInfoRequest, new NodesResponseRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) GET(org.elasticsearch.rest.RestRequest.Method.GET) Set(java.util.Set) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Sets(org.elasticsearch.common.util.set.Sets) Strings(org.elasticsearch.common.Strings) NodesResponseRestListener(org.elasticsearch.rest.action.RestActions.NodesResponseRestListener) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)874 IndexSettings (org.elasticsearch.index.IndexSettings)112 Path (java.nio.file.Path)91 IOException (java.io.IOException)83 ClusterState (org.elasticsearch.cluster.ClusterState)76 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)68 HashMap (java.util.HashMap)66 ArrayList (java.util.ArrayList)65 Version (org.elasticsearch.Version)63 Environment (org.elasticsearch.env.Environment)63 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)61 Test (org.junit.Test)60 Map (java.util.Map)55 Index (org.elasticsearch.index.Index)55 Matchers.containsString (org.hamcrest.Matchers.containsString)54 List (java.util.List)45 ThreadPool (org.elasticsearch.threadpool.ThreadPool)41 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)37 MetaData (org.elasticsearch.cluster.metadata.MetaData)36