Search in sources :

Example 66 with Settings

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

the class GetIndexResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeStringArray(indices);
    out.writeVInt(mappings.size());
    for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexEntry : mappings) {
        out.writeString(indexEntry.key);
        out.writeVInt(indexEntry.value.size());
        for (ObjectObjectCursor<String, MappingMetaData> mappingEntry : indexEntry.value) {
            out.writeString(mappingEntry.key);
            mappingEntry.value.writeTo(out);
        }
    }
    out.writeVInt(aliases.size());
    for (ObjectObjectCursor<String, List<AliasMetaData>> indexEntry : aliases) {
        out.writeString(indexEntry.key);
        out.writeVInt(indexEntry.value.size());
        for (AliasMetaData aliasEntry : indexEntry.value) {
            aliasEntry.writeTo(out);
        }
    }
    out.writeVInt(settings.size());
    for (ObjectObjectCursor<String, Settings> indexEntry : settings) {
        out.writeString(indexEntry.key);
        Settings.writeSettingsToStream(indexEntry.value, out);
    }
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Settings(org.elasticsearch.common.settings.Settings)

Example 67 with Settings

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

the class GetIndexResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    this.indices = in.readStringArray();
    int mappingsSize = in.readVInt();
    ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappingsMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < mappingsSize; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        ImmutableOpenMap.Builder<String, MappingMetaData> mappingEntryBuilder = ImmutableOpenMap.builder();
        for (int j = 0; j < valueSize; j++) {
            mappingEntryBuilder.put(in.readString(), new MappingMetaData(in));
        }
        mappingsMapBuilder.put(key, mappingEntryBuilder.build());
    }
    mappings = mappingsMapBuilder.build();
    int aliasesSize = in.readVInt();
    ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliasesMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < aliasesSize; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        List<AliasMetaData> aliasEntryBuilder = new ArrayList<>();
        for (int j = 0; j < valueSize; j++) {
            aliasEntryBuilder.add(new AliasMetaData(in));
        }
        aliasesMapBuilder.put(key, Collections.unmodifiableList(aliasEntryBuilder));
    }
    aliases = aliasesMapBuilder.build();
    int settingsSize = in.readVInt();
    ImmutableOpenMap.Builder<String, Settings> settingsMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < settingsSize; i++) {
        String key = in.readString();
        settingsMapBuilder.put(key, Settings.readSettingsFromStream(in));
    }
    settings = settingsMapBuilder.build();
}
Also used : ArrayList(java.util.ArrayList) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) List(java.util.List) ArrayList(java.util.ArrayList) Settings(org.elasticsearch.common.settings.Settings)

Example 68 with Settings

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

the class TransportGetIndexAction method doMasterOperation.

@Override
protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state, final ActionListener<GetIndexResponse> listener) {
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsResult = ImmutableOpenMap.of();
    ImmutableOpenMap<String, List<AliasMetaData>> aliasesResult = ImmutableOpenMap.of();
    ImmutableOpenMap<String, Settings> settings = ImmutableOpenMap.of();
    Feature[] features = request.features();
    boolean doneAliases = false;
    boolean doneMappings = false;
    boolean doneSettings = false;
    for (Feature feature : features) {
        switch(feature) {
            case MAPPINGS:
                if (!doneMappings) {
                    mappingsResult = state.metaData().findMappings(concreteIndices, request.types());
                    doneMappings = true;
                }
                break;
            case ALIASES:
                if (!doneAliases) {
                    aliasesResult = state.metaData().findAliases(Strings.EMPTY_ARRAY, concreteIndices);
                    doneAliases = true;
                }
                break;
            case SETTINGS:
                if (!doneSettings) {
                    ImmutableOpenMap.Builder<String, Settings> settingsMapBuilder = ImmutableOpenMap.builder();
                    for (String index : concreteIndices) {
                        Settings indexSettings = state.metaData().index(index).getSettings();
                        if (request.humanReadable()) {
                            indexSettings = IndexMetaData.addHumanReadableSettings(indexSettings);
                        }
                        settingsMapBuilder.put(index, indexSettings);
                    }
                    settings = settingsMapBuilder.build();
                    doneSettings = true;
                }
                break;
            default:
                throw new IllegalStateException("feature [" + feature + "] is not valid");
        }
    }
    listener.onResponse(new GetIndexResponse(concreteIndices, mappingsResult, aliasesResult, settings));
}
Also used : ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) Feature(org.elasticsearch.action.admin.indices.get.GetIndexRequest.Feature) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings)

Example 69 with Settings

use of org.graylog.shaded.elasticsearch7.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 70 with Settings

use of org.graylog.shaded.elasticsearch7.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)

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