Skip to content

Commit

Permalink
Fix incorrect generic type in PolicyStepsRegistry (#78628)
Browse files Browse the repository at this point in the history
  • Loading branch information
asce0705 authored and joegallo committed Oct 7, 2021
1 parent b3a4218 commit 5c7cf55
Showing 1 changed file with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,32 +91,29 @@ Map<String, Map<Step.StepKey, Step>> 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<Map<String, LifecyclePolicyMetadata>> 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<String, LifecyclePolicyMetadata>() {
@Override
public void write(LifecyclePolicyMetadata value, StreamOutput out) {
// This is never called
throw new UnsupportedOperationException("should never be called");
}
DiffableUtils.MapDiff<String, LifecyclePolicyMetadata, Map<String, LifecyclePolicyMetadata>> 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<String, LifecyclePolicyMetadata>() {
@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<String, LifecyclePolicyMetadata, DiffableUtils.KeySerializer<String>> 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);
Expand All @@ -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<Step> policyAsSteps = policyMetadata.getPolicy().toSteps(policyClient, licenseState);
if (policyAsSteps.isEmpty() == false) {
Expand Down

0 comments on commit 5c7cf55

Please sign in to comment.