Skip to content

Commit

Permalink
Resolved merge conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bogan <[email protected]>
  • Loading branch information
ryanbogan committed Oct 10, 2022
2 parents 7dfb491 + 8fbcc6e commit 75275a9
Show file tree
Hide file tree
Showing 23 changed files with 611 additions and 568 deletions.
10 changes: 1 addition & 9 deletions src/main/java/org/opensearch/sdk/BaseExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import java.util.Collections;

import org.opensearch.cluster.service.ClusterService;
import org.opensearch.env.Environment;
import org.opensearch.threadpool.ThreadPool;

public abstract class BaseExtension implements Extension {
protected SDKClient client;
protected ClusterService clusterService;
protected ThreadPool threadPool;
protected Environment environment;

/**
* Empty constructor to fulfill abstract class requirements
Expand All @@ -27,16 +25,10 @@ protected BaseExtension() {

}

public Collection<Object> createComponents(
SDKClient client,
ClusterService clusterService,
ThreadPool threadPool,
Environment environment
) {
public Collection<Object> createComponents(SDKClient client, ClusterService clusterService, ThreadPool threadPool) {
this.client = client;
this.clusterService = clusterService;
this.threadPool = threadPool;
this.environment = environment;

return Collections.emptyList();
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/org/opensearch/sdk/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import java.util.Collection;
import java.util.List;

import org.opensearch.client.OpenSearchClient;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.env.Environment;
import org.opensearch.threadpool.ThreadPool;

import org.opensearch.common.settings.Setting;
Expand Down Expand Up @@ -60,14 +58,8 @@ default List<Setting<?>> getSettings() {
* @param client A client to make requests to the system
* @param clusterService A service to allow watching and updating cluster state
* @param threadPool A service to allow retrieving an executor to run an async action
* @param environment the environment for path and setting configurations
*/
public Collection<Object> createComponents(
OpenSearchClient client,
ClusterService clusterService,
ThreadPool threadPool,
Environment environment
);
public Collection<Object> createComponents(SDKClient client, ClusterService clusterService, ThreadPool threadPool);

/**
* Helper method to read extension settings from a YAML file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@
/**
* API used to handle named writeable registry requests from OpenSearch
*/
public class NamedWriteableRegistryAPI {
private final Logger logger = LogManager.getLogger(NamedWriteableRegistryAPI.class);
public class ExtensionNamedWriteableRegistry {
private final Logger logger = LogManager.getLogger(ExtensionNamedWriteableRegistry.class);
private List<NamedWriteableRegistry.Entry> namedWriteables;
private final NamedWriteableRegistry namedWriteableRegistry;

/**
* Constructor for NamedWriteableRegistryAPI. Creates a NamedWriteableRegistry for this extension
* Constructor for ExtensionNamedWriteableRegistry. Creates a NamedWriteableRegistry for this extension
*/
public NamedWriteableRegistryAPI() {
public ExtensionNamedWriteableRegistry() {
this.namedWriteables = getNamedWriteables();
this.namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
}

/**
* Constructor for NamedWriteableRegistryAPI. Creates and populates a NamedWriteableRegistry with the given NamedWriteableRegistry entries for this extension
* Constructor for ExtensionNamedWriteableRegistry. Creates and populates a NamedWriteableRegistry with the given NamedWriteableRegistry entries for this extension
*
* @param extensionNamedWriteables List of NamedWriteableRegistry.Entry to be registered
*/
public NamedWriteableRegistryAPI(List<NamedWriteableRegistry.Entry> extensionNamedWriteables) {
public ExtensionNamedWriteableRegistry(List<NamedWriteableRegistry.Entry> extensionNamedWriteables) {
this.namedWriteables = extensionNamedWriteables;
this.namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/opensearch/sdk/ExtensionRestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.List;

import org.opensearch.extensions.rest.ExtensionRestRequest;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestHandler;
import org.opensearch.rest.RestHandler.Route;
Expand All @@ -29,12 +30,11 @@ public interface ExtensionRestHandler {

/**
* Handles REST Requests forwarded from OpenSearch for a configured route on an extension.
* Parameters are components of the {@link RestRequest} received from a user.
* Parameter contains components of the {@link RestRequest} received from a user.
* This method corresponds to the {@link BaseRestHandler#prepareRequest} method.
* As in that method, consumed parameters must be tracked and returned in the response.
*
* @param restRequest a REST request object for a request to be forwarded to extensions
* @param request a REST request object for a request to be forwarded to extensions
* @return An {@link ExtensionRestResponse} to the request.
*/
ExtensionRestResponse handleRequest(ExtensionRestRequest restRequest);
ExtensionRestResponse handleRequest(ExtensionRestRequest request);
}
22 changes: 11 additions & 11 deletions src/main/java/org/opensearch/sdk/ExtensionRestPathRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class ExtensionRestPathRegistry {
* Register a REST handler to handle a method and route in this extension's path registry.
*
* @param method The method to register.
* @param uri The URI to register. May include named wildcards.
* @param path The path to register. May include named wildcards.
* @param extensionRestHandler The RestHandler to handle this route
*/
public void registerHandler(Method method, String uri, ExtensionRestHandler extensionRestHandler) {
String restPath = restPathToString(method, uri);
public void registerHandler(Method method, String path, ExtensionRestHandler extensionRestHandler) {
String restPath = restPathToString(method, path);
pathTrie.insert(restPath, extensionRestHandler);
registeredPaths.add(restPath);
}
Expand All @@ -41,11 +41,11 @@ public void registerHandler(Method method, String uri, ExtensionRestHandler exte
* Get the registered REST handler for the specified method and URI.
*
* @param method the registered method.
* @param uri the registered URI.
* @param path the registered path.
* @return The REST handler registered to handle this method and URI combination if found, null otherwise.
*/
public ExtensionRestHandler getHandler(Method method, String uri) {
return pathTrie.retrieve(restPathToString(method, uri));
public ExtensionRestHandler getHandler(Method method, String path) {
return pathTrie.retrieve(restPathToString(method, path));
}

/**
Expand All @@ -58,13 +58,13 @@ public List<String> getRegisteredPaths() {
}

/**
* Converts a REST method and URI to a string.
* Converts a REST method and path to a space delimited string to be used as a map lookup key.
*
* @param method the method.
* @param uri the URI.
* @return A string appending the method and URI.
* @param path the path.
* @return A string appending the method and path.
*/
public static String restPathToString(Method method, String uri) {
return method.name() + " " + uri;
public static String restPathToString(Method method, String path) {
return method.name() + " " + path;
}
}
121 changes: 0 additions & 121 deletions src/main/java/org/opensearch/sdk/ExtensionRestRequest.java

This file was deleted.

38 changes: 22 additions & 16 deletions src/main/java/org/opensearch/sdk/ExtensionRestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.extensions.rest.ExtensionRestRequest;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestStatus;

Expand All @@ -23,71 +24,76 @@ public class ExtensionRestResponse extends BytesRestResponse {
* Key passed in {@link BytesRestResponse} headers to identify parameters consumed by the handler. For internal use.
*/
static final String CONSUMED_PARAMS_KEY = "extension.consumed.parameters";
/**
* Key passed in {@link BytesRestResponse} headers to identify content consumed by the handler. For internal use.
*/
static final String CONSUMED_CONTENT_KEY = "extension.consumed.content";

/**
* Creates a new response based on {@link XContentBuilder}.
*
* @param request the REST request being responded to.
* @param status The REST status.
* @param builder The builder for the response.
* @param consumedParams Parameters consumed by the handler.
*/
public ExtensionRestResponse(RestStatus status, XContentBuilder builder, List<String> consumedParams) {
public ExtensionRestResponse(ExtensionRestRequest request, RestStatus status, XContentBuilder builder) {
super(status, builder);
addConsumedParamHeader(consumedParams);
addConsumedHeaders(request.consumedParams(), request.isContentConsumed());
}

/**
* Creates a new plain text response.
*
* @param request the REST request being responded to.
* @param status The REST status.
* @param content A plain text response string.
* @param consumedParams Parameters consumed by the handler.
*/
public ExtensionRestResponse(RestStatus status, String content, List<String> consumedParams) {
public ExtensionRestResponse(ExtensionRestRequest request, RestStatus status, String content) {
super(status, content);
addConsumedParamHeader(consumedParams);
addConsumedHeaders(request.consumedParams(), request.isContentConsumed());
}

/**
* Creates a new plain text response.
*
* @param request the REST request being responded to.
* @param status The REST status.
* @param contentType The content type of the response string.
* @param content A response string.
* @param consumedParams Parameters consumed by the handler.
*/
public ExtensionRestResponse(RestStatus status, String contentType, String content, List<String> consumedParams) {
public ExtensionRestResponse(ExtensionRestRequest request, RestStatus status, String contentType, String content) {
super(status, contentType, content);
addConsumedParamHeader(consumedParams);
addConsumedHeaders(request.consumedParams(), request.isContentConsumed());
}

/**
* Creates a binary response.
*
* @param request the REST request being responded to.
* @param status The REST status.
* @param contentType The content type of the response bytes.
* @param content Response bytes.
* @param consumedParams Parameters consumed by the handler.
*/
public ExtensionRestResponse(RestStatus status, String contentType, byte[] content, List<String> consumedParams) {
public ExtensionRestResponse(ExtensionRestRequest request, RestStatus status, String contentType, byte[] content) {
super(status, contentType, content);
addConsumedParamHeader(consumedParams);
addConsumedHeaders(request.consumedParams(), request.isContentConsumed());
}

/**
* Creates a binary response.
*
* @param request the REST request being responded to.
* @param status The REST status.
* @param contentType The content type of the response bytes.
* @param content Response bytes.
* @param consumedParams Parameters consumed by the handler.
*/
public ExtensionRestResponse(RestStatus status, String contentType, BytesReference content, List<String> consumedParams) {
public ExtensionRestResponse(ExtensionRestRequest request, RestStatus status, String contentType, BytesReference content) {
super(status, contentType, content);
addConsumedParamHeader(consumedParams);
addConsumedHeaders(request.consumedParams(), request.isContentConsumed());
}

private void addConsumedParamHeader(List<String> consumedParams) {
private void addConsumedHeaders(List<String> consumedParams, boolean contentConusmed) {
consumedParams.stream().forEach(p -> addHeader(CONSUMED_PARAMS_KEY, p));
addHeader(CONSUMED_CONTENT_KEY, Boolean.toString(contentConusmed));
}
}
Loading

0 comments on commit 75275a9

Please sign in to comment.