From 2832b24ca12fd192f7e41ee63ed5dbe751d07387 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Mon, 5 Feb 2024 08:49:57 -0600 Subject: [PATCH] Spotless and compile issue Signed-off-by: Peter Nied --- .../action/admin/indices/view/ViewIT.java | 19 ++- .../admin/indices/view/CreateViewAction.java | 26 ++-- .../admin/indices/view/SearchViewAction.java | 22 ++- .../admin/indices/view/ViewService.java | 11 +- .../org/opensearch/cluster/metadata/View.java | 3 +- .../main/java/org/opensearch/node/Node.java | 5 +- .../action/admin/indices/RestViewAction.java | 141 ++++++++---------- .../admin/indices/view/CreateViewTests.java | 18 ++- .../admin/indices/view/SearchViewTests.java | 7 +- .../cluster/metadata/ViewTests.java | 2 +- 10 files changed, 121 insertions(+), 133 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/view/ViewIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/view/ViewIT.java index ac706491478d1..2da1f5d187e2d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/view/ViewIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/view/ViewIT.java @@ -8,11 +8,6 @@ package org.opensearch.action.admin.indices.view; -import static org.hamcrest.Matchers.is; -import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; - -import java.util.List; - import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; import org.opensearch.index.IndexNotFoundException; @@ -20,7 +15,11 @@ import org.opensearch.test.OpenSearchIntegTestCase; import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope; import org.opensearch.test.OpenSearchIntegTestCase.Scope; -import org.opensearch.test.junit.annotations.TestLogging; + +import java.util.List; + +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; +import static org.hamcrest.Matchers.is; @ClusterScope(scope = Scope.TEST, numDataNodes = 2) public class ViewIT extends OpenSearchIntegTestCase { @@ -40,7 +39,11 @@ private int createIndexWithDocs(final String indexName) throws Exception { } private CreateViewAction.Response createView(final String name, final String indexPattern) throws Exception { - final CreateViewAction.Request request = new CreateViewAction.Request(name, null, List.of(new CreateViewAction.Request.Target(indexPattern))); + final CreateViewAction.Request request = new CreateViewAction.Request( + name, + null, + List.of(new CreateViewAction.Request.Target(indexPattern)) + ); final CreateViewAction.Response response = client().admin().indices().createView(request).actionGet(); performRemoteStoreTestAction(); return response; @@ -48,7 +51,7 @@ private CreateViewAction.Response createView(final String name, final String ind private SearchResponse searchView(final String viewName) throws Exception { final SearchViewAction.Request request = SearchViewAction.createRequestWith(viewName, new SearchRequest()); - final SearchResponse response = client().searchView(request).actionGet(); + final SearchResponse response = client().admin().indices().searchView(request).actionGet(); return response; } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/view/CreateViewAction.java b/server/src/main/java/org/opensearch/action/admin/indices/view/CreateViewAction.java index f4e8b1db1956a..c47eb9ea5432d 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/view/CreateViewAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/view/CreateViewAction.java @@ -1,10 +1,5 @@ package org.opensearch.action.admin.indices.view; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.ActionType; import org.opensearch.action.ValidateActions; @@ -34,6 +29,11 @@ import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + /** Action to create a view */ public class CreateViewAction extends ActionType { @@ -83,11 +83,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request that = (Request) o; - return name.equals(that.name) - && description.equals(that.description) - && targets.equals(that.targets); + return name.equals(that.name) && description.equals(that.description) && targets.equals(that.targets); } - + @Override public int hashCode() { return Objects.hash(name, description, targets); @@ -142,7 +140,7 @@ public boolean equals(Object o) { Target that = (Target) o; return indexPattern.equals(that.indexPattern); } - + @Override public int hashCode() { return Objects.hash(indexPattern); @@ -170,7 +168,7 @@ public ActionRequestValidationException validate() { static { PARSER.declareString(ConstructingObjectParser.constructorArg(), View.Target.INDEX_PATTERN_FIELD); } - + public static Target fromXContent(final XContentParser parser) throws IOException { return PARSER.parse(parser, null); } @@ -187,7 +185,7 @@ public static Target fromXContent(final XContentParser parser) throws IOExceptio PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), View.DESCRIPTION_FIELD); PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), (p, c) -> Target.fromXContent(p), View.TARGETS_FIELD); } - + public static Request fromXContent(final XContentParser parser) throws IOException { return PARSER.parse(parser, null); } @@ -197,7 +195,7 @@ public static Request fromXContent(final XContentParser parser) throws IOExcepti @ExperimentalApi public static class Response extends ActionResponse implements ToXContentObject { - private final View createdView; + private final View createdView; public Response(final View createdView) { this.createdView = createdView; @@ -220,7 +218,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa builder.endObject(); return builder; } - + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "create_view_response", args -> new Response((View) args[0]) diff --git a/server/src/main/java/org/opensearch/action/admin/indices/view/SearchViewAction.java b/server/src/main/java/org/opensearch/action/admin/indices/view/SearchViewAction.java index b27fb6339418b..b089d04751a63 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/view/SearchViewAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/view/SearchViewAction.java @@ -1,9 +1,5 @@ package org.opensearch.action.admin.indices.view; -import java.io.IOException; -import java.util.Objects; -import java.util.function.Function; - import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.ActionType; import org.opensearch.action.search.SearchRequest; @@ -21,6 +17,10 @@ import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; +import java.io.IOException; +import java.util.Objects; +import java.util.function.Function; + import static org.opensearch.action.ValidateActions.addValidationError; /** Action to create a view */ @@ -34,8 +34,7 @@ private SearchViewAction() { } /** Given a search request, creates a ViewSearchRequest */ - public static Request createRequestWith(final String view, final SearchRequest searchRequest) - throws IOException { + public static Request createRequestWith(final String view, final SearchRequest searchRequest) throws IOException { final BytesStreamOutput savedSearchRequest = new BytesStreamOutput(); searchRequest.writeTo(savedSearchRequest); savedSearchRequest.writeString(view); @@ -43,6 +42,7 @@ public static Request createRequestWith(final String view, final SearchRequest s final BytesStreamInput input = new BytesStreamInput(savedSearchRequest.bytes().toBytesRef().bytes); return new Request(input); } + /** * Wraps the functionality of search requests and tailors for what is available * when searching through views @@ -71,10 +71,9 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Request that = (Request) o; - return view.equals(that.view) - && super.equals(that); + return view.equals(that.view) && super.equals(that); } - + @Override public int hashCode() { return Objects.hash(view, super.hashCode()); @@ -118,10 +117,7 @@ public static class TransportAction extends HandledTransportAction pluginComponents = pluginsService.filterPlugins(Plugin.class) .stream() diff --git a/server/src/main/java/org/opensearch/rest/action/admin/indices/RestViewAction.java b/server/src/main/java/org/opensearch/rest/action/admin/indices/RestViewAction.java index bfc97c309155e..126348e71c971 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/indices/RestViewAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/indices/RestViewAction.java @@ -8,30 +8,17 @@ package org.opensearch.rest.action.admin.indices; -import joptsimple.internal.Strings; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.admin.indices.view.CreateViewAction; import org.opensearch.action.admin.indices.view.SearchViewAction; import org.opensearch.action.search.SearchAction; import org.opensearch.client.node.NodeClient; -import org.opensearch.cluster.ClusterState; -import org.opensearch.cluster.ClusterStateUpdateTask; -import org.opensearch.cluster.metadata.Metadata; -import org.opensearch.cluster.metadata.View; -import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.ValidationException; -import org.opensearch.common.inject.Inject; -import org.opensearch.core.rest.RestStatus; -import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.rest.BaseRestHandler; -import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.NamedRoute; -import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; -import org.opensearch.rest.RestResponse; import org.opensearch.rest.action.RestCancellableNodeClient; import org.opensearch.rest.action.RestStatusToXContentListener; import org.opensearch.rest.action.RestToXContentListener; @@ -39,14 +26,10 @@ import java.io.IOException; import java.util.List; -import java.util.Optional; import java.util.function.IntConsumer; -import java.util.stream.Collectors; -import static org.opensearch.rest.RestRequest.Method.DELETE; import static org.opensearch.rest.RestRequest.Method.GET; import static org.opensearch.rest.RestRequest.Method.POST; -import static org.opensearch.rest.RestRequest.Method.PUT; /** All rest handlers for view actions */ public class RestViewAction { @@ -82,8 +65,14 @@ public static class SearchViewHandler extends BaseRestHandler { @Override public List routes() { return List.of( - new NamedRoute.Builder().path("/views/" + VIEW_ID_PARAMETER + "/_search").method(GET).uniqueName("cluster:views:search").build(), - new NamedRoute.Builder().path("/views/" + VIEW_ID_PARAMETER + "/_search").method(POST).uniqueName("cluster:views:search").build() + new NamedRoute.Builder().path("/views/" + VIEW_ID_PARAMETER + "/_search") + .method(GET) + .uniqueName("cluster:views:search") + .build(), + new NamedRoute.Builder().path("/views/" + VIEW_ID_PARAMETER + "/_search") + .method(POST) + .uniqueName("cluster:views:search") + .build() ); } @@ -114,7 +103,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC throw validationResult; } - return channel -> { + return channel -> { final RestCancellableNodeClient cancelClient = new RestCancellableNodeClient(client, request.getHttpChannel()); cancelClient.execute(SearchAction.INSTANCE, viewSearchRequest, new RestStatusToXContentListener<>(channel)); }; @@ -123,78 +112,78 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC // public List routes() { - // return List.of( - // new NamedRoute.Builder().path("/views").method(GET).uniqueName("cluster:views:list").build(), - // new NamedRoute.Builder().path("/views/" + viewIdParameter).method(GET).uniqueName("cluster:views:get").build(), - // new NamedRoute.Builder().path("/views/" + viewIdParameter).method(DELETE).uniqueName("cluster:views:delete").build(), - // new NamedRoute.Builder().path("/views/" + viewIdParameter).method(PUT).uniqueName("cluster:views:update").build() - // ); + // return List.of( + // new NamedRoute.Builder().path("/views").method(GET).uniqueName("cluster:views:list").build(), + // new NamedRoute.Builder().path("/views/" + viewIdParameter).method(GET).uniqueName("cluster:views:get").build(), + // new NamedRoute.Builder().path("/views/" + viewIdParameter).method(DELETE).uniqueName("cluster:views:delete").build(), + // new NamedRoute.Builder().path("/views/" + viewIdParameter).method(PUT).uniqueName("cluster:views:update").build() + // ); // } // public RestResponse handlePost(final RestRequest r, final RestChannel channel) throws IOException { - // final View inputView; - // try (final XContentParser parser = r.contentParser()) { - // inputView = View.fromXContent(parser); - // } - - // final long currentTime = System.currentTimeMillis(); - // final View view = new View(inputView.name, inputView.description, currentTime, currentTime, inputView.targets); - - // clusterService.submitStateUpdateTask("create_view_task", new ClusterStateUpdateTask() { - // @Override - // public ClusterState execute(final ClusterState currentState) throws Exception { - // return new ClusterState.Builder(clusterService.state()).metadata(Metadata.builder(currentState.metadata()).put(view)) - // .build(); - // } - - // @Override - // public void onFailure(final String source, final Exception e) { - // LOG.error("Unable to create view, due to {}", source, e); - // channel.sendResponse( - // new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, "Unknown error occurred, see the log for details.") - // ); - // } - - // @Override - // public void clusterStateProcessed(final String source, final ClusterState oldState, final ClusterState newState) { - // try { - // channel.sendResponse( - // new BytesRestResponse(RestStatus.CREATED, channel.newBuilder().startObject().field(view.name, view).endObject()) - // ); - // } catch (final IOException e) { - // // TODO? - // LOG.error(e); - // } - // } - // }); - // // TODO: Handle CREATED vs UPDATED - // return null; + // final View inputView; + // try (final XContentParser parser = r.contentParser()) { + // inputView = View.fromXContent(parser); + // } + + // final long currentTime = System.currentTimeMillis(); + // final View view = new View(inputView.name, inputView.description, currentTime, currentTime, inputView.targets); + + // clusterService.submitStateUpdateTask("create_view_task", new ClusterStateUpdateTask() { + // @Override + // public ClusterState execute(final ClusterState currentState) throws Exception { + // return new ClusterState.Builder(clusterService.state()).metadata(Metadata.builder(currentState.metadata()).put(view)) + // .build(); + // } + + // @Override + // public void onFailure(final String source, final Exception e) { + // LOG.error("Unable to create view, due to {}", source, e); + // channel.sendResponse( + // new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, "Unknown error occurred, see the log for details.") + // ); + // } + + // @Override + // public void clusterStateProcessed(final String source, final ClusterState oldState, final ClusterState newState) { + // try { + // channel.sendResponse( + // new BytesRestResponse(RestStatus.CREATED, channel.newBuilder().startObject().field(view.name, view).endObject()) + // ); + // } catch (final IOException e) { + // // TODO? + // LOG.error(e); + // } + // } + // }); + // // TODO: Handle CREATED vs UPDATED + // return null; // } // public RestResponse handleSingleGet(final RestRequest r, final XContentBuilder builder) throws IOException { - // final String viewId = r.param(VIEW_ID); + // final String viewId = r.param(VIEW_ID); - // if (Strings.isNullOrEmpty(viewId)) { - // return new BytesRestResponse(RestStatus.NOT_FOUND, ""); - // } + // if (Strings.isNullOrEmpty(viewId)) { + // return new BytesRestResponse(RestStatus.NOT_FOUND, ""); + // } - // final Optional view = Optional.ofNullable(clusterService.state().getMetadata()) - // .map(m -> m.views()) - // .map(views -> views.get(viewId)); + // final Optional view = Optional.ofNullable(clusterService.state().getMetadata()) + // .map(m -> m.views()) + // .map(views -> views.get(viewId)); - // if (view.isEmpty()) { - // return new BytesRestResponse(RestStatus.NOT_FOUND, ""); - // } + // if (view.isEmpty()) { + // return new BytesRestResponse(RestStatus.NOT_FOUND, ""); + // } - // return new BytesRestResponse(RestStatus.OK, builder.startObject().value(view).endObject()); + // return new BytesRestResponse(RestStatus.OK, builder.startObject().value(view).endObject()); // } // public RestResponse handleSinglePut(final RestRequest r) { - // return new BytesRestResponse(RestStatus.NOT_IMPLEMENTED, ""); + // return new BytesRestResponse(RestStatus.NOT_IMPLEMENTED, ""); // } // public RestResponse handleSingleDelete(final RestRequest r) { - // return new BytesRestResponse(RestStatus.NOT_IMPLEMENTED, ""); + // return new BytesRestResponse(RestStatus.NOT_IMPLEMENTED, ""); // } } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/view/CreateViewTests.java b/server/src/test/java/org/opensearch/action/admin/indices/view/CreateViewTests.java index 146b6e68ddef6..3879da72243af 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/view/CreateViewTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/view/CreateViewTests.java @@ -16,11 +16,11 @@ import org.opensearch.core.common.io.stream.Writeable; import org.opensearch.test.AbstractWireSerializingTestCase; +import java.util.List; + import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import java.util.List; - public class CreateViewTests extends AbstractWireSerializingTestCase { @Override @@ -30,13 +30,19 @@ protected Writeable.Reader instanceReader() { @Override protected CreateViewAction.Request createTestInstance() { - return new CreateViewAction.Request(randomAlphaOfLength(8), randomAlphaOfLength(8), - randomList(5, () -> new CreateViewAction.Request.Target(randomAlphaOfLength(8)))); + return new CreateViewAction.Request( + randomAlphaOfLength(8), + randomAlphaOfLength(8), + randomList(5, () -> new CreateViewAction.Request.Target(randomAlphaOfLength(8))) + ); } public void testValidateRequest() { - final CreateViewAction.Request request = new CreateViewAction.Request("my-view", "this is a description", - List.of(new CreateViewAction.Request.Target("my-indices-*"))); + final CreateViewAction.Request request = new CreateViewAction.Request( + "my-view", + "this is a description", + List.of(new CreateViewAction.Request.Target("my-indices-*")) + ); assertNull(request.validate()); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/view/SearchViewTests.java b/server/src/test/java/org/opensearch/action/admin/indices/view/SearchViewTests.java index 2e2eb6a2ab5d2..1e56676a10e29 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/view/SearchViewTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/view/SearchViewTests.java @@ -17,12 +17,11 @@ import org.opensearch.core.common.io.stream.Writeable; import org.opensearch.test.AbstractWireSerializingTestCase; +import java.io.IOException; + import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import java.io.IOException; -import java.util.List; - public class SearchViewTests extends AbstractWireSerializingTestCase { @Override @@ -45,7 +44,7 @@ public void testValidateRequest() throws IOException { } public void testValidateRequestWithoutName() { - final SearchViewAction.Request request = new SearchViewAction.Request((String)null); + final SearchViewAction.Request request = new SearchViewAction.Request((String) null); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertThat(e.validationErrors().size(), equalTo(1)); diff --git a/server/src/test/java/org/opensearch/cluster/metadata/ViewTests.java b/server/src/test/java/org/opensearch/cluster/metadata/ViewTests.java index 9dc57f519aa43..e417dbd1b33a2 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/ViewTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/ViewTests.java @@ -67,7 +67,7 @@ public void testNullTargets() { } public void testNullTargetIndexPattern() { - final NullPointerException npe = assertThrows(NullPointerException.class, () -> new View.Target((String)null)); + final NullPointerException npe = assertThrows(NullPointerException.class, () -> new View.Target((String) null)); assertThat(npe.getMessage(), equalTo("IndexPattern is required")); }