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

Add put index template api to high level rest client #30400

Merged
merged 3 commits into from
May 6, 2018

Conversation

dnhatn
Copy link
Member

@dnhatn dnhatn commented May 4, 2018

Relates #27205

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@dnhatn dnhatn requested a review from dakrone May 4, 2018 16:45
Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

LGTM, I left one question/comment but it's nothing required

@@ -662,6 +662,15 @@ public static String randomRealisticUnicodeOfCodepointLength(int codePoints) {
return generateRandomStringArray(maxArraySize, maxStringSize, allowNull, true);
}

public static List<String> randomStringList(int minListSize, int maxListSize, int minStringLength, int maxStringLength) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add javadocs for this please?

Copy link
Member

Choose a reason for hiding this comment

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

Also, do we use the minStringLength and maxStringLength? Just wondering if instead we could do Arrays.asList(generateRandomStringArray(...)), unless we need the unicode-ness and the min/max string size

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I removed the new method and used generateRandomStringArray.

@dnhatn
Copy link
Member Author

dnhatn commented May 6, 2018

Thanks @dakrone for reviewing!

@dnhatn dnhatn merged commit eed8a3b into elastic:master May 6, 2018
@dnhatn dnhatn deleted the rest-put-template branch May 6, 2018 13:47
dnhatn added a commit that referenced this pull request May 6, 2018
dnhatn added a commit that referenced this pull request May 6, 2018
This commit fixes the broken doc introduced in #30400

Relates #30400
dnhatn added a commit that referenced this pull request May 6, 2018
This commit fixes the broken doc introduced in #30400

Relates #30400
dnhatn added a commit that referenced this pull request May 6, 2018
The mapping tags were not named consistently and not linked correctly.

Relates #30400
dnhatn added a commit that referenced this pull request May 6, 2018
The mapping tags were not named consistently and not linked correctly.

Relates #30400
jasontedor added a commit that referenced this pull request May 6, 2018
* master: (35 commits)
  DOCS: Correct mapping tags in put-template api
  DOCS: Fix broken link in the put index template api
  Add put index template api to high level rest client (#30400)
  Relax testAckedIndexing to allow document updating
  [Docs] Add snippets for POS stop tags default value
  Move respect accept header on no handler to 6.3.1
  Respect accept header on no handler (#30383)
  [Test] Add analysis-nori plugin to the vagrant tests
  [Docs] Fix bad link
  [Docs] Fix end of section in the korean plugin docs
  Expose the Lucene Korean analyzer module in a plugin (#30397)
  Docs: remove transport_client from CCS role example (#30263)
  [Rollup] Validate timezone in range queries (#30338)
  Use readFully() to read bytes from CipherInputStream (#28515)
  Fix  docs Recently merged #29229 had a doc bug that broke the doc build. This commit fixes.
  Test: remove cluster permission from CCS user (#30262)
  Add Get Settings API support to java high-level rest client (#29229)
  Watcher: Remove unneeded index deletion in tests
  Set the new lucene version for 6.4.0
  [ML][TEST] Clean up jobs in ModelPlotIT
  ...
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
if (customs.isEmpty() == false) {
throw new IllegalArgumentException("Custom data type is no longer supported in index template [" + customs + "]");
Copy link
Member

Choose a reason for hiding this comment

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

why throw exception when calling toXContent? if customs are not supported anymore why can users set them but not serialize them to json?

builder.startObject("mappings");
for (Map.Entry<String, String> entry : mappings.entrySet()) {
Map<String, Object> mapping = XContentHelper.convertToMap(new BytesArray(entry.getValue()), false).v2();
builder.field(entry.getKey(), mapping);
Copy link
Member

Choose a reason for hiding this comment

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

could of things here: we should not use a deprecated method, I think it is guaranteed that the request holds json (we convert it on the setter methods), hence we should not need content-type auto-detection. Furthermore, we don't need to parse stuff back into a map to the write it back to the builder. I would try and do something like this:

builder.field(entry.getKey());
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler
                    .THROW_UNSUPPORTED_OPERATION, entry.getValue());
builder.copyCurrentStructure(parser);

@@ -131,4 +137,52 @@ public void testValidateErrorMessage() throws Exception {
assertThat(noError, is(nullValue()));
}

private PutIndexTemplateRequest randomPutIndexTemplateRequest() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

can this be static?

assertThat(parsed.aliases(), equalTo(expected.aliases()));
assertThat(parsed.mappings(), equalTo(expected.mappings()));
assertThat(parsed.settings(), equalTo(expected.settings()));
}
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 make this class extend AbstractXContentTestCase, then your randomPutIndexTemplateRequest would become createTestInstance, and

    @Override
    protected PutIndexTemplateRequest doParseInstance(XContentParser parser) throws IOException {
        return new PutIndexTemplateRequest().source(parser.map());
    }

    @Override
    protected boolean supportsUnknownFields() {
        return false;
    }

    @Override
    protected void assertEqualInstances(PutIndexTemplateRequest expected, PutIndexTemplateRequest parsed) {
        assertNotSame(expected, parsed);
        assertThat(parsed.version(), equalTo(expected.version()));
        assertThat(parsed.order(), equalTo(expected.order()));
        assertThat(parsed.patterns(), equalTo(expected.patterns()));
        assertThat(parsed.aliases(), equalTo(expected.aliases()));
        assertThat(parsed.mappings(), equalTo(expected.mappings()));
        assertThat(parsed.settings(), equalTo(expected.settings()));
    }

}

public static PutIndexTemplateResponse fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
Copy link
Member

Choose a reason for hiding this comment

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

Although this response is super simple, we may want to add a PutIndexTemplateResponseTests similar to UpdateSettingsResponseTests ?

@javanna
Copy link
Member

javanna commented May 7, 2018

heya @dnhatn thanks a lot for working on this, I left a few minor comments.

@dnhatn
Copy link
Member Author

dnhatn commented May 7, 2018

Hi @javanna, thanks for reviewing! I will address your comments in a follow-up.

jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request May 7, 2018
…r-you

* origin/master:
  Update forcemerge.asciidoc (elastic#30113)
  Added zentity to the list of API extension plugins (elastic#29143)
  Fix the search request default operation behavior doc (elastic#29302) (elastic#29405)
  Watcher: Mark watcher as started only after loading watches (elastic#30403)
  Pass the task to broadcast actions (elastic#29672)
  Disable REST default settings testing until elastic#29229 is back-ported
  Correct wording in log message (elastic#30336)
  Do not fail snapshot when deleting a missing snapshotted file (elastic#30332)
  AwaitsFix testCreateShrinkIndexToN
  DOCS: Correct mapping tags in put-template api
  DOCS: Fix broken link in the put index template api
  Add put index template api to high level rest client (elastic#30400)
  Relax testAckedIndexing to allow document updating
  [Docs] Add snippets for POS stop tags default value
  Move respect accept header on no handler to 6.3.1
jasontedor added a commit to jaymode/elasticsearch that referenced this pull request May 7, 2018
* origin/master: (39 commits)
  Docs: fix changelog merge
  Fix line length violation in cache tests
  Add stricter geohash parsing (elastic#30376)
  Add failing test for core cache deadlock
  [DOCS] convert forcemerge snippet
  Update forcemerge.asciidoc (elastic#30113)
  Added zentity to the list of API extension plugins (elastic#29143)
  Fix the search request default operation behavior doc (elastic#29302) (elastic#29405)
  Watcher: Mark watcher as started only after loading watches (elastic#30403)
  Pass the task to broadcast actions (elastic#29672)
  Disable REST default settings testing until elastic#29229 is back-ported
  Correct wording in log message (elastic#30336)
  Do not fail snapshot when deleting a missing snapshotted file (elastic#30332)
  AwaitsFix testCreateShrinkIndexToN
  DOCS: Correct mapping tags in put-template api
  DOCS: Fix broken link in the put index template api
  Add put index template api to high level rest client (elastic#30400)
  Relax testAckedIndexing to allow document updating
  [Docs] Add snippets for POS stop tags default value
  Move respect accept header on no handler to 6.3.1
  ...
dnhatn added a commit that referenced this pull request May 8, 2018
* elastic-master:
  Watcher: Mark watcher as started only after loading watches (#30403)
  Pass the task to broadcast actions (#29672)
  Disable REST default settings testing until #29229 is back-ported
  Correct wording in log message (#30336)
  Do not fail snapshot when deleting a missing snapshotted file (#30332)
  AwaitsFix testCreateShrinkIndexToN
  DOCS: Correct mapping tags in put-template api
  DOCS: Fix broken link in the put index template api
  Add put index template api to high level rest client (#30400)
  Relax testAckedIndexing to allow document updating
  [Docs] Add snippets for POS stop tags default value
  Move respect accept header on no handler to 6.3.1
  Respect accept header on no handler (#30383)
  [Test] Add analysis-nori plugin to the vagrant tests
  [Docs] Fix bad link
  [Docs] Fix end of section in the korean plugin docs
  Expose the Lucene Korean analyzer module in a plugin (#30397)
  Docs: remove transport_client from CCS role example (#30263)
  [Rollup] Validate timezone in range queries (#30338)
  Use readFully() to read bytes from CipherInputStream (#28515)
  Fix  docs Recently merged #29229 had a doc bug that broke the doc build. This commit fixes.
  Test: remove cluster permission from CCS user (#30262)
  Add Get Settings API support to java high-level rest client (#29229)
  Watcher: Remove unneeded index deletion in tests
dnhatn added a commit that referenced this pull request May 8, 2018
* 6.x:
  Stop forking javac (#30462)
  Fix tribe tests
  Docs: Use task_id in examples of tasks (#30436)
  Security: Rename IndexLifecycleManager to SecurityIndexManager (#30442)
  Packaging: Set elasticsearch user to have non-existent homedir (#29007)
  [Docs] Fix typo in cardinality-aggregation.asciidoc (#30434)
  Avoid NPE in `more_like_this` when field has zero tokens (#30365)
  Build: Switch to building javadoc with html5 (#30440)
  Add a quick tour of the project to CONTRIBUTING (#30187)
  Add stricter geohash parsing (#30376)
  Reindex: Use request flavored methods (#30317)
  Silence SplitIndexIT.testSplitIndexPrimaryTerm test failure.  (#30432)
  Auto-expand replicas when adding or removing nodes (#30423)
  Silence IndexUpgradeIT test failures. (#30430)
  Fix line length violation in cache tests
  Add failing test for core cache deadlock
  [DOCS] convert forcemerge snippet
  Update forcemerge.asciidoc (#30113)
  Added zentity to the list of API extension plugins (#29143)
  Fix the search request default operation behavior doc (#29302) (#29405)
  Watcher: Mark watcher as started only after loading watches (#30403)
  Correct wording in log message (#30336)
  Do not fail snapshot when deleting a missing snapshotted file (#30332)
  AwaitsFix testCreateShrinkIndexToN
  DOCS: Correct mapping tags in put-template api
  DOCS: Fix broken link in the put index template api
  Add put index template api to high level rest client (#30400)
  [Docs] Add snippets for POS stop tags default value
  Remove entry inadvertently picked into changelog
  Move respect accept header on no handler to 6.3.1
  Respect accept header on no handler (#30383)
  [Test] Add analysis-nori plugin to the vagrant tests
  [Rollup] Validate timezone in range queries (#30338)
  [Docs] Fix bad link
  [Docs] Fix end of section in the korean plugin docs
  add the Korean nori plugin to the change logs
  Expose the Lucene Korean analyzer module in a plugin (#30397)
  Docs: remove transport_client from CCS role example (#30263)
  Test: remove cluster permission from CCS user (#30262)
  Watcher: Remove unneeded index deletion in tests
  fix docs branch version
  fix lucene snapshot version
  Upgrade to 7.4.0-snapshot-1ed95c097b (#30357)
  [ML][TEST] Clean up jobs in ModelPlotIT
  Watcher: Ensure trigger service pauses execution (#30363)
  [DOCS] Fixes ordering of changelog sections
  [DOCS] Commented out empty sections in the changelog to fix the doc build. (#30372)
  Make RepositoriesMetaData contents unmodifiable (#30361)
  Change signature of Get Repositories Response (#30333)
  6.x Backport: Terms query validate bug  (#30319)
  InternalEngineTests.testConcurrentOutOfOrderDocsOnReplica should use two documents (#30121)
  Security: reduce garbage during index resolution (#30180)
  Test: use trial license in qa tests with security
  [ML] Add integration test for model plots (#30359)
  SQL: Fix bug caused by empty composites (#30343)
  [ML] Account for gaps in data counts after job is reopened (#30294)
  [ML] Refactor DataStreamDiagnostics to use array (#30129)
  Make licensing FIPS-140 compliant (#30251)
  Do not load global state when deleting a snapshot (#29278)
  Don't load global state when only restoring indices (#29239)
  Tests: Use different watch ids per test in smoke test (#30331)
  Watcher: Make start/stop cycle more predictable and synchronous (#30118)
  [Docs] Add term query with normalizer example
  Adds Eclipse config for xpack licence headers (#30299)
  Fix message content in users tool (#30293)
  [DOCS] Removed X-Pack breaking changes page
  [DOCS] Added security breaking change
  [DOCS] Fixes link to TLS LDAP info
  [DOCS] Merges X-Pack release notes into changelog (#30350)
  [DOCS] Fixes broken links to bootstrap user (#30349)
  [Docs] Remove errant changelog line
  Fix NPE when CumulativeSum agg encounters null/empty bucket (#29641)
  [DOCS] Reorganizes authentication details in Stack Overview (#30280)
  Tests: Simplify VersionUtils released version splitting (#30322)
  Fix merging logic of Suggester Options (#29514)
  ReplicationTracker.markAllocationIdAsInSync may hang if allocation is cancelled (#30316)
  [DOCS] Adds LDAP realm configuration details (#30214)
  [DOCS] Adds native realm configuration details (#30215)
  Disable SSL on testing old BWC nodes (#30337)
  [DOCS] Enables edit links for X-Pack pages
  Cancelling a peer recovery on the source can leak a primary permit (#30318)
  SQL: Reduce number of ranges generated for comparisons (#30267)
  [DOCS] Adds links to changelog sections
  Convert server javadoc to html5 (#30279)
  REST Client: Add Request object flavored methods (#29623)
  Create default ES_TMPDIR on Windows (#30325)
  [Docs] Clarify `fuzzy_like_this` redirect (#30183)
  Fix docs of the `_ignored` meta field.
  Add a new `_ignored` meta field. (#29658)
  Move repository-azure fixture test to QA project (#30253)
dnhatn added a commit to dnhatn/elasticsearch that referenced this pull request May 14, 2018
This commit addresses some comments given after the original PR was in.

Follow-up elastic#30400
dnhatn added a commit that referenced this pull request May 15, 2018
This commit addresses some comments given after the original PR was in.

Follow-up #30400
dnhatn added a commit that referenced this pull request May 15, 2018
This commit addresses some comments given after the original PR was in.

Follow-up #30400
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.

5 participants