-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Implement patch API for datasources * Change patch implementation to Map * Fix up, everything complete except unit test * Revise PR to use existing functions * Remove unused utility function * Add tests * Add back line * fix build issue * Fix tests and add in rst * Register patch * Add imports * Patch * Fix integration test * Update IT * Add tests * Fix test * Fix tests and increase code cov * Add more coverage to impl * Fix test and jacoco passing * Test fix * Add docs --------- (cherry picked from commit f835112) Signed-off-by: Derek Ho <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3d1a376
commit 4c151fe
Showing
15 changed files
with
580 additions
and
32 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
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
49 changes: 49 additions & 0 deletions
49
...ain/java/org/opensearch/sql/datasources/model/transport/PatchDataSourceActionRequest.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,49 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.datasources.model.transport; | ||
|
||
import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; | ||
import static org.opensearch.sql.datasources.utils.XContentParserUtils.CONNECTOR_FIELD; | ||
import static org.opensearch.sql.datasources.utils.XContentParserUtils.NAME_FIELD; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
|
||
public class PatchDataSourceActionRequest extends ActionRequest { | ||
|
||
@Getter private Map<String, Object> dataSourceData; | ||
|
||
/** Constructor of UpdateDataSourceActionRequest from StreamInput. */ | ||
public PatchDataSourceActionRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public PatchDataSourceActionRequest(Map<String, Object> dataSourceData) { | ||
this.dataSourceData = dataSourceData; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (this.dataSourceData.get(NAME_FIELD).equals(DEFAULT_DATASOURCE_NAME)) { | ||
ActionRequestValidationException exception = new ActionRequestValidationException(); | ||
exception.addValidationError( | ||
"Not allowed to update datasource with name : " + DEFAULT_DATASOURCE_NAME); | ||
return exception; | ||
} else if (this.dataSourceData.get(CONNECTOR_FIELD) != null) { | ||
ActionRequestValidationException exception = new ActionRequestValidationException(); | ||
exception.addValidationError("Not allowed to update connector for datasource"); | ||
return exception; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...in/java/org/opensearch/sql/datasources/model/transport/PatchDataSourceActionResponse.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,31 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.datasources.model.transport; | ||
|
||
import java.io.IOException; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
@RequiredArgsConstructor | ||
public class PatchDataSourceActionResponse extends ActionResponse { | ||
|
||
@Getter private final String result; | ||
|
||
public PatchDataSourceActionResponse(StreamInput in) throws IOException { | ||
super(in); | ||
result = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
streamOutput.writeString(result); | ||
} | ||
} |
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
74 changes: 74 additions & 0 deletions
74
...rc/main/java/org/opensearch/sql/datasources/transport/TransportPatchDataSourceAction.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,74 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.datasources.transport; | ||
|
||
import static org.opensearch.sql.datasources.utils.XContentParserUtils.NAME_FIELD; | ||
import static org.opensearch.sql.protocol.response.format.JsonResponseFormatter.Style.PRETTY; | ||
|
||
import org.opensearch.action.ActionType; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.HandledTransportAction; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.sql.datasource.DataSourceService; | ||
import org.opensearch.sql.datasources.model.transport.PatchDataSourceActionRequest; | ||
import org.opensearch.sql.datasources.model.transport.PatchDataSourceActionResponse; | ||
import org.opensearch.sql.datasources.service.DataSourceServiceImpl; | ||
import org.opensearch.sql.protocol.response.format.JsonResponseFormatter; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.transport.TransportService; | ||
|
||
public class TransportPatchDataSourceAction | ||
extends HandledTransportAction<PatchDataSourceActionRequest, PatchDataSourceActionResponse> { | ||
|
||
public static final String NAME = "cluster:admin/opensearch/ql/datasources/patch"; | ||
public static final ActionType<PatchDataSourceActionResponse> ACTION_TYPE = | ||
new ActionType<>(NAME, PatchDataSourceActionResponse::new); | ||
|
||
private DataSourceService dataSourceService; | ||
|
||
/** | ||
* TransportPatchDataSourceAction action for updating datasource. | ||
* | ||
* @param transportService transportService. | ||
* @param actionFilters actionFilters. | ||
* @param dataSourceService dataSourceService. | ||
*/ | ||
@Inject | ||
public TransportPatchDataSourceAction( | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
DataSourceServiceImpl dataSourceService) { | ||
super( | ||
TransportPatchDataSourceAction.NAME, | ||
transportService, | ||
actionFilters, | ||
PatchDataSourceActionRequest::new); | ||
this.dataSourceService = dataSourceService; | ||
} | ||
|
||
@Override | ||
protected void doExecute( | ||
Task task, | ||
PatchDataSourceActionRequest request, | ||
ActionListener<PatchDataSourceActionResponse> actionListener) { | ||
try { | ||
dataSourceService.patchDataSource(request.getDataSourceData()); | ||
String responseContent = | ||
new JsonResponseFormatter<String>(PRETTY) { | ||
@Override | ||
protected Object buildJsonObject(String response) { | ||
return response; | ||
} | ||
}.format("Updated DataSource with name " + request.getDataSourceData().get(NAME_FIELD)); | ||
actionListener.onResponse(new PatchDataSourceActionResponse(responseContent)); | ||
} catch (Exception e) { | ||
actionListener.onFailure(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.