This avoids NPE when executing SLM policy when no config was provided. Related to #44465 Closes #53171 Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
20bbe5bae4
commit
847ac9c7d7
|
@ -254,10 +254,10 @@ public class SnapshotLifecyclePolicy extends AbstractDiffable<SnapshotLifecycleP
|
|||
*/
|
||||
public CreateSnapshotRequest toRequest() {
|
||||
CreateSnapshotRequest req = new CreateSnapshotRequest(repository, generateSnapshotName(new ResolverContext()));
|
||||
Map<String, Object> mergedConfiguration = configuration == null ? new HashMap<>() : new HashMap<>(configuration);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> metadata = (Map<String, Object>) configuration.get("metadata");
|
||||
Map<String, Object> metadata = (Map<String, Object>) mergedConfiguration.get("metadata");
|
||||
Map<String, Object> metadataWithAddedPolicyName = addPolicyNameToMetadata(metadata);
|
||||
Map<String, Object> mergedConfiguration = new HashMap<>(configuration);
|
||||
mergedConfiguration.put("metadata", metadataWithAddedPolicyName);
|
||||
req.source(mergedConfiguration);
|
||||
req.waitForCompletion(true);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package org.elasticsearch.xpack.slm;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
|
||||
import org.elasticsearch.common.ValidationException;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -30,6 +31,18 @@ public class SnapshotLifecyclePolicyTests extends AbstractSerializingTestCase<Sn
|
|||
|
||||
private String id;
|
||||
|
||||
public void testToRequest() {
|
||||
SnapshotLifecyclePolicy p = new SnapshotLifecyclePolicy("id", "name", "0 1 2 3 4 ? 2099", "repo", Collections.emptyMap(),
|
||||
SnapshotRetentionConfiguration.EMPTY);
|
||||
CreateSnapshotRequest request = p.toRequest();
|
||||
CreateSnapshotRequest expected = new CreateSnapshotRequest().userMetadata(Collections.singletonMap("policy", "id"));
|
||||
|
||||
p = new SnapshotLifecyclePolicy("id", "name", "0 1 2 3 4 ? 2099", "repo", null, null);
|
||||
request = p.toRequest();
|
||||
expected.waitForCompletion(true).snapshot(request.snapshot()).repository("repo");
|
||||
assertEquals(expected, request);
|
||||
}
|
||||
|
||||
public void testNameGeneration() {
|
||||
long time = 1552684146542L; // Fri Mar 15 2019 21:09:06 UTC
|
||||
SnapshotLifecyclePolicy.ResolverContext context = new SnapshotLifecyclePolicy.ResolverContext(time);
|
||||
|
|
Loading…
Reference in New Issue