diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java index 6871737324217..9753448a7ec89 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java @@ -11,7 +11,6 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.DiffableUtils; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; @@ -92,32 +91,29 @@ Map> getStepMap() { return stepMap; } - @SuppressWarnings({ "unchecked", "rawtypes" }) public void update(ClusterState clusterState) { final IndexLifecycleMetadata meta = clusterState.metadata().custom(IndexLifecycleMetadata.TYPE); - assert meta != null : "IndexLifecycleMetadata cannot be null when updating the policy steps registry"; - Diff> diff = DiffableUtils.diff(lifecyclePolicyMap, meta.getPolicyMetadatas(), - DiffableUtils.getStringKeySerializer(), - // Use a non-diffable value serializer. Otherwise actions in the same - // action and phase that are changed show up as diffs instead of upserts. - // We want to treat any change in the policy as an upsert so the map is - // correctly rebuilt - new DiffableUtils.NonDiffableValueSerializer() { - @Override - public void write(LifecyclePolicyMetadata value, StreamOutput out) { - // This is never called - throw new UnsupportedOperationException("should never be called"); - } + DiffableUtils.MapDiff> mapDiff = + DiffableUtils.diff(lifecyclePolicyMap, meta.getPolicyMetadatas(), DiffableUtils.getStringKeySerializer(), + // Use a non-diffable value serializer. Otherwise actions in the same + // action and phase that are changed show up as diffs instead of upserts. + // We want to treat any change in the policy as an upsert so the map is + // correctly rebuilt + new DiffableUtils.NonDiffableValueSerializer<>() { + @Override + public void write(LifecyclePolicyMetadata value, StreamOutput out) { + // This is never called + throw new UnsupportedOperationException("should never be called"); + } - @Override - public LifecyclePolicyMetadata read(StreamInput in, String key) { - // This is never called - throw new UnsupportedOperationException("should never be called"); - } - }); - DiffableUtils.MapDiff> mapDiff = (DiffableUtils.MapDiff) diff; + @Override + public LifecyclePolicyMetadata read(StreamInput in, String key) { + // This is never called + throw new UnsupportedOperationException("should never be called"); + } + }); for (String deletedPolicyName : mapDiff.getDeletes()) { lifecyclePolicyMap.remove(deletedPolicyName); @@ -128,7 +124,7 @@ public LifecyclePolicyMetadata read(StreamInput in, String key) { if (mapDiff.getUpserts().isEmpty() == false) { for (LifecyclePolicyMetadata policyMetadata : mapDiff.getUpserts().values()) { LifecyclePolicySecurityClient policyClient = new LifecyclePolicySecurityClient(client, ClientHelper.INDEX_LIFECYCLE_ORIGIN, - policyMetadata.getHeaders()); + policyMetadata.getHeaders()); lifecyclePolicyMap.put(policyMetadata.getName(), policyMetadata); List policyAsSteps = policyMetadata.getPolicy().toSteps(policyClient, licenseState); if (policyAsSteps.isEmpty() == false) {