diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java index 6ca351365db..42496822090 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CustomRestHighLevelClientTests.java @@ -37,11 +37,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.main.MainRequest; import org.elasticsearch.action.main.MainResponse; import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.ResponseListener; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.xcontent.XContentHelper; @@ -162,7 +157,7 @@ public class CustomRestHighLevelClientTests extends ESTestCase { ProtocolVersion protocol = new ProtocolVersion("HTTP", 1, 1); when(mockResponse.getStatusLine()).thenReturn(new BasicStatusLine(protocol, 200, "OK")); - MainResponse response = new MainResponse(httpHeader.getValue(), Version.CURRENT, ClusterName.DEFAULT, "_na", Build.CURRENT, true); + MainResponse response = new MainResponse(httpHeader.getValue(), Version.CURRENT, ClusterName.DEFAULT, "_na", Build.CURRENT); BytesRef bytesRef = XContentHelper.toXContent(response, XContentType.JSON, false).toBytesRef(); when(mockResponse.getEntity()).thenReturn(new ByteArrayEntity(bytesRef.bytes, ContentType.APPLICATION_JSON)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 79b8d8d1503..ce932adb285 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -163,7 +163,7 @@ public class RestHighLevelClientTests extends ESTestCase { public void testInfo() throws IOException { Header[] headers = randomHeaders(random(), "Header"); MainResponse testInfo = new MainResponse("nodeName", Version.CURRENT, new ClusterName("clusterName"), "clusterUuid", - Build.CURRENT, true); + Build.CURRENT); mockResponse(testInfo); MainResponse receivedInfo = restHighLevelClient.info(headers); assertEquals(testInfo, receivedInfo); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MainDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MainDocumentationIT.java index 0558091a76c..72986d44f97 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MainDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MainDocumentationIT.java @@ -52,7 +52,6 @@ public class MainDocumentationIT extends ESRestHighLevelClientTestCase { //tag::main-execute MainResponse response = client.info(); //end::main-execute - assertTrue(response.isAvailable()); //tag::main-response ClusterName clusterName = response.getClusterName(); // <1> String clusterUuid = response.getClusterUuid(); // <2> diff --git a/server/src/main/java/org/elasticsearch/action/main/MainResponse.java b/server/src/main/java/org/elasticsearch/action/main/MainResponse.java index 9bed7691374..a8bd1acbe43 100644 --- a/server/src/main/java/org/elasticsearch/action/main/MainResponse.java +++ b/server/src/main/java/org/elasticsearch/action/main/MainResponse.java @@ -41,18 +41,16 @@ public class MainResponse extends ActionResponse implements ToXContentObject { private ClusterName clusterName; private String clusterUuid; private Build build; - boolean available; MainResponse() { } - public MainResponse(String nodeName, Version version, ClusterName clusterName, String clusterUuid, Build build, boolean available) { + public MainResponse(String nodeName, Version version, ClusterName clusterName, String clusterUuid, Build build) { this.nodeName = nodeName; this.version = version; this.clusterName = clusterName; this.clusterUuid = clusterUuid; this.build = build; - this.available = available; } public String getNodeName() { @@ -75,10 +73,6 @@ public class MainResponse extends ActionResponse implements ToXContentObject { return build; } - public boolean isAvailable() { - return available; - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); @@ -87,7 +81,9 @@ public class MainResponse extends ActionResponse implements ToXContentObject { clusterName.writeTo(out); out.writeString(clusterUuid); Build.writeBuild(build, out); - out.writeBoolean(available); + if (out.getVersion().before(Version.V_7_0_0_alpha1)) { + out.writeBoolean(true); + } } @Override @@ -98,7 +94,9 @@ public class MainResponse extends ActionResponse implements ToXContentObject { clusterName = new ClusterName(in); clusterUuid = in.readString(); build = Build.readBuild(in); - available = in.readBoolean(); + if (in.getVersion().before(Version.V_7_0_0_alpha1)) { + in.readBoolean(); + } } @Override @@ -133,7 +131,6 @@ public class MainResponse extends ActionResponse implements ToXContentObject { response.build = new Build((String) value.get("build_hash"), (String) value.get("build_date"), (boolean) value.get("build_snapshot")); response.version = Version.fromString((String) value.get("number")); - response.available = true; }, (parser, context) -> parser.map(), new ParseField("version")); } @@ -154,12 +151,11 @@ public class MainResponse extends ActionResponse implements ToXContentObject { Objects.equals(version, other.version) && Objects.equals(clusterUuid, other.clusterUuid) && Objects.equals(build, other.build) && - Objects.equals(available, other.available) && Objects.equals(clusterName, other.clusterName); } @Override public int hashCode() { - return Objects.hash(nodeName, version, clusterUuid, build, clusterName, available); + return Objects.hash(nodeName, version, clusterUuid, build, clusterName); } } diff --git a/server/src/main/java/org/elasticsearch/action/main/TransportMainAction.java b/server/src/main/java/org/elasticsearch/action/main/TransportMainAction.java index 368696a9553..d560a7ecc11 100644 --- a/server/src/main/java/org/elasticsearch/action/main/TransportMainAction.java +++ b/server/src/main/java/org/elasticsearch/action/main/TransportMainAction.java @@ -53,6 +53,6 @@ public class TransportMainAction extends HandledTransportAction VersionUtils.randomVersion(random())); break; - case 5: + case 4: clusterName = new ClusterName(clusterName + randomAlphaOfLength(5)); break; } - return new MainResponse(nodeName, version, clusterName, clusterUuid, build, available); + return new MainResponse(nodeName, version, clusterName, clusterUuid, build); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java index 13e6de063e8..656b020d532 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.util.HashMap; import java.util.Map; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; public class RestMainActionTests extends ESTestCase { @@ -44,12 +45,10 @@ public class RestMainActionTests extends ESTestCase { final String nodeName = "node1"; final ClusterName clusterName = new ClusterName("cluster1"); final String clusterUUID = randomAlphaOfLengthBetween(10, 20); - final boolean available = randomBoolean(); - final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; final Version version = Version.CURRENT; final Build build = Build.CURRENT; - final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available); + final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build); XContentBuilder builder = JsonXContent.contentBuilder(); RestRequest restRequest = new FakeRestRequest() { @Override @@ -60,7 +59,7 @@ public class RestMainActionTests extends ESTestCase { BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder); assertNotNull(response); - assertEquals(expectedStatus, response.status()); + assertThat(response.status(), equalTo(RestStatus.OK)); // the empty responses are handled in the HTTP layer so we do // not assert on them here @@ -70,13 +69,11 @@ public class RestMainActionTests extends ESTestCase { final String nodeName = "node1"; final ClusterName clusterName = new ClusterName("cluster1"); final String clusterUUID = randomAlphaOfLengthBetween(10, 20); - final boolean available = randomBoolean(); - final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; final Version version = Version.CURRENT; final Build build = Build.CURRENT; final boolean prettyPrint = randomBoolean(); - final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available); + final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build); XContentBuilder builder = JsonXContent.contentBuilder(); Map params = new HashMap<>(); @@ -87,7 +84,7 @@ public class RestMainActionTests extends ESTestCase { BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder); assertNotNull(response); - assertEquals(expectedStatus, response.status()); + assertThat(response.status(), equalTo(RestStatus.OK)); assertThat(response.content().length(), greaterThan(0)); XContentBuilder responseBuilder = JsonXContent.contentBuilder();