-
Notifications
You must be signed in to change notification settings - Fork 25k
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 api - upgrade #34898
Changes from all commits
a47e432
ff3ddd1
1af129c
b6683d1
bcb8f38
0deb3c1
e63914f
0e67a92
a71d5c8
0c14987
30a1694
37fbf88
77875e4
614e711
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.migration; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A request for performing Upgrade on Index | ||
* Part of Migration API | ||
*/ | ||
public class IndexUpgradeRequest implements Validatable { | ||
|
||
private String index; | ||
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. Why did we change this from an array of strings to a single one? 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. for other kind of requests you can specify indices comma separated like _xpack/migration/assistance/index1,index2,index3 |
||
|
||
public IndexUpgradeRequest(String index) { | ||
this.index = index; | ||
} | ||
|
||
public String index() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
IndexUpgradeRequest request = (IndexUpgradeRequest) o; | ||
return Objects.equals(index, request.index); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(index); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,30 @@ | |
|
||
package org.elasticsearch.client.documentation; | ||
|
||
import org.elasticsearch.ElasticsearchStatusException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.LatchedActionListener; | ||
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.client.migration.IndexUpgradeInfoRequest; | ||
import org.elasticsearch.client.migration.IndexUpgradeInfoResponse; | ||
import org.elasticsearch.client.migration.IndexUpgradeRequest; | ||
import org.elasticsearch.client.migration.UpgradeActionRequired; | ||
import org.elasticsearch.client.tasks.TaskSubmissionResponse; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.reindex.BulkByScrollResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.isEmptyOrNullString; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
/** | ||
* This class is used to generate the Java Migration API documentation. | ||
|
@@ -80,4 +93,66 @@ public void testGetAssistance() throws IOException { | |
} | ||
// end::get-assistance-response | ||
} | ||
|
||
public void testUpgrade() throws IOException { | ||
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. here I am adding these test cases which are duplicates of the one I have in MigrationIT. I made it more documentation friendly here though. 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. ++ |
||
|
||
RestHighLevelClient client = highLevelClient(); | ||
createIndex("test", Settings.EMPTY); | ||
|
||
|
||
// tag::upgrade-request | ||
IndexUpgradeRequest request = new IndexUpgradeRequest("test"); // <1> | ||
// end::upgrade-request | ||
|
||
try { | ||
|
||
// tag::upgrade-execute | ||
BulkByScrollResponse response = client.migration().upgrade(request, RequestOptions.DEFAULT); | ||
// end::upgrade-execute | ||
|
||
} catch (ElasticsearchStatusException e) { | ||
assertThat(e.getMessage(), containsString("cannot be upgraded")); | ||
} | ||
} | ||
|
||
public void testUpgradeAsync() throws IOException, InterruptedException { | ||
RestHighLevelClient client = highLevelClient(); | ||
createIndex("test", Settings.EMPTY); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
|
||
// tag::upgrade-async-listener | ||
ActionListener<BulkByScrollResponse> listener = new ActionListener<BulkByScrollResponse>() { | ||
@Override | ||
public void onResponse(BulkByScrollResponse bulkResponse) { | ||
// <1> | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
// <2> | ||
} | ||
}; | ||
// end::upgrade-async-listener | ||
|
||
listener = new LatchedActionListener<>(listener, latch); | ||
|
||
// tag::upgrade-async-execute | ||
client.migration().upgradeAsync(new IndexUpgradeRequest("test"), RequestOptions.DEFAULT, listener); // <1> | ||
// end::upgrade-async-execute | ||
|
||
assertTrue(latch.await(30L, TimeUnit.SECONDS)); | ||
} | ||
|
||
public void testUpgradeWithTaskApi() throws IOException { | ||
createIndex("test", Settings.EMPTY); | ||
RestHighLevelClient client = highLevelClient(); | ||
// tag::upgrade-task-api | ||
IndexUpgradeRequest request = new IndexUpgradeRequest("test"); | ||
|
||
TaskSubmissionResponse response = client.migration() | ||
.submitUpgradeTask(request, RequestOptions.DEFAULT); | ||
String taskId = response.getTask(); | ||
// end::upgrade-task-api | ||
assertThat(taskId, not(isEmptyOrNullString())); | ||
} | ||
} |
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.
remove empty line