Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Oct 17, 2023
1 parent 6fa4b27 commit 7c43b35
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.core.common.io.stream.StreamInput;

public class PatchDataSourceActionRequest extends DataSourceActionRequest {
public class PatchDataSourceActionRequest extends PatchableDataSourceActionRequest {

@Getter private Map<String, Object> dataSourceData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.opensearch.core.common.io.stream.StreamOutput;

@RequiredArgsConstructor
public class PatchDataSourceActionResponse extends DataSourceActionResponse {
public class PatchDataSourceActionResponse extends PatchableDataSourceActionResponse {

@Getter private final String result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.core.common.io.stream.StreamInput;

public class DataSourceActionRequest extends ActionRequest {
public class PatchableDataSourceActionRequest extends ActionRequest {

public DataSourceActionRequest(StreamInput in) throws IOException {
public PatchableDataSourceActionRequest(StreamInput in) throws IOException {
super(in);
}

Check warning on line 12 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/PatchableDataSourceActionRequest.java

View check run for this annotation

Codecov / codecov/patch

datasources/src/main/java/org/opensearch/sql/datasources/model/transport/PatchableDataSourceActionRequest.java#L11-L12

Added lines #L11 - L12 were not covered by tests

Expand All @@ -16,7 +16,7 @@ public ActionRequestValidationException validate() {
return null;

Check warning on line 16 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/PatchableDataSourceActionRequest.java

View check run for this annotation

Codecov / codecov/patch

datasources/src/main/java/org/opensearch/sql/datasources/model/transport/PatchableDataSourceActionRequest.java#L16

Added line #L16 was not covered by tests
}

public DataSourceActionRequest() {}
public PatchableDataSourceActionRequest() {}

// public DataSourceMetadata getSourceMetadata() {
// return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;

public class DataSourceActionResponse extends ActionResponse {
public class PatchableDataSourceActionResponse extends ActionResponse {
@Getter String result;

public DataSourceActionResponse() {}
public PatchableDataSourceActionResponse() {}

public DataSourceActionResponse(StreamInput in) throws IOException {
public PatchableDataSourceActionResponse(StreamInput in) throws IOException {
super(in);
}

Check warning on line 16 in datasources/src/main/java/org/opensearch/sql/datasources/model/transport/PatchableDataSourceActionResponse.java

View check run for this annotation

Codecov / codecov/patch

datasources/src/main/java/org/opensearch/sql/datasources/model/transport/PatchableDataSourceActionResponse.java#L15-L16

Added lines #L15 - L16 were not covered by tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.sql.datasource.model.DataSourceMetadata;

public class UpdateDataSourceActionRequest extends DataSourceActionRequest {
public class UpdateDataSourceActionRequest extends PatchableDataSourceActionRequest {

@Getter private DataSourceMetadata dataSourceMetadata;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.opensearch.core.common.io.stream.StreamOutput;

@RequiredArgsConstructor
public class UpdateDataSourceActionResponse extends DataSourceActionResponse {
public class UpdateDataSourceActionResponse extends PatchableDataSourceActionResponse {

@Getter private final String result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ private RestChannelConsumer executeUpdateRequest(RestRequest restRequest, NodeCl
nodeClient,
() ->
nodeClient.execute(
TransportDataSourceAction.ACTION_TYPE,
TransportPatchableDataSourceAction.ACTION_TYPE,
new UpdateDataSourceActionRequest(dataSourceMetadata),
new ActionListener<>() {
@Override
public void onResponse(
DataSourceActionResponse updateDataSourceActionResponse) {
PatchableDataSourceActionResponse updateDataSourceActionResponse) {
restChannel.sendResponse(
new BytesRestResponse(
RestStatus.OK,
Expand All @@ -225,11 +225,12 @@ private RestChannelConsumer executePatchRequest(RestRequest restRequest, NodeCli
nodeClient,
() -> {
nodeClient.execute(

Check warning on line 227 in datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java

View check run for this annotation

Codecov / codecov/patch

datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java#L227

Added line #L227 was not covered by tests
TransportDataSourceAction.ACTION_TYPE,
TransportPatchableDataSourceAction.ACTION_TYPE,
new PatchDataSourceActionRequest(dataSourceData),
new ActionListener<>() {

Check warning on line 230 in datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java

View check run for this annotation

Codecov / codecov/patch

datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java#L230

Added line #L230 was not covered by tests
@Override
public void onResponse(DataSourceActionResponse patchDataSourceActionResponse) {
public void onResponse(
PatchableDataSourceActionResponse patchDataSourceActionResponse) {
restChannel.sendResponse(

Check warning on line 234 in datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java

View check run for this annotation

Codecov / codecov/patch

datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java#L234

Added line #L234 was not covered by tests
new BytesRestResponse(
RestStatus.OK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

public class TransportDataSourceAction
extends HandledTransportAction<DataSourceActionRequest, DataSourceActionResponse> {
public class TransportPatchableDataSourceAction
extends HandledTransportAction<
PatchableDataSourceActionRequest, PatchableDataSourceActionResponse> {

public static final String NAME = "cluster:admin/opensearch/ql/datasources/update";
public static final ActionType<DataSourceActionResponse> ACTION_TYPE =
new ActionType<>(NAME, DataSourceActionResponse::new);
public static final ActionType<PatchableDataSourceActionResponse> ACTION_TYPE =
new ActionType<>(NAME, PatchableDataSourceActionResponse::new);

private DataSourceService dataSourceService;

Expand All @@ -39,23 +40,23 @@ public class TransportDataSourceAction
* @param dataSourceService dataSourceService.
*/
@Inject
public TransportDataSourceAction(
public TransportPatchableDataSourceAction(
TransportService transportService,
ActionFilters actionFilters,
DataSourceServiceImpl dataSourceService) {
super(
TransportDataSourceAction.NAME,
TransportPatchableDataSourceAction.NAME,
transportService,
actionFilters,
DataSourceActionRequest::new);
PatchableDataSourceActionRequest::new);
this.dataSourceService = dataSourceService;
}

@Override
protected void doExecute(
Task task,
DataSourceActionRequest request,
ActionListener<DataSourceActionResponse> actionListener) {
PatchableDataSourceActionRequest request,
ActionListener<PatchableDataSourceActionResponse> actionListener) {
try {
if (request instanceof UpdateDataSourceActionRequest) {
UpdateDataSourceActionRequest request1 = (UpdateDataSourceActionRequest) request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensearch.core.action.ActionListener;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.datasource.model.DataSourceType;
import org.opensearch.sql.datasources.model.transport.DataSourceActionResponse;
import org.opensearch.sql.datasources.model.transport.PatchableDataSourceActionResponse;
import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionRequest;
import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionResponse;
import org.opensearch.sql.datasources.service.DataSourceServiceImpl;
Expand All @@ -29,10 +29,10 @@
public class TransportDataSourceActionTest {

@Mock private TransportService transportService;
@Mock private TransportDataSourceAction action;
@Mock private TransportPatchableDataSourceAction action;
@Mock private DataSourceServiceImpl dataSourceService;
@Mock private Task task;
@Mock private ActionListener<DataSourceActionResponse> actionListener;
@Mock private ActionListener<PatchableDataSourceActionResponse> actionListener;

@Captor
private ArgumentCaptor<UpdateDataSourceActionResponse>
Expand All @@ -43,7 +43,7 @@ public class TransportDataSourceActionTest {
@BeforeEach
public void setUp() {
action =
new TransportDataSourceAction(
new TransportPatchableDataSourceAction(
transportService, new ActionFilters(new HashSet<>()), dataSourceService);
}

Expand Down
9 changes: 3 additions & 6 deletions plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,9 @@ public List<RestHandler> getRestHandlers(
new ActionType<>(TransportGetDataSourceAction.NAME, GetDataSourceActionResponse::new),
TransportGetDataSourceAction.class),
new ActionHandler<>(
new ActionType<>(TransportDataSourceAction.NAME, DataSourceActionResponse::new),
TransportDataSourceAction.class),
// new ActionHandler<>(
// new ActionType<>(
// TransportPatchDataSourceAction.NAME, PatchDataSourceActionResponse::new),
// TransportPatchDataSourceAction.class),
new ActionType<>(
TransportPatchableDataSourceAction.NAME, PatchableDataSourceActionResponse::new),
TransportPatchableDataSourceAction.class),
new ActionHandler<>(
new ActionType<>(
TransportDeleteDataSourceAction.NAME, DeleteDataSourceActionResponse::new),
Expand Down

0 comments on commit 7c43b35

Please sign in to comment.