Skip to content

Commit bec1cf8

Browse files
authored
Summary option for listing ingest pipelines without their definitions (#69756)
1 parent aab3f30 commit bec1cf8

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/ingest.get_pipeline.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
]
3333
},
3434
"params":{
35+
"summary":{
36+
"type":"boolean",
37+
"description":"Return pipelines without their definitions (default: false)"
38+
},
3539
"master_timeout":{
3640
"type":"time",
3741
"description":"Explicit operation timeout for connection to master node"

rest-api-spec/src/main/resources/rest-api-spec/test/ingest/10_basic.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,35 @@
152152
"processors": [],
153153
"invalid_field" : {}
154154
}
155+
156+
---
157+
"Test Get Summarized Pipelines":
158+
- skip:
159+
version: " - 7.99.99"
160+
reason: "change to appropriate 7.x release after backport"
161+
162+
- do:
163+
ingest.put_pipeline:
164+
id: "first_pipeline"
165+
body: >
166+
{
167+
"description": "first",
168+
"processors": []
169+
}
170+
- do:
171+
ingest.put_pipeline:
172+
id: "second_pipeline"
173+
body: >
174+
{
175+
"description": "second",
176+
"processors": []
177+
}
178+
179+
- do:
180+
ingest.get_pipeline:
181+
summary: true
182+
183+
- is_true: first_pipeline
184+
- is_false: first_pipeline.description
185+
- is_true: second_pipeline
186+
- is_false: second_pipeline.description

server/src/main/java/org/elasticsearch/action/ingest/GetPipelineRequest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.action.ingest;
1010

11+
import org.elasticsearch.Version;
1112
import org.elasticsearch.action.ActionRequestValidationException;
1213
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
1314
import org.elasticsearch.common.Strings;
@@ -19,33 +20,47 @@
1920
public class GetPipelineRequest extends MasterNodeReadRequest<GetPipelineRequest> {
2021

2122
private String[] ids;
23+
private final boolean summary;
2224

23-
public GetPipelineRequest(String... ids) {
25+
public GetPipelineRequest(boolean summary, String... ids) {
2426
if (ids == null) {
2527
throw new IllegalArgumentException("ids cannot be null");
2628
}
2729
this.ids = ids;
30+
this.summary = summary;
31+
}
32+
33+
public GetPipelineRequest(String... ids) {
34+
this(false, ids);
2835
}
2936

3037
GetPipelineRequest() {
31-
this.ids = Strings.EMPTY_ARRAY;
38+
this(false, Strings.EMPTY_ARRAY);
3239
}
3340

3441
public GetPipelineRequest(StreamInput in) throws IOException {
3542
super(in);
3643
ids = in.readStringArray();
44+
summary = in.getVersion().onOrAfter(Version.V_8_0_0) ? in.readBoolean() : false;
3745
}
3846

3947
@Override
4048
public void writeTo(StreamOutput out) throws IOException {
4149
super.writeTo(out);
4250
out.writeStringArray(ids);
51+
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
52+
out.writeBoolean(summary);
53+
}
4354
}
4455

4556
public String[] getIds() {
4657
return ids;
4758
}
4859

60+
public boolean isSummary() {
61+
return summary;
62+
}
63+
4964
@Override
5065
public ActionRequestValidationException validate() {
5166
return null;

server/src/main/java/org/elasticsearch/action/ingest/GetPipelineResponse.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.action.ingest;
1010

11+
import org.elasticsearch.Version;
1112
import org.elasticsearch.action.ActionResponse;
1213
import org.elasticsearch.common.Strings;
1314
import org.elasticsearch.common.bytes.BytesReference;
@@ -32,6 +33,7 @@
3233
public class GetPipelineResponse extends ActionResponse implements StatusToXContentObject {
3334

3435
private List<PipelineConfiguration> pipelines;
36+
private final boolean summary;
3537

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

45-
public GetPipelineResponse(List<PipelineConfiguration> pipelines) {
48+
public GetPipelineResponse(List<PipelineConfiguration> pipelines, boolean summary) {
4649
this.pipelines = pipelines;
50+
this.summary = summary;
51+
}
52+
53+
public GetPipelineResponse(List<PipelineConfiguration> pipelines) {
54+
this(pipelines, false);
4755
}
4856

4957
/**
@@ -61,12 +69,19 @@ public void writeTo(StreamOutput out) throws IOException {
6169
for (PipelineConfiguration pipeline : pipelines) {
6270
pipeline.writeTo(out);
6371
}
72+
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
73+
out.writeBoolean(summary);
74+
}
6475
}
6576

6677
public boolean isFound() {
6778
return pipelines.isEmpty() == false;
6879
}
6980

81+
public boolean isSummary() {
82+
return summary;
83+
}
84+
7085
@Override
7186
public RestStatus status() {
7287
return isFound() ? RestStatus.OK : RestStatus.NOT_FOUND;
@@ -76,7 +91,7 @@ public RestStatus status() {
7691
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
7792
builder.startObject();
7893
for (PipelineConfiguration pipeline : pipelines) {
79-
builder.field(pipeline.getId(), pipeline.getConfigAsMap());
94+
builder.field(pipeline.getId(), summary ? Map.of() : pipeline.getConfigAsMap());
8095
}
8196
builder.endObject();
8297
return builder;

server/src/main/java/org/elasticsearch/action/ingest/GetPipelineTransportAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public GetPipelineTransportAction(ThreadPool threadPool, ClusterService clusterS
3535
@Override
3636
protected void masterOperation(Task task, GetPipelineRequest request, ClusterState state, ActionListener<GetPipelineResponse> listener)
3737
throws Exception {
38-
listener.onResponse(new GetPipelineResponse(IngestService.getPipelines(state, request.getIds())));
38+
listener.onResponse(new GetPipelineResponse(IngestService.getPipelines(state, request.getIds()), request.isSummary()));
3939
}
4040

4141
@Override

server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public String getName() {
3636

3737
@Override
3838
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
39-
GetPipelineRequest request = new GetPipelineRequest(Strings.splitStringByCommaToArray(restRequest.param("id")));
39+
GetPipelineRequest request = new GetPipelineRequest(
40+
restRequest.paramAsBoolean("summary", false),
41+
Strings.splitStringByCommaToArray(restRequest.param("id"))
42+
);
4043
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
4144
return channel -> client.admin().cluster().getPipeline(request, new RestStatusToXContentListener<>(channel));
4245
}

0 commit comments

Comments
 (0)