Skip to content

Commit

Permalink
Initial commit of new job APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Vamsi Manohar <[email protected]>
  • Loading branch information
vmmusings committed Sep 6, 2023
1 parent 3e25a61 commit b56cf42
Show file tree
Hide file tree
Showing 14 changed files with 719 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.spark.rest;

import static org.opensearch.core.rest.RestStatus.BAD_REQUEST;
import static org.opensearch.core.rest.RestStatus.SERVICE_UNAVAILABLE;
import static org.opensearch.rest.RestRequest.Method.DELETE;
import static org.opensearch.rest.RestRequest.Method.GET;
import static org.opensearch.rest.RestRequest.Method.POST;

import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchException;
import org.opensearch.client.node.NodeClient;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.RestRequest;
import org.opensearch.sql.datasources.exceptions.ErrorMessage;
import org.opensearch.sql.datasources.utils.Scheduler;
import org.opensearch.sql.spark.rest.model.CreateJobRequest;
import org.opensearch.sql.spark.transport.TransportDeleteJobRequest;
import org.opensearch.sql.spark.transport.TransportGetQueryResultRequest;
import org.opensearch.sql.spark.transport.TransportCreateJobRequest;
import org.opensearch.sql.spark.transport.model.DeleteJobActionRequest;
import org.opensearch.sql.spark.transport.model.DeleteJobActionResponse;
import org.opensearch.sql.spark.transport.model.GetJobQueryResultActionRequest;
import org.opensearch.sql.spark.transport.model.GetJobQueryResultActionResponse;
import org.opensearch.sql.spark.transport.model.CreateJobActionRequest;
import org.opensearch.sql.spark.transport.model.CreateJobActionResponse;

public class RestJobManagementAction extends BaseRestHandler {

Check warning on line 41 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L41

Added line #L41 was not covered by tests

public static final String JOB_ACTIONS = "job_actions";
public static final String BASE_JOB_ACTION_URL = "/_plugins/_query/_jobs";

private static final Logger LOG = LogManager.getLogger(RestJobManagementAction.class);

Check warning on line 46 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L46

Added line #L46 was not covered by tests

@Override
public String getName() {
return JOB_ACTIONS;

Check warning on line 50 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L50

Added line #L50 was not covered by tests
}

@Override
public List<Route> routes() {
return ImmutableList.of(

Check warning on line 55 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L55

Added line #L55 was not covered by tests

/*
*
* Create a new job with spark execution engine.
* Request URL: POST
* Request body:
* Ref [org.opensearch.sql.spark.transport.model.SubmitJobActionRequest]
* Response body:
* Ref [org.opensearch.sql.spark.transport.model.SubmitJobActionResponse]
*/
new Route(POST, BASE_JOB_ACTION_URL),

/*
*
* GET jobs with in spark execution engine.
* Request URL: GET
* Request body:
* Ref [org.opensearch.sql.spark.transport.model.SubmitJobActionRequest]
* Response body:
* Ref [org.opensearch.sql.spark.transport.model.SubmitJobActionResponse]
*/
new Route(GET, String.format(Locale.ROOT, "%s/{%s}", BASE_JOB_ACTION_URL, "jobId")),

Check warning on line 77 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L77

Added line #L77 was not covered by tests
new Route(GET, BASE_JOB_ACTION_URL),

/*
*
* Cancel a job within spark execution engine.
* Request URL: DELETE
* Request body:
* Ref [org.opensearch.sql.spark.transport.model.SubmitJobActionRequest]
* Response body:
* Ref [org.opensearch.sql.spark.transport.model.SubmitJobActionResponse]
*/
new Route(DELETE, String.format(Locale.ROOT, "%s/{%s}", BASE_JOB_ACTION_URL, "jobId")),

Check warning on line 89 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L89

Added line #L89 was not covered by tests

/*
* GET query result from job {{jobId}} execution.
* Request URL: GET
* Request body:
* Ref [org.opensearch.sql.spark.transport.model.GetJobQueryResultActionRequest]
* Response body:
* Ref [org.opensearch.sql.spark.transport.model.GetJobQueryResultActionResponse]
*/
new Route(
GET,
String.format(Locale.ROOT, "%s/{%s}/result", BASE_JOB_ACTION_URL, "jobId")));

Check warning on line 101 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L101

Added line #L101 was not covered by tests
}

@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient nodeClient)
throws IOException {
switch (restRequest.method()) {
case POST:
return executePostRequest(restRequest, nodeClient);

Check warning on line 109 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L109

Added line #L109 was not covered by tests
case GET:
return executeGetRequest(restRequest, nodeClient);

Check warning on line 111 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L111

Added line #L111 was not covered by tests
case DELETE:
return executeDeleteRequest(restRequest, nodeClient);

Check warning on line 113 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L113

Added line #L113 was not covered by tests
default:
return restChannel ->
restChannel.sendResponse(

Check warning on line 116 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L115-L116

Added lines #L115 - L116 were not covered by tests
new BytesRestResponse(
RestStatus.METHOD_NOT_ALLOWED, String.valueOf(restRequest.method())));

Check warning on line 118 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L118

Added line #L118 was not covered by tests
}
}

private RestChannelConsumer executePostRequest(RestRequest restRequest, NodeClient nodeClient)
throws IOException {

CreateJobRequest submitJobRequest
= CreateJobRequest.fromXContentParser(restRequest.contentParser());
return restChannel ->
Scheduler.schedule(

Check warning on line 128 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L125-L128

Added lines #L125 - L128 were not covered by tests
nodeClient,
() ->
nodeClient.execute(

Check warning on line 131 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L131

Added line #L131 was not covered by tests
TransportCreateJobRequest.ACTION_TYPE,
new CreateJobActionRequest(submitJobRequest),
new ActionListener<>() {

Check warning on line 134 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L134

Added line #L134 was not covered by tests
@Override
public void onResponse(
CreateJobActionResponse createJobActionResponse) {
restChannel.sendResponse(

Check warning on line 138 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L138

Added line #L138 was not covered by tests
new BytesRestResponse(
RestStatus.CREATED,
"application/json; charset=UTF-8",
submitJobRequest.getQuery()));
}

Check warning on line 143 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L142-L143

Added lines #L142 - L143 were not covered by tests

@Override
public void onFailure(Exception e) {
handleException(e, restChannel);
}

Check warning on line 148 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L147-L148

Added lines #L147 - L148 were not covered by tests
}));
}

private RestChannelConsumer executeGetRequest(RestRequest restRequest, NodeClient nodeClient) {
String jobId = restRequest.param("jobId");
return restChannel ->
Scheduler.schedule(

Check warning on line 155 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L153-L155

Added lines #L153 - L155 were not covered by tests
nodeClient,
() ->
nodeClient.execute(

Check warning on line 158 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L158

Added line #L158 was not covered by tests
TransportGetQueryResultRequest.ACTION_TYPE,
new GetJobQueryResultActionRequest(jobId),
new ActionListener<>() {

Check warning on line 161 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L161

Added line #L161 was not covered by tests
@Override
public void onResponse(
GetJobQueryResultActionResponse getJobQueryResultActionResponse) {
restChannel.sendResponse(

Check warning on line 165 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L165

Added line #L165 was not covered by tests
new BytesRestResponse(
RestStatus.OK,
"application/json; charset=UTF-8",
getJobQueryResultActionResponse.getResult()));
}

Check warning on line 170 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L169-L170

Added lines #L169 - L170 were not covered by tests

@Override
public void onFailure(Exception e) {
handleException(e, restChannel);
}

Check warning on line 175 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L174-L175

Added lines #L174 - L175 were not covered by tests
}));
}


private void handleException(Exception e, RestChannel restChannel) {
if (e instanceof OpenSearchException) {
OpenSearchException exception = (OpenSearchException) e;
reportError(restChannel, exception, exception.status());
} else {
LOG.error("Error happened during request handling", e);

Check warning on line 185 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L182-L185

Added lines #L182 - L185 were not covered by tests
if (isClientError(e)) {
reportError(restChannel, e, BAD_REQUEST);

Check warning on line 187 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L187

Added line #L187 was not covered by tests
} else {
reportError(restChannel, e, SERVICE_UNAVAILABLE);

Check warning on line 189 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L189

Added line #L189 was not covered by tests
}
}
}

Check warning on line 192 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L192

Added line #L192 was not covered by tests


private RestChannelConsumer executeDeleteRequest(RestRequest restRequest, NodeClient nodeClient) {
String jobId = restRequest.param("jobId");
return restChannel ->
Scheduler.schedule(

Check warning on line 198 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L196-L198

Added lines #L196 - L198 were not covered by tests
nodeClient,
() ->
nodeClient.execute(

Check warning on line 201 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L201

Added line #L201 was not covered by tests
TransportDeleteJobRequest.ACTION_TYPE,
new DeleteJobActionRequest(jobId),
new ActionListener<>() {

Check warning on line 204 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L204

Added line #L204 was not covered by tests
@Override
public void onResponse(
DeleteJobActionResponse deleteJobActionResponse) {
restChannel.sendResponse(

Check warning on line 208 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L208

Added line #L208 was not covered by tests
new BytesRestResponse(
RestStatus.OK,
"application/json; charset=UTF-8",
deleteJobActionResponse.getResult()));
}

Check warning on line 213 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L212-L213

Added lines #L212 - L213 were not covered by tests

@Override
public void onFailure(Exception e) {
handleException(e, restChannel);
}

Check warning on line 218 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L217-L218

Added lines #L217 - L218 were not covered by tests
}));
}

private String handleGetAllJobs() {
return "all_jobs";

Check warning on line 223 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L223

Added line #L223 was not covered by tests
}

private String handleGetJob() {
return "job";

Check warning on line 227 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L227

Added line #L227 was not covered by tests
}

private String handleJobResult() {
return "all_jobs";

Check warning on line 231 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L231

Added line #L231 was not covered by tests
}


private void reportError(final RestChannel channel, final Exception e, final RestStatus status) {
channel.sendResponse(
new BytesRestResponse(status, new ErrorMessage(e, status.getStatus()).toString()));
}

Check warning on line 238 in spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/RestJobManagementAction.java#L236-L238

Added lines #L236 - L238 were not covered by tests

private static boolean isClientError(Exception e) {
return e instanceof IllegalArgumentException
|| e instanceof IllegalStateException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.spark.rest.model;

import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;

import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.opensearch.core.xcontent.XContentParser;

@Data
@AllArgsConstructor
public class CreateJobRequest {

private String query;

public static CreateJobRequest fromXContentParser(XContentParser parser) throws IOException {
String query = null;
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);

Check warning on line 23 in spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java#L22-L23

Added lines #L22 - L23 were not covered by tests
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
String fieldName = parser.currentName();
parser.nextToken();

Check warning on line 26 in spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java#L25-L26

Added lines #L25 - L26 were not covered by tests
if (fieldName.equals("query")) {
query = parser.textOrNull();

Check warning on line 28 in spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java#L28

Added line #L28 was not covered by tests
} else {
throw new IllegalArgumentException("Unknown field: " + fieldName);

Check warning on line 30 in spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java#L30

Added line #L30 was not covered by tests
}
}
return new CreateJobRequest(query);

Check warning on line 33 in spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/rest/model/CreateJobRequest.java#L32-L33

Added lines #L32 - L33 were not covered by tests
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* * Copyright OpenSearch Contributors
* * SPDX-License-Identifier: Apache-2.0
*
*/

package org.opensearch.sql.spark.transport;

import org.opensearch.action.ActionType;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.core.action.ActionListener;
import org.opensearch.sql.spark.transport.model.CreateJobActionRequest;
import org.opensearch.sql.spark.transport.model.CreateJobActionResponse;
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

public class TransportCreateJobRequest
extends HandledTransportAction<CreateJobActionRequest, CreateJobActionResponse> {

public static final String NAME = "cluster:admin/opensearch/ql/jobs/write";
public static final ActionType<CreateJobActionResponse> ACTION_TYPE =

Check warning on line 23 in spark/src/main/java/org/opensearch/sql/spark/transport/TransportCreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/transport/TransportCreateJobRequest.java#L23

Added line #L23 was not covered by tests
new ActionType<>(NAME, CreateJobActionResponse::new);



protected TransportCreateJobRequest(TransportService transportService,
ActionFilters actionFilters) {
super(NAME, transportService, actionFilters, CreateJobActionRequest::new);
}

Check warning on line 31 in spark/src/main/java/org/opensearch/sql/spark/transport/TransportCreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/transport/TransportCreateJobRequest.java#L30-L31

Added lines #L30 - L31 were not covered by tests

@Override
protected void doExecute(Task task, CreateJobActionRequest request,
ActionListener<CreateJobActionResponse> listener) {
try {
String responseContent = "submitted_job";
listener.onResponse(new CreateJobActionResponse(responseContent));
} catch (Exception e) {
listener.onFailure(e);
}
}

Check warning on line 42 in spark/src/main/java/org/opensearch/sql/spark/transport/TransportCreateJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/transport/TransportCreateJobRequest.java#L37-L42

Added lines #L37 - L42 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* * Copyright OpenSearch Contributors
* * SPDX-License-Identifier: Apache-2.0
*
*/

package org.opensearch.sql.spark.transport;

import org.opensearch.action.ActionType;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.core.action.ActionListener;
import org.opensearch.sql.spark.transport.model.DeleteJobActionRequest;
import org.opensearch.sql.spark.transport.model.DeleteJobActionResponse;
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

public class TransportDeleteJobRequest
extends HandledTransportAction<DeleteJobActionRequest, DeleteJobActionResponse> {

public static final String NAME = "cluster:admin/opensearch/ql/jobs/delete";
public static final ActionType<DeleteJobActionResponse> ACTION_TYPE =

Check warning on line 23 in spark/src/main/java/org/opensearch/sql/spark/transport/TransportDeleteJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/transport/TransportDeleteJobRequest.java#L23

Added line #L23 was not covered by tests
new ActionType<>(NAME, DeleteJobActionResponse::new);


protected TransportDeleteJobRequest(TransportService transportService,
ActionFilters actionFilters) {
super(NAME, transportService, actionFilters, DeleteJobActionRequest::new);
}

Check warning on line 30 in spark/src/main/java/org/opensearch/sql/spark/transport/TransportDeleteJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/transport/TransportDeleteJobRequest.java#L29-L30

Added lines #L29 - L30 were not covered by tests

@Override
protected void doExecute(Task task, DeleteJobActionRequest request,
ActionListener<DeleteJobActionResponse> listener) {
try {
String responseContent = "deleted_job";
listener.onResponse(new DeleteJobActionResponse(responseContent));
} catch (Exception e) {
listener.onFailure(e);
}
}

Check warning on line 41 in spark/src/main/java/org/opensearch/sql/spark/transport/TransportDeleteJobRequest.java

View check run for this annotation

Codecov / codecov/patch

spark/src/main/java/org/opensearch/sql/spark/transport/TransportDeleteJobRequest.java#L36-L41

Added lines #L36 - L41 were not covered by tests
}
Loading

0 comments on commit b56cf42

Please sign in to comment.