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 8, 2023
1 parent 24e01d6 commit 1ac3dd7
Show file tree
Hide file tree
Showing 23 changed files with 974 additions and 11 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ configurations.all {
// enforce 1.1.3, https://www.whitesourcesoftware.com/vulnerability-database/WS-2019-0379
resolutionStrategy.force 'commons-codec:commons-codec:1.13'
resolutionStrategy.force 'com.google.guava:guava:32.0.1-jre'
exclude(group: "org.apache.commons", module: "commons-lang3")
}

// updateVersion: Task to auto increment to the next development iteration
Expand Down
8 changes: 0 additions & 8 deletions integ-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ ext {

var projectAbsPath = projectDir.getAbsolutePath()

// add a check to avoid re-downloading multiple times during single test run
if (downloadedSecurityPlugin == null) {
downloadedSecurityPlugin = Paths.get(projectAbsPath, 'bin', 'opensearch-security-snapshot.zip').toFile()
download.run {
src getSecurityPluginDownloadLink()
dest downloadedSecurityPlugin
}
}

// Config below including files are copied from security demo configuration
['esnode.pem', 'esnode-key.pem', 'root-ca.pem'].forEach { file ->
Expand Down
27 changes: 25 additions & 2 deletions plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@
import org.opensearch.sql.plugin.transport.TransportPPLQueryAction;
import org.opensearch.sql.plugin.transport.TransportPPLQueryResponse;
import org.opensearch.sql.prometheus.storage.PrometheusStorageFactory;
import org.opensearch.sql.spark.rest.RestJobManagementAction;
import org.opensearch.sql.spark.storage.SparkStorageFactory;
import org.opensearch.sql.spark.transport.TransportCreateJobRequestAction;
import org.opensearch.sql.spark.transport.TransportDeleteJobRequestAction;
import org.opensearch.sql.spark.transport.TransportGetJobRequestAction;
import org.opensearch.sql.spark.transport.TransportGetQueryResultRequestAction;
import org.opensearch.sql.spark.transport.model.CreateJobActionResponse;
import org.opensearch.sql.spark.transport.model.DeleteJobActionResponse;
import org.opensearch.sql.spark.transport.model.GetJobActionResponse;
import org.opensearch.sql.spark.transport.model.GetJobQueryResultActionResponse;
import org.opensearch.sql.storage.DataSourceFactory;
import org.opensearch.threadpool.ExecutorBuilder;
import org.opensearch.threadpool.FixedExecutorBuilder;
Expand Down Expand Up @@ -131,7 +140,8 @@ public List<RestHandler> getRestHandlers(
new RestSqlStatsAction(settings, restController),
new RestPPLStatsAction(settings, restController),
new RestQuerySettingsAction(settings, restController),
new RestDataSourceQueryAction());
new RestDataSourceQueryAction(),
new RestJobManagementAction());
}

/** Register action and handler so that transportClient can find proxy for action. */
Expand All @@ -155,7 +165,20 @@ public List<RestHandler> getRestHandlers(
new ActionHandler<>(
new ActionType<>(
TransportDeleteDataSourceAction.NAME, DeleteDataSourceActionResponse::new),
TransportDeleteDataSourceAction.class));
TransportDeleteDataSourceAction.class),
new ActionHandler<>(
new ActionType<>(TransportCreateJobRequestAction.NAME, CreateJobActionResponse::new),
TransportCreateJobRequestAction.class),
new ActionHandler<>(
new ActionType<>(TransportGetJobRequestAction.NAME, GetJobActionResponse::new),
TransportGetJobRequestAction.class),
new ActionHandler<>(
new ActionType<>(
TransportGetQueryResultRequestAction.NAME, GetJobQueryResultActionResponse::new),
TransportGetQueryResultRequestAction.class),
new ActionHandler<>(
new ActionType<>(TransportDeleteJobRequestAction.NAME, DeleteJobActionResponse::new),
TransportDeleteJobRequestAction.class));
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion spark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.2.0'
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.2.0'
testImplementation 'junit:junit:4.13.1'
testImplementation "org.opensearch.test:framework:${opensearch_version}"
}

test {
Expand Down Expand Up @@ -53,7 +54,9 @@ jacocoTestCoverageVerification {
rule {
element = 'CLASS'
excludes = [
'org.opensearch.sql.spark.data.constants.*'
'org.opensearch.sql.spark.data.constants.*',
'org.opensearch.sql.spark.rest.*',
'org.opensearch.sql.spark.transport.model.*'
]
limit {
counter = 'LINE'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
/*
* 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.TransportCreateJobRequestAction;
import org.opensearch.sql.spark.transport.TransportDeleteJobRequestAction;
import org.opensearch.sql.spark.transport.TransportGetJobRequestAction;
import org.opensearch.sql.spark.transport.TransportGetQueryResultRequestAction;
import org.opensearch.sql.spark.transport.model.CreateJobActionRequest;
import org.opensearch.sql.spark.transport.model.CreateJobActionResponse;
import org.opensearch.sql.spark.transport.model.DeleteJobActionRequest;
import org.opensearch.sql.spark.transport.model.DeleteJobActionResponse;
import org.opensearch.sql.spark.transport.model.GetJobActionRequest;
import org.opensearch.sql.spark.transport.model.GetJobActionResponse;
import org.opensearch.sql.spark.transport.model.GetJobQueryResultActionRequest;
import org.opensearch.sql.spark.transport.model.GetJobQueryResultActionResponse;

public class RestJobManagementAction extends BaseRestHandler {

Check warning on line 44 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#L44

Added line #L44 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 49 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#L49

Added line #L49 was not covered by tests

@Override
public String getName() {
return JOB_ACTIONS;

Check warning on line 53 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#L53

Added line #L53 was not covered by tests
}

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

Check warning on line 58 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#L58

Added line #L58 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 80 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#L80

Added line #L80 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 92 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#L92

Added line #L92 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 102 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#L102

Added line #L102 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 110 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#L110

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

Check warning on line 112 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#L112

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

Check warning on line 114 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#L114

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

Check warning on line 117 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#L116-L117

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

Check warning on line 119 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#L119

Added line #L119 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
TransportCreateJobRequestAction.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 137 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#L137

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

Check warning on line 142 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#L141-L142

Added lines #L141 - L142 were not covered by tests

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

Check warning on line 147 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#L146-L147

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

private RestChannelConsumer executeGetRequest(RestRequest restRequest, NodeClient nodeClient) {
Boolean isResultRequest = restRequest.rawPath().contains("result");

Check warning on line 152 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#L152

Added line #L152 was not covered by tests
if (isResultRequest) {
return executeGetJobQueryResultRequest(nodeClient, restRequest);

Check warning on line 154 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#L154

Added line #L154 was not covered by tests
} else {
return executeGetJobRequest(nodeClient, restRequest);

Check warning on line 156 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#L156

Added line #L156 was not covered by tests
}
}

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

Check warning on line 164 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#L162-L164

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

Check warning on line 167 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#L167

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

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#L170

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

Check warning on line 174 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

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

Check warning on line 179 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#L178-L179

Added lines #L178 - L179 were not covered by tests

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

Check warning on line 184 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#L183-L184

Added lines #L183 - L184 were not covered by tests
}));
}

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

Check warning on line 191 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-L191

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

Check warning on line 194 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#L194

Added line #L194 was not covered by tests
TransportGetJobRequestAction.ACTION_TYPE,
new GetJobActionRequest(jobId),
new ActionListener<>() {

Check warning on line 197 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#L197

Added line #L197 was not covered by tests
@Override
public void onResponse(GetJobActionResponse getJobActionResponse) {
restChannel.sendResponse(

Check warning on line 200 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#L200

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

Check warning on line 205 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-L205

Added lines #L204 - L205 were not covered by tests

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

Check warning on line 210 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#L209-L210

Added lines #L209 - L210 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 219 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#L216-L219

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

Check warning on line 221 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#L221

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

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
}
}
}

Check warning on line 226 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#L226

Added line #L226 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 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#L229-L231

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

Check warning on line 234 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#L234

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

Check warning on line 237 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#L237

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

Check warning on line 240 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#L240

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

Check warning on line 245 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#L244-L245

Added lines #L244 - L245 were not covered by tests

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

Check warning on line 250 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#L249-L250

Added lines #L249 - L250 were 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 257 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#L255-L257

Added lines #L255 - L257 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,35 @@
/*
* 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
}
}
Loading

0 comments on commit 1ac3dd7

Please sign in to comment.