-
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 support for Rollover Index API #28698
Merged
javanna
merged 15 commits into
elastic:master
from
javanna:enhancement/rest_hl_client_rollover
Feb 20, 2018
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c25f268
REST high-level client: add support for Rollover Index API
javanna 5704be0
fix test failure
javanna 58513c2
remove the setCreateIndexrRequest from RolloverRequest. It is not nee…
javanna 955a6cf
fix test failure
javanna 6b66c81
Merge branch 'master' into enhancement/rest_hl_client_rollover
javanna eb4931d
fix create index response parsing and add test
javanna 07a6fe7
address review comments
javanna 07a6361
address review comments
javanna 7a55875
add serialization tests for RolloverResponse, also change base class …
javanna 97f7f10
adapt Condition equals/hashcode to take value into account
javanna 5e81283
Merge branch 'master' into enhancement/rest_hl_client_rollover
javanna d188e54
shorten serialization code
javanna ee0141e
shorten serialization code
javanna 4e74af3
add mutate function
javanna 9b7a4de
adjust rollover response tests
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
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 |
---|---|---|
|
@@ -39,11 +39,18 @@ | |
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; | ||
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; | ||
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; | ||
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; | ||
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; | ||
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest; | ||
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse; | ||
import org.elasticsearch.action.admin.indices.shrink.ResizeType; | ||
import org.elasticsearch.action.index.IndexRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.ByteSizeUnit; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
|
@@ -435,4 +442,57 @@ public void testSplit() throws IOException { | |
Map<String, Object> aliasData = (Map<String, Object>)XContentMapValues.extractValue("target.aliases.alias", getIndexResponse); | ||
assertNotNull(aliasData); | ||
} | ||
|
||
public void testRollover() throws IOException { | ||
highLevelClient().indices().create(new CreateIndexRequest("test").alias(new Alias("alias"))); | ||
RolloverRequest rolloverRequest = new RolloverRequest("alias", "test_new"); | ||
rolloverRequest.addMaxIndexDocsCondition(1); | ||
|
||
{ | ||
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover, | ||
highLevelClient().indices()::rolloverAsync); | ||
assertFalse(rolloverResponse.isRolledOver()); | ||
assertFalse(rolloverResponse.isDryRun()); | ||
Map<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus(); | ||
assertEquals(1, conditionStatus.size()); | ||
assertFalse(conditionStatus.get("[max_docs: 1]")); | ||
assertEquals("test", rolloverResponse.getOldIndex()); | ||
assertEquals("test_new", rolloverResponse.getNewIndex()); | ||
} | ||
|
||
highLevelClient().index(new IndexRequest("test", "type", "1").source("field", "value")); | ||
highLevelClient().index(new IndexRequest("test", "type", "2").source("field", "value") | ||
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)); | ||
//without the refresh the rollover may not happen as the number of docs seen may be off | ||
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. thanks |
||
|
||
{ | ||
rolloverRequest.addMaxIndexAgeCondition(new TimeValue(1)); | ||
rolloverRequest.dryRun(true); | ||
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover, | ||
highLevelClient().indices()::rolloverAsync); | ||
assertFalse(rolloverResponse.isRolledOver()); | ||
assertTrue(rolloverResponse.isDryRun()); | ||
Map<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus(); | ||
assertEquals(2, conditionStatus.size()); | ||
assertTrue(conditionStatus.get("[max_docs: 1]")); | ||
assertTrue(conditionStatus.get("[max_age: 1ms]")); | ||
assertEquals("test", rolloverResponse.getOldIndex()); | ||
assertEquals("test_new", rolloverResponse.getNewIndex()); | ||
} | ||
{ | ||
rolloverRequest.dryRun(false); | ||
rolloverRequest.addMaxIndexSizeCondition(new ByteSizeValue(1, ByteSizeUnit.MB)); | ||
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover, | ||
highLevelClient().indices()::rolloverAsync); | ||
assertTrue(rolloverResponse.isRolledOver()); | ||
assertFalse(rolloverResponse.isDryRun()); | ||
Map<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus(); | ||
assertEquals(3, conditionStatus.size()); | ||
assertTrue(conditionStatus.get("[max_docs: 1]")); | ||
assertTrue(conditionStatus.get("[max_age: 1ms]")); | ||
assertFalse(conditionStatus.get("[max_size: 1mb]")); | ||
assertEquals("test", rolloverResponse.getOldIndex()); | ||
assertEquals("test_new", rolloverResponse.getNewIndex()); | ||
} | ||
} | ||
} |
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.
Just curious why we need the refresh policy here. Maybe worth a comment.
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 rollover API doesn't see the proper number of docs otherwise. At least that's why I think the test fails without it.
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.
Can you add this explanation as a short comment then? Thanks.