-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: Add Get Lifecycle Policy API to HLRC #33323
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f69035
HLRC: Add Get Lifecycle Policy API to HLRC
gwbrown d016a81
Move XContentProvider for ILM to ILM namespace
gwbrown 3099a39
Merge branch 'index-lifecycle' into ilm-hlrc-get
gwbrown 168b98f
Merge branch 'index-lifecycle' into ilm-hlrc-get
gwbrown 720be81
Merge branch 'index-lifecycle' into ilm-hlrc-get
gwbrown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...evel/src/main/java/org/elasticsearch/client/indexlifecycle/GetLifecyclePolicyRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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; | ||
import org.elasticsearch.common.Strings; | ||
|
||
import java.util.Arrays; | ||
|
||
public class GetLifecyclePolicyRequest extends TimedRequest { | ||
|
||
private final String[] policyNames; | ||
|
||
public GetLifecyclePolicyRequest(String... policyNames) { | ||
if (policyNames == null) { | ||
this.policyNames = Strings.EMPTY_ARRAY; | ||
} else { | ||
for (String name : policyNames) { | ||
if (name == null) { | ||
throw new IllegalArgumentException("cannot include null policy name"); | ||
} | ||
} | ||
this.policyNames = policyNames; | ||
} | ||
} | ||
|
||
public String[] getPolicyNames() { | ||
return policyNames; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GetLifecyclePolicyRequest request = (GetLifecyclePolicyRequest) o; | ||
return Arrays.equals(getPolicyNames(), request.getPolicyNames()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(getPolicyNames()); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...vel/src/main/java/org/elasticsearch/client/indexlifecycle/GetLifecyclePolicyResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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 com.carrotsearch.hppc.cursors.ObjectObjectCursor; | ||
import org.elasticsearch.common.collect.ImmutableOpenMap; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
public class GetLifecyclePolicyResponse implements ToXContentObject { | ||
|
||
private final ImmutableOpenMap<String, LifecyclePolicyMetadata> policies; | ||
|
||
public GetLifecyclePolicyResponse(ImmutableOpenMap<String, LifecyclePolicyMetadata> policies) { | ||
this.policies = policies; | ||
} | ||
|
||
public ImmutableOpenMap<String, LifecyclePolicyMetadata> getPolicies() { | ||
return policies; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
for (ObjectObjectCursor<String, LifecyclePolicyMetadata> stringLifecyclePolicyObjectObjectCursor : policies) { | ||
builder.field(stringLifecyclePolicyObjectObjectCursor.key, stringLifecyclePolicyObjectObjectCursor.value); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public static GetLifecyclePolicyResponse fromXContent(XContentParser parser) throws IOException { | ||
ImmutableOpenMap.Builder<String, LifecyclePolicyMetadata> policies = ImmutableOpenMap.builder(); | ||
|
||
if (parser.currentToken() == null) { | ||
parser.nextToken(); | ||
} | ||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); | ||
parser.nextToken(); | ||
|
||
while (!parser.isClosed()) { | ||
if (parser.currentToken() == XContentParser.Token.START_OBJECT) { | ||
String policyName = parser.currentName(); | ||
LifecyclePolicyMetadata policyDefinion = LifecyclePolicyMetadata.parse(parser, policyName); | ||
policies.put(policyName, policyDefinion); | ||
} else { | ||
parser.nextToken(); | ||
} | ||
} | ||
|
||
return new GetLifecyclePolicyResponse(policies.build()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GetLifecyclePolicyResponse that = (GetLifecyclePolicyResponse) o; | ||
return Objects.equals(getPolicies(), that.getPolicies()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getPolicies()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ain/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleNamedXContentProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.NamedXContentRegistry; | ||
import org.elasticsearch.plugins.spi.NamedXContentProvider; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class IndexLifecycleNamedXContentProvider implements NamedXContentProvider { | ||
|
||
|
||
@Override | ||
public List<NamedXContentRegistry.Entry> getNamedXContentParsers() { | ||
return Arrays.asList( | ||
// ILM | ||
new NamedXContentRegistry.Entry(LifecycleAction.class, | ||
new ParseField(AllocateAction.NAME), | ||
AllocateAction::parse), | ||
new NamedXContentRegistry.Entry(LifecycleAction.class, | ||
new ParseField(DeleteAction.NAME), | ||
DeleteAction::parse), | ||
new NamedXContentRegistry.Entry(LifecycleAction.class, | ||
new ParseField(ForceMergeAction.NAME), | ||
ForceMergeAction::parse), | ||
new NamedXContentRegistry.Entry(LifecycleAction.class, | ||
new ParseField(ReadOnlyAction.NAME), | ||
ReadOnlyAction::parse), | ||
new NamedXContentRegistry.Entry(LifecycleAction.class, | ||
new ParseField(RolloverAction.NAME), | ||
RolloverAction::parse), | ||
new NamedXContentRegistry.Entry(LifecycleAction.class, | ||
new ParseField(ShrinkAction.NAME), | ||
ShrinkAction::parse) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you need this? I dont see it being used anywhere.
Uh oh!
There was an error while loading. Please reload this page.
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.
It's used to leverage
AbstractXContentTestCase
for testing parsing inGetLifecyclePolicyResponseTests
. If there's a better way of doing that, please let me know!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.
I dont have a good answer for this yet. While we can totally test this, the value in the server -> client.fromXContent is greater than just testing the client.toXContent -> client.fromXContent. I think these kinds of tests are not really providing much value, and we also test the former in the IT tests.