Skip to content

Commit

Permalink
Rebased to use public interfaces added in opensearch-project/OpenSear…
Browse files Browse the repository at this point in the history
…ch#11876.

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jan 19, 2024
1 parent fb20d3d commit 5adec70
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 225 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,3 @@ jobs:
- name: Build and Run Tests
run: |
./gradlew build
# Generated by 'opensearch.pluginzip' custom gradle plugin
./gradlew publishPluginZipPublicationToZipStagingRepository
- name: Update version to the next development iteration
if: matrix.os != 'windows-latest'
run: |
# Task to auto update version to the next development iteration
./gradlew updateVersion -DnewVersion=3.1.0-SNAPSHOT
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply plugin: 'opensearch.pluginzip'
def pluginName = 'opensearch-api'
def pluginDescription = 'OpenSearch API plugin.'
def projectPath = 'org.opensearch'
def pathToPlugin = 'api'
def pathToPlugin = 'plugin.api'
def pluginClassName = 'APIPlugin'
group = "APIPluginGroup"

Expand Down
133 changes: 0 additions & 133 deletions src/main/java/org/opensearch/api/action/api/APIResponse.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,55 @@
* compatible open source license.
*/

package org.opensearch.api;

import static java.util.Collections.singletonList;

import java.util.List;
import java.util.function.Supplier;
package org.opensearch.plugin.api;

import org.opensearch.action.ActionRequest;
import org.opensearch.api.action.api.APIAction;
import org.opensearch.api.action.api.TransportAPIAction;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.IndexScopedSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsFilter;
import org.opensearch.core.action.ActionResponse;
import org.opensearch.plugin.api.action.api.APIAction;
import org.opensearch.plugin.api.action.api.TransportAPIAction;
import org.opensearch.plugins.ActionPlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.rest.RestController;
import org.opensearch.rest.RestHandler;

import java.util.List;
import java.util.function.Supplier;

import static java.util.Collections.singletonList;

/**
* A plugin that returns the OpenAPI spec for the current OpenSearch instance.
*/
public class APIPlugin extends Plugin implements ActionPlugin {
/**
* Instantiate this plugin.
*/
public APIPlugin() {

}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return singletonList(new ActionHandler<>(APIAction.INSTANCE, TransportAPIAction.class));
}

@Override
public List getRestHandlers(final Settings settings,
public List<RestHandler> getRestHandlers(
final Settings settings,
final RestController restController,
final ClusterSettings clusterSettings,
final IndexScopedSettings indexScopedSettings,
final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier nodesInCluster) {
final Supplier<DiscoveryNodes> nodesInCluster
) {

return singletonList(new RestAPIAction());
return singletonList(new RestAPIAction(restController));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,69 @@
* compatible open source license.
*/

package org.opensearch.api;
package org.opensearch.plugin.api;

import java.io.IOException;
import java.util.List;

import org.opensearch.api.action.api.APIAction;
import org.opensearch.api.action.api.APIRequest;
import org.opensearch.api.action.api.APIResponse;
import org.opensearch.client.node.NodeClient;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.plugin.api.action.api.APIAction;
import org.opensearch.plugin.api.action.api.APIRequest;
import org.opensearch.plugin.api.action.api.APIResponse;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestController;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestResponse;
import org.opensearch.rest.action.RestBuilderListener;

import static org.opensearch.rest.RestRequest.Method.GET;
import java.io.IOException;
import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.opensearch.rest.RestRequest.Method.GET;

/**
* A REST handler.
*/
public class RestAPIAction extends BaseRestHandler {
RestController restController;

RestAPIAction(RestController restController) {
this.restController = restController;
}

/**
*
* @return
*/
@Override
public String getName() {
return "api";
}

/**
*
* @return
*/
@Override
public List routes() {
return unmodifiableList(asList(
new Route(GET, "/_plugins/api")
));
public List<Route> routes() {
return unmodifiableList(asList(new Route(GET, "/_plugins/api")));
}

/**
*
* @param request the request to execute
* @param client client for executing actions on the local node
* @return
* @throws IOException
*/
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
return channel -> client.execute(APIAction.INSTANCE, new APIRequest(), new RestBuilderListener<APIResponse>(channel) {
@Override
public RestResponse buildResponse(APIResponse response, XContentBuilder builder) throws Exception {
response.setRestController(restController);
response.toXContent(builder, request);
return new BytesRestResponse(RestStatus.OK, builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.api.action.api;
package org.opensearch.plugin.api.action.api;

import org.opensearch.action.ActionType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.api.action.api;
package org.opensearch.plugin.api.action.api;

import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionRequestValidationException;
Expand All @@ -16,8 +16,16 @@

public class APIRequest extends ActionRequest {

/**
*
*/
public APIRequest() {}

/**
*
* @param in
* @throws IOException
*/
APIRequest(StreamInput in) throws IOException {
super(in);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.api.action.api;
package org.opensearch.plugin.api.action.api;

import org.opensearch.action.ActionRequestBuilder;
import org.opensearch.client.OpenSearchClient;
Expand Down
Loading

0 comments on commit 5adec70

Please sign in to comment.