-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
REST high-level client: add put ingest pipeline API #30793
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c5d70e
REST high-level client: add put ingest pipeline API
sohaibiftikhar a5c389a
Fixed docs and tests
sohaibiftikhar 42942b6
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
sohaibiftikhar 4c3c61a
Fixed documentation strings
sohaibiftikhar a11026b
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
sohaibiftikhar aa0d270
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
sohaibiftikhar e77799d
fixed XContentBuilder indentation
sohaibiftikhar 977c259
Fixed asciidoc response object reference
sohaibiftikhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,19 @@ | |
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.LatchedActionListener; | ||
import org.elasticsearch.action.TaskOperationFailure; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; | ||
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup; | ||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; | ||
import org.elasticsearch.action.ingest.PutPipelineRequest; | ||
import org.elasticsearch.action.ingest.PutPipelineResponse; | ||
import org.elasticsearch.client.ESRestHighLevelClientTestCase; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.ByteSizeUnit; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
@@ -41,6 +43,7 @@ | |
import org.elasticsearch.tasks.TaskInfo; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -80,19 +83,19 @@ public void testClusterPutSettings() throws IOException { | |
// end::put-settings-request | ||
|
||
// tag::put-settings-create-settings | ||
String transientSettingKey = | ||
String transientSettingKey = | ||
RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(); | ||
int transientSettingValue = 10; | ||
Settings transientSettings = | ||
Settings transientSettings = | ||
Settings.builder() | ||
.put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES) | ||
.build(); // <1> | ||
|
||
String persistentSettingKey = | ||
String persistentSettingKey = | ||
EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(); | ||
String persistentSettingValue = | ||
String persistentSettingValue = | ||
EnableAllocationDecider.Allocation.NONE.name(); | ||
Settings persistentSettings = | ||
Settings persistentSettings = | ||
Settings.builder() | ||
.put(persistentSettingKey, persistentSettingValue) | ||
.build(); // <2> | ||
|
@@ -105,9 +108,9 @@ public void testClusterPutSettings() throws IOException { | |
|
||
{ | ||
// tag::put-settings-settings-builder | ||
Settings.Builder transientSettingsBuilder = | ||
Settings.Builder transientSettingsBuilder = | ||
Settings.builder() | ||
.put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES); | ||
.put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES); | ||
request.transientSettings(transientSettingsBuilder); // <1> | ||
// end::put-settings-settings-builder | ||
} | ||
|
@@ -164,7 +167,7 @@ public void testClusterUpdateSettingsAsync() throws Exception { | |
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest(); | ||
|
||
// tag::put-settings-execute-listener | ||
ActionListener<ClusterUpdateSettingsResponse> listener = | ||
ActionListener<ClusterUpdateSettingsResponse> listener = | ||
new ActionListener<ClusterUpdateSettingsResponse>() { | ||
@Override | ||
public void onResponse(ClusterUpdateSettingsResponse response) { | ||
|
@@ -272,4 +275,80 @@ public void onFailure(Exception e) { | |
assertTrue(latch.await(30L, TimeUnit.SECONDS)); | ||
} | ||
} | ||
|
||
public void testPutPipeline() throws IOException { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
{ | ||
// tag::put-pipeline-request | ||
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. This tag seems to be missing its end 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. Fixed. |
||
String source = | ||
"{\"description\":\"my set of processors\"," + | ||
"\"processors\":[{\"set\":{\"field\":\"foo\",\"value\":\"bar\"}}]}"; | ||
PutPipelineRequest request = new PutPipelineRequest( | ||
"my-pipeline-id", // <1> | ||
new BytesArray(source.getBytes(StandardCharsets.UTF_8)), // <2> | ||
XContentType.JSON // <3> | ||
); | ||
// end::put-pipeline-request | ||
|
||
// tag::put-pipeline-request-timeout | ||
request.timeout(TimeValue.timeValueMinutes(2)); // <1> | ||
request.timeout("2m"); // <2> | ||
// end::put-pipeline-request-timeout | ||
|
||
// tag::put-pipeline-request-masterTimeout | ||
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> | ||
request.masterNodeTimeout("1m"); // <2> | ||
// end::put-pipeline-request-masterTimeout | ||
|
||
// tag::put-pipeline-execute | ||
PutPipelineResponse response = client.cluster().putPipeline(request); // <1> | ||
// end::put-pipeline-execute | ||
|
||
// tag::put-pipeline-response | ||
boolean acknowledged = response.isAcknowledged(); // <1> | ||
// end::put-pipeline-response | ||
assertTrue(acknowledged); | ||
} | ||
} | ||
|
||
public void testPutPipelineAsync() throws Exception { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
{ | ||
String source = | ||
"{\"description\":\"my set of processors\"," + | ||
"\"processors\":[{\"set\":{\"field\":\"foo\",\"value\":\"bar\"}}]}"; | ||
PutPipelineRequest request = new PutPipelineRequest( | ||
"my-pipeline-id", | ||
new BytesArray(source.getBytes(StandardCharsets.UTF_8)), | ||
XContentType.JSON | ||
); | ||
|
||
// tag::put-pipeline-execute-listener | ||
ActionListener<PutPipelineResponse> listener = | ||
new ActionListener<PutPipelineResponse>() { | ||
@Override | ||
public void onResponse(PutPipelineResponse response) { | ||
// <1> | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
// <2> | ||
} | ||
}; | ||
// end::put-pipeline-execute-listener | ||
|
||
// Replace the empty listener by a blocking listener in test | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
listener = new LatchedActionListener<>(listener, latch); | ||
|
||
// tag::put-pipeline-execute-async | ||
client.cluster().putPipelineAsync(request, listener); // <1> | ||
// end::put-pipeline-execute-async | ||
|
||
assertTrue(latch.await(30L, TimeUnit.SECONDS)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
sorry for being late to the party. I just realized that the spec here defines the API as
ingest.put_pipeline
. Instead of adding this API (and all of the other ingest API) to the cluster ones, we should create a new namespace called ingest, similar to what we recently did with snapshot. @sohaibiftikhar would you mind taking care of this ?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.
Sure. Should I combine this change with #30847 or put in a separate PR?
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.
I would do it in a separate PR, thanks!