Skip to content
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

Fix SnapshotLifecycleMetadata xcontent serialization #46500

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SnapshotLifecycleMetadata implements XPackMetaDataCustom {
v -> {
throw new IllegalArgumentException("ordered " + POLICIES_FIELD.getPreferredName() + " are not supported");
}, POLICIES_FIELD);
PARSER.declareString(ConstructingObjectParser.constructorArg(), OPERATION_MODE_FIELD);
}

private final Map<String, SnapshotLifecyclePolicyMetadata> snapshotConfigurations;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.core.slm;

import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.xpack.core.ilm.OperationMode;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class SnapshotLifecycleMetadataTests extends AbstractSerializingTestCase<SnapshotLifecycleMetadata> {
@Override
protected SnapshotLifecycleMetadata doParseInstance(XContentParser parser) throws IOException {
return SnapshotLifecycleMetadata.PARSER.apply(parser, null);
}

@Override
protected SnapshotLifecycleMetadata createTestInstance() {
int policyCount = randomIntBetween(0, 3);
Map<String, SnapshotLifecyclePolicyMetadata> policies = new HashMap<>(policyCount);
for (int i = 0; i < policyCount; i++) {
String id = "policy-" + randomAlphaOfLength(3);
policies.put(id, SnapshotLifecyclePolicyMetadataTests.createRandomPolicyMetadata(id));
}
return new SnapshotLifecycleMetadata(policies, randomFrom(OperationMode.values()));
}

@Override
protected Writeable.Reader<SnapshotLifecycleMetadata> instanceReader() {
return SnapshotLifecycleMetadata::new;
}
}