-
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 7 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,28 @@ | ||
/* | ||
* 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.client.TimedRequest; | ||
|
||
/** | ||
* A {@link TimedRequest} to get the current status of index lifecycle management. | ||
*/ | ||
public class LifecycleManagementStatusRequest extends TimedRequest { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
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")); | ||
} | ||
|
||
//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); | ||
} | ||
|
||
@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 |
---|---|---|
|
@@ -20,6 +20,9 @@ | |
|
||
import org.elasticsearch.action.admin.indices.shrink.ShrinkAction; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Locale; | ||
|
||
/** | ||
* Enum representing the different modes that Index Lifecycle Service can operate in. | ||
*/ | ||
|
@@ -56,4 +59,10 @@ public boolean isValidChange(OperationMode nextMode) { | |
}; | ||
|
||
public abstract boolean isValidChange(OperationMode nextMode); | ||
|
||
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))); | ||
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. We use 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. done |
||
} | ||
} |
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); | ||
} | ||
} |
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 you put the
ParseField
into a class private var and then use it in the parser (so we don't accidentally typo/change it in the future)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.
moved "operation_mode" to a static final string (not exactly the ask, but i believe same outcome)