|
|
@@ -20,6 +20,8 @@
|
|
|
package org.elasticsearch.action.admin.indices.alias;
|
|
|
|
|
|
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
|
|
+
|
|
|
+import org.elasticsearch.ElasticsearchGenerationException;
|
|
|
import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
import org.elasticsearch.action.AliasesRequest;
|
|
|
import org.elasticsearch.action.CompositeIndicesRequest;
|
|
|
@@ -27,30 +29,41 @@ import org.elasticsearch.action.IndicesRequest;
|
|
|
import org.elasticsearch.action.support.IndicesOptions;
|
|
|
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
|
|
import org.elasticsearch.cluster.metadata.AliasAction;
|
|
|
-import org.elasticsearch.cluster.metadata.AliasAction.Type;
|
|
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
|
|
import org.elasticsearch.cluster.metadata.MetaData;
|
|
|
+import org.elasticsearch.common.ParseField;
|
|
|
+import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
|
+import org.elasticsearch.common.ParsingException;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
-import org.elasticsearch.common.util.CollectionUtils;
|
|
|
+import org.elasticsearch.common.io.stream.Writeable;
|
|
|
+import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
|
|
+import org.elasticsearch.common.xcontent.ObjectParser;
|
|
|
+import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
|
|
+import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
+import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
+import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
-import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
import static org.elasticsearch.action.ValidateActions.addValidationError;
|
|
|
-import static org.elasticsearch.cluster.metadata.AliasAction.readAliasAction;
|
|
|
+import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
|
|
+import static org.elasticsearch.common.xcontent.ObjectParser.fromList;
|
|
|
|
|
|
/**
|
|
|
* A request to add/remove aliases for one or more indices.
|
|
|
*/
|
|
|
public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesRequest> implements CompositeIndicesRequest {
|
|
|
-
|
|
|
private List<AliasActions> allAliasActions = new ArrayList<>();
|
|
|
|
|
|
//indices options that require every specified index to exist, expand wildcards only to open indices and
|
|
|
@@ -61,94 +74,317 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|
|
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * Aliases can be added by passing multiple indices to the Request and
|
|
|
- * deleted by passing multiple indices and aliases. They are expanded into
|
|
|
- * distinct AliasAction instances when the request is processed. This class
|
|
|
- * holds the AliasAction and in addition the arrays or alias names and
|
|
|
- * indices that is later used to create the final AliasAction instances.
|
|
|
+ /**
|
|
|
+ * Request to take one or more actions on one or more indexes and alias combinations.
|
|
|
*/
|
|
|
- public static class AliasActions implements AliasesRequest {
|
|
|
- private String[] indices = Strings.EMPTY_ARRAY;
|
|
|
- private String[] aliases = Strings.EMPTY_ARRAY;
|
|
|
- private AliasAction aliasAction;
|
|
|
+ public static class AliasActions implements AliasesRequest, Writeable {
|
|
|
+ public enum Type {
|
|
|
+ ADD((byte) 0),
|
|
|
+ REMOVE((byte) 1),
|
|
|
+ REMOVE_INDEX((byte) 2);
|
|
|
+
|
|
|
+ private final byte value;
|
|
|
+
|
|
|
+ Type(byte value) {
|
|
|
+ this.value = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public byte value() {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
|
|
|
- public AliasActions(AliasAction.Type type, String[] indices, String[] aliases) {
|
|
|
- aliasAction = new AliasAction(type);
|
|
|
- indices(indices);
|
|
|
- aliases(aliases);
|
|
|
+ public static Type fromValue(byte value) {
|
|
|
+ switch (value) {
|
|
|
+ case 0: return ADD;
|
|
|
+ case 1: return REMOVE;
|
|
|
+ case 2: return REMOVE_INDEX;
|
|
|
+ default: throw new IllegalArgumentException("No type for action [" + value + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public AliasActions(AliasAction.Type type, String index, String alias) {
|
|
|
- aliasAction = new AliasAction(type);
|
|
|
- indices(index);
|
|
|
- aliases(alias);
|
|
|
+ /**
|
|
|
+ * Build a new {@link AliasAction} to add aliases.
|
|
|
+ */
|
|
|
+ public static AliasActions add() {
|
|
|
+ return new AliasActions(AliasActions.Type.ADD);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Build a new {@link AliasAction} to remove aliases.
|
|
|
+ */
|
|
|
+ public static AliasActions remove() {
|
|
|
+ return new AliasActions(AliasActions.Type.REMOVE);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Build a new {@link AliasAction} to remove aliases.
|
|
|
+ */
|
|
|
+ public static AliasActions removeIndex() {
|
|
|
+ return new AliasActions(AliasActions.Type.REMOVE_INDEX);
|
|
|
+ }
|
|
|
+ private static ObjectParser<AliasActions, ParseFieldMatcherSupplier> parser(String name, Supplier<AliasActions> supplier) {
|
|
|
+ ObjectParser<AliasActions, ParseFieldMatcherSupplier> parser = new ObjectParser<>(name, supplier);
|
|
|
+ parser.declareString((action, index) -> {
|
|
|
+ if (action.indices() != null) {
|
|
|
+ throw new IllegalArgumentException("Only one of [index] and [indices] is supported");
|
|
|
+ }
|
|
|
+ action.index(index);
|
|
|
+ }, new ParseField("index"));
|
|
|
+ parser.declareStringArray(fromList(String.class, (action, indices) -> {
|
|
|
+ if (action.indices() != null) {
|
|
|
+ throw new IllegalArgumentException("Only one of [index] and [indices] is supported");
|
|
|
+ }
|
|
|
+ action.indices(indices);
|
|
|
+ }), new ParseField("indices"));
|
|
|
+ parser.declareString((action, alias) -> {
|
|
|
+ if (action.aliases() != null && action.aliases().length != 0) {
|
|
|
+ throw new IllegalArgumentException("Only one of [alias] and [aliases] is supported");
|
|
|
+ }
|
|
|
+ action.alias(alias);
|
|
|
+ }, new ParseField("alias"));
|
|
|
+ parser.declareStringArray(fromList(String.class, (action, aliases) -> {
|
|
|
+ if (action.aliases() != null && action.aliases().length != 0) {
|
|
|
+ throw new IllegalArgumentException("Only one of [alias] and [aliases] is supported");
|
|
|
+ }
|
|
|
+ action.aliases(aliases);
|
|
|
+ }), new ParseField("aliases"));
|
|
|
+ return parser;
|
|
|
}
|
|
|
|
|
|
- AliasActions(AliasAction.Type type, String[] index, String alias) {
|
|
|
- aliasAction = new AliasAction(type);
|
|
|
- indices(index);
|
|
|
- aliases(alias);
|
|
|
+ private static final ObjectParser<AliasActions, ParseFieldMatcherSupplier> ADD_PARSER = parser("add", AliasActions::add);
|
|
|
+ static {
|
|
|
+ ADD_PARSER.declareObject(AliasActions::filter, (parser, m) -> {
|
|
|
+ try {
|
|
|
+ return parser.mapOrdered();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ParsingException(parser.getTokenLocation(), "Problems parsing [filter]", e);
|
|
|
+ }
|
|
|
+ }, new ParseField("filter"));
|
|
|
+ // Since we need to support numbers AND strings here we have to use ValueType.INT.
|
|
|
+ ADD_PARSER.declareField(AliasActions::routing, p -> p.text(), new ParseField("routing"), ValueType.INT);
|
|
|
+ ADD_PARSER.declareField(AliasActions::indexRouting, p -> p.text(), new ParseField("index_routing"), ValueType.INT);
|
|
|
+ ADD_PARSER.declareField(AliasActions::searchRouting, p -> p.text(), new ParseField("search_routing"), ValueType.INT);
|
|
|
+ }
|
|
|
+ private static final ObjectParser<AliasActions, ParseFieldMatcherSupplier> REMOVE_PARSER = parser("remove", AliasActions::remove);
|
|
|
+ private static final ObjectParser<AliasActions, ParseFieldMatcherSupplier> REMOVE_INDEX_PARSER = parser("remove_index",
|
|
|
+ AliasActions::removeIndex);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Parser for any one {@link AliasAction}.
|
|
|
+ */
|
|
|
+ public static final ConstructingObjectParser<AliasActions, ParseFieldMatcherSupplier> PARSER = new ConstructingObjectParser<>(
|
|
|
+ "alias_action", a -> {
|
|
|
+ // Take the first action and complain if there are more than one actions
|
|
|
+ AliasActions action = null;
|
|
|
+ for (Object o : a) {
|
|
|
+ if (o != null) {
|
|
|
+ if (action == null) {
|
|
|
+ action = (AliasActions) o;
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException("Too many operations declared in on opeation entry");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return action;
|
|
|
+ });
|
|
|
+ static {
|
|
|
+ PARSER.declareObject(optionalConstructorArg(), ADD_PARSER, new ParseField("add"));
|
|
|
+ PARSER.declareObject(optionalConstructorArg(), REMOVE_PARSER, new ParseField("remove"));
|
|
|
+ PARSER.declareObject(optionalConstructorArg(), REMOVE_INDEX_PARSER, new ParseField("remove_index"));
|
|
|
}
|
|
|
|
|
|
- public AliasActions(AliasAction action) {
|
|
|
- this.aliasAction = action;
|
|
|
- indices(action.index());
|
|
|
- aliases(action.alias());
|
|
|
+ private final AliasActions.Type type;
|
|
|
+ private String[] indices;
|
|
|
+ private String[] aliases = Strings.EMPTY_ARRAY;
|
|
|
+ private String filter;
|
|
|
+ private String routing;
|
|
|
+ private String indexRouting;
|
|
|
+ private String searchRouting;
|
|
|
+
|
|
|
+ AliasActions(AliasActions.Type type) {
|
|
|
+ this.type = type;
|
|
|
}
|
|
|
|
|
|
- public AliasActions(Type type, String index, String[] aliases) {
|
|
|
- aliasAction = new AliasAction(type);
|
|
|
- indices(index);
|
|
|
- aliases(aliases);
|
|
|
+ /**
|
|
|
+ * Read from a stream.
|
|
|
+ */
|
|
|
+ public AliasActions(StreamInput in) throws IOException {
|
|
|
+ type = AliasActions.Type.fromValue(in.readByte());
|
|
|
+ indices = in.readStringArray();
|
|
|
+ aliases = in.readStringArray();
|
|
|
+ filter = in.readOptionalString();
|
|
|
+ routing = in.readOptionalString();
|
|
|
+ searchRouting = in.readOptionalString();
|
|
|
+ indexRouting = in.readOptionalString();
|
|
|
}
|
|
|
|
|
|
- public AliasActions() {
|
|
|
+ @Override
|
|
|
+ public void writeTo(StreamOutput out) throws IOException {
|
|
|
+ out.writeByte(type.value());
|
|
|
+ out.writeStringArray(indices);
|
|
|
+ out.writeStringArray(aliases);
|
|
|
+ out.writeOptionalString(filter);
|
|
|
+ out.writeOptionalString(routing);
|
|
|
+ out.writeOptionalString(searchRouting);
|
|
|
+ out.writeOptionalString(indexRouting);
|
|
|
}
|
|
|
|
|
|
- public AliasActions filter(Map<String, Object> filter) {
|
|
|
- aliasAction.filter(filter);
|
|
|
+ /**
|
|
|
+ * Validate that the action is sane. Called when the action is added to the request because actions can be invalid while being
|
|
|
+ * built.
|
|
|
+ */
|
|
|
+ void validate() {
|
|
|
+ if (indices == null) {
|
|
|
+ throw new IllegalArgumentException("One of [index] or [indices] is required");
|
|
|
+ }
|
|
|
+ if (type != AliasActions.Type.REMOVE_INDEX && (aliases == null || aliases.length == 0)) {
|
|
|
+ throw new IllegalArgumentException("One of [alias] or [aliases] is required");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Type of the action to perform.
|
|
|
+ */
|
|
|
+ public AliasActions.Type actionType() {
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AliasActions indices(String... indices) {
|
|
|
+ if (indices == null || indices.length == 0) {
|
|
|
+ throw new IllegalArgumentException("[indices] can't be empty");
|
|
|
+ }
|
|
|
+ for (String index : indices) {
|
|
|
+ if (false == Strings.hasLength(index)) {
|
|
|
+ throw new IllegalArgumentException("[indices] can't contain empty string");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.indices = indices;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public AliasActions filter(QueryBuilder filter) {
|
|
|
- aliasAction.filter(filter);
|
|
|
+ /**
|
|
|
+ * Set the index this action is operating on.
|
|
|
+ */
|
|
|
+ public AliasActions index(String index) {
|
|
|
+ if (false == Strings.hasLength(index)) {
|
|
|
+ throw new IllegalArgumentException("[index] can't be empty string");
|
|
|
+ }
|
|
|
+ this.indices = new String[] {index};
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Type actionType() {
|
|
|
- return aliasAction.actionType();
|
|
|
+ /**
|
|
|
+ * Aliases to use with this action.
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AliasActions aliases(String... aliases) {
|
|
|
+ if (type == AliasActions.Type.REMOVE_INDEX) {
|
|
|
+ throw new IllegalArgumentException("[aliases] is unsupported for [" + type + "]");
|
|
|
+ }
|
|
|
+ if (aliases == null || aliases.length == 0) {
|
|
|
+ throw new IllegalArgumentException("[aliases] can't be empty");
|
|
|
+ }
|
|
|
+ for (String alias : aliases) {
|
|
|
+ if (false == Strings.hasLength(alias)) {
|
|
|
+ throw new IllegalArgumentException("[aliases] can't contain empty string");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.aliases = aliases;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
- public void routing(String routing) {
|
|
|
- aliasAction.routing(routing);
|
|
|
+ /**
|
|
|
+ * Set the alias this action is operating on.
|
|
|
+ */
|
|
|
+ public AliasActions alias(String alias) {
|
|
|
+ if (type == AliasActions.Type.REMOVE_INDEX) {
|
|
|
+ throw new IllegalArgumentException("[alias] is unsupported for [" + type + "]");
|
|
|
+ }
|
|
|
+ if (false == Strings.hasLength(alias)) {
|
|
|
+ throw new IllegalArgumentException("[alias] can't be empty string");
|
|
|
+ }
|
|
|
+ this.aliases = new String[] {alias};
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
- public void searchRouting(String searchRouting) {
|
|
|
- aliasAction.searchRouting(searchRouting);
|
|
|
+ /**
|
|
|
+ * Set the default routing.
|
|
|
+ */
|
|
|
+ public AliasActions routing(String routing) {
|
|
|
+ if (type != AliasActions.Type.ADD) {
|
|
|
+ throw new IllegalArgumentException("[routing] is unsupported for [" + type + "]");
|
|
|
+ }
|
|
|
+ this.routing = routing;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
- public void indexRouting(String indexRouting) {
|
|
|
- aliasAction.indexRouting(indexRouting);
|
|
|
+ public String searchRouting() {
|
|
|
+ return searchRouting == null ? routing : searchRouting;
|
|
|
}
|
|
|
|
|
|
- public AliasActions filter(String filter) {
|
|
|
- aliasAction.filter(filter);
|
|
|
+ public AliasActions searchRouting(String searchRouting) {
|
|
|
+ if (type != AliasActions.Type.ADD) {
|
|
|
+ throw new IllegalArgumentException("[search_routing] is unsupported for [" + type + "]");
|
|
|
+ }
|
|
|
+ this.searchRouting = searchRouting;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public AliasActions indices(String... indices) {
|
|
|
- this.indices = indices;
|
|
|
+ public String indexRouting() {
|
|
|
+ return indexRouting == null ? routing : indexRouting;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AliasActions indexRouting(String indexRouting) {
|
|
|
+ if (type != AliasActions.Type.ADD) {
|
|
|
+ throw new IllegalArgumentException("[index_routing] is unsupported for [" + type + "]");
|
|
|
+ }
|
|
|
+ this.indexRouting = indexRouting;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public AliasActions aliases(String... aliases) {
|
|
|
- this.aliases = aliases;
|
|
|
+ public String filter() {
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AliasActions filter(String filter) {
|
|
|
+ if (type != AliasActions.Type.ADD) {
|
|
|
+ throw new IllegalArgumentException("[filter] is unsupported for [" + type + "]");
|
|
|
+ }
|
|
|
+ this.filter = filter;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public AliasActions filter(Map<String, Object> filter) {
|
|
|
+ if (filter == null || filter.isEmpty()) {
|
|
|
+ this.filter = null;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
|
|
+ builder.map(filter);
|
|
|
+ this.filter = builder.string();
|
|
|
+ return this;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ElasticsearchGenerationException("Failed to generate [" + filter + "]", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public AliasActions filter(QueryBuilder filter) {
|
|
|
+ if (filter == null) {
|
|
|
+ this.filter = null;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
|
+ filter.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
|
|
+ builder.close();
|
|
|
+ this.filter = builder.string();
|
|
|
+ return this;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String[] aliases() {
|
|
|
return aliases;
|
|
|
@@ -157,7 +393,7 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|
|
@Override
|
|
|
public boolean expandAliasesWildcards() {
|
|
|
//remove operations support wildcards among aliases, add operations don't
|
|
|
- return aliasAction.actionType() == Type.REMOVE;
|
|
|
+ return type == Type.REMOVE;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -170,10 +406,6 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|
|
return INDICES_OPTIONS;
|
|
|
}
|
|
|
|
|
|
- public AliasAction aliasAction() {
|
|
|
- return aliasAction;
|
|
|
- }
|
|
|
-
|
|
|
public String[] concreteAliases(MetaData metaData, String concreteIndex) {
|
|
|
if (expandAliasesWildcards()) {
|
|
|
//for DELETE we expand the aliases
|
|
|
@@ -191,83 +423,48 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|
|
return aliases;
|
|
|
}
|
|
|
}
|
|
|
- public AliasActions readFrom(StreamInput in) throws IOException {
|
|
|
- indices = in.readStringArray();
|
|
|
- aliases = in.readStringArray();
|
|
|
- aliasAction = readAliasAction(in);
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- public void writeTo(StreamOutput out) throws IOException {
|
|
|
- out.writeStringArray(indices);
|
|
|
- out.writeStringArray(aliases);
|
|
|
- this.aliasAction.writeTo(out);
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "AliasActions["
|
|
|
+ + "type=" + type
|
|
|
+ + ",indices=" + Arrays.toString(indices)
|
|
|
+ + ",aliases=" + Arrays.deepToString(aliases)
|
|
|
+ + ",filter=" + filter
|
|
|
+ + ",routing=" + routing
|
|
|
+ + ",indexRouting=" + indexRouting
|
|
|
+ + ",searchRouting=" + searchRouting
|
|
|
+ + "]";
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Adds an alias to the index.
|
|
|
- * @param alias The alias
|
|
|
- * @param indices The indices
|
|
|
- */
|
|
|
- public IndicesAliasesRequest addAlias(String alias, String... indices) {
|
|
|
- addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias));
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void addAliasAction(AliasActions aliasAction) {
|
|
|
- allAliasActions.add(aliasAction);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public IndicesAliasesRequest addAliasAction(AliasAction action) {
|
|
|
- addAliasAction(new AliasActions(action));
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Adds an alias to the index.
|
|
|
- * @param alias The alias
|
|
|
- * @param filter The filter
|
|
|
- * @param indices The indices
|
|
|
- */
|
|
|
- public IndicesAliasesRequest addAlias(String alias, Map<String, Object> filter, String... indices) {
|
|
|
- addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filter));
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Adds an alias to the index.
|
|
|
- * @param alias The alias
|
|
|
- * @param filterBuilder The filter
|
|
|
- * @param indices The indices
|
|
|
- */
|
|
|
- public IndicesAliasesRequest addAlias(String alias, QueryBuilder filterBuilder, String... indices) {
|
|
|
- addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filterBuilder));
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
+ // equals, and hashCode implemented for easy testing of round trip
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object obj) {
|
|
|
+ if (obj == null || obj.getClass() != getClass()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ AliasActions other = (AliasActions) obj;
|
|
|
+ return Objects.equals(type, other.type)
|
|
|
+ && Arrays.equals(indices, other.indices)
|
|
|
+ && Arrays.equals(aliases, other.aliases)
|
|
|
+ && Objects.equals(filter, other.filter)
|
|
|
+ && Objects.equals(routing, other.routing)
|
|
|
+ && Objects.equals(indexRouting, other.indexRouting)
|
|
|
+ && Objects.equals(searchRouting, other.searchRouting);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Removes an alias to the index.
|
|
|
- *
|
|
|
- * @param indices The indices
|
|
|
- * @param aliases The aliases
|
|
|
- */
|
|
|
- public IndicesAliasesRequest removeAlias(String[] indices, String... aliases) {
|
|
|
- addAliasAction(new AliasActions(AliasAction.Type.REMOVE, indices, aliases));
|
|
|
- return this;
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return Objects.hash(type, indices, aliases, filter, routing, indexRouting, searchRouting);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Removes an alias to the index.
|
|
|
- *
|
|
|
- * @param index The index
|
|
|
- * @param aliases The aliases
|
|
|
+ * Add the action to this request and validate it.
|
|
|
*/
|
|
|
- public IndicesAliasesRequest removeAlias(String index, String... aliases) {
|
|
|
- addAliasAction(new AliasActions(AliasAction.Type.REMOVE, index, aliases));
|
|
|
+ public IndicesAliasesRequest addAliasAction(AliasActions aliasAction) {
|
|
|
+ aliasAction.validate();
|
|
|
+ allAliasActions.add(aliasAction);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
@@ -285,50 +482,20 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|
|
if (allAliasActions.isEmpty()) {
|
|
|
return addValidationError("Must specify at least one alias action", validationException);
|
|
|
}
|
|
|
- for (AliasActions aliasAction : allAliasActions) {
|
|
|
- if (CollectionUtils.isEmpty(aliasAction.aliases)) {
|
|
|
- validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
|
|
- + "]: Property [alias/aliases] is either missing or null", validationException);
|
|
|
- } else {
|
|
|
- for (String alias : aliasAction.aliases) {
|
|
|
- if (!Strings.hasText(alias)) {
|
|
|
- validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
|
|
- + "]: [alias/aliases] may not be empty string", validationException);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(aliasAction.indices)) {
|
|
|
- validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
|
|
- + "]: Property [index/indices] is either missing or null", validationException);
|
|
|
- } else {
|
|
|
- for (String index : aliasAction.indices) {
|
|
|
- if (!Strings.hasText(index)) {
|
|
|
- validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
|
|
- + "]: [index/indices] may not be empty string", validationException);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
return validationException;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void readFrom(StreamInput in) throws IOException {
|
|
|
super.readFrom(in);
|
|
|
- int size = in.readVInt();
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
- allAliasActions.add(readAliasActions(in));
|
|
|
- }
|
|
|
+ allAliasActions = in.readList(AliasActions::new);
|
|
|
readTimeout(in);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
super.writeTo(out);
|
|
|
- out.writeVInt(allAliasActions.size());
|
|
|
- for (AliasActions aliasAction : allAliasActions) {
|
|
|
- aliasAction.writeTo(out);
|
|
|
- }
|
|
|
+ out.writeList(allAliasActions);
|
|
|
writeTimeout(out);
|
|
|
}
|
|
|
|
|
|
@@ -336,11 +503,6 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|
|
return INDICES_OPTIONS;
|
|
|
}
|
|
|
|
|
|
- private static AliasActions readAliasActions(StreamInput in) throws IOException {
|
|
|
- AliasActions actions = new AliasActions();
|
|
|
- return actions.readFrom(in);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public List<? extends IndicesRequest> subRequests() {
|
|
|
return allAliasActions;
|