-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
HLRC: migration get assistance API #32744
Merged
javanna
merged 7 commits into
elastic:master
from
javanna:enhancement/hlrc_migration_get_assistance
Aug 13, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4c56dd
HLRC: migration get assistance API
javanna 2b8b7db
HLRC: migration get assistance API
javanna 0e08121
checkstyle
javanna f946ad2
review comments
javanna 30e848d
Merge branch 'master' into enhancement/hlrc_migration_get_assistance
javanna 3101504
license
javanna 51bc893
Merge branch 'master' into enhancement/hlrc_migration_get_assistance
javanna 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
55 changes: 55 additions & 0 deletions
55
client/rest-high-level/src/main/java/org/elasticsearch/client/MigrationClient.java
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client; | ||
|
||
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest; | ||
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
/** | ||
* A wrapper for the {@link RestHighLevelClient} that provides methods for | ||
* accessing the Elastic License-related methods | ||
* <p> | ||
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api.html"> | ||
* X-Pack Migration APIs on elastic.co</a> for more information. | ||
*/ | ||
public final class MigrationClient { | ||
|
||
private final RestHighLevelClient restHighLevelClient; | ||
|
||
MigrationClient(RestHighLevelClient restHighLevelClient) { | ||
this.restHighLevelClient = restHighLevelClient; | ||
} | ||
|
||
/** | ||
* Get Migration Assistance for one or more indices | ||
* | ||
* @param request the request | ||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @return the response | ||
* @throws IOException in case there is a problem sending the request or parsing back the response | ||
*/ | ||
public IndexUpgradeInfoResponse getAssistance(IndexUpgradeInfoRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::getMigrationAssistance, options, | ||
IndexUpgradeInfoResponse::fromXContent, Collections.emptySet()); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client; | ||
|
||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest; | ||
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse; | ||
|
||
import java.io.IOException; | ||
|
||
public class MigrationIT extends ESRestHighLevelClientTestCase { | ||
|
||
public void testGetAssistance() throws IOException { | ||
RestHighLevelClient client = highLevelClient(); | ||
{ | ||
IndexUpgradeInfoResponse response = client.migration().getAssistance(new IndexUpgradeInfoRequest(), RequestOptions.DEFAULT); | ||
assertEquals(0, response.getActions().size()); | ||
} | ||
{ | ||
client.indices().create(new CreateIndexRequest("test"), RequestOptions.DEFAULT); | ||
IndexUpgradeInfoResponse response = client.migration().getAssistance( | ||
new IndexUpgradeInfoRequest("test"), RequestOptions.DEFAULT); | ||
assertEquals(0, response.getActions().size()); | ||
} | ||
} | ||
} |
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
83 changes: 83 additions & 0 deletions
83
.../src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.documentation; | ||
|
||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.client.ESRestHighLevelClientTestCase; | ||
import org.elasticsearch.client.RequestOptions; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest; | ||
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse; | ||
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* This class is used to generate the Java Migration API documentation. | ||
* You need to wrap your code between two tags like: | ||
* // tag::example | ||
* // end::example | ||
* | ||
* Where example is your tag name. | ||
* | ||
* Then in the documentation, you can extract what is between tag and end tags with | ||
* ["source","java",subs="attributes,callouts,macros"] | ||
* -------------------------------------------------- | ||
* include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[example] | ||
* -------------------------------------------------- | ||
* | ||
* The column width of the code block is 84. If the code contains a line longer | ||
* than 84, the line will be cut and a horizontal scroll bar will be displayed. | ||
* (the code indentation of the tag is not included in the width) | ||
*/ | ||
public class MigrationClientDocumentationIT extends ESRestHighLevelClientTestCase { | ||
|
||
public void testGetAssistance() throws IOException { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
// tag::get-assistance-request | ||
IndexUpgradeInfoRequest request = new IndexUpgradeInfoRequest(); // <1> | ||
// end::get-assistance-request | ||
|
||
// tag::get-assistance-request-indices | ||
request.indices("index1", "index2"); // <1> | ||
// end::get-assistance-request-indices | ||
|
||
request.indices(Strings.EMPTY_ARRAY); | ||
|
||
// tag::get-assistance-request-indices-options | ||
request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> | ||
// end::get-assistance-request-indices-options | ||
|
||
// tag::get-assistance-execute | ||
IndexUpgradeInfoResponse response = client.migration().getAssistance(request, RequestOptions.DEFAULT); | ||
// end::get-assistance-execute | ||
|
||
// tag::get-assistance-response | ||
Map<String, UpgradeActionRequired> actions = response.getActions(); | ||
for (Map.Entry<String, UpgradeActionRequired> entry : actions.entrySet()) { | ||
String index = entry.getKey(); // <1> | ||
UpgradeActionRequired actionRequired = entry.getValue(); // <2> | ||
} | ||
// end::get-assistance-response | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
docs/java-rest/high-level/migration/get-assistance.asciidoc
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[[java-rest-high-migration-get-assistance]] | ||
=== Migration Get Assistance | ||
|
||
[[java-rest-high-migraton-get-assistance-request]] | ||
==== Index Upgrade Info Request | ||
|
||
An `IndexUpgradeInfoRequest` does not require any argument: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-request] | ||
-------------------------------------------------- | ||
<1> Create a new request instance | ||
|
||
==== Optional arguments | ||
The following arguments can optionally be provided: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-request-indices] | ||
-------------------------------------------------- | ||
<1> Set the indices to the request | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-request-indices-options] | ||
-------------------------------------------------- | ||
<1> Set the `IndicesOptions` to control how unavailable indices are resolved and | ||
how wildcard expressions are expanded | ||
|
||
[[java-rest-high-migration-get-assistance-execution]] | ||
==== Execution | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-execute] | ||
-------------------------------------------------- | ||
|
||
[[java-rest-high-migration-get-assistance-response]] | ||
==== Response | ||
|
||
The returned `IndexUpgradeInfoResponse` contains the actions required for each index. | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[get-assistance-response] | ||
-------------------------------------------------- | ||
<1> Retrieve the index | ||
<2> Retrieve the action required for the migration of the current index |
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
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.
I consciously did not add the async variant of this API, I do not think it's needed.
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've always thought we're better off being consistent but I'm fine with it this way.
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.
The initial idea was that not all the API will have the async method variant. We ended up adding it to almost all the methods, but I think this one is another where async is not really needed?