register prelert metadata as named writables

Original commit: elastic/x-pack-elasticsearch@628a4aa154
This commit is contained in:
Martijn van Groningen 2017-01-03 11:59:23 +01:00
parent 161eefe7d8
commit 16bd07b603
2 changed files with 18 additions and 1 deletions

View File

@ -11,9 +11,11 @@ import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.component.LifecycleListener; import org.elasticsearch.common.component.LifecycleListener;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -156,6 +158,21 @@ public class PrelertPlugin extends Plugin implements ActionPlugin {
AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE)); AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE));
} }
@Override
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
return Collections.singletonList(new NamedWriteableRegistry.Entry(MetaData.Custom.class, "prelert", PrelertMetadata::new));
}
@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
NamedXContentRegistry.Entry entry = new NamedXContentRegistry.Entry(
MetaData.Custom.class,
new ParseField("prelert"),
parser -> PrelertMetadata.PRELERT_METADATA_PARSER.parse(parser, parseFieldMatcherSupplier).build()
);
return Collections.singletonList(entry);
}
@Override @Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService, ResourceWatcherService resourceWatcherService, ScriptService scriptService,

View File

@ -50,7 +50,7 @@ public class PrelertMetadata implements MetaData.Custom {
public static final PrelertMetadata EMPTY_METADATA = new PrelertMetadata(Collections.emptySortedMap(), public static final PrelertMetadata EMPTY_METADATA = new PrelertMetadata(Collections.emptySortedMap(),
Collections.emptySortedMap(), Collections.emptySortedMap()); Collections.emptySortedMap(), Collections.emptySortedMap());
static final ObjectParser<Builder, ParseFieldMatcherSupplier> PRELERT_METADATA_PARSER = new ObjectParser<>("prelert_metadata", public static final ObjectParser<Builder, ParseFieldMatcherSupplier> PRELERT_METADATA_PARSER = new ObjectParser<>("prelert_metadata",
Builder::new); Builder::new);
static { static {