forked from opensearch-project/sql
-
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.
Initial try at using same permissions for patch and put
Signed-off-by: Derek Ho <dxho@amazon.com>
- Loading branch information
Showing
11 changed files
with
175 additions
and
93 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionRequest.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,37 @@ | ||
package org.opensearch.sql.datasources.model.transport; | ||
|
||
import lombok.Getter; | ||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.sql.datasource.model.DataSourceMetadata; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
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; | ||
|
||
public class DataSourceActionRequest extends ActionRequest { | ||
|
||
public DataSourceActionRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
public DataSourceActionRequest() { | ||
} | ||
|
||
// public DataSourceMetadata getSourceMetadata() { | ||
// return null; | ||
// } | ||
// | ||
// public Map<String, Object> getDataSourceData() { | ||
// return Map.of(); | ||
// } | ||
} |
25 changes: 25 additions & 0 deletions
25
...rc/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionResponse.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,25 @@ | ||
package org.opensearch.sql.datasources.model.transport; | ||
|
||
import lombok.Getter; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
public class DataSourceActionResponse extends ActionResponse { | ||
@Getter | ||
String result; | ||
|
||
public DataSourceActionResponse() { | ||
} | ||
|
||
public DataSourceActionResponse(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
|
||
} | ||
} |
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
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
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
90 changes: 90 additions & 0 deletions
90
...ces/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.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,90 @@ | ||
/* | ||
* | ||
* * 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.*; | ||
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 TransportDataSourceAction | ||
extends HandledTransportAction<DataSourceActionRequest, DataSourceActionResponse> { | ||
|
||
public static final String NAME = "cluster:admin/opensearch/ql/datasources/update"; | ||
public static final ActionType<DataSourceActionResponse> ACTION_TYPE = | ||
new ActionType<>(NAME, DataSourceActionResponse::new); | ||
|
||
private DataSourceService dataSourceService; | ||
|
||
/** | ||
* TransportUpdateDataSourceAction action for updating datasource. | ||
* | ||
* @param transportService transportService. | ||
* @param actionFilters actionFilters. | ||
* @param dataSourceService dataSourceService. | ||
*/ | ||
@Inject | ||
public TransportDataSourceAction( | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
DataSourceServiceImpl dataSourceService) { | ||
super( | ||
TransportDataSourceAction.NAME, | ||
transportService, | ||
actionFilters, | ||
DataSourceActionRequest::new); | ||
this.dataSourceService = dataSourceService; | ||
} | ||
|
||
@Override | ||
protected void doExecute( | ||
Task task, | ||
DataSourceActionRequest request, | ||
ActionListener<DataSourceActionResponse> actionListener) { | ||
try { | ||
if (request instanceof UpdateDataSourceActionRequest) { | ||
UpdateDataSourceActionRequest request1 = (UpdateDataSourceActionRequest) request; | ||
dataSourceService.updateDataSource(request1.getDataSourceMetadata()); | ||
String responseContent = | ||
new JsonResponseFormatter<String>(PRETTY) { | ||
@Override | ||
protected Object buildJsonObject(String response) { | ||
return response; | ||
} | ||
}.format("Updated DataSource with name " + request1.getDataSourceMetadata().getName()); | ||
actionListener.onResponse(new UpdateDataSourceActionResponse(responseContent)); | ||
} else if (request instanceof PatchDataSourceActionRequest) { | ||
PatchDataSourceActionRequest request2 = (PatchDataSourceActionRequest) request; | ||
dataSourceService.patchDataSource(request2.getDataSourceData()); | ||
String responseContent = | ||
new JsonResponseFormatter<String>(PRETTY) { | ||
@Override | ||
protected Object buildJsonObject(String response) { | ||
return response; | ||
} | ||
}.format("Updated DataSource with name " + request2.getDataSourceData().get(NAME_FIELD)); | ||
actionListener.onResponse(new PatchDataSourceActionResponse(responseContent)); | ||
} else { | ||
throw new IllegalArgumentException("Unexpected request type"); | ||
} | ||
// actionListener.onResponse(new UpdateDataSourceActionResponse(responseContent)); | ||
} catch (Exception e) { | ||
actionListener.onFailure(e); | ||
} | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
...c/main/java/org/opensearch/sql/datasources/transport/TransportUpdateDataSourceAction.java
This file was deleted.
Oops, something went wrong.
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