entry : customs.entrySet()) {
- builder.field(entry.getKey(), entry.getValue(), params);
- }
-
return builder;
}
}
diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java
index bd8621a1a7d..34eccbf9d8a 100644
--- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java
+++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java
@@ -84,7 +84,6 @@ public class TransportPutIndexTemplateAction extends TransportMasterNodeAction> responseMap,
List indexResponses) {
- this.responseMap = responseMap;
- this.indexResponses = indexResponses;
+ this.responseMap = Objects.requireNonNull(responseMap);
+ this.indexResponses = Objects.requireNonNull(indexResponses);
}
/**
* Used for serialization
*/
FieldCapabilitiesResponse() {
- this.responseMap = Collections.emptyMap();
+ this(Collections.emptyMap(), Collections.emptyList());
}
/**
@@ -81,6 +82,7 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont
List getIndexResponses() {
return indexResponses;
}
+
/**
*
* Get the field capabilities per type for the provided {@code field}.
diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java
index ef0d19a2655..b8d1f477ac1 100644
--- a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java
+++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java
@@ -90,7 +90,7 @@ public class TransportFieldCapabilitiesAction extends HandledTransportAction innerListener = new ActionListener() {
@Override
diff --git a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java
index fecee5f265f..7514a41f575 100644
--- a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java
+++ b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java
@@ -171,9 +171,11 @@ public class SimulatePipelineRequest extends ActionRequest implements ToXContent
return new Parsed(pipeline, ingestDocumentList, verbose);
}
- static Parsed parse(Map config, boolean verbose, IngestService pipelineStore) throws Exception {
+ static Parsed parse(Map config, boolean verbose, IngestService ingestService) throws Exception {
Map pipelineConfig = ConfigurationUtils.readMap(null, null, config, Fields.PIPELINE);
- Pipeline pipeline = Pipeline.create(SIMULATED_PIPELINE_ID, pipelineConfig, pipelineStore.getProcessorFactories());
+ Pipeline pipeline = Pipeline.create(
+ SIMULATED_PIPELINE_ID, pipelineConfig, ingestService.getProcessorFactories(), ingestService.getScriptService()
+ );
List ingestDocumentList = parseDocs(config);
return new Parsed(pipeline, ingestDocumentList, verbose);
}
diff --git a/server/src/main/java/org/elasticsearch/client/Client.java b/server/src/main/java/org/elasticsearch/client/Client.java
index adb2f509b99..f97f618347a 100644
--- a/server/src/main/java/org/elasticsearch/client/Client.java
+++ b/server/src/main/java/org/elasticsearch/client/Client.java
@@ -455,7 +455,7 @@ public interface Client extends ElasticsearchClient, Releasable {
/**
* Builder for the field capabilities request.
*/
- FieldCapabilitiesRequestBuilder prepareFieldCaps();
+ FieldCapabilitiesRequestBuilder prepareFieldCaps(String... indices);
/**
* An action that returns the field capabilities from the provided request
diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java
index 86d9d2c445f..553c92e6de8 100644
--- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java
+++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java
@@ -651,8 +651,8 @@ public abstract class AbstractClient extends AbstractComponent implements Client
}
@Override
- public FieldCapabilitiesRequestBuilder prepareFieldCaps() {
- return new FieldCapabilitiesRequestBuilder(this, FieldCapabilitiesAction.INSTANCE);
+ public FieldCapabilitiesRequestBuilder prepareFieldCaps(String... indices) {
+ return new FieldCapabilitiesRequestBuilder(this, FieldCapabilitiesAction.INSTANCE, indices);
}
static class Admin implements AdminClient {
diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java
new file mode 100644
index 00000000000..4aa429f5704
--- /dev/null
+++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.cluster.metadata;
+
+import org.elasticsearch.cluster.Diff;
+import org.elasticsearch.cluster.Diffable;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.io.stream.StreamOutput;
+
+import java.io.IOException;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This is a {@code Map} that implements AbstractDiffable so it
+ * can be used for cluster state purposes
+ */
+public class DiffableStringMap extends AbstractMap implements Diffable {
+
+ private final Map innerMap;
+
+ DiffableStringMap(final Map map) {
+ this.innerMap = map;
+ }
+
+ @SuppressWarnings("unchecked")
+ DiffableStringMap(final StreamInput in) throws IOException {
+ this.innerMap = (Map) (Map) in.readMap();
+ }
+
+ @Override
+ public String put(String key, String value) {
+ return innerMap.put(key, value);
+ }
+
+ @Override
+ public Set> entrySet() {
+ return innerMap.entrySet();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void writeTo(StreamOutput out) throws IOException {
+ out.writeMap((Map) (Map) innerMap);
+ }
+
+ @Override
+ public Diff diff(DiffableStringMap previousState) {
+ return new DiffableStringMapDiff(previousState, this);
+ }
+
+ public static Diff readDiffFrom(StreamInput in) throws IOException {
+ return new DiffableStringMapDiff(in);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj instanceof DiffableStringMap) {
+ DiffableStringMap other = (DiffableStringMap) obj;
+ return innerMap.equals(other.innerMap);
+ } else if (obj instanceof Map) {
+ Map other = (Map) obj;
+ return innerMap.equals(other);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return innerMap.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "DiffableStringMap[" + innerMap.toString() + "]";
+ }
+
+ /**
+ * Represents differences between two DiffableStringMaps.
+ */
+ public static class DiffableStringMapDiff implements Diff {
+
+ private final List deletes;
+ private final Map upserts; // diffs also become upserts
+
+ private DiffableStringMapDiff(DiffableStringMap before, DiffableStringMap after) {
+ final List tempDeletes = new ArrayList<>();
+ final Map tempUpserts = new HashMap<>();
+ for (String key : before.keySet()) {
+ if (after.containsKey(key) == false) {
+ tempDeletes.add(key);
+ }
+ }
+
+ for (Map.Entry partIter : after.entrySet()) {
+ String beforePart = before.get(partIter.getKey());
+ if (beforePart == null) {
+ tempUpserts.put(partIter.getKey(), partIter.getValue());
+ } else if (partIter.getValue().equals(beforePart) == false) {
+ tempUpserts.put(partIter.getKey(), partIter.getValue());
+ }
+ }
+ deletes = tempDeletes;
+ upserts = tempUpserts;
+ }
+
+ private DiffableStringMapDiff(StreamInput in) throws IOException {
+ deletes = new ArrayList<>();
+ upserts = new HashMap<>();
+ int deletesCount = in.readVInt();
+ for (int i = 0; i < deletesCount; i++) {
+ deletes.add(in.readString());
+ }
+ int upsertsCount = in.readVInt();
+ for (int i = 0; i < upsertsCount; i++) {
+ String key = in.readString();
+ String newValue = in.readString();
+ upserts.put(key, newValue);
+ }
+ }
+
+ public List getDeletes() {
+ return deletes;
+ }
+
+ public Map> getDiffs() {
+ return Collections.emptyMap();
+ }
+
+ public Map getUpserts() {
+ return upserts;
+ }
+
+ @Override
+ public void writeTo(StreamOutput out) throws IOException {
+ out.writeVInt(deletes.size());
+ for (String delete : deletes) {
+ out.writeString(delete);
+ }
+ out.writeVInt(upserts.size());
+ for (Map.Entry entry : upserts.entrySet()) {
+ out.writeString(entry.getKey());
+ out.writeString(entry.getValue());
+ }
+ }
+
+ @Override
+ public DiffableStringMap apply(DiffableStringMap part) {
+ Map builder = new HashMap<>(part.innerMap);
+ List deletes = getDeletes();
+ for (String delete : deletes) {
+ builder.remove(delete);
+ }
+ assert getDiffs().size() == 0 : "there should never be diffs for DiffableStringMap";
+
+ for (Map.Entry upsert : upserts.entrySet()) {
+ builder.put(upsert.getKey(), upsert.getValue());
+ }
+ return new DiffableStringMap(builder);
+ }
+ }
+}
diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
index 11c489f63ab..e3af709ec5f 100644
--- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
+++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
@@ -23,7 +23,6 @@ import com.carrotsearch.hppc.LongArrayList;
import com.carrotsearch.hppc.cursors.IntObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
-
import org.elasticsearch.Assertions;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
@@ -65,7 +64,6 @@ import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
@@ -81,59 +79,6 @@ import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
public class IndexMetaData implements Diffable, ToXContentFragment {
- /**
- * This class will be removed in v7.0
- */
- @Deprecated
- public interface Custom extends Diffable, ToXContent {
-
- String type();
-
- Custom fromMap(Map map) throws IOException;
-
- Custom fromXContent(XContentParser parser) throws IOException;
-
- /**
- * Reads the {@link org.elasticsearch.cluster.Diff} from StreamInput
- */
- Diff readDiffFrom(StreamInput in) throws IOException;
-
- /**
- * Reads an object of this type from the provided {@linkplain StreamInput}. The receiving instance remains unchanged.
- */
- Custom readFrom(StreamInput in) throws IOException;
-
- /**
- * Merges from this to another, with this being more important, i.e., if something exists in this and another,
- * this will prevail.
- */
- Custom mergeWith(Custom another);
- }
-
- public static Map customPrototypes = new HashMap<>();
-
- /**
- * Register a custom index meta data factory. Make sure to call it from a static block.
- */
- public static void registerPrototype(String type, Custom proto) {
- customPrototypes.put(type, proto);
- }
-
- @Nullable
- public static T lookupPrototype(String type) {
- //noinspection unchecked
- return (T) customPrototypes.get(type);
- }
-
- public static T lookupPrototypeSafe(String type) {
- //noinspection unchecked
- T proto = (T) customPrototypes.get(type);
- if (proto == null) {
- throw new IllegalArgumentException("No custom metadata prototype registered for type [" + type + "]");
- }
- return proto;
- }
-
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(5, "index read-only (api)", false, false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE));
public static final ClusterBlock INDEX_READ_BLOCK = new ClusterBlock(7, "index read (api)", false, false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.READ));
public static final ClusterBlock INDEX_WRITE_BLOCK = new ClusterBlock(8, "index write (api)", false, false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE));
@@ -324,7 +269,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
private final ImmutableOpenMap mappings;
- private final ImmutableOpenMap customs;
+ private final ImmutableOpenMap customData;
private final ImmutableOpenIntMap> inSyncAllocationIds;
@@ -343,7 +288,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
private IndexMetaData(Index index, long version, long mappingVersion, long[] primaryTerms, State state, int numberOfShards, int numberOfReplicas, Settings settings,
ImmutableOpenMap mappings, ImmutableOpenMap aliases,
- ImmutableOpenMap customs, ImmutableOpenIntMap> inSyncAllocationIds,
+ ImmutableOpenMap customData, ImmutableOpenIntMap> inSyncAllocationIds,
DiscoveryNodeFilters requireFilters, DiscoveryNodeFilters initialRecoveryFilters, DiscoveryNodeFilters includeFilters, DiscoveryNodeFilters excludeFilters,
Version indexCreatedVersion, Version indexUpgradedVersion,
int routingNumShards, int routingPartitionSize, ActiveShardCount waitForActiveShards, ImmutableOpenMap rolloverInfos) {
@@ -360,7 +305,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
this.totalNumberOfShards = numberOfShards * (numberOfReplicas + 1);
this.settings = settings;
this.mappings = mappings;
- this.customs = customs;
+ this.customData = customData;
this.aliases = aliases;
this.inSyncAllocationIds = inSyncAllocationIds;
this.requireFilters = requireFilters;
@@ -485,22 +430,14 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
return mappings.get(mappingType);
}
- // we keep the shrink settings for BWC - this can be removed in 8.0
- // we can't remove in 7 since this setting might be baked into an index coming in via a full cluster restart from 6.0
- public static final String INDEX_SHRINK_SOURCE_UUID_KEY = "index.shrink.source.uuid";
- public static final String INDEX_SHRINK_SOURCE_NAME_KEY = "index.shrink.source.name";
public static final String INDEX_RESIZE_SOURCE_UUID_KEY = "index.resize.source.uuid";
public static final String INDEX_RESIZE_SOURCE_NAME_KEY = "index.resize.source.name";
- public static final Setting INDEX_SHRINK_SOURCE_UUID = Setting.simpleString(INDEX_SHRINK_SOURCE_UUID_KEY);
- public static final Setting INDEX_SHRINK_SOURCE_NAME = Setting.simpleString(INDEX_SHRINK_SOURCE_NAME_KEY);
- public static final Setting INDEX_RESIZE_SOURCE_UUID = Setting.simpleString(INDEX_RESIZE_SOURCE_UUID_KEY,
- INDEX_SHRINK_SOURCE_UUID);
- public static final Setting INDEX_RESIZE_SOURCE_NAME = Setting.simpleString(INDEX_RESIZE_SOURCE_NAME_KEY,
- INDEX_SHRINK_SOURCE_NAME);
+ public static final Setting INDEX_RESIZE_SOURCE_UUID = Setting.simpleString(INDEX_RESIZE_SOURCE_UUID_KEY);
+ public static final Setting INDEX_RESIZE_SOURCE_NAME = Setting.simpleString(INDEX_RESIZE_SOURCE_NAME_KEY);
public Index getResizeSourceIndex() {
- return INDEX_RESIZE_SOURCE_UUID.exists(settings) || INDEX_SHRINK_SOURCE_UUID.exists(settings)
- ? new Index(INDEX_RESIZE_SOURCE_NAME.get(settings), INDEX_RESIZE_SOURCE_UUID.get(settings)) : null;
+ return INDEX_RESIZE_SOURCE_UUID.exists(settings) ? new Index(INDEX_RESIZE_SOURCE_NAME.get(settings),
+ INDEX_RESIZE_SOURCE_UUID.get(settings)) : null;
}
/**
@@ -519,13 +456,12 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
return mappings.get(MapperService.DEFAULT_MAPPING);
}
- public ImmutableOpenMap getCustoms() {
- return this.customs;
+ ImmutableOpenMap getCustomData() {
+ return this.customData;
}
- @SuppressWarnings("unchecked")
- public T custom(String type) {
- return (T) customs.get(type);
+ public Map getCustomData(final String key) {
+ return Collections.unmodifiableMap(this.customData.get(key));
}
public ImmutableOpenIntMap> getInSyncAllocationIds() {
@@ -591,7 +527,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
if (state != that.state) {
return false;
}
- if (!customs.equals(that.customs)) {
+ if (!customData.equals(that.customData)) {
return false;
}
if (routingNumShards != that.routingNumShards) {
@@ -620,7 +556,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
result = 31 * result + aliases.hashCode();
result = 31 * result + settings.hashCode();
result = 31 * result + mappings.hashCode();
- result = 31 * result + customs.hashCode();
+ result = 31 * result + customData.hashCode();
result = 31 * result + Long.hashCode(routingFactor);
result = 31 * result + Long.hashCode(routingNumShards);
result = 31 * result + Arrays.hashCode(primaryTerms);
@@ -660,7 +596,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
private final Settings settings;
private final Diff> mappings;
private final Diff> aliases;
- private final Diff> customs;
+ private final Diff> customData;
private final Diff>> inSyncAllocationIds;
private final Diff> rolloverInfos;
@@ -674,7 +610,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
primaryTerms = after.primaryTerms;
mappings = DiffableUtils.diff(before.mappings, after.mappings, DiffableUtils.getStringKeySerializer());
aliases = DiffableUtils.diff(before.aliases, after.aliases, DiffableUtils.getStringKeySerializer());
- customs = DiffableUtils.diff(before.customs, after.customs, DiffableUtils.getStringKeySerializer());
+ customData = DiffableUtils.diff(before.customData, after.customData, DiffableUtils.getStringKeySerializer());
inSyncAllocationIds = DiffableUtils.diff(before.inSyncAllocationIds, after.inSyncAllocationIds,
DiffableUtils.getVIntKeySerializer(), DiffableUtils.StringSetValueSerializer.getInstance());
rolloverInfos = DiffableUtils.diff(before.rolloverInfos, after.rolloverInfos, DiffableUtils.getStringKeySerializer());
@@ -696,18 +632,8 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
MappingMetaData::readDiffFrom);
aliases = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), AliasMetaData::new,
AliasMetaData::readDiffFrom);
- customs = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(),
- new DiffableUtils.DiffableValueSerializer() {
- @Override
- public Custom read(StreamInput in, String key) throws IOException {
- return lookupPrototypeSafe(key).readFrom(in);
- }
-
- @Override
- public Diff readDiff(StreamInput in, String key) throws IOException {
- return lookupPrototypeSafe(key).readDiffFrom(in);
- }
- });
+ customData = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), DiffableStringMap::new,
+ DiffableStringMap::readDiffFrom);
inSyncAllocationIds = DiffableUtils.readImmutableOpenIntMapDiff(in, DiffableUtils.getVIntKeySerializer(),
DiffableUtils.StringSetValueSerializer.getInstance());
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
@@ -732,7 +658,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
out.writeVLongArray(primaryTerms);
mappings.writeTo(out);
aliases.writeTo(out);
- customs.writeTo(out);
+ customData.writeTo(out);
inSyncAllocationIds.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
rolloverInfos.writeTo(out);
@@ -750,7 +676,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
builder.primaryTerms(primaryTerms);
builder.mappings.putAll(mappings.apply(part.mappings));
builder.aliases.putAll(aliases.apply(part.aliases));
- builder.customs.putAll(customs.apply(part.customs));
+ builder.customMetaData.putAll(customData.apply(part.customData));
builder.inSyncAllocationIds.putAll(inSyncAllocationIds.apply(part.inSyncAllocationIds));
builder.rolloverInfos.putAll(rolloverInfos.apply(part.rolloverInfos));
return builder.build();
@@ -780,10 +706,17 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
builder.putAlias(aliasMd);
}
int customSize = in.readVInt();
- for (int i = 0; i < customSize; i++) {
- String type = in.readString();
- Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in);
- builder.putCustom(type, customIndexMetaData);
+ if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
+ for (int i = 0; i < customSize; i++) {
+ String key = in.readString();
+ DiffableStringMap custom = new DiffableStringMap(in);
+ builder.putCustom(key, custom);
+ }
+ } else {
+ assert customSize == 0 : "expected no custom index metadata";
+ if (customSize > 0) {
+ throw new IllegalStateException("unexpected custom metadata when none is supported");
+ }
}
int inSyncAllocationIdsSize = in.readVInt();
for (int i = 0; i < inSyncAllocationIdsSize; i++) {
@@ -819,10 +752,14 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
for (ObjectCursor cursor : aliases.values()) {
cursor.value.writeTo(out);
}
- out.writeVInt(customs.size());
- for (ObjectObjectCursor cursor : customs) {
- out.writeString(cursor.key);
- cursor.value.writeTo(out);
+ if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
+ out.writeVInt(customData.size());
+ for (final ObjectObjectCursor cursor : customData) {
+ out.writeString(cursor.key);
+ cursor.value.writeTo(out);
+ }
+ } else {
+ out.writeVInt(0);
}
out.writeVInt(inSyncAllocationIds.size());
for (IntObjectCursor> cursor : inSyncAllocationIds) {
@@ -855,7 +792,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
private Settings settings = Settings.Builder.EMPTY_SETTINGS;
private final ImmutableOpenMap.Builder mappings;
private final ImmutableOpenMap.Builder aliases;
- private final ImmutableOpenMap.Builder customs;
+ private final ImmutableOpenMap.Builder customMetaData;
private final ImmutableOpenIntMap.Builder> inSyncAllocationIds;
private final ImmutableOpenMap.Builder rolloverInfos;
private Integer routingNumShards;
@@ -864,7 +801,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
this.index = index;
this.mappings = ImmutableOpenMap.builder();
this.aliases = ImmutableOpenMap.builder();
- this.customs = ImmutableOpenMap.builder();
+ this.customMetaData = ImmutableOpenMap.builder();
this.inSyncAllocationIds = ImmutableOpenIntMap.builder();
this.rolloverInfos = ImmutableOpenMap.builder();
}
@@ -878,7 +815,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
this.primaryTerms = indexMetaData.primaryTerms.clone();
this.mappings = ImmutableOpenMap.builder(indexMetaData.mappings);
this.aliases = ImmutableOpenMap.builder(indexMetaData.aliases);
- this.customs = ImmutableOpenMap.builder(indexMetaData.customs);
+ this.customMetaData = ImmutableOpenMap.builder(indexMetaData.customData);
this.routingNumShards = indexMetaData.routingNumShards;
this.inSyncAllocationIds = ImmutableOpenIntMap.builder(indexMetaData.inSyncAllocationIds);
this.rolloverInfos = ImmutableOpenMap.builder(indexMetaData.rolloverInfos);
@@ -1008,8 +945,8 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
return this;
}
- public Builder putCustom(String type, Custom customIndexMetaData) {
- this.customs.put(type, customIndexMetaData);
+ public Builder putCustom(String type, Map customIndexMetaData) {
+ this.customMetaData.put(type, new DiffableStringMap(customIndexMetaData));
return this;
}
@@ -1177,7 +1114,7 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
final String uuid = settings.get(SETTING_INDEX_UUID, INDEX_UUID_NA_VALUE);
return new IndexMetaData(new Index(index, uuid), version, mappingVersion, primaryTerms, state, numberOfShards, numberOfReplicas, tmpSettings, mappings.build(),
- tmpAliases.build(), customs.build(), filledInSyncAllocationIds.build(), requireFilters, initialRecoveryFilters, includeFilters, excludeFilters,
+ tmpAliases.build(), customMetaData.build(), filledInSyncAllocationIds.build(), requireFilters, initialRecoveryFilters, includeFilters, excludeFilters,
indexCreatedVersion, indexUpgradedVersion, getRoutingNumShards(), routingPartitionSize, waitForActiveShards, rolloverInfos.build());
}
@@ -1205,10 +1142,9 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
}
builder.endArray();
- for (ObjectObjectCursor cursor : indexMetaData.getCustoms()) {
- builder.startObject(cursor.key);
- cursor.value.toXContent(builder, params);
- builder.endObject();
+ for (ObjectObjectCursor cursor : indexMetaData.customData) {
+ builder.field(cursor.key);
+ builder.map(cursor.value);
}
builder.startObject(KEY_ALIASES);
@@ -1317,15 +1253,8 @@ public class IndexMetaData implements Diffable, ToXContentFragmen
assert Version.CURRENT.major <= 5;
parser.skipChildren();
} else {
- // check if its a custom index metadata
- Custom proto = lookupPrototype(currentFieldName);
- if (proto == null) {
- //TODO warn
- parser.skipChildren();
- } else {
- Custom custom = proto.fromXContent(parser);
- builder.putCustom(custom.type(), custom);
- }
+ // assume it's custom index metadata
+ builder.putCustom(currentFieldName, parser.mapStrings());
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (KEY_MAPPINGS.equals(currentFieldName)) {
diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java
index d35a4baa1e6..c3f0f86e3e9 100644
--- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java
+++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java
@@ -20,7 +20,7 @@ package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
-
+import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.AbstractDiffable;
import org.elasticsearch.cluster.Diff;
@@ -87,13 +87,10 @@ public class IndexTemplateMetaData extends AbstractDiffable aliases;
- private final ImmutableOpenMap customs;
-
public IndexTemplateMetaData(String name, int order, Integer version,
List patterns, Settings settings,
ImmutableOpenMap mappings,
- ImmutableOpenMap aliases,
- ImmutableOpenMap customs) {
+ ImmutableOpenMap aliases) {
if (patterns == null || patterns.isEmpty()) {
throw new IllegalArgumentException("Index patterns must not be null or empty; got " + patterns);
}
@@ -104,7 +101,6 @@ public class IndexTemplateMetaData extends AbstractDiffable customs() {
- return this.customs;
- }
-
- public ImmutableOpenMap getCustoms() {
- return this.customs;
- }
-
- @SuppressWarnings("unchecked")
- public T custom(String type) {
- return (T) customs.get(type);
- }
-
public static Builder builder(String name) {
return new Builder(name);
}
@@ -227,11 +210,13 @@ public class IndexTemplateMetaData extends AbstractDiffable 0) {
+ throw new IllegalStateException("unexpected custom metadata when none is supported");
+ }
}
builder.version(in.readOptionalVInt());
return builder.build();
@@ -260,10 +245,8 @@ public class IndexTemplateMetaData extends AbstractDiffable cursor : aliases.values()) {
cursor.value.writeTo(out);
}
- out.writeVInt(customs.size());
- for (ObjectObjectCursor cursor : customs) {
- out.writeString(cursor.key);
- cursor.value.writeTo(out);
+ if (out.getVersion().before(Version.V_7_0_0_alpha1)) {
+ out.writeVInt(0);
}
out.writeOptionalVInt(version);
}
@@ -272,9 +255,6 @@ public class IndexTemplateMetaData extends AbstractDiffable VALID_FIELDS = Sets.newHashSet(
"template", "order", "mappings", "settings", "index_patterns", "aliases", "version");
- static {
- VALID_FIELDS.addAll(IndexMetaData.customPrototypes.keySet());
- }
private String name;
@@ -290,13 +270,10 @@ public class IndexTemplateMetaData extends AbstractDiffable aliases;
- private final ImmutableOpenMap.Builder customs;
-
public Builder(String name) {
this.name = name;
mappings = ImmutableOpenMap.builder();
aliases = ImmutableOpenMap.builder();
- customs = ImmutableOpenMap.builder();
}
public Builder(IndexTemplateMetaData indexTemplateMetaData) {
@@ -308,7 +285,6 @@ public class IndexTemplateMetaData extends AbstractDiffable