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 Repository High Level REST API #30501

Merged
merged 8 commits into from
May 16, 2018

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented May 10, 2018

This commit adds PUT Repository, the associated docs and tests for the
high level REST API client. A few small changes to the PutRepository
Request and Response went into the commit as well.

Relates #27205

This commit adds PUT Repository, the associated docs and tests for the
high level REST API client. A few small changes to the PutRepository
Request and Response went into the commit as well.

Relates elastic#27205
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@hub-cap hub-cap added the review label May 10, 2018
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 like it!

* API on elastic.co</a>
*/
public void putRepositoryAsync(PutRepositoryRequest putRepositoryRequest,
ActionListener<PutRepositoryResponse> 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.

Add a space after ) and before { please!

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

thanks @hub-cap I left some comments!

parameters.withMasterTimeout(putRepositoryRequest.masterNodeTimeout());
parameters.withTimeout(putRepositoryRequest.timeout());

request.setEntity(createEntity(putRepositoryRequest, REQUEST_BODY_CONTENT_TYPE));
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 in the corresponding REST action that we also support the verify parameter. I guess we should support it here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea definitely, ty for pointing it out. Cant believe i missed it!

* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
* 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.

remove this empty line?

String repository = "repo";
PutRepositoryRequest putRepositoryRequest = new PutRepositoryRequest(repository);
putRepositoryRequest.type(FsRepository.TYPE);
putRepositoryRequest.settings("{\"location\": \".\"}", 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.

would it be possible to randomize the values that the request holds like in other tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrt this, should i be putting different types of plugins as well? Or just use the FS plugin? The other plugins would have to be loaded in gradle (which im sure is super easy), but I just want to make sure I have the scope here correctly. Also, putting other values for the location that are not approved by the config will result in exceptions, this is why i chose that generic thing. Just trying to test that its accepted and comes back w what i want.

Copy link
Member

Choose a reason for hiding this comment

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

I assumed that there is no problem setting values and checking that the output of the conversion from high-level request to low-level request is the expected one. We don't validate etc. I would do only what is straight-forward.

@@ -49,4 +58,8 @@ public void writeTo(StreamOutput out) throws IOException {
writeAcknowledged(out);
}

public static PutRepositoryResponse 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.

can you add a test for this class although very simple?

builder.endObject();

builder.endObject();
return builder;
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 a unit test for this method?

* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
* API on elastic.co</a>
*/
public void putRepositoryAsync(PutRepositoryRequest putRepositoryRequest,
Copy link
Member

Choose a reason for hiding this comment

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

in the spec we call this "snapshot.create_repository" . Could you rename the methods to createRepository please?

@@ -1448,6 +1451,18 @@ public void testGetRepositories() {
assertThat(expectedParams, equalTo(request.getParameters()));
}

public void testPutRepository() 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.

testCreateRepository?

private static final String testRepository = "test_repository";
private static final String repositoryName = "test_repository";

public void testSnapshotPutRepository() 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.

testSnapshotCreateRepository?

assertTrue(acknowledged);
}

public void testSnapshotPutRepositoryAsync() throws InterruptedException {
Copy link
Member

Choose a reason for hiding this comment

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

testSnapshotCreateRepositoryAsync

@@ -0,0 +1,139 @@
[[java-rest-high-snapshot-put-repository]]
=== Snapshot Put Repository API
Copy link
Member

Choose a reason for hiding this comment

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

in the docs as well, can you rename put repository to create repository. We leave requests and responses as they are as we reuse them from the transport client, but for the rest we should follow the spec naming like other language clients already do.

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 went ahead and changed it in all the headings and links (eg, [[java-rest-high-snapshot-create-repository]])

@hub-cap
Copy link
Contributor Author

hub-cap commented May 15, 2018

@javanna ive addressed comments, pls review. I have also added repository request/response tests so i can cover most of the new things im adding to these request/responses in this and subsequent PRs.

@hub-cap hub-cap requested a review from javanna May 15, 2018 13:37

import static org.hamcrest.Matchers.equalTo;

public class RepositoryResponseTests extends ESTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

could this extend AbstractXContentTestCase or AbstractStreamableXContentTestCase ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed it can, and it makes it much simple. TYVM for showing me this test class!!!

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

thanks @hub-cap left one comment on testing, LGTM otherwise. feel free to push once addressed

@hub-cap hub-cap merged commit b94bc70 into elastic:master May 16, 2018
@lcawl
Copy link
Contributor

lcawl commented May 16, 2018

I think the docs/java-rest/high-level/snapshot/create_repository.asciidoc is missing from the 6.x branch. Is that intentional? It's causing some documentation build issues.

hub-cap added a commit that referenced this pull request May 16, 2018
This commit adds Create Repository, the associated docs and tests
for the high level REST API client. A few small changes to the
PutRepository Request and Response went into the commit as well.
@hub-cap
Copy link
Contributor Author

hub-cap commented May 16, 2018

@lcawl I had not yet pushed it. I was in backport hell for a while today. I pushed it just now.

martijnvg added a commit that referenced this pull request May 17, 2018
* es/6.x: (44 commits)
  SQL: Remove dependency for server's version from JDBC driver (#30631)
  Make xpack modules instead of a meta plugin (#30589)
  Security: Remove SecurityLifecycleService (#30526)
  Build: Add task interdependencies for ssl configuration (#30633)
  Mute ShrinkIndexIT
  [ML] DeleteExpiredDataAction should use client with origin (#30646)
  Reindex: Fixed typo in assertion failure message (#30619)
  [DOCS] Fixes list of unconverted snippets in build.gradle
  Use readFully() to read bytes from CipherInputStream (#30640)
  Add Create Repository High Level REST API (#30501)
  [DOCS] Reorganizes RBAC documentation
  Test: increase search logging for LicensingTests
  Delay _uid field data deprecation warning (#30651)
  Deprecate Empty Templates (#30194)
  Remove unused DirectoryUtils class. (#30582)
  Mitigate date histogram slowdowns with non-fixed timezones. (#30534)
  [TEST] Remove AwaitsFix in IndicesOptionsTests#testSerialization
  S3 repo plugin populates SettingsFilter (#30652)
  Rest High Level client: Add List Tasks (#29546)
  Fixes IndiceOptionsTests to serialise correctly (#30644)
  ...
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.

6 participants