-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add rest and transport plumbing #40997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.elasticsearch.xpack.core.enrich; | ||
|
||
import org.elasticsearch.action.Action; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeReadRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class GetEnrichPolicyAction extends Action<GetEnrichPolicyAction.Response> { | ||
public static final GetEnrichPolicyAction INSTANCE = new GetEnrichPolicyAction(); | ||
public static final String NAME = "indices:admin/xpack/enrich/get"; | ||
|
||
private GetEnrichPolicyAction() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public Response newResponse() { | ||
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); | ||
} | ||
|
||
@Override | ||
public Writeable.Reader<Response> getResponseReader() { | ||
return Response::new; | ||
} | ||
|
||
public static class Request extends MasterNodeReadRequest<Request> { | ||
|
||
private String name; | ||
|
||
public Request(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.name = in.readOptionalString(); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Request request = (Request) o; | ||
return Objects.equals(name, request.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name); | ||
} | ||
} | ||
|
||
public static class Response extends ActionResponse implements ToXContentObject { | ||
|
||
public Response() { | ||
|
||
} | ||
|
||
public Response(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
// placeholder until more data is returned | ||
return new AcknowledgedResponse(true).toXContent(builder, params); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.elasticsearch.xpack.enrich.action; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeAction; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.block.ClusterBlockLevel; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.enrich.GetEnrichPolicyAction; | ||
|
||
import java.io.IOException; | ||
|
||
public class TransportGetEnrichPolicyAction extends TransportMasterNodeAction<GetEnrichPolicyAction.Request, | ||
GetEnrichPolicyAction.Response> { | ||
|
||
@Inject | ||
public TransportGetEnrichPolicyAction(TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver) { | ||
super(GetEnrichPolicyAction.NAME, transportService, clusterService, threadPool, actionFilters, | ||
GetEnrichPolicyAction.Request::new, indexNameExpressionResolver); | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return ThreadPool.Names.SAME; | ||
} | ||
|
||
@Override | ||
protected GetEnrichPolicyAction.Response newResponse() { | ||
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); | ||
} | ||
|
||
@Override | ||
protected GetEnrichPolicyAction.Response read(StreamInput in) throws IOException { | ||
return new GetEnrichPolicyAction.Response(); | ||
} | ||
|
||
@Override | ||
protected void masterOperation(GetEnrichPolicyAction.Request request, | ||
ClusterState state, | ||
ActionListener<GetEnrichPolicyAction.Response> listener) throws Exception { | ||
listener.onResponse(new GetEnrichPolicyAction.Response()); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(GetEnrichPolicyAction.Request request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.elasticsearch.xpack.enrich.rest; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
import org.elasticsearch.xpack.core.enrich.GetEnrichPolicyAction; | ||
|
||
import java.io.IOException; | ||
|
||
public class RestGenEnrichPolicyAction extends BaseRestHandler { | ||
|
||
public RestGenEnrichPolicyAction(final Settings settings, final RestController controller) { | ||
super(settings); | ||
controller.registerHandler(RestRequest.Method.GET, "/{index}/_enrich", this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have the following path structure: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, so completely remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the payload would contain the: source index, decorate fields etc. |
||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "get_enrich_policy"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) throws IOException { | ||
// need to parse out the index param as it may refer to > 1 index. | ||
final GetEnrichPolicyAction.Request request = new GetEnrichPolicyAction.Request(restRequest.param("index")); | ||
return channel -> client.execute(GetEnrichPolicyAction.INSTANCE, request, new RestToXContentListener<>(channel)); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RestGenEnrichPolicyAction -> RestGetEnrichPolicyAction