-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: Add ILM Status to HLRC #33283
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: Add ILM Status to HLRC #33283
Changes from 2 commits
f5918db
916b535
3bcaee4
8b06ccd
4f77a09
12f7a15
d755bd0
80462d5
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,97 @@ | ||
/* | ||
* 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 LifecycleManagementStatusResponse { | ||
|
||
private final OperationMode operationMode; | ||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<LifecycleManagementStatusResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"operation_mode", a -> new LifecycleManagementStatusResponse((String) a[0])); | ||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField("operation_mode")); | ||
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. Can you put the 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. moved "operation_mode" to a static final string (not exactly the ask, but i believe same outcome) |
||
} | ||
|
||
//package private for testing | ||
LifecycleManagementStatusResponse(String operationMode) { | ||
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. I think this should take an This is just my personal preference though, so up to you if you want to change it. 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. leaving as-is |
||
this.operationMode = OperationMode.fromString(operationMode); | ||
} | ||
|
||
public OperationMode getOperationMode() { | ||
return operationMode; | ||
} | ||
|
||
public static LifecycleManagementStatusResponse 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))); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
LifecycleManagementStatusResponse that = (LifecycleManagementStatusResponse) o; | ||
return operationMode == that.operationMode; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(operationMode); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,11 @@ | |
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.LifecycleManagementStatusResponse; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; | ||
import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; | ||
|
@@ -169,35 +169,33 @@ public void testStartStopILM() throws Exception { | |
createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build()); | ||
createIndex("squash", Settings.EMPTY); | ||
|
||
// 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); | ||
TimedRequest statusRequest = new TimedRequest(); | ||
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. While I get the logic behind why you did it this way, I think generic classes make more sense for responses than requests. As a user of the HLRC, this feels really strange - even if 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. I don't have a strong opinion beyond consistency in the API. Perhaps we should allow a no-arg method in the client that creates the request for them. However, that also creates inconsistency (unless you create a bunch of new methods).
..same 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. @hub-cap Could you weigh in on this? |
||
LifecycleManagementStatusResponse statusResponse = execute( | ||
statusRequest, | ||
highLevelClient().indexLifecycle()::lifecycleManagementStatus, | ||
highLevelClient().indexLifecycle()::lifecycleManagementStatusAsync); | ||
assertEquals(statusResponse.getOperationMode(), LifecycleManagementStatusResponse.OperationMode.RUNNING); | ||
|
||
StopILMRequest stopReq = new StopILMRequest(); | ||
AcknowledgedResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM, | ||
highLevelClient().indexLifecycle()::stopILMAsync); | ||
assertTrue(stopResponse.isAcknowledged()); | ||
|
||
// 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\"}"))); | ||
|
||
statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::lifecycleManagementStatus, | ||
highLevelClient().indexLifecycle()::lifecycleManagementStatusAsync); | ||
assertThat(statusResponse.getOperationMode(), | ||
Matchers.anyOf(equalTo(LifecycleManagementStatusResponse.OperationMode.STOPPING), | ||
equalTo(LifecycleManagementStatusResponse.OperationMode.STOPPED))); | ||
|
||
StartILMRequest startReq = new StartILMRequest(); | ||
AcknowledgedResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM, | ||
highLevelClient().indexLifecycle()::startILMAsync); | ||
assertTrue(startResponse.isAcknowledged()); | ||
|
||
// 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); | ||
statusResponse = execute(statusRequest, highLevelClient().indexLifecycle()::lifecycleManagementStatus, | ||
highLevelClient().indexLifecycle()::lifecycleManagementStatusAsync); | ||
assertEquals(statusResponse.getOperationMode(), LifecycleManagementStatusResponse.OperationMode.RUNNING); | ||
} | ||
|
||
public void testExplainLifecycle() throws Exception { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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 LifecycleManagementStatusResponseTests extends ESTestCase { | ||
|
||
public void testClientServerStatuses() { | ||
assertEquals( | ||
EnumSet.allOf(LifecycleManagementStatusResponse.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(LifecycleManagementStatusResponse.OperationMode.class) | ||
.forEach(e -> assertEquals(LifecycleManagementStatusResponse.OperationMode.fromString(e.name()), e)); | ||
} | ||
|
||
public void testInvalidStatus() { | ||
String invalidName = randomAlphaOfLength(10); | ||
Exception e = expectThrows(IllegalArgumentException.class, | ||
() -> LifecycleManagementStatusResponse.OperationMode.fromString(invalidName)); | ||
assertThat(e.getMessage(), CoreMatchers.containsString(invalidName + " is not a valid operation_mode")); | ||
} | ||
|
||
public void testValidStatuses() { | ||
EnumSet.allOf(LifecycleManagementStatusResponse.OperationMode.class) | ||
.forEach(e -> assertEquals(new LifecycleManagementStatusResponse(e.name()).getOperationMode(), e)); | ||
} | ||
|
||
public void testXContent() throws IOException { | ||
XContentType xContentType = XContentType.JSON; | ||
String mode = randomFrom(EnumSet.allOf(LifecycleManagementStatusResponse.OperationMode.class) | ||
.stream().map(Enum::name).collect(Collectors.toList())); | ||
XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, | ||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, "{\"operation_mode\" : \"" + mode + "\"}"); | ||
assertEquals(LifecycleManagementStatusResponse.fromXContent(parser).getOperationMode(), | ||
LifecycleManagementStatusResponse.OperationMode.fromString(mode)); | ||
} | ||
} |
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.
Can we make this
lifecycleManagementStatus
to match the method in the client?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.
thanks missed this one. done.