mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Make PutStoredScriptRequest
immutable (#117556)
No need for this request to be mutable, we always know all the values at creation time. Also adjusts the `toString()` impl to use the `source` field, since this is the only spot that we use the `content` so with this change we can follow up with a 9.x-only change to remove it.
This commit is contained in:
parent
1495c550ad
commit
2bc1b4f606
6 changed files with 60 additions and 106 deletions
|
@ -13,12 +13,10 @@ import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRe
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptAction;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.TransportDeleteStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.TransportDeleteStoredScriptAction;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
|
||||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.script.ScriptType;
|
import org.elasticsearch.script.ScriptType;
|
||||||
|
@ -39,6 +37,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.admin.cluster.storedscripts.StoredScriptIntegTestUtils.newPutStoredScriptTestRequest;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
|
||||||
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
@ -467,12 +466,6 @@ public class SearchTemplateIT extends ESSingleNodeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putJsonStoredScript(String id, String jsonContent) {
|
private void putJsonStoredScript(String id, String jsonContent) {
|
||||||
assertAcked(
|
assertAcked(safeExecute(TransportPutStoredScriptAction.TYPE, newPutStoredScriptTestRequest(id, jsonContent)));
|
||||||
safeExecute(
|
|
||||||
TransportPutStoredScriptAction.TYPE,
|
|
||||||
new PutStoredScriptRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).id(id)
|
|
||||||
.content(new BytesArray(jsonContent), XContentType.JSON)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,13 @@ package org.elasticsearch.script;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptAction;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.TransportDeleteStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.TransportDeleteStoredScriptAction;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.core.Strings;
|
import org.elasticsearch.core.Strings;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.xcontent.XContentType;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -28,6 +25,7 @@ import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.admin.cluster.storedscripts.StoredScriptIntegTestUtils.newPutStoredScriptTestRequest;
|
||||||
import static org.elasticsearch.action.admin.cluster.storedscripts.StoredScriptIntegTestUtils.putJsonStoredScript;
|
import static org.elasticsearch.action.admin.cluster.storedscripts.StoredScriptIntegTestUtils.putJsonStoredScript;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
|
|
||||||
|
@ -73,14 +71,9 @@ public class StoredScriptsIT extends ESIntegTestCase {
|
||||||
safeAwaitAndUnwrapFailure(
|
safeAwaitAndUnwrapFailure(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
AcknowledgedResponse.class,
|
AcknowledgedResponse.class,
|
||||||
l -> client().execute(
|
l -> client().execute(TransportPutStoredScriptAction.TYPE, newPutStoredScriptTestRequest("id#", Strings.format("""
|
||||||
TransportPutStoredScriptAction.TYPE,
|
{"script": {"lang": "%s", "source": "1"} }
|
||||||
new PutStoredScriptRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).id("id#")
|
""", LANG)), l)
|
||||||
.content(new BytesArray(Strings.format("""
|
|
||||||
{"script": {"lang": "%s", "source": "1"} }
|
|
||||||
""", LANG)), XContentType.JSON),
|
|
||||||
l
|
|
||||||
)
|
|
||||||
).getMessage()
|
).getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -91,14 +84,9 @@ public class StoredScriptsIT extends ESIntegTestCase {
|
||||||
safeAwaitAndUnwrapFailure(
|
safeAwaitAndUnwrapFailure(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
AcknowledgedResponse.class,
|
AcknowledgedResponse.class,
|
||||||
l -> client().execute(
|
l -> client().execute(TransportPutStoredScriptAction.TYPE, newPutStoredScriptTestRequest("foobar", Strings.format("""
|
||||||
TransportPutStoredScriptAction.TYPE,
|
{"script": { "lang": "%s", "source":"0123456789abcdef"} }\
|
||||||
new PutStoredScriptRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).id("foobar")
|
""", LANG)), l)
|
||||||
.content(new BytesArray(Strings.format("""
|
|
||||||
{"script": { "lang": "%s", "source":"0123456789abcdef"} }\
|
|
||||||
""", LANG)), XContentType.JSON),
|
|
||||||
l
|
|
||||||
)
|
|
||||||
).getMessage()
|
).getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,12 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||||
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
|
import org.elasticsearch.core.Nullable;
|
||||||
import org.elasticsearch.core.TimeValue;
|
import org.elasticsearch.core.TimeValue;
|
||||||
import org.elasticsearch.script.StoredScriptSource;
|
import org.elasticsearch.script.StoredScriptSource;
|
||||||
import org.elasticsearch.xcontent.ToXContentFragment;
|
import org.elasticsearch.xcontent.ToXContentFragment;
|
||||||
|
@ -28,11 +30,15 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
|
|
||||||
public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptRequest> implements ToXContentFragment {
|
public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptRequest> implements ToXContentFragment {
|
||||||
|
|
||||||
private String id;
|
@Nullable
|
||||||
private String context;
|
private final String id;
|
||||||
private BytesReference content;
|
|
||||||
private XContentType xContentType;
|
@Nullable
|
||||||
private StoredScriptSource source;
|
private final String context;
|
||||||
|
|
||||||
|
private final BytesReference content;
|
||||||
|
private final XContentType xContentType;
|
||||||
|
private final StoredScriptSource source;
|
||||||
|
|
||||||
public PutStoredScriptRequest(StreamInput in) throws IOException {
|
public PutStoredScriptRequest(StreamInput in) throws IOException {
|
||||||
super(in);
|
super(in);
|
||||||
|
@ -43,15 +49,11 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
|
||||||
source = new StoredScriptSource(in);
|
source = new StoredScriptSource(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutStoredScriptRequest(TimeValue masterNodeTimeout, TimeValue ackTimeout) {
|
|
||||||
super(masterNodeTimeout, ackTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PutStoredScriptRequest(
|
public PutStoredScriptRequest(
|
||||||
TimeValue masterNodeTimeout,
|
TimeValue masterNodeTimeout,
|
||||||
TimeValue ackTimeout,
|
TimeValue ackTimeout,
|
||||||
String id,
|
@Nullable String id,
|
||||||
String context,
|
@Nullable String context,
|
||||||
BytesReference content,
|
BytesReference content,
|
||||||
XContentType xContentType,
|
XContentType xContentType,
|
||||||
StoredScriptSource source
|
StoredScriptSource source
|
||||||
|
@ -59,9 +61,9 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
|
||||||
super(masterNodeTimeout, ackTimeout);
|
super(masterNodeTimeout, ackTimeout);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.content = content;
|
this.content = Objects.requireNonNull(content);
|
||||||
this.xContentType = Objects.requireNonNull(xContentType);
|
this.xContentType = Objects.requireNonNull(xContentType);
|
||||||
this.source = source;
|
this.source = Objects.requireNonNull(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,10 +76,6 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
|
||||||
validationException = addValidationError("id cannot contain '#' for stored script", validationException);
|
validationException = addValidationError("id cannot contain '#' for stored script", validationException);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content == null) {
|
|
||||||
validationException = addValidationError("must specify code for stored script", validationException);
|
|
||||||
}
|
|
||||||
|
|
||||||
return validationException;
|
return validationException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,20 +83,10 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutStoredScriptRequest id(String id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String context() {
|
public String context() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutStoredScriptRequest context(String context) {
|
|
||||||
this.context = context;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BytesReference content() {
|
public BytesReference content() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
@ -111,16 +99,6 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the script source and the content type of the bytes.
|
|
||||||
*/
|
|
||||||
public PutStoredScriptRequest content(BytesReference content, XContentType xContentType) {
|
|
||||||
this.content = content;
|
|
||||||
this.xContentType = Objects.requireNonNull(xContentType);
|
|
||||||
this.source = StoredScriptSource.parse(content, xContentType);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
|
@ -133,28 +111,16 @@ public class PutStoredScriptRequest extends AcknowledgedRequest<PutStoredScriptR
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String source = "_na_";
|
return Strings.format(
|
||||||
|
"put stored script {id [%s]%s, content [%s]}",
|
||||||
try {
|
id,
|
||||||
source = XContentHelper.convertToJson(content, false, xContentType);
|
context != null ? ", context [" + context + "]" : "",
|
||||||
} catch (Exception e) {
|
source
|
||||||
// ignore
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return "put stored script {id ["
|
|
||||||
+ id
|
|
||||||
+ "]"
|
|
||||||
+ (context != null ? ", context [" + context + "]" : "")
|
|
||||||
+ ", content ["
|
|
||||||
+ source
|
|
||||||
+ "]}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.field("script");
|
return builder.field("script", source, params);
|
||||||
source.toXContent(builder, params);
|
|
||||||
|
|
||||||
return builder;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,15 @@ public class PutStoredScriptRequestTests extends ESTestCase {
|
||||||
|
|
||||||
BytesReference expectedRequestBody = BytesReference.bytes(builder);
|
BytesReference expectedRequestBody = BytesReference.bytes(builder);
|
||||||
|
|
||||||
PutStoredScriptRequest request = new PutStoredScriptRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT);
|
PutStoredScriptRequest request = new PutStoredScriptRequest(
|
||||||
request.id("test1");
|
TEST_REQUEST_TIMEOUT,
|
||||||
request.content(expectedRequestBody, xContentType);
|
TEST_REQUEST_TIMEOUT,
|
||||||
|
"test1",
|
||||||
|
null,
|
||||||
|
expectedRequestBody,
|
||||||
|
xContentType,
|
||||||
|
StoredScriptSource.parse(expectedRequestBody, xContentType)
|
||||||
|
);
|
||||||
|
|
||||||
XContentBuilder requestBuilder = XContentBuilder.builder(xContentType.xContent());
|
XContentBuilder requestBuilder = XContentBuilder.builder(xContentType.xContent());
|
||||||
requestBuilder.startObject();
|
requestBuilder.startObject();
|
||||||
|
|
|
@ -11,6 +11,7 @@ package org.elasticsearch.action.admin.cluster.storedscripts;
|
||||||
|
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
import org.elasticsearch.script.StoredScriptSource;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.xcontent.XContentType;
|
import org.elasticsearch.xcontent.XContentType;
|
||||||
|
|
||||||
|
@ -25,11 +26,22 @@ public class StoredScriptIntegTestUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void putJsonStoredScript(String id, BytesReference jsonContent) {
|
public static void putJsonStoredScript(String id, BytesReference jsonContent) {
|
||||||
assertAcked(
|
assertAcked(ESIntegTestCase.safeExecute(TransportPutStoredScriptAction.TYPE, newPutStoredScriptTestRequest(id, jsonContent)));
|
||||||
ESIntegTestCase.safeExecute(
|
}
|
||||||
TransportPutStoredScriptAction.TYPE,
|
|
||||||
new PutStoredScriptRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).id(id).content(jsonContent, XContentType.JSON)
|
public static PutStoredScriptRequest newPutStoredScriptTestRequest(String id, String jsonContent) {
|
||||||
)
|
return newPutStoredScriptTestRequest(id, new BytesArray(jsonContent));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PutStoredScriptRequest newPutStoredScriptTestRequest(String id, BytesReference jsonContent) {
|
||||||
|
return new PutStoredScriptRequest(
|
||||||
|
TEST_REQUEST_TIMEOUT,
|
||||||
|
TEST_REQUEST_TIMEOUT,
|
||||||
|
id,
|
||||||
|
null,
|
||||||
|
jsonContent,
|
||||||
|
XContentType.JSON,
|
||||||
|
StoredScriptSource.parse(jsonContent, XContentType.JSON)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,11 @@
|
||||||
package org.elasticsearch.integration;
|
package org.elasticsearch.integration;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchSecurityException;
|
import org.elasticsearch.ElasticsearchSecurityException;
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest;
|
|
||||||
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
|
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
|
||||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||||
import org.elasticsearch.client.internal.Client;
|
import org.elasticsearch.client.internal.Client;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
|
||||||
import org.elasticsearch.common.settings.SecureString;
|
import org.elasticsearch.common.settings.SecureString;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.core.Strings;
|
import org.elasticsearch.core.Strings;
|
||||||
|
@ -24,7 +22,6 @@ import org.elasticsearch.script.mustache.MustachePlugin;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.test.SecuritySingleNodeTestCase;
|
import org.elasticsearch.test.SecuritySingleNodeTestCase;
|
||||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||||
import org.elasticsearch.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.xpack.core.XPackSettings;
|
import org.elasticsearch.xpack.core.XPackSettings;
|
||||||
import org.elasticsearch.xpack.core.security.action.apikey.CreateApiKeyAction;
|
import org.elasticsearch.xpack.core.security.action.apikey.CreateApiKeyAction;
|
||||||
import org.elasticsearch.xpack.core.security.action.apikey.CreateApiKeyRequest;
|
import org.elasticsearch.xpack.core.security.action.apikey.CreateApiKeyRequest;
|
||||||
|
@ -43,6 +40,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.admin.cluster.storedscripts.StoredScriptIntegTestUtils.newPutStoredScriptTestRequest;
|
||||||
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE;
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE;
|
||||||
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.WAIT_UNTIL;
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.WAIT_UNTIL;
|
||||||
|
@ -350,17 +348,8 @@ public class DlsFlsRequestCacheTests extends SecuritySingleNodeTestCase {
|
||||||
private void prepareIndices() {
|
private void prepareIndices() {
|
||||||
final Client client = client();
|
final Client client = client();
|
||||||
|
|
||||||
assertAcked(
|
assertAcked(safeExecute(TransportPutStoredScriptAction.TYPE, newPutStoredScriptTestRequest("my-script", """
|
||||||
safeExecute(
|
{"script":{"source":"{\\"match\\":{\\"username\\":\\"{{_user.username}}\\"}}","lang":"mustache"}}""")));
|
||||||
TransportPutStoredScriptAction.TYPE,
|
|
||||||
new PutStoredScriptRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).id("my-script")
|
|
||||||
.content(
|
|
||||||
new BytesArray("""
|
|
||||||
{"script":{"source":"{\\"match\\":{\\"username\\":\\"{{_user.username}}\\"}}","lang":"mustache"}}"""),
|
|
||||||
XContentType.JSON
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
assertAcked(indicesAdmin().prepareCreate(DLS_INDEX).addAlias(new Alias("dls-alias")).get());
|
assertAcked(indicesAdmin().prepareCreate(DLS_INDEX).addAlias(new Alias("dls-alias")).get());
|
||||||
client.prepareIndex(DLS_INDEX).setId("101").setSource("number", 101, "letter", "A").get();
|
client.prepareIndex(DLS_INDEX).setId("101").setSource("number", 101, "letter", "A").get();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue