forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Connectors API] Implement update service type action (elastic#104643)
- Loading branch information
1 parent
62fb40a
commit 231c76c
Showing
11 changed files
with
494 additions
and
0 deletions.
There are no files selected for viewing
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,5 @@ | ||
pr: 104643 | ||
summary: "[Connectors API] Implement update service type action" | ||
area: Application | ||
type: enhancement | ||
issues: [] |
38 changes: 38 additions & 0 deletions
38
rest-api-spec/src/main/resources/rest-api-spec/api/connector.update_service_type.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,38 @@ | ||
{ | ||
"connector.update_service_type": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/connector-apis.html", | ||
"description": "Updates the service type of the connector." | ||
}, | ||
"stability": "experimental", | ||
"visibility": "public", | ||
"headers": { | ||
"accept": [ | ||
"application/json" | ||
], | ||
"content_type": [ | ||
"application/json" | ||
] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_connector/{connector_id}/_service_type", | ||
"methods": [ | ||
"PUT" | ||
], | ||
"parts": { | ||
"connector_id": { | ||
"type": "string", | ||
"description": "The unique identifier of the connector to be updated." | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"body": { | ||
"description": "An object containing the connector's service type.", | ||
"required": true | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...yamlRestTest/resources/rest-api-spec/test/entsearch/337_connector_update_service_type.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,61 @@ | ||
setup: | ||
- skip: | ||
version: " - 8.12.99" | ||
reason: Introduced in 8.13.0 | ||
|
||
- do: | ||
connector.put: | ||
connector_id: test-connector | ||
body: | ||
index_name: search-1-test | ||
name: my-connector | ||
language: pl | ||
is_native: false | ||
service_type: super-connector | ||
|
||
--- | ||
"Update Connector Service Type": | ||
- do: | ||
connector.update_service_type: | ||
connector_id: test-connector | ||
body: | ||
service_type: even-better-connector | ||
|
||
|
||
- match: { result: updated } | ||
|
||
- do: | ||
connector.get: | ||
connector_id: test-connector | ||
|
||
- match: { service_type: even-better-connector } | ||
- match: { status: created } | ||
|
||
--- | ||
"Update Connector Service Type - 404 when connector doesn't exist": | ||
- do: | ||
catch: "missing" | ||
connector.update_service_type: | ||
connector_id: test-non-existent-connector | ||
body: | ||
service_type: even-better-connector | ||
|
||
--- | ||
"Update Connector Service Type - 400 status code when connector_id is empty": | ||
- do: | ||
catch: "bad_request" | ||
connector.update_service_type: | ||
connector_id: "" | ||
body: | ||
service_type: even-better-connector | ||
|
||
--- | ||
"Update Connector Service Type - 400 status code when payload is not string": | ||
- do: | ||
catch: "bad_request" | ||
connector.update_service_type: | ||
connector_id: test-connector | ||
body: | ||
service_type: | ||
field_1: test | ||
field_2: something |
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
48 changes: 48 additions & 0 deletions
48
...lasticsearch/xpack/application/connector/action/RestUpdateConnectorServiceTypeAction.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,48 @@ | ||
/* | ||
* 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.action; | ||
|
||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.Scope; | ||
import org.elasticsearch.rest.ServerlessScope; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
import org.elasticsearch.xpack.application.EnterpriseSearch; | ||
|
||
import java.util.List; | ||
|
||
import static org.elasticsearch.rest.RestRequest.Method.PUT; | ||
|
||
@ServerlessScope(Scope.PUBLIC) | ||
public class RestUpdateConnectorServiceTypeAction extends BaseRestHandler { | ||
|
||
@Override | ||
public String getName() { | ||
return "connector_update_service_type_action"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(PUT, "/" + EnterpriseSearch.CONNECTOR_API_ENDPOINT + "/{connector_id}/_service_type")); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { | ||
UpdateConnectorServiceTypeAction.Request request = UpdateConnectorServiceTypeAction.Request.fromXContentBytes( | ||
restRequest.param("connector_id"), | ||
restRequest.content(), | ||
restRequest.getXContentType() | ||
); | ||
return channel -> client.execute( | ||
UpdateConnectorServiceTypeAction.INSTANCE, | ||
request, | ||
new RestToXContentListener<>(channel, ConnectorUpdateActionResponse::status) | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...csearch/xpack/application/connector/action/TransportUpdateConnectorServiceTypeAction.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,52 @@ | ||
/* | ||
* 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.action; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.HandledTransportAction; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.application.connector.ConnectorIndexService; | ||
|
||
public class TransportUpdateConnectorServiceTypeAction extends HandledTransportAction< | ||
UpdateConnectorServiceTypeAction.Request, | ||
ConnectorUpdateActionResponse> { | ||
|
||
protected final ConnectorIndexService connectorIndexService; | ||
|
||
@Inject | ||
public TransportUpdateConnectorServiceTypeAction( | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ActionFilters actionFilters, | ||
Client client | ||
) { | ||
super( | ||
UpdateConnectorServiceTypeAction.NAME, | ||
transportService, | ||
actionFilters, | ||
UpdateConnectorServiceTypeAction.Request::new, | ||
EsExecutors.DIRECT_EXECUTOR_SERVICE | ||
); | ||
this.connectorIndexService = new ConnectorIndexService(client); | ||
} | ||
|
||
@Override | ||
protected void doExecute( | ||
Task task, | ||
UpdateConnectorServiceTypeAction.Request request, | ||
ActionListener<ConnectorUpdateActionResponse> listener | ||
) { | ||
connectorIndexService.updateConnectorServiceType(request, listener.map(r -> new ConnectorUpdateActionResponse(r.getResult()))); | ||
} | ||
} |
Oops, something went wrong.