From 4257d05869683e8984db854ae2fb33b06598aa4f Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Thu, 30 Aug 2018 13:46:52 -0500 Subject: [PATCH] Revert "HLRC: Add ILM Status to HLRC" This reverts commit 5a705e96645b285477af438a149f96ead3fa8a60. (accidental push to wrong branch) --- .../client/IndexLifecycleClient.java | 29 ------ .../client/RequestConverters.java | 12 --- .../elasticsearch/client/TimedRequest.java | 1 + .../indexlifecycle/StatusILMResponse.java | 99 ------------------- .../client/IndexLifecycleIT.java | 31 +++--- .../client/RequestConvertersTests.java | 12 --- .../client/TimedRequestTests.java | 42 -------- .../StatusILMResponseTests.java | 66 ------------- 8 files changed, 19 insertions(+), 273 deletions(-) delete mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/StatusILMResponse.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/TimedRequestTests.java delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/StatusILMResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java index 01cf7b90d7f..78816a4f787 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java @@ -22,7 +22,6 @@ package org.elasticsearch.client; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest; -import org.elasticsearch.client.indexlifecycle.StatusILMResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; @@ -140,34 +139,6 @@ public class IndexLifecycleClient { AcknowledgedResponse::fromXContent, emptySet()); } - /** - * Get the status of index lifecycle management - * See - * the docs for more. - * - * @param request the request with user defined timeouts. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - */ - public StatusILMResponse StatusILM(TimedRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::statusILM, options, - StatusILMResponse::fromXContent, emptySet()); - } - - /** - * Asynchronously get the status of index lifecycle management - * See - * the docs for more. - * - * @param request the request with user defined timeouts. - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - */ - public void StatusILMAsync(TimedRequest request, RequestOptions options, - ActionListener listener) { - restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::statusILM, options, - StatusILMResponse::fromXContent, listener, emptySet()); - } - /** * Asynchronously stop the Index Lifecycle Management feature. * See diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 026f87bfc8c..4fb4edcf1af 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -1241,18 +1241,6 @@ final class RequestConverters { return request; } - static Request statusILM(TimedRequest ilmStatusRequest){ - Request request = new Request(HttpGet.METHOD_NAME, - new EndpointBuilder() - .addPathPartAsIs("_ilm") - .addPathPartAsIs("status") - .build()); - Params params = new Params(request); - params.withMasterTimeout(ilmStatusRequest.masterNodeTimeout()); - params.withTimeout(ilmStatusRequest.timeout()); - return request; - } - static Request explainLifecycle(ExplainLifecycleRequest explainLifecycleRequest) { String[] indices = explainLifecycleRequest.indices() == null ? Strings.EMPTY_ARRAY : explainLifecycleRequest.indices(); Request request = new Request(HttpGet.METHOD_NAME, diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/TimedRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/TimedRequest.java index ba92e8dbee1..40388eae288 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/TimedRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/TimedRequest.java @@ -36,6 +36,7 @@ public class TimedRequest implements Validatable { public void setTimeout(TimeValue timeout) { this.timeout = timeout; + } public void setMasterTimeout(TimeValue masterTimeout) { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/StatusILMResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/StatusILMResponse.java deleted file mode 100644 index acdacfa10a4..00000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/StatusILMResponse.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.indexlifecycle; - -import org.elasticsearch.action.admin.indices.shrink.ShrinkAction; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.util.EnumSet; -import java.util.Locale; -import java.util.Objects; - -/** - * The current status of index lifecycle management. See {@link OperationMode} for available statuses. - */ -public class StatusILMResponse { - - private final OperationMode operationMode; - @SuppressWarnings("unchecked") - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "operation_mode", a -> new StatusILMResponse((String) a[0])); - - static { - PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField("operation_mode")); - } - - //package private for testing - StatusILMResponse(String operationMode) { - this.operationMode = OperationMode.fromString(operationMode); - } - - public OperationMode getOperationMode() { - return operationMode; - } - - public static StatusILMResponse fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - /** - * Enum representing the different modes that Index Lifecycle Service can operate in. - */ - public enum OperationMode { - /** - * This represents a state where no policies are executed - */ - STOPPED, - - /** - * this represents a state where only sensitive actions (like {@link ShrinkAction}) will be executed - * until they finish, at which point the operation mode will move to STOPPED. - */ - STOPPING, - - /** - * Normal operation where all policies are executed as normal. - */ - RUNNING; - - static OperationMode fromString(String string) { - return EnumSet.allOf(OperationMode.class).stream() - .filter(e -> string.equalsIgnoreCase(e.name())).findFirst() - .orElseThrow(() -> new IllegalArgumentException(String.format(Locale.ENGLISH, "%s is not a valid operation_mode", string))); - } - } - - // generated - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - StatusILMResponse that = (StatusILMResponse) o; - return operationMode == that.operationMode; - } - - // generated - @Override - public int hashCode() { - return Objects.hash(operationMode); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index 7308dca03b7..c2ce908efe3 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -22,11 +22,11 @@ package org.elasticsearch.client; import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.nio.entity.NStringEntity; +import org.apache.http.util.EntityUtils; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest; -import org.elasticsearch.client.indexlifecycle.StatusILMResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; @@ -169,30 +169,35 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase { createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build()); createIndex("squash", Settings.EMPTY); - TimedRequest statusRequest = new TimedRequest(); - StatusILMResponse statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::StatusILM, - highLevelClient().indexLifecycle()::StatusILMAsync); - assertEquals(statusResponse.getOperationMode(), StatusILMResponse.OperationMode.RUNNING); + // TODO: NORELEASE convert this to using the high level client once + // there are APIs for it + Request statusReq = new Request("GET", "/_ilm/status"); + Response statusResponse = client().performRequest(statusReq); + String statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); StopILMRequest stopReq = new StopILMRequest(); AcknowledgedResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM, highLevelClient().indexLifecycle()::stopILMAsync); assertTrue(stopResponse.isAcknowledged()); - - statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::StatusILM, - highLevelClient().indexLifecycle()::StatusILMAsync); - assertThat(statusResponse.getOperationMode(), - Matchers.anyOf(equalTo(StatusILMResponse.OperationMode.STOPPING), equalTo(StatusILMResponse.OperationMode.STOPPED))); + // TODO: NORELEASE convert this to using the high level client once there are APIs for it + statusReq = new Request("GET", "/_ilm/status"); + statusResponse = client().performRequest(statusReq); + statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertThat(statusResponseString, + Matchers.anyOf(equalTo("{\"operation_mode\":\"STOPPING\"}"), equalTo("{\"operation_mode\":\"STOPPED\"}"))); StartILMRequest startReq = new StartILMRequest(); AcknowledgedResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM, highLevelClient().indexLifecycle()::startILMAsync); assertTrue(startResponse.isAcknowledged()); - statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::StatusILM, - highLevelClient().indexLifecycle()::StatusILMAsync); - assertEquals(statusResponse.getOperationMode(), StatusILMResponse.OperationMode.RUNNING); + // TODO: NORELEASE convert this to using the high level client once there are APIs for it + statusReq = new Request("GET", "/_ilm/status"); + statusResponse = client().performRequest(statusReq); + statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); } public void testExplainLifecycle() throws Exception { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index e050c0c91b2..13de640a91f 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -2755,18 +2755,6 @@ public class RequestConvertersTests extends ESTestCase { assertThat(request.getParameters(), equalTo(expectedParams)); } - public void testStatusILM() throws Exception { - TimedRequest req = new TimedRequest(); - Map expectedParams = new HashMap<>(); - setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_TIMEOUT, expectedParams); - setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_MASTER_TIMEOUT, expectedParams); - - Request request = RequestConverters.statusILM(req); - assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); - assertThat(request.getEndpoint(), equalTo("/_ilm/status")); - assertThat(request.getParameters(), equalTo(expectedParams)); - } - public void testExplainLifecycle() throws Exception { ExplainLifecycleRequest req = new ExplainLifecycleRequest(); String[] indices = rarely() ? null : randomIndicesNames(0, 10); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/TimedRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/TimedRequestTests.java deleted file mode 100644 index 1faf14a9547..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/TimedRequestTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.common.unit.TimeValue; -import org.elasticsearch.test.ESTestCase; - -public class TimedRequestTests extends ESTestCase { - - public void testDefaults() { - TimedRequest timedRequest = new TimedRequest(); - assertEquals(timedRequest.timeout(), TimedRequest.DEFAULT_TIMEOUT); - assertEquals(timedRequest.masterNodeTimeout(), TimedRequest.DEFAULT_MASTER_TIMEOUT); - } - - public void testNonDefaults() { - TimedRequest timedRequest = new TimedRequest(); - TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000)); - TimeValue masterTimeout = TimeValue.timeValueSeconds(randomIntBetween(0,1000)); - timedRequest.setTimeout(timeout); - timedRequest.setMasterTimeout(masterTimeout); - assertEquals(timedRequest.timeout(), timeout); - assertEquals(timedRequest.masterNodeTimeout(), masterTimeout); - } -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/StatusILMResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/StatusILMResponseTests.java deleted file mode 100644 index 46fb76749a2..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/StatusILMResponseTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.indexlifecycle; - -import org.elasticsearch.common.xcontent.DeprecationHandler; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; -import org.elasticsearch.test.ESTestCase; -import org.hamcrest.CoreMatchers; - -import java.io.IOException; -import java.util.EnumSet; -import java.util.stream.Collectors; - -public class StatusILMResponseTests extends ESTestCase { - - public void testClientServerStatuses() { - assertEquals( - EnumSet.allOf(StatusILMResponse.OperationMode.class).stream().map(Enum::name).collect(Collectors.toSet()), - EnumSet.allOf(OperationMode.class).stream().map(Enum::name).collect(Collectors.toSet())); - } - - public void testFromName() { - EnumSet.allOf(StatusILMResponse.OperationMode.class) - .forEach(e -> assertEquals(StatusILMResponse.OperationMode.fromString(e.name()), e)); - } - - public void testInvalidStatus() { - String invalidName = randomAlphaOfLength(10); - Exception e = expectThrows(IllegalArgumentException.class, () -> StatusILMResponse.OperationMode.fromString(invalidName)); - assertThat(e.getMessage(), CoreMatchers.containsString(invalidName + " is not a valid operation_mode")); - } - - public void testValidStatuses() { - EnumSet.allOf(StatusILMResponse.OperationMode.class) - .forEach(e -> assertEquals(new StatusILMResponse(e.name()).getOperationMode(), e)); - } - - public void testXContent() throws IOException { - XContentType xContentType = XContentType.JSON; - String mode = randomFrom(EnumSet.allOf(StatusILMResponse.OperationMode.class) - .stream().map(Enum::name).collect(Collectors.toList())); - XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, "{\"operation_mode\" : \"" + mode + "\"}"); - assertEquals(StatusILMResponse.fromXContent(parser).getOperationMode(), StatusILMResponse.OperationMode.fromString(mode)); - } -}