-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
Signed-off-by: Derek Ho <[email protected]>
- Loading branch information
There are no files selected for viewing
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); | ||
} | ||
Check warning on line 20 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionRequest.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionRequest.java#L19-L20
|
||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
Check warning on line 24 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionRequest.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionRequest.java#L24
|
||
} | ||
|
||
public DataSourceActionRequest() { | ||
} | ||
|
||
// public DataSourceMetadata getSourceMetadata() { | ||
// return null; | ||
// } | ||
// | ||
// public Map<String, Object> getDataSourceData() { | ||
// return Map.of(); | ||
// } | ||
} |
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); | ||
} | ||
Check warning on line 19 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionResponse.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionResponse.java#L18-L19
|
||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
|
||
} | ||
Check warning on line 24 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionResponse.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/model/transport/DataSourceActionResponse.java#L24
|
||
} |
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) { | ||
Check warning on line 75 in datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.java#L72-L75
|
||
@Override | ||
protected Object buildJsonObject(String response) { | ||
return response; | ||
Check warning on line 78 in datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.java#L78
|
||
} | ||
}.format("Updated DataSource with name " + request2.getDataSourceData().get(NAME_FIELD)); | ||
actionListener.onResponse(new PatchDataSourceActionResponse(responseContent)); | ||
} else { | ||
throw new IllegalArgumentException("Unexpected request type"); | ||
Check warning on line 83 in datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.java Codecov / codecov/patchdatasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDataSourceAction.java#L80-L83
|
||
} | ||
// actionListener.onResponse(new UpdateDataSourceActionResponse(responseContent)); | ||
} catch (Exception e) { | ||
actionListener.onFailure(e); | ||
} | ||
} | ||
} |
This file was deleted.