|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.client.documentation; |
| 21 | + |
| 22 | +import org.elasticsearch.action.support.IndicesOptions; |
| 23 | +import org.elasticsearch.client.ESRestHighLevelClientTestCase; |
| 24 | +import org.elasticsearch.client.RequestOptions; |
| 25 | +import org.elasticsearch.client.RestHighLevelClient; |
| 26 | +import org.elasticsearch.common.Strings; |
| 27 | +import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest; |
| 28 | +import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse; |
| 29 | +import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired; |
| 30 | + |
| 31 | +import java.io.IOException; |
| 32 | +import java.util.Map; |
| 33 | + |
| 34 | +/** |
| 35 | + * This class is used to generate the Java Migration API documentation. |
| 36 | + * You need to wrap your code between two tags like: |
| 37 | + * // tag::example |
| 38 | + * // end::example |
| 39 | + * |
| 40 | + * Where example is your tag name. |
| 41 | + * |
| 42 | + * Then in the documentation, you can extract what is between tag and end tags with |
| 43 | + * ["source","java",subs="attributes,callouts,macros"] |
| 44 | + * -------------------------------------------------- |
| 45 | + * include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[example] |
| 46 | + * -------------------------------------------------- |
| 47 | + * |
| 48 | + * The column width of the code block is 84. If the code contains a line longer |
| 49 | + * than 84, the line will be cut and a horizontal scroll bar will be displayed. |
| 50 | + * (the code indentation of the tag is not included in the width) |
| 51 | + */ |
| 52 | +public class MigrationClientDocumentationIT extends ESRestHighLevelClientTestCase { |
| 53 | + |
| 54 | + public void testGetAssistance() throws IOException { |
| 55 | + RestHighLevelClient client = highLevelClient(); |
| 56 | + |
| 57 | + // tag::get-assistance-request |
| 58 | + IndexUpgradeInfoRequest request = new IndexUpgradeInfoRequest(); // <1> |
| 59 | + // end::get-assistance-request |
| 60 | + |
| 61 | + // tag::get-assistance-request-indices |
| 62 | + request.indices("index1", "index2"); // <1> |
| 63 | + // end::get-assistance-request-indices |
| 64 | + |
| 65 | + request.indices(Strings.EMPTY_ARRAY); |
| 66 | + |
| 67 | + // tag::get-assistance-request-indices-options |
| 68 | + request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> |
| 69 | + // end::get-assistance-request-indices-options |
| 70 | + |
| 71 | + // tag::get-assistance-execute |
| 72 | + IndexUpgradeInfoResponse response = client.migration().getAssistance(request, RequestOptions.DEFAULT); |
| 73 | + // end::get-assistance-execute |
| 74 | + |
| 75 | + // tag::get-assistance-response |
| 76 | + Map<String, UpgradeActionRequired> actions = response.getActions(); |
| 77 | + for (Map.Entry<String, UpgradeActionRequired> entry : actions.entrySet()) { |
| 78 | + String index = entry.getKey(); // <1> |
| 79 | + UpgradeActionRequired actionRequired = entry.getValue(); // <2> |
| 80 | + } |
| 81 | + // end::get-assistance-response |
| 82 | + } |
| 83 | +} |
0 commit comments