Search in sources :

Example 1 with DeleteStoredScriptRequest

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());
}
Also used : DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) HashMap(java.util.HashMap) RandomSearchRequestGenerator.randomSearchRequest(org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest) MasterNodeRequest(org.opensearch.action.support.master.MasterNodeRequest) WriteRequest(org.opensearch.action.support.WriteRequest) AbstractBulkByScrollRequest(org.opensearch.index.reindex.AbstractBulkByScrollRequest) RatedRequest(org.opensearch.index.rankeval.RatedRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) BulkRequest(org.opensearch.action.bulk.BulkRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) ReplicationRequest(org.opensearch.action.support.replication.ReplicationRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) CountRequest(org.opensearch.client.core.CountRequest) BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest)

Example 2 with DeleteStoredScriptRequest

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));
}
Also used : DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) BytesArray(org.opensearch.common.bytes.BytesArray) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) StoredScriptSource(org.opensearch.script.StoredScriptSource) OpenSearchStatusException(org.opensearch.OpenSearchStatusException)

Example 3 with DeleteStoredScriptRequest

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));
}
Also used : DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) StoredScriptSource(org.opensearch.script.StoredScriptSource) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Example 4 with DeleteStoredScriptRequest

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;
}
Also used : BulkRequest(org.opensearch.action.bulk.BulkRequest) WriteRequest(org.opensearch.action.support.WriteRequest) AbstractBulkByScrollRequest(org.opensearch.index.reindex.AbstractBulkByScrollRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) CountRequest(org.opensearch.client.core.CountRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ClusterHealthRequest(org.opensearch.action.admin.cluster.health.ClusterHealthRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 5 with DeleteStoredScriptRequest

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));
}
Also used : DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) DELETE(org.opensearch.rest.RestRequest.Method.DELETE) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Collections.singletonList(java.util.Collections.singletonList) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)

Aggregations

DeleteStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)5 GetStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest)3 PutStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)3 IOException (java.io.IOException)2 DocWriteRequest (org.opensearch.action.DocWriteRequest)2 BulkRequest (org.opensearch.action.bulk.BulkRequest)2 DeleteRequest (org.opensearch.action.delete.DeleteRequest)2 ExplainRequest (org.opensearch.action.explain.ExplainRequest)2 FieldCapabilitiesRequest (org.opensearch.action.fieldcaps.FieldCapabilitiesRequest)2 GetRequest (org.opensearch.action.get.GetRequest)2 MultiGetRequest (org.opensearch.action.get.MultiGetRequest)2 IndexRequest (org.opensearch.action.index.IndexRequest)2 ClearScrollRequest (org.opensearch.action.search.ClearScrollRequest)2 MultiSearchRequest (org.opensearch.action.search.MultiSearchRequest)2 SearchRequest (org.opensearch.action.search.SearchRequest)2 SearchScrollRequest (org.opensearch.action.search.SearchScrollRequest)2 WriteRequest (org.opensearch.action.support.WriteRequest)2 UpdateRequest (org.opensearch.action.update.UpdateRequest)2 CountRequest (org.opensearch.client.core.CountRequest)2 GetSourceRequest (org.opensearch.client.core.GetSourceRequest)2