forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Add cancel connector sync job endpoint (elastic#1…
…02865) Add cancel connector sync job endpoint.
- Loading branch information
Showing
13 changed files
with
641 additions
and
60 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
rest-api-spec/src/main/resources/rest-api-spec/api/connector_sync_job.cancel.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"connector_sync_job.cancel": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/guide/en/enterprise-search/current/connectors.html", | ||
"description": "Cancels a connector sync job." | ||
}, | ||
"stability": "experimental", | ||
"visibility": "feature_flag", | ||
"feature_flag": "es.connector_api_feature_flag_enabled", | ||
"headers": { | ||
"accept": [ | ||
"application/json" | ||
] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_connector/_sync_job/{connector_sync_job_id}/_cancel", | ||
"methods": [ | ||
"PUT" | ||
], | ||
"parts": { | ||
"connector_sync_job_id": { | ||
"type": "string", | ||
"description": "The unique identifier of the connector sync job to be canceled" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...src/yamlRestTest/resources/rest-api-spec/test/entsearch/430_connector_sync_job_cancel.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
setup: | ||
- skip: | ||
version: " - 8.11.99" | ||
reason: Introduced in 8.12.0 | ||
- do: | ||
connector.put: | ||
connector_id: test-connector | ||
body: | ||
index_name: search-test | ||
name: my-connector | ||
language: de | ||
is_native: false | ||
service_type: super-connector | ||
|
||
--- | ||
"Cancel a Connector Sync Job": | ||
- do: | ||
connector_sync_job.post: | ||
body: | ||
id: test-connector | ||
job_type: full | ||
trigger_method: on_demand | ||
- set: { id: sync-job-id-to-cancel } | ||
- do: | ||
connector_sync_job.cancel: | ||
connector_sync_job_id: $sync-job-id-to-cancel | ||
|
||
- match: { acknowledged: true } | ||
|
||
|
||
--- | ||
"Cancel a Connector Sync Job - Connector Sync Job does not exist": | ||
- do: | ||
connector_sync_job.check_in: | ||
connector_sync_job_id: test-nonexistent-connector-sync-job-id | ||
catch: missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...lasticsearch/xpack/application/connector/syncjob/action/CancelConnectorSyncJobAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.connector.syncjob.action; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.xcontent.ParseField; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.elasticsearch.xpack.application.connector.syncjob.ConnectorSyncJobConstants.EMPTY_CONNECTOR_SYNC_JOB_ID_ERROR_MESSAGE; | ||
|
||
public class CancelConnectorSyncJobAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final CancelConnectorSyncJobAction INSTANCE = new CancelConnectorSyncJobAction(); | ||
public static final String NAME = "cluster:admin/xpack/connector/sync_job/cancel"; | ||
|
||
private CancelConnectorSyncJobAction() { | ||
super(NAME, AcknowledgedResponse::readFrom); | ||
} | ||
|
||
public static class Request extends ActionRequest implements ToXContentObject { | ||
public static final ParseField CONNECTOR_SYNC_JOB_ID_FIELD = new ParseField("connector_sync_job_id"); | ||
|
||
private final String connectorSyncJobId; | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.connectorSyncJobId = in.readString(); | ||
} | ||
|
||
public Request(String connectorSyncJobId) { | ||
this.connectorSyncJobId = connectorSyncJobId; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
|
||
if (Strings.isNullOrEmpty(connectorSyncJobId)) { | ||
validationException = addValidationError(EMPTY_CONNECTOR_SYNC_JOB_ID_ERROR_MESSAGE, validationException); | ||
} | ||
|
||
return validationException; | ||
} | ||
|
||
public String getConnectorSyncJobId() { | ||
return connectorSyncJobId; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(connectorSyncJobId); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Request request = (Request) o; | ||
return Objects.equals(connectorSyncJobId, request.connectorSyncJobId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(connectorSyncJobId); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(CONNECTOR_SYNC_JOB_ID_FIELD.getPreferredName(), connectorSyncJobId); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
private static final ConstructingObjectParser<CancelConnectorSyncJobAction.Request, Void> PARSER = new ConstructingObjectParser<>( | ||
"cancel_connector_sync_job_request", | ||
false, | ||
(args) -> new Request((String) args[0]) | ||
); | ||
|
||
static { | ||
PARSER.declareString(constructorArg(), CONNECTOR_SYNC_JOB_ID_FIELD); | ||
} | ||
|
||
public static CancelConnectorSyncJobAction.Request parse(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.