Search in sources :

Example 1 with Entry

use of org.opensearch.common.io.stream.NamedWriteableRegistry.Entry in project OpenSearch by opensearch-project.

the class ClusterModule method getNamedWriteables.

public static List<Entry> getNamedWriteables() {
    List<Entry> entries = new ArrayList<>();
    // Cluster State
    registerClusterCustom(entries, SnapshotsInProgress.TYPE, SnapshotsInProgress::new, SnapshotsInProgress::readDiffFrom);
    registerClusterCustom(entries, RestoreInProgress.TYPE, RestoreInProgress::new, RestoreInProgress::readDiffFrom);
    registerClusterCustom(entries, SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress::new, SnapshotDeletionsInProgress::readDiffFrom);
    registerClusterCustom(entries, RepositoryCleanupInProgress.TYPE, RepositoryCleanupInProgress::new, RepositoryCleanupInProgress::readDiffFrom);
    // Metadata
    registerMetadataCustom(entries, RepositoriesMetadata.TYPE, RepositoriesMetadata::new, RepositoriesMetadata::readDiffFrom);
    registerMetadataCustom(entries, IngestMetadata.TYPE, IngestMetadata::new, IngestMetadata::readDiffFrom);
    registerMetadataCustom(entries, ScriptMetadata.TYPE, ScriptMetadata::new, ScriptMetadata::readDiffFrom);
    registerMetadataCustom(entries, IndexGraveyard.TYPE, IndexGraveyard::new, IndexGraveyard::readDiffFrom);
    registerMetadataCustom(entries, PersistentTasksCustomMetadata.TYPE, PersistentTasksCustomMetadata::new, PersistentTasksCustomMetadata::readDiffFrom);
    registerMetadataCustom(entries, ComponentTemplateMetadata.TYPE, ComponentTemplateMetadata::new, ComponentTemplateMetadata::readDiffFrom);
    registerMetadataCustom(entries, ComposableIndexTemplateMetadata.TYPE, ComposableIndexTemplateMetadata::new, ComposableIndexTemplateMetadata::readDiffFrom);
    registerMetadataCustom(entries, DataStreamMetadata.TYPE, DataStreamMetadata::new, DataStreamMetadata::readDiffFrom);
    // Task Status (not Diffable)
    entries.add(new Entry(Task.Status.class, PersistentTasksNodeService.Status.NAME, PersistentTasksNodeService.Status::new));
    return entries;
}
Also used : PersistentTasksNodeService(org.opensearch.persistent.PersistentTasksNodeService) ComponentTemplateMetadata(org.opensearch.cluster.metadata.ComponentTemplateMetadata) ArrayList(java.util.ArrayList) PersistentTasksCustomMetadata(org.opensearch.persistent.PersistentTasksCustomMetadata) DataStreamMetadata(org.opensearch.cluster.metadata.DataStreamMetadata) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) ScriptMetadata(org.opensearch.script.ScriptMetadata) IngestMetadata(org.opensearch.ingest.IngestMetadata) ComposableIndexTemplateMetadata(org.opensearch.cluster.metadata.ComposableIndexTemplateMetadata) IndexGraveyard(org.opensearch.cluster.metadata.IndexGraveyard)

Example 2 with Entry

use of org.opensearch.common.io.stream.NamedWriteableRegistry.Entry in project OpenSearch by opensearch-project.

the class SearchModule method registerSmoothingModels.

public static void registerSmoothingModels(List<Entry> namedWriteables) {
    namedWriteables.add(new NamedWriteableRegistry.Entry(SmoothingModel.class, Laplace.NAME, Laplace::new));
    namedWriteables.add(new NamedWriteableRegistry.Entry(SmoothingModel.class, LinearInterpolation.NAME, LinearInterpolation::new));
    namedWriteables.add(new NamedWriteableRegistry.Entry(SmoothingModel.class, StupidBackoff.NAME, StupidBackoff::new));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SmoothingModel(org.opensearch.search.suggest.phrase.SmoothingModel) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry)

Example 3 with Entry

use of org.opensearch.common.io.stream.NamedWriteableRegistry.Entry in project OpenSearch by opensearch-project.

the class DocValueFormatTests method testSerialization.

public void testSerialization() throws Exception {
    List<Entry> entries = new ArrayList<>();
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.BOOLEAN.getWriteableName(), in -> DocValueFormat.BOOLEAN));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.DateTime.NAME, DocValueFormat.DateTime::new));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.Decimal.NAME, DocValueFormat.Decimal::new));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.GEOHASH.getWriteableName(), in -> DocValueFormat.GEOHASH));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.GEOTILE.getWriteableName(), in -> DocValueFormat.GEOTILE));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.IP.getWriteableName(), in -> DocValueFormat.IP));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.RAW.getWriteableName(), in -> DocValueFormat.RAW));
    entries.add(new Entry(DocValueFormat.class, DocValueFormat.BINARY.getWriteableName(), in -> DocValueFormat.BINARY));
    NamedWriteableRegistry registry = new NamedWriteableRegistry(entries);
    BytesStreamOutput out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.BOOLEAN);
    StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.BOOLEAN, in.readNamedWriteable(DocValueFormat.class));
    DocValueFormat.Decimal decimalFormat = new DocValueFormat.Decimal("###.##");
    out = new BytesStreamOutput();
    out.writeNamedWriteable(decimalFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    DocValueFormat vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.Decimal.class, vf.getClass());
    assertEquals("###.##", ((DocValueFormat.Decimal) vf).pattern);
    DateFormatter formatter = DateFormatter.forPattern("epoch_second");
    DocValueFormat.DateTime dateFormat = new DocValueFormat.DateTime(formatter, ZoneOffset.ofHours(1), Resolution.MILLISECONDS);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(dateFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.DateTime.class, vf.getClass());
    assertEquals("epoch_second", ((DocValueFormat.DateTime) vf).formatter.pattern());
    assertEquals(ZoneOffset.ofHours(1), ((DocValueFormat.DateTime) vf).timeZone);
    assertEquals(Resolution.MILLISECONDS, ((DocValueFormat.DateTime) vf).resolution);
    DocValueFormat.DateTime nanosDateFormat = new DocValueFormat.DateTime(formatter, ZoneOffset.ofHours(1), Resolution.NANOSECONDS);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(nanosDateFormat);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    vf = in.readNamedWriteable(DocValueFormat.class);
    assertEquals(DocValueFormat.DateTime.class, vf.getClass());
    assertEquals("epoch_second", ((DocValueFormat.DateTime) vf).formatter.pattern());
    assertEquals(ZoneOffset.ofHours(1), ((DocValueFormat.DateTime) vf).timeZone);
    assertEquals(Resolution.NANOSECONDS, ((DocValueFormat.DateTime) vf).resolution);
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.GEOHASH);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.GEOHASH, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.GEOTILE);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.GEOTILE, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.IP);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.IP, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.RAW);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.RAW, in.readNamedWriteable(DocValueFormat.class));
    out = new BytesStreamOutput();
    out.writeNamedWriteable(DocValueFormat.BINARY);
    in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry);
    assertSame(DocValueFormat.BINARY, in.readNamedWriteable(DocValueFormat.class));
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) InetAddresses(org.opensearch.common.network.InetAddresses) InetAddressPoint(org.apache.lucene.document.InetAddressPoint) BytesRef(org.apache.lucene.util.BytesRef) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Resolution(org.opensearch.index.mapper.DateFieldMapper.Resolution) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ZoneOffset(java.time.ZoneOffset) DateFormatter(org.opensearch.common.time.DateFormatter) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) GeoTileUtils.longEncode(org.opensearch.search.aggregations.bucket.geogrid.GeoTileUtils.longEncode) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) DateFormatter(org.opensearch.common.time.DateFormatter) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)

Example 4 with Entry

use of org.opensearch.common.io.stream.NamedWriteableRegistry.Entry in project OpenSearch by opensearch-project.

the class ClusterModule method registerCustom.

private static <T extends NamedWriteable> void registerCustom(List<Entry> entries, Class<T> category, String name, Reader<? extends T> reader, Reader<NamedDiff> diffReader) {
    entries.add(new Entry(category, name, reader));
    entries.add(new Entry(NamedDiff.class, name, diffReader));
}
Also used : Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry)

Aggregations

Entry (org.opensearch.common.io.stream.NamedWriteableRegistry.Entry)4 ArrayList (java.util.ArrayList)2 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)2 ZoneOffset (java.time.ZoneOffset)1 List (java.util.List)1 InetAddressPoint (org.apache.lucene.document.InetAddressPoint)1 BytesRef (org.apache.lucene.util.BytesRef)1 ComponentTemplateMetadata (org.opensearch.cluster.metadata.ComponentTemplateMetadata)1 ComposableIndexTemplateMetadata (org.opensearch.cluster.metadata.ComposableIndexTemplateMetadata)1 DataStreamMetadata (org.opensearch.cluster.metadata.DataStreamMetadata)1 IndexGraveyard (org.opensearch.cluster.metadata.IndexGraveyard)1 RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)1 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)1 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)1 StreamInput (org.opensearch.common.io.stream.StreamInput)1 InetAddresses (org.opensearch.common.network.InetAddresses)1 DateFormatter (org.opensearch.common.time.DateFormatter)1 Resolution (org.opensearch.index.mapper.DateFieldMapper.Resolution)1 IngestMetadata (org.opensearch.ingest.IngestMetadata)1 PersistentTasksCustomMetadata (org.opensearch.persistent.PersistentTasksCustomMetadata)1