Skip to content

Commit 1fb31c9

Browse files
Moved pipeline APIs to ingest namespace
1 parent 11887fa commit 1fb31c9

File tree

11 files changed

+532
-387
lines changed

11 files changed

+532
-387
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/ClusterClient.java

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
import org.elasticsearch.action.ActionListener;
2424
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
2525
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
26-
import org.elasticsearch.action.ingest.PutPipelineRequest;
27-
import org.elasticsearch.action.ingest.GetPipelineRequest;
28-
import org.elasticsearch.action.ingest.GetPipelineResponse;
29-
import org.elasticsearch.action.ingest.DeletePipelineRequest;
30-
import org.elasticsearch.action.ingest.WritePipelineResponse;
3126

3227
import java.io.IOException;
3328

@@ -68,72 +63,4 @@ public void putSettingsAsync(ClusterUpdateSettingsRequest clusterUpdateSettingsR
6863
restHighLevelClient.performRequestAsyncAndParseEntity(clusterUpdateSettingsRequest, RequestConverters::clusterPutSettings,
6964
ClusterUpdateSettingsResponse::fromXContent, listener, emptySet(), headers);
7065
}
71-
72-
/**
73-
* Add a pipeline or update an existing pipeline in the cluster
74-
* <p>
75-
* See
76-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
77-
*/
78-
public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException {
79-
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline,
80-
WritePipelineResponse::fromXContent, emptySet(), headers);
81-
}
82-
83-
/**
84-
* Asynchronously add a pipeline or update an existing pipeline in the cluster
85-
* <p>
86-
* See
87-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
88-
*/
89-
public void putPipelineAsync(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
90-
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline,
91-
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
92-
}
93-
94-
/**
95-
* Get an existing pipeline
96-
* <p>
97-
* See
98-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/get-pipeline-api.html"> Get Pipeline API on elastic.co</a>
99-
*/
100-
public GetPipelineResponse getPipeline(GetPipelineRequest request, Header... headers) throws IOException {
101-
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::getPipeline,
102-
GetPipelineResponse::fromXContent, emptySet(), headers);
103-
}
104-
105-
/**
106-
* Asynchronously get an existing pipeline
107-
* <p>
108-
* See
109-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/get-pipeline-api.html"> Get Pipeline API on elastic.co</a>
110-
*/
111-
public void getPipelineAsync(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener, Header... headers) {
112-
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::getPipeline,
113-
GetPipelineResponse::fromXContent, listener, emptySet(), headers);
114-
}
115-
116-
/**
117-
* Delete an existing pipeline
118-
* <p>
119-
* See
120-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
121-
* Delete Pipeline API on elastic.co</a>
122-
*/
123-
public WritePipelineResponse deletePipeline(DeletePipelineRequest request, Header... headers) throws IOException {
124-
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::deletePipeline,
125-
WritePipelineResponse::fromXContent, emptySet(), headers);
126-
}
127-
128-
/**
129-
* Asynchronously delete an existing pipeline
130-
* <p>
131-
* See
132-
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
133-
* Delete Pipeline API on elastic.co</a>
134-
*/
135-
public void deletePipelineAsync(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
136-
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline,
137-
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
138-
}
13966
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client;
21+
22+
import org.apache.http.Header;
23+
import org.elasticsearch.action.ActionListener;
24+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
25+
import org.elasticsearch.action.ingest.GetPipelineRequest;
26+
import org.elasticsearch.action.ingest.GetPipelineResponse;
27+
import org.elasticsearch.action.ingest.PutPipelineRequest;
28+
import org.elasticsearch.action.ingest.WritePipelineResponse;
29+
30+
import java.io.IOException;
31+
32+
import static java.util.Collections.emptySet;
33+
34+
/**
35+
* A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Ingest API.
36+
* <p>
37+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html">Ingest API on elastic.co</a>
38+
*/
39+
public final class IngestClient {
40+
41+
private final RestHighLevelClient restHighLevelClient;
42+
43+
IngestClient(RestHighLevelClient restHighLevelClient) {
44+
this.restHighLevelClient = restHighLevelClient;
45+
}
46+
47+
/**
48+
* Add a pipeline or update an existing pipeline
49+
* <p>
50+
* See
51+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
52+
*/
53+
public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException {
54+
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline,
55+
WritePipelineResponse::fromXContent, emptySet(), headers);
56+
}
57+
58+
/**
59+
* Asynchronously add a pipeline or update an existing pipeline
60+
* <p>
61+
* See
62+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
63+
*/
64+
public void putPipelineAsync(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
65+
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline,
66+
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
67+
}
68+
69+
/**
70+
* Get an existing pipeline
71+
* <p>
72+
* See
73+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/get-pipeline-api.html"> Get Pipeline API on elastic.co</a>
74+
*/
75+
public GetPipelineResponse getPipeline(GetPipelineRequest request, Header... headers) throws IOException {
76+
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::getPipeline,
77+
GetPipelineResponse::fromXContent, emptySet(), headers);
78+
}
79+
80+
/**
81+
* Asynchronously get an existing pipeline
82+
* <p>
83+
* See
84+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/get-pipeline-api.html"> Get Pipeline API on elastic.co</a>
85+
*/
86+
public void getPipelineAsync(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener, Header... headers) {
87+
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::getPipeline,
88+
GetPipelineResponse::fromXContent, listener, emptySet(), headers);
89+
}
90+
91+
/**
92+
* Delete an existing pipeline
93+
* <p>
94+
* See
95+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
96+
* Delete Pipeline API on elastic.co</a>
97+
*/
98+
public WritePipelineResponse deletePipeline(DeletePipelineRequest request, Header... headers) throws IOException {
99+
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::deletePipeline,
100+
WritePipelineResponse::fromXContent, emptySet(), headers);
101+
}
102+
103+
/**
104+
* Asynchronously delete an existing pipeline
105+
* <p>
106+
* See
107+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
108+
* Delete Pipeline API on elastic.co</a>
109+
*/
110+
public void deletePipelineAsync(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
111+
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline,
112+
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
113+
}
114+
}

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public class RestHighLevelClient implements Closeable {
191191

192192
private final IndicesClient indicesClient = new IndicesClient(this);
193193
private final ClusterClient clusterClient = new ClusterClient(this);
194+
private final IngestClient ingestClient = new IngestClient(this);
194195
private final SnapshotClient snapshotClient = new SnapshotClient(this);
195196
private final TasksClient tasksClient = new TasksClient(this);
196197

@@ -256,6 +257,15 @@ public final ClusterClient cluster() {
256257
return clusterClient;
257258
}
258259

260+
/**
261+
* Provides a {@link IngestClient} which can be used to access the Ingest API.
262+
*
263+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html">Ingest API on elastic.co</a>
264+
*/
265+
public final IngestClient ingest() {
266+
return ingestClient;
267+
}
268+
259269
/**
260270
* Provides a {@link SnapshotClient} which can be used to access the Snapshot API.
261271
*

client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@
2222
import org.elasticsearch.ElasticsearchException;
2323
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
2424
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
25-
import org.elasticsearch.action.ingest.GetPipelineRequest;
26-
import org.elasticsearch.action.ingest.GetPipelineResponse;
27-
import org.elasticsearch.action.ingest.PutPipelineRequest;
28-
import org.elasticsearch.action.ingest.DeletePipelineRequest;
29-
import org.elasticsearch.action.ingest.WritePipelineResponse;
3025
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
31-
import org.elasticsearch.common.bytes.BytesReference;
3226
import org.elasticsearch.common.settings.Settings;
3327
import org.elasticsearch.common.unit.ByteSizeUnit;
34-
import org.elasticsearch.common.xcontent.XContentBuilder;
3528
import org.elasticsearch.common.xcontent.XContentType;
3629
import org.elasticsearch.common.xcontent.support.XContentMapValues;
3730
import org.elasticsearch.indices.recovery.RecoverySettings;
38-
import org.elasticsearch.ingest.PipelineConfiguration;
3931
import org.elasticsearch.rest.RestStatus;
4032

4133
import java.io.IOException;
@@ -113,53 +105,4 @@ public void testClusterUpdateSettingNonExistent() {
113105
assertThat(exception.getMessage(), equalTo(
114106
"Elasticsearch exception [type=illegal_argument_exception, reason=transient setting [" + setting + "], not recognized]"));
115107
}
116-
117-
public void testPutPipeline() throws IOException {
118-
String id = "some_pipeline_id";
119-
XContentBuilder pipelineBuilder = buildRandomXContentPipeline();
120-
PutPipelineRequest request = new PutPipelineRequest(
121-
id,
122-
BytesReference.bytes(pipelineBuilder),
123-
pipelineBuilder.contentType());
124-
125-
WritePipelineResponse putPipelineResponse =
126-
execute(request, highLevelClient().cluster()::putPipeline, highLevelClient().cluster()::putPipelineAsync);
127-
assertTrue(putPipelineResponse.isAcknowledged());
128-
}
129-
130-
public void testGetPipeline() throws IOException {
131-
String id = "some_pipeline_id";
132-
XContentBuilder pipelineBuilder = buildRandomXContentPipeline();
133-
{
134-
PutPipelineRequest request = new PutPipelineRequest(
135-
id,
136-
BytesReference.bytes(pipelineBuilder),
137-
pipelineBuilder.contentType()
138-
);
139-
createPipeline(request);
140-
}
141-
142-
GetPipelineRequest request = new GetPipelineRequest(id);
143-
144-
GetPipelineResponse response =
145-
execute(request, highLevelClient().cluster()::getPipeline, highLevelClient().cluster()::getPipelineAsync);
146-
assertTrue(response.isFound());
147-
assertEquals(response.pipelines().get(0).getId(), id);
148-
PipelineConfiguration expectedConfig =
149-
new PipelineConfiguration(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType());
150-
assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap());
151-
}
152-
153-
public void testDeletePipeline() throws IOException {
154-
String id = "some_pipeline_id";
155-
{
156-
createPipeline(id);
157-
}
158-
159-
DeletePipelineRequest request = new DeletePipelineRequest(id);
160-
161-
WritePipelineResponse response =
162-
execute(request, highLevelClient().cluster()::deletePipeline, highLevelClient().cluster()::deletePipelineAsync);
163-
assertTrue(response.isAcknowledged());
164-
}
165108
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client;
21+
22+
import org.elasticsearch.action.ingest.DeletePipelineRequest;
23+
import org.elasticsearch.action.ingest.GetPipelineRequest;
24+
import org.elasticsearch.action.ingest.GetPipelineResponse;
25+
import org.elasticsearch.action.ingest.PutPipelineRequest;
26+
import org.elasticsearch.action.ingest.WritePipelineResponse;
27+
import org.elasticsearch.common.bytes.BytesReference;
28+
import org.elasticsearch.common.xcontent.XContentBuilder;
29+
import org.elasticsearch.ingest.PipelineConfiguration;
30+
31+
import java.io.IOException;
32+
33+
public class IngestClientIT extends ESRestHighLevelClientTestCase {
34+
35+
public void testPutPipeline() throws IOException {
36+
String id = "some_pipeline_id";
37+
XContentBuilder pipelineBuilder = buildRandomXContentPipeline();
38+
PutPipelineRequest request = new PutPipelineRequest(
39+
id,
40+
BytesReference.bytes(pipelineBuilder),
41+
pipelineBuilder.contentType());
42+
43+
WritePipelineResponse putPipelineResponse =
44+
execute(request, highLevelClient().ingest()::putPipeline, highLevelClient().ingest()::putPipelineAsync);
45+
assertTrue(putPipelineResponse.isAcknowledged());
46+
}
47+
48+
public void testGetPipeline() throws IOException {
49+
String id = "some_pipeline_id";
50+
XContentBuilder pipelineBuilder = buildRandomXContentPipeline();
51+
{
52+
PutPipelineRequest request = new PutPipelineRequest(
53+
id,
54+
BytesReference.bytes(pipelineBuilder),
55+
pipelineBuilder.contentType()
56+
);
57+
createPipeline(request);
58+
}
59+
60+
GetPipelineRequest request = new GetPipelineRequest(id);
61+
62+
GetPipelineResponse response =
63+
execute(request, highLevelClient().ingest()::getPipeline, highLevelClient().ingest()::getPipelineAsync);
64+
assertTrue(response.isFound());
65+
assertEquals(response.pipelines().get(0).getId(), id);
66+
PipelineConfiguration expectedConfig =
67+
new PipelineConfiguration(id, BytesReference.bytes(pipelineBuilder), pipelineBuilder.contentType());
68+
assertEquals(expectedConfig.getConfigAsMap(), response.pipelines().get(0).getConfigAsMap());
69+
}
70+
71+
public void testDeletePipeline() throws IOException {
72+
String id = "some_pipeline_id";
73+
{
74+
createPipeline(id);
75+
}
76+
77+
DeletePipelineRequest request = new DeletePipelineRequest(id);
78+
79+
WritePipelineResponse response =
80+
execute(request, highLevelClient().ingest()::deletePipeline, highLevelClient().ingest()::deletePipelineAsync);
81+
assertTrue(response.isAcknowledged());
82+
}
83+
}

0 commit comments

Comments
 (0)