use of org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest in project OpenSearch by opensearch-project.
the class RequestConvertersTests method testDeleteScriptRequest.
public void testDeleteScriptRequest() {
DeleteStoredScriptRequest deleteStoredScriptRequest = new DeleteStoredScriptRequest("x-script");
Map<String, String> expectedParams = new HashMap<>();
setRandomTimeout(deleteStoredScriptRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
setRandomMasterTimeout(deleteStoredScriptRequest, expectedParams);
Request request = RequestConverters.deleteScript(deleteStoredScriptRequest);
assertThat(request.getEndpoint(), equalTo("/_scripts/" + deleteStoredScriptRequest.id()));
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
assertThat(request.getParameters(), equalTo(expectedParams));
assertThat(request.getEntity(), nullValue());
}
use of org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest in project OpenSearch by opensearch-project.
the class StoredScriptsIT method testDeleteStoredScript.
public void testDeleteStoredScript() throws Exception {
final StoredScriptSource scriptSource = new StoredScriptSource("painless", "Math.log(_score * 2) + params.my_modifier", Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()));
PutStoredScriptRequest request = new PutStoredScriptRequest(id, "score", new BytesArray("{}"), XContentType.JSON, scriptSource);
assertAcked(execute(request, highLevelClient()::putScript, highLevelClient()::putScriptAsync));
DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest(id);
deleteRequest.masterNodeTimeout("50s");
deleteRequest.timeout("50s");
assertAcked(execute(deleteRequest, highLevelClient()::deleteScript, highLevelClient()::deleteScriptAsync));
GetStoredScriptRequest getRequest = new GetStoredScriptRequest(id);
final OpenSearchStatusException statusException = expectThrows(OpenSearchStatusException.class, () -> execute(getRequest, highLevelClient()::getScript, highLevelClient()::getScriptAsync));
assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND));
}
use of org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest in project OpenSearch by opensearch-project.
the class StoredScriptsDocumentationIT method testDeleteStoredScript.
@SuppressWarnings("unused")
public void testDeleteStoredScript() throws Exception {
RestHighLevelClient client = highLevelClient();
final StoredScriptSource scriptSource = new StoredScriptSource("painless", "Math.log(_score * 2) + params.my_modifier", Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()));
putStoredScript("calculate-score", scriptSource);
// tag::delete-stored-script-request
// <1>
DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest("calculate-score");
// end::delete-stored-script-request
// tag::delete-stored-script-request-masterTimeout
// <1>
deleteRequest.masterNodeTimeout(TimeValue.timeValueSeconds(50));
// <2>
deleteRequest.masterNodeTimeout("50s");
// end::delete-stored-script-request-masterTimeout
// tag::delete-stored-script-request-timeout
// <1>
deleteRequest.timeout(TimeValue.timeValueSeconds(60));
// <2>
deleteRequest.timeout("60s");
// end::delete-stored-script-request-timeout
// tag::delete-stored-script-execute
AcknowledgedResponse deleteResponse = client.deleteScript(deleteRequest, RequestOptions.DEFAULT);
// end::delete-stored-script-execute
// tag::delete-stored-script-response
// <1>
boolean acknowledged = deleteResponse.isAcknowledged();
// end::delete-stored-script-response
putStoredScript("calculate-score", scriptSource);
// tag::delete-stored-script-execute-listener
ActionListener<AcknowledgedResponse> listener = new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::delete-stored-script-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::delete-stored-script-execute-async
// <1>
client.deleteScriptAsync(deleteRequest, RequestOptions.DEFAULT, listener);
// end::delete-stored-script-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest in project OpenSearch by opensearch-project.
the class RequestConverters method deleteScript.
static Request deleteScript(DeleteStoredScriptRequest deleteStoredScriptRequest) {
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(deleteStoredScriptRequest.id()).build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
Params params = new Params();
params.withTimeout(deleteStoredScriptRequest.timeout());
params.withMasterTimeout(deleteStoredScriptRequest.masterNodeTimeout());
request.addParameters(params.asMap());
return request;
}
use of org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest in project OpenSearch by opensearch-project.
the class RestDeleteStoredScriptAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
String id = request.param("id");
DeleteStoredScriptRequest deleteStoredScriptRequest = new DeleteStoredScriptRequest(id);
deleteStoredScriptRequest.timeout(request.paramAsTime("timeout", deleteStoredScriptRequest.timeout()));
deleteStoredScriptRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteStoredScriptRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().deleteStoredScript(deleteStoredScriptRequest, new RestToXContentListener<>(channel));
}
Aggregations