-
Notifications
You must be signed in to change notification settings - Fork 25.5k
[CPS] Create Cross Project IndicesOptions #135470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e4fe9c5
b187fa7
2e6a384
458fe27
e15fc1a
6cc3611
558bb0d
b7d325f
372f220
279fa5a
b9eb664
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,11 @@ | |
package org.elasticsearch.action.support; | ||
|
||
import org.elasticsearch.ElasticsearchParseException; | ||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.TransportVersions; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.logging.DeprecationCategory; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.core.Nullable; | ||
|
@@ -49,7 +51,8 @@ | |
public record IndicesOptions( | ||
ConcreteTargetOptions concreteTargetOptions, | ||
WildcardOptions wildcardOptions, | ||
GatekeeperOptions gatekeeperOptions | ||
GatekeeperOptions gatekeeperOptions, | ||
ResolutionModeOptions resolutionModeOptions | ||
) implements ToXContentFragment { | ||
|
||
public static IndicesOptions.Builder builder() { | ||
|
@@ -413,6 +416,42 @@ public static Builder builder(GatekeeperOptions gatekeeperOptions) { | |
} | ||
} | ||
|
||
/** | ||
* The resolution mode options are internal-only options that apply on all indices that have been selected by the other Options. These | ||
* options may contextually change over the lifetime of the request. | ||
* @param crossProject determines that the index expression must be resolved for cross-project requests, defaults to false. | ||
*/ | ||
public record ResolutionModeOptions(boolean crossProject) implements ToXContentFragment, Writeable { | ||
|
||
public static final ResolutionModeOptions DEFAULT = new ResolutionModeOptions(false); | ||
|
||
private static final TransportVersion INDICES_OPTIONS_RESOLUTION_MODE = TransportVersion.fromName( | ||
"indices_options_resolution_mode" | ||
); | ||
|
||
private static final String CROSS_PROJECT_NAME = "resolve_cross_project"; | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.field(CROSS_PROJECT_NAME, crossProject); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
if (out.getTransportVersion().supports(INDICES_OPTIONS_RESOLUTION_MODE)) { | ||
out.writeBoolean(crossProject); | ||
} | ||
} | ||
|
||
public static ResolutionModeOptions readFrom(StreamInput in) throws IOException { | ||
if (in.getTransportVersion().supports(INDICES_OPTIONS_RESOLUTION_MODE)) { | ||
return new ResolutionModeOptions(in.readBoolean()); | ||
} else { | ||
return ResolutionModeOptions.DEFAULT; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This class is maintained for backwards compatibility and performance purposes. We use it for serialisation along with {@link Option}. | ||
*/ | ||
|
@@ -463,7 +502,8 @@ private enum Option { | |
public static final IndicesOptions DEFAULT = new IndicesOptions( | ||
ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS, | ||
WildcardOptions.DEFAULT, | ||
GatekeeperOptions.DEFAULT | ||
GatekeeperOptions.DEFAULT, | ||
ResolutionModeOptions.DEFAULT | ||
); | ||
|
||
public static final IndicesOptions STRICT_EXPAND_OPEN = IndicesOptions.builder() | ||
|
@@ -857,6 +897,13 @@ public boolean ignoreThrottled() { | |
return gatekeeperOptions().ignoreThrottled(); | ||
} | ||
|
||
/** | ||
* @return whether indices will resolve to the cross-project "flat world" expression | ||
*/ | ||
public boolean resolveCrossProject() { | ||
return resolutionModeOptions().crossProject(); | ||
} | ||
|
||
public void writeIndicesOptions(StreamOutput out) throws IOException { | ||
EnumSet<Option> backwardsCompatibleOptions = EnumSet.noneOf(Option.class); | ||
if (allowNoIndices()) { | ||
|
@@ -917,6 +964,7 @@ public void writeIndicesOptions(StreamOutput out) throws IOException { | |
out.writeByte((byte) 0); // ordinal 0 (::data selector) | ||
} | ||
} | ||
out.writeWriteable(resolutionModeOptions); | ||
} | ||
|
||
public static IndicesOptions readIndicesOptions(StreamInput in) throws IOException { | ||
|
@@ -968,14 +1016,16 @@ public static IndicesOptions readIndicesOptions(StreamInput in) throws IOExcepti | |
? ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS | ||
: ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS, | ||
wildcardOptions, | ||
gatekeeperOptions | ||
gatekeeperOptions, | ||
ResolutionModeOptions.readFrom(in) | ||
); | ||
} | ||
|
||
public static class Builder { | ||
private ConcreteTargetOptions concreteTargetOptions; | ||
private WildcardOptions wildcardOptions; | ||
private GatekeeperOptions gatekeeperOptions; | ||
private ResolutionModeOptions resolutionModeOptions; | ||
|
||
Builder() { | ||
this(DEFAULT); | ||
|
@@ -985,6 +1035,7 @@ public static class Builder { | |
concreteTargetOptions = indicesOptions.concreteTargetOptions; | ||
wildcardOptions = indicesOptions.wildcardOptions; | ||
gatekeeperOptions = indicesOptions.gatekeeperOptions; | ||
resolutionModeOptions = indicesOptions.resolutionModeOptions; | ||
} | ||
|
||
public Builder concreteTargetOptions(ConcreteTargetOptions concreteTargetOptions) { | ||
|
@@ -1012,8 +1063,13 @@ public Builder gatekeeperOptions(GatekeeperOptions.Builder generalOptions) { | |
return this; | ||
} | ||
|
||
public Builder resolutionModeOptions(ResolutionModeOptions resolutionModeOptions) { | ||
this.resolutionModeOptions = resolutionModeOptions; | ||
return this; | ||
} | ||
|
||
public IndicesOptions build() { | ||
return new IndicesOptions(concreteTargetOptions, wildcardOptions, gatekeeperOptions); | ||
return new IndicesOptions(concreteTargetOptions, wildcardOptions, gatekeeperOptions, resolutionModeOptions); | ||
} | ||
} | ||
|
||
|
@@ -1115,7 +1171,8 @@ public static IndicesOptions fromOptions( | |
return new IndicesOptions( | ||
ignoreUnavailable ? ConcreteTargetOptions.ALLOW_UNAVAILABLE_TARGETS : ConcreteTargetOptions.ERROR_WHEN_UNAVAILABLE_TARGETS, | ||
wildcards, | ||
gatekeeperOptions | ||
gatekeeperOptions, | ||
ResolutionModeOptions.DEFAULT | ||
); | ||
} | ||
|
||
|
@@ -1157,7 +1214,8 @@ public static boolean isIndicesOptions(String name) { | |
|| GatekeeperOptions.IGNORE_THROTTLED.equals(name) | ||
|| "ignoreThrottled".equals(name) | ||
|| WildcardOptions.ALLOW_NO_INDICES.equals(name) | ||
|| "allowNoIndices".equals(name); | ||
|| "allowNoIndices".equals(name) | ||
|| ResolutionModeOptions.CROSS_PROJECT_NAME.equals(name); | ||
|
||
} | ||
|
||
public static IndicesOptions fromParameters( | ||
|
@@ -1202,13 +1260,15 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par | |
concreteTargetOptions.toXContent(builder, params); | ||
wildcardOptions.toXContent(builder, params); | ||
gatekeeperOptions.toXContent(builder, params); | ||
resolutionModeOptions.toXContent(builder, params); | ||
return builder; | ||
} | ||
|
||
private static final ParseField EXPAND_WILDCARDS_FIELD = new ParseField(WildcardOptions.EXPAND_WILDCARDS); | ||
private static final ParseField IGNORE_UNAVAILABLE_FIELD = new ParseField(ConcreteTargetOptions.IGNORE_UNAVAILABLE); | ||
private static final ParseField IGNORE_THROTTLED_FIELD = new ParseField(GatekeeperOptions.IGNORE_THROTTLED).withAllDeprecated(); | ||
private static final ParseField ALLOW_NO_INDICES_FIELD = new ParseField(WildcardOptions.ALLOW_NO_INDICES); | ||
private static final ParseField RESOLVE_CROSS_PROJECT = new ParseField(ResolutionModeOptions.CROSS_PROJECT_NAME); | ||
|
||
public static IndicesOptions fromXContent(XContentParser parser) throws IOException { | ||
return fromXContent(parser, null); | ||
|
@@ -1221,6 +1281,7 @@ public static IndicesOptions fromXContent(XContentParser parser, @Nullable Indic | |
.ignoreThrottled(defaults != null && defaults.gatekeeperOptions().ignoreThrottled()); | ||
Boolean allowNoIndices = defaults == null ? null : defaults.allowNoIndices(); | ||
Boolean ignoreUnavailable = defaults == null ? null : defaults.ignoreUnavailable(); | ||
boolean resolveCrossProject = defaults == null ? ResolutionModeOptions.DEFAULT.crossProject() : defaults.resolveCrossProject(); | ||
Token token = parser.currentToken() == Token.START_OBJECT ? parser.currentToken() : parser.nextToken(); | ||
String currentFieldName = null; | ||
if (token != Token.START_OBJECT) { | ||
|
@@ -1268,6 +1329,8 @@ public static IndicesOptions fromXContent(XContentParser parser, @Nullable Indic | |
allowNoIndices = parser.booleanValue(); | ||
} else if (IGNORE_THROTTLED_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { | ||
generalOptions.ignoreThrottled(parser.booleanValue()); | ||
} else if (RESOLVE_CROSS_PROJECT.match(currentFieldName, parser.getDeprecationHandler())) { | ||
resolveCrossProject = parser.booleanValue(); | ||
} else { | ||
throw new ElasticsearchParseException( | ||
"could not read indices options. Unexpected index option [" + currentFieldName + "]" | ||
|
@@ -1298,6 +1361,7 @@ public static IndicesOptions fromXContent(XContentParser parser, @Nullable Indic | |
.concreteTargetOptions(new ConcreteTargetOptions(ignoreUnavailable)) | ||
.wildcardOptions(wildcards) | ||
.gatekeeperOptions(generalOptions) | ||
.resolutionModeOptions(new ResolutionModeOptions(resolveCrossProject)) | ||
.build(); | ||
} | ||
|
||
|
@@ -1459,6 +1523,8 @@ public String toString() { | |
+ allowSelectors() | ||
+ ", include_failure_indices=" | ||
+ includeFailureIndices() | ||
+ ", resolve_cross_project=" | ||
+ resolveCrossProject() | ||
+ ']'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9188000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
resolved_index_expressions,9187000 | ||
indices_options_resolution_mode,9188000 |
Uh oh!
There was an error while loading. Please reload this page.