Revert "HLRC: Add ILM Status to HLRC"

This reverts commit 5a705e9664.

(accidental push to wrong branch)
This commit is contained in:
Jake Landis 2018-08-30 13:46:52 -05:00
parent 5a705e9664
commit 4257d05869
No known key found for this signature in database
GPG Key ID: 508157BFF65D51DD
8 changed files with 19 additions and 273 deletions

View File

@ -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 <a href="https://fix-me-when-we-have-docs.com">
* the docs</a> 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 <a href="https://fix-me-when-we-have-docs.com">
* the docs</a> 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<StatusILMResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::statusILM, options,
StatusILMResponse::fromXContent, listener, emptySet());
}
/**
* Asynchronously stop the Index Lifecycle Management feature.
* See <a href="https://fix-me-when-we-have-docs.com">

View File

@ -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,

View File

@ -36,6 +36,7 @@ public class TimedRequest implements Validatable {
public void setTimeout(TimeValue timeout) {
this.timeout = timeout;
}
public void setMasterTimeout(TimeValue masterTimeout) {

View File

@ -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<StatusILMResponse, Void> 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 <code>STOPPED</code>.
*/
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);
}
}

View File

@ -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 {

View File

@ -2755,18 +2755,6 @@ public class RequestConvertersTests extends ESTestCase {
assertThat(request.getParameters(), equalTo(expectedParams));
}
public void testStatusILM() throws Exception {
TimedRequest req = new TimedRequest();
Map<String, String> 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);

View File

@ -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);
}
}

View File

@ -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));
}
}