-
Notifications
You must be signed in to change notification settings - Fork 25.2k
add notion of version and creation_date to LifecyclePolicyMetadata #33450
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 1 commit
Commits
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
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
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 |
---|---|---|
|
@@ -15,19 +15,23 @@ | |
import org.elasticsearch.cluster.block.ClusterBlockLevel; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; | ||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; | ||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; | ||
import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; | ||
import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction.Request; | ||
import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction.Response; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TransportGetLifecycleAction extends TransportMasterNodeAction<Request, Response> { | ||
|
||
|
@@ -49,32 +53,37 @@ protected Response newResponse() { | |
} | ||
|
||
@Override | ||
protected void masterOperation(Request request, ClusterState state, ActionListener<Response> listener) throws Exception { | ||
protected void masterOperation(Request request, ClusterState state, ActionListener<Response> listener) { | ||
IndexLifecycleMetadata metadata = clusterService.state().metaData().custom(IndexLifecycleMetadata.TYPE); | ||
if (metadata == null) { | ||
listener.onFailure(new ResourceNotFoundException("Lifecycle policy not found: {}", Arrays.toString(request.getPolicyNames()))); | ||
} else { | ||
List<LifecyclePolicy> requestedPolicies; | ||
List<LifecyclePolicyMetadata> requestedPolicies; | ||
// if no policies explicitly provided, behave as if `*` was specified | ||
if (request.getPolicyNames().length == 0) { | ||
requestedPolicies = new ArrayList<>(metadata.getPolicies().values()); | ||
requestedPolicies = new ArrayList<>(metadata.getPolicyMetadatas().values()); | ||
} else { | ||
requestedPolicies = new ArrayList<>(request.getPolicyNames().length); | ||
for (String name : request.getPolicyNames()) { | ||
LifecyclePolicy policy = metadata.getPolicies().get(name); | ||
if (policy == null) { | ||
LifecyclePolicyMetadata policyMetadata = metadata.getPolicyMetadatas().get(name); | ||
if (policyMetadata == null) { | ||
listener.onFailure(new ResourceNotFoundException("Lifecycle policy not found: {}", name)); | ||
return; | ||
} | ||
requestedPolicies.add(policy); | ||
requestedPolicies.add(policyMetadata); | ||
} | ||
} | ||
listener.onResponse(new Response(requestedPolicies)); | ||
Map<LifecyclePolicy, Tuple<Long, String>> policyMap = new HashMap<>(requestedPolicies.size()); | ||
for (LifecyclePolicyMetadata policyMetadata : requestedPolicies) { | ||
policyMap.put(policyMetadata.getPolicy(), | ||
new Tuple<>(policyMetadata.getVersion(), policyMetadata.getCreationDateString())); | ||
} | ||
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 we not create the list of |
||
listener.onResponse(new Response(policyMap)); | ||
} | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(Request request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
} | ||
} | ||
} |
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
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.
I think we should make this nicer here. Having a map is not nice because the key is not something you are realistically going to to use to lookup things and Tuples are generally not particularly nice to consume. Can we create a wrapper class around the policy, date and version so we have an object that is easier to consume both for us internally and for users of the transport API (given this class will be exposed to the Transport API)?