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

REST high-level client: add put ingest pipeline API #30793

Merged
merged 8 commits into from
May 24, 2018

Conversation

sohaibiftikhar
Copy link
Contributor

Relates to #27205

@imotov
Copy link
Contributor

imotov commented May 22, 2018

@elasticmachine add to whitelist

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@imotov imotov requested review from javanna and nik9000 May 22, 2018 20:17
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sohaibiftikhar, great PR, thanks! I did a first round of review and left a few comments but nothing big.

* Add a pipeline or update an existing pipeline in the cluster
* <p>
* See
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you update the link to the add pipeline API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing! I see I have made some stupid mistakes. Will do the change.

* Asynchronously add a pipeline or update an existing pipeline in the cluster
* <p>
* See
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you update the link to the add pipeline API?

* See
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
*/
public void putPipelineAsync(ListTasksRequest request, ActionListener<ListTasksResponse> listener, Header... headers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems to be concerned with ListTasksRequest, I think it might have accidentally slipped in?

RestHighLevelClient client = highLevelClient();

{
// tag::put-pipeline-request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tag seems to be missing its end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

request.timeout("2m"); // <2>
// end::put-pipeline-request-timeout
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1>
// tag::put-pipeline-request-masterTimeout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tag seems to be in the wron place and missing its end.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
if (source != null) {
builder.rawValue(source.streamInput(), XContentType.JSON);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the xContentType associated with the source.


public void testPutPipeline() throws IOException {
String id = "some_pipeline_id";
XContentBuilder pipelineBuilder = JsonXContent.contentBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a random xContentType here

@@ -43,4 +48,25 @@ public void testSerializationWithXContent() throws IOException {
assertEquals(XContentType.JSON, serialized.getXContentType());
assertEquals("{}", serialized.getSource().utf8ToString());
}

public void testToXContent() throws IOException {
XContentBuilder pipelineBuilder = JsonXContent.contentBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a random xContentType and adapt the expected value accordingly

import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Objects;

public class PutPipelineRequest extends AcknowledgedRequest<PutPipelineRequest> {
public class PutPipelineRequest extends AcknowledgedRequest<PutPipelineRequest> implements ToXContentObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if we want to add ToXContent here. Other requests where the body consist of a BytesReference source (e.g. IndexRequest) don't seem to do this, instead we convert them to a ByteArrayEntity in RequestConverters. Not sure whats the benefit of either of those choices, maybe @javanna has an opinion on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was kind of following the example of put mapping for this which does the same. If you guys think it should change I'll make it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I was curious. I don't have a strong opinion either way at the moment, interested in hearing the pros and cons that others might think of

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion either, it can be convenient to implement ToXContentObject I think. IndexRequest is a bit of a different one as the body is the document itself.

@cbuescher cbuescher self-assigned this May 23, 2018
@javanna javanna removed their request for review May 23, 2018 10:33
-- Fixed java doc for ClusterClient::putPipeline
-- Fixed doc tags in ClusterClientDocumentationIT::testPutPipeline
-- Fixed java doc for ClusterClient::putPipelineAsync
-- Randomized xContentType in ClusterClientIT::putPipeline
-- Randomized xContentType in PutPipelineTests::testToXContent
@sohaibiftikhar
Copy link
Contributor Author

Failures seem unrelated. Was unable to reproduce locally.

@cbuescher
Copy link
Member

@sohaibiftikhar thanks for the update, looks good to me, but will give everything a final look while tests are running. The failure you see seems unrelated indeed, but we still need a full CI build to pass. Usually it helps merging in the current version of master, hopefully the failure source is fixed in the meantime. Could you do that once more? Tests should start automatically I think.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two very small remaining remarks about the docs, but the rest looks great. I think this is good, thanks a lot.
I will wait a bit to see if @nik9000 wants to take another look at this, otherwise I think this is ready for merging once the above things are adressed and CI build passes green.

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[put-pipeline-execute]
--------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super small follow up request: there is a callout in this exaple (1), but no explanation text. Could you either remove the callout or add some explanation? Otherwise it looks a bit funny on the rendered page, also seems to mess up the following examples.

{
// tag::put-pipeline-request
String source =
"{\"description\":\"some random set of processors\"," +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you remove "random" here? Its okay in tests I think, reads better without in documentation though. Just my 2cents though.

@sohaibiftikhar
Copy link
Contributor Author

@cbuescher CI looks good now.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two minor things but this looks good to me!

pipelineBuilder.startObject().field(Pipeline.DESCRIPTION_KEY, "some random set of processors");
pipelineBuilder.startArray(Pipeline.PROCESSORS_KEY);
//Start first processor
pipelineBuilder.startObject();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to like doing something like this:

builder.startObject();
{
    builder.field(Pipeline.DESCRIPTION_KEY, "some random set of processors");
    builder.startArray(Pipeline.PROCESSORS_KEY);
    {
        pipelineBuilder.startObject().startObject("set").field("field", "foo").field("value", "bar").endObject().endObject();
        pipelineBuilder.startObject().startObject("convert").field("field", "rank").field("type", "integer").endObject().endObject();
    }
}

The { and } makes block which beg for the "normal" indentation you'd get in json so it kind of lines up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I only saw one thing to do (you mentioned two). Made the change for that.

RestHighLevelClient client = highLevelClient();

{
// tag::put-pipeline-request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@nik9000
Copy link
Member

nik9000 commented May 24, 2018

Sorry I didn't get the ping earlier. I need to be better about emails.

@nik9000
Copy link
Member

nik9000 commented May 24, 2018

@sohaibiftikhar Thanks for you patience with this one. I keep getting distracted with upgrade issues. I've merged this to master and am backporting it to 6.x now. That is pretty much just cherry-picking it back and re-running the tests. So in a few hours I ought to merge it to 6.x as well, so long as the tests run well.

martijnvg added a commit that referenced this pull request May 25, 2018
* es/master:
  Move score script context from SearchScript to its own class (#30816)
  Fix bad version check writing Repository nodes (#30846)
  [docs] explainer for java packaging tests (#30825)
  Remove Throwable usage from transport modules (#30845)
  REST high-level client: add put ingest pipeline API (#30793)
  Update the version checks around ip_range bucket keys, now that the change was backported.
  Mute IndexMasterFailoverIT.testMasterFailoverDuringIndexingWithMappingChanges
  Use geohash cell instead of just a corner in geo_bounding_box (#30698)
  Limit user to single concurrent auth per realm (#30794)
  [Tests] Move templated _rank_eval tests (#30679)
  Security: fix dynamic mapping updates with aliases (#30787)
  Ensure that ip_range aggregations always return bucket keys. (#30701)
  Use remote client in TransportFieldCapsAction (#30838)
  Move Watcher versioning setting to meta field (#30832)
  [Docs] Explain incomplete dates in range queries (#30689)
  Move persistent task registrations to core (#30755)
  Decouple ClusterStateTaskListener & ClusterApplier (#30809)
  Send client headers from TransportClient (#30803)
  Packaging: Ensure upgrade_is_oss flag file is always deleted (#30732)
  Force stable file modes for built packages (#30823)
@nik9000
Copy link
Member

nik9000 commented May 25, 2018

I wasn't able to get a clean build last night. I got one this morning but now the intake build is failing. I'm going to wait for that to go green. I think that is another hour and a half or so, assuming it doesn't fail again.

nik9000 pushed a commit that referenced this pull request May 25, 2018
REST high-level client: add put ingest pipeline API

Adds the put ingest pipeline API to the high level rest client.
@nik9000
Copy link
Member

nik9000 commented May 25, 2018

Backported! Wow that took longer than it ought.....

* See
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
*/
public void putPipelineAsync(PutPipelineRequest request, ActionListener<PutPipelineResponse> listener, Header... headers) {
Copy link
Member

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 ?

Copy link
Contributor Author

@sohaibiftikhar sohaibiftikhar May 28, 2018

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?

Copy link
Member

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!

dnhatn added a commit that referenced this pull request May 28, 2018
* 6.x:
  Fix double semicolon in import statement
  [TEST] Fix minor random bug from #30794
  Enabling testing against an external cluster (#30885)
  SQL: Remove the last remaining server dependencies from jdbc (#30771)
  Add public key header/footer (#30877)
  Include size of snapshot in snapshot metadata (#29602)
  QA: Test template creation during rolling restart (#30850)
  REST high-level client: add put ingest pipeline API (#30793)
  Do not serialize basic license exp in x-pack info (#30848)
  [docs] explainer for java packaging tests (#30825)
  Verify signatures on official plugins (#30800)
  [DOCS] Document index name limitations (#30826)
  [Docs] Add reindex.remote.whitelist example (#30828)
@sohaibiftikhar sohaibiftikhar deleted the put_pipeline branch June 5, 2018 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants