Skip to content
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

Summary option for listing ingest pipelines without their definitions #69756

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
]
},
"params":{
"summary":{
"type":"boolean",
"description":"Return pipelines without their definitions (default: false)"
},
"master_timeout":{
"type":"time",
"description":"Explicit operation timeout for connection to master node"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,35 @@
"processors": [],
"invalid_field" : {}
}

---
"Test Get Summarized Pipelines":
- skip:
version: " - 7.99.99"
reason: "change to appropriate 7.x release after backport"

- do:
ingest.put_pipeline:
id: "first_pipeline"
body: >
{
"description": "first",
"processors": []
}
- do:
ingest.put_pipeline:
id: "second_pipeline"
body: >
{
"description": "second",
"processors": []
}

- do:
ingest.get_pipeline:
summary: true

- is_true: first_pipeline
- is_false: first_pipeline.description
- is_true: second_pipeline
- is_false: second_pipeline.description
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.action.ingest;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.common.Strings;
Expand All @@ -19,33 +20,47 @@
public class GetPipelineRequest extends MasterNodeReadRequest<GetPipelineRequest> {

private String[] ids;
private final boolean summary;

public GetPipelineRequest(String... ids) {
public GetPipelineRequest(boolean summary, String... ids) {
if (ids == null) {
throw new IllegalArgumentException("ids cannot be null");
}
this.ids = ids;
this.summary = summary;
}

public GetPipelineRequest(String... ids) {
this(false, ids);
}

GetPipelineRequest() {
this.ids = Strings.EMPTY_ARRAY;
this(false, Strings.EMPTY_ARRAY);
}

public GetPipelineRequest(StreamInput in) throws IOException {
super(in);
ids = in.readStringArray();
summary = in.getVersion().onOrAfter(Version.V_8_0_0) ? in.readBoolean() : false;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(ids);
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
out.writeBoolean(summary);
}
}

public String[] getIds() {
return ids;
}

public boolean isSummary() {
return summary;
}

@Override
public ActionRequestValidationException validate() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.action.ingest;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
Expand All @@ -32,6 +33,7 @@
public class GetPipelineResponse extends ActionResponse implements StatusToXContentObject {

private List<PipelineConfiguration> pipelines;
private final boolean summary;

public GetPipelineResponse(StreamInput in) throws IOException {
super(in);
Expand All @@ -40,10 +42,16 @@ public GetPipelineResponse(StreamInput in) throws IOException {
for (int i = 0; i < size; i++) {
pipelines.add(PipelineConfiguration.readFrom(in));
}
summary = in.getVersion().onOrAfter(Version.V_8_0_0) ? in.readBoolean() : false;
}

public GetPipelineResponse(List<PipelineConfiguration> pipelines) {
public GetPipelineResponse(List<PipelineConfiguration> pipelines, boolean summary) {
this.pipelines = pipelines;
this.summary = summary;
}

public GetPipelineResponse(List<PipelineConfiguration> pipelines) {
this(pipelines, false);
}

/**
Expand All @@ -61,12 +69,19 @@ public void writeTo(StreamOutput out) throws IOException {
for (PipelineConfiguration pipeline : pipelines) {
pipeline.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
out.writeBoolean(summary);
}
}

public boolean isFound() {
return pipelines.isEmpty() == false;
}

public boolean isSummary() {
return summary;
}

@Override
public RestStatus status() {
return isFound() ? RestStatus.OK : RestStatus.NOT_FOUND;
Expand All @@ -76,7 +91,7 @@ public RestStatus status() {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
for (PipelineConfiguration pipeline : pipelines) {
builder.field(pipeline.getId(), pipeline.getConfigAsMap());
builder.field(pipeline.getId(), summary ? Map.of() : pipeline.getConfigAsMap());
}
builder.endObject();
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public GetPipelineTransportAction(ThreadPool threadPool, ClusterService clusterS
@Override
protected void masterOperation(Task task, GetPipelineRequest request, ClusterState state, ActionListener<GetPipelineResponse> listener)
throws Exception {
listener.onResponse(new GetPipelineResponse(IngestService.getPipelines(state, request.getIds())));
listener.onResponse(new GetPipelineResponse(IngestService.getPipelines(state, request.getIds()), request.isSummary()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public String getName() {

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
GetPipelineRequest request = new GetPipelineRequest(Strings.splitStringByCommaToArray(restRequest.param("id")));
GetPipelineRequest request = new GetPipelineRequest(
restRequest.paramAsBoolean("summary", false),
Strings.splitStringByCommaToArray(restRequest.param("id"))
);
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
return channel -> client.admin().cluster().getPipeline(request, new RestStatusToXContentListener<>(channel));
}
Expand Down