Removes redundent NORELEASES and ObjectParserUtils (#32427)

This commit is contained in:
Colin Goodheart-Smithe 2018-07-30 09:08:30 +01:00 committed by GitHub
parent 783e427d36
commit 0682b4bbc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 43 deletions

View File

@ -38,10 +38,11 @@ public class IndexLifecycleMetadata implements XPackMetaDataCustom {
public static final IndexLifecycleMetadata EMPTY = new IndexLifecycleMetadata(Collections.emptySortedMap(), OperationMode.RUNNING);
@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<IndexLifecycleMetadata, Void> PARSER = new ConstructingObjectParser<>(
TYPE, a -> new IndexLifecycleMetadata(
ObjectParserUtils.convertListToMapValues(LifecyclePolicyMetadata::getName, (List<LifecyclePolicyMetadata>) a[0]),
OperationMode.valueOf((String) a[1])));
public static final ConstructingObjectParser<IndexLifecycleMetadata, Void> PARSER = new ConstructingObjectParser<>(TYPE,
a -> new IndexLifecycleMetadata(
((List<LifecyclePolicyMetadata>) a[0]).stream()
.collect(Collectors.toMap(LifecyclePolicyMetadata::getName, Function.identity())),
OperationMode.valueOf((String) a[1])));
static {
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> LifecyclePolicyMetadata.parse(p, n),
v -> {

View File

@ -1,29 +0,0 @@
/*
* 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.indexlifecycle;
import org.elasticsearch.common.io.stream.Writeable;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Function;
/**
* NORELEASE: these utility methods should be brought into the core API for
* parsing namedWriteables
*/
public class ObjectParserUtils {
public static <V extends Writeable> SortedMap<String, V> convertListToMapValues(Function<V, String> keyFunction,
List<V> list) {
SortedMap<String, V> map = new TreeMap<>();
for (V writeable : list) {
map.put(keyFunction.apply(writeable), writeable);
}
return map;
}
}

View File

@ -22,8 +22,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import static org.elasticsearch.xpack.core.indexlifecycle.ObjectParserUtils.convertListToMapValues;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Represents set of {@link LifecycleAction}s which should be executed at a
@ -36,8 +36,8 @@ public class Phase implements ToXContentObject, Writeable {
@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Phase, String> PARSER = new ConstructingObjectParser<>("phase", false,
(a, name) -> new Phase(name, (TimeValue) a[0],
convertListToMapValues(LifecycleAction::getWriteableName, (List<LifecycleAction>) a[1])));
(a, name) -> new Phase(name, (TimeValue) a[0], ((List<LifecycleAction>) a[1]).stream()
.collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity()))));
static {
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, c) -> TimeValue.parseTimeValue(p.text(), AFTER_FIELD.getPreferredName()), AFTER_FIELD, ValueType.VALUE);

View File

@ -28,8 +28,7 @@ public class LifecyclePolicyMetadataTests extends AbstractSerializingTestCase<Li
@Before
public void setup() {
lifecycleName = randomAlphaOfLength(20); // NORELEASE we need to randomise the lifecycle name rather
// than use the same name for all instances
lifecycleName = randomAlphaOfLength(20);
}
@Override

View File

@ -28,8 +28,7 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
@Before
public void setup() {
phaseName = randomAlphaOfLength(20); // NORELEASE we need to randomise the phase name rather
// than use the same name for all instances
phaseName = randomAlphaOfLength(20);
}
@Override

View File

@ -34,8 +34,7 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase
@Before
public void setup() {
lifecycleName = randomAlphaOfLength(20); // NORELEASE we need to randomise the lifecycle name rather
// than use the same name for all instances
lifecycleName = randomAlphaOfLength(20);
}
@Override