Search in sources :

Example 1 with VersionedSchemaSet

use of com.linkedin.databus2.schemas.VersionedSchemaSet in project databus by linkedin.

the class BootstrapTableReader method init.

public static void init(String[] args) throws Exception {
    parseArgs(args);
    BootstrapSeederMain.Config bsConf = new BootstrapSeederMain.Config();
    ConfigLoader<BootstrapSeederMain.StaticConfig> configLoader = new ConfigLoader<BootstrapSeederMain.StaticConfig>("databus.reader.", bsConf);
    _bsStaticConfig = configLoader.loadConfig(_sBootstrapConfigProps);
    Config qConf = new Config();
    ConfigLoader<StaticConfig> configLoader2 = new ConfigLoader<StaticConfig>("databus.query.", qConf);
    _queryStaticConfig = configLoader2.loadConfig(_sQueryConfigProps);
    SchemaRegistryService schemaRegistry = FileSystemSchemaRegistryService.build(_bsStaticConfig.getSchemaRegistry().getFileSystem());
    LOG.info("Schema = " + schemaRegistry.fetchLatestSchemaBySourceName(_queryStaticConfig.getSourceName()));
    _schema = Schema.parse(schemaRegistry.fetchLatestSchemaBySourceName(_queryStaticConfig.getSourceName()));
    VersionedSchema vs = new VersionedSchema(_schema.getFullName(), (short) 1, _schema, null);
    VersionedSchemaSet schemaSet = new VersionedSchemaSet();
    schemaSet.add(vs);
    _decoder = new DbusEventAvroDecoder(schemaSet);
}
Also used : ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) DbusEventAvroDecoder(com.linkedin.databus.client.DbusEventAvroDecoder) FileSystemSchemaRegistryService(com.linkedin.databus2.schemas.FileSystemSchemaRegistryService) SchemaRegistryService(com.linkedin.databus2.schemas.SchemaRegistryService) VersionedSchemaSet(com.linkedin.databus2.schemas.VersionedSchemaSet) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema)

Example 2 with VersionedSchemaSet

use of com.linkedin.databus2.schemas.VersionedSchemaSet in project databus by linkedin.

the class RegisterRequestProcessor method getMetadataSchemas.

/**
 * Returns list of versioned metadata schemas.
 * TODO (DDSDBUS-2093):  implement this.
 */
private // IN
void getMetadataSchemas(// IN
SchemaRegistryService schemaRegistry, // OUT
ArrayList<RegisterResponseMetadataEntry> registeredMetadata) throws RequestProcessingException {
    Map<SchemaId, VersionedSchema> versionedSchemas = null;
    try {
        VersionedSchemaSet schemaSet = schemaRegistry.fetchAllMetadataSchemaVersions();
        if (schemaSet != null) {
            versionedSchemas = schemaSet.getAllVersionsWithSchemaId(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE);
        }
    } catch (DatabusException ie) {
        HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
        if (relayStatsCollector != null)
            relayStatsCollector.registerInvalidRegisterCall();
        throw new RequestProcessingException(ie);
    }
    if (versionedSchemas != null && !versionedSchemas.isEmpty()) {
        for (SchemaId id : versionedSchemas.keySet()) {
            VersionedSchema entry = versionedSchemas.get(id);
            if (entry.getOrigSchemaStr() == null) {
                throw new RequestProcessingException("Null schema string for metadata version " + entry.getVersion());
            }
            registeredMetadata.add(new RegisterResponseMetadataEntry((short) entry.getVersion(), entry.getOrigSchemaStr(), id.getByteArray()));
        }
    }
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) RegisterResponseMetadataEntry(com.linkedin.databus2.core.container.request.RegisterResponseMetadataEntry) HttpStatisticsCollector(com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector) SchemaId(com.linkedin.databus2.schemas.SchemaId) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) VersionedSchemaSet(com.linkedin.databus2.schemas.VersionedSchemaSet) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema)

Example 3 with VersionedSchemaSet

use of com.linkedin.databus2.schemas.VersionedSchemaSet in project databus by linkedin.

the class TestInternalMetadata method testGetMetadata_UnhappyPath_EventHasNoMetadata.

/**
 * Verifies that getMetadata() returns null if event has no metadata.
 */
@Test
public void testGetMetadata_UnhappyPath_EventHasNoMetadata() throws Exception {
    LOG.info("starting testGetMetadata_UnhappyPath_EventHasNoMetadata()");
    // build the event without any metadata
    DbusEvent event = createEvent(null);
    // create a metadata schema set, just because we like to
    VersionedSchemaSet metadataSchemaSet = new VersionedSchemaSet();
    metadataSchemaSet.add(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE, METADATA_SCHEMA_VERSION, new SchemaId(METADATA_SCHEMA_CHECKSUM), CORRECT_METADATA_SCHEMA, // preserve original string
    true);
    // now create the decoder and attempt to use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try {
        GenericRecord reuse = null;
        GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
        Assert.assertNull(decodedMetadata, "getMetadata() should have returned null;");
    } catch (Exception ex) {
        Assert.fail("getMetadata() should not have thrown exception: " + ex);
    }
    LOG.info("leaving testGetMetadata_UnhappyPath_EventHasNoMetadata()");
}
Also used : DbusEvent(com.linkedin.databus.core.DbusEvent) DbusEventAvroDecoder(com.linkedin.databus.client.DbusEventAvroDecoder) SchemaId(com.linkedin.databus2.schemas.SchemaId) VersionedSchemaSet(com.linkedin.databus2.schemas.VersionedSchemaSet) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Example 4 with VersionedSchemaSet

use of com.linkedin.databus2.schemas.VersionedSchemaSet in project databus by linkedin.

the class TestInternalMetadata method testGetMetadata_UnhappyPath_BadSchema.

/**
 * Verifies that getMetadata() returns null if there's a mismatch between the event's metadata
 * and the metadata schema whose signature/checksum is specified in the event header.
 */
@Test
public void testGetMetadata_UnhappyPath_BadSchema() throws Exception {
    LOG.info("starting testGetMetadata_UnhappyPath_BadSchema()");
    // build the event's metadata and then the event
    DbusEventPart metadataPart = createMetadataPart();
    DbusEvent event = createEvent(metadataPart);
    // create a metadata schema set with a schema that claims to match the event's
    // metadata but doesn't actually
    VersionedSchemaSet metadataSchemaSet = new VersionedSchemaSet();
    metadataSchemaSet.add(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE, // METADATA_SCHEMA_VERSION
    metadataPart.getSchemaVersion(), // METADATA_SCHEMA_CHECKSUM
    new SchemaId(metadataPart.getSchemaDigest()), INCORRECT_METADATA_SCHEMA, // preserve original string
    true);
    // now create the decoder and attempt to use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try {
        GenericRecord reuse = null;
        GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
        Assert.assertNull(decodedMetadata, "getMetadata() should have returned null;");
    } catch (Exception ex) {
        Assert.fail("getMetadata() should not have thrown exception: " + ex);
    }
    LOG.info("leaving testGetMetadata_UnhappyPath_BadSchema()");
}
Also used : DbusEventPart(com.linkedin.databus.core.DbusEventPart) DbusEvent(com.linkedin.databus.core.DbusEvent) DbusEventAvroDecoder(com.linkedin.databus.client.DbusEventAvroDecoder) SchemaId(com.linkedin.databus2.schemas.SchemaId) VersionedSchemaSet(com.linkedin.databus2.schemas.VersionedSchemaSet) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Example 5 with VersionedSchemaSet

use of com.linkedin.databus2.schemas.VersionedSchemaSet in project databus by linkedin.

the class TestInternalMetadata method testGetMetadata_HappyPath.

/**
 * Verifies that getMetadata() returns the expected GenericRecord for the event's
 * metadata and that it has the expected fields and values in it.
 */
@Test
public void testGetMetadata_HappyPath() throws Exception {
    LOG.info("starting testGetMetadata_HappyPath()");
    // build the event's metadata and then the event
    DbusEventPart metadataPart = createMetadataPart();
    DbusEvent event = createEvent(metadataPart);
    // create a metadata schema set that correctly corresponds to the metadata
    VersionedSchemaSet metadataSchemaSet = new VersionedSchemaSet();
    metadataSchemaSet.add(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE, // METADATA_SCHEMA_VERSION
    metadataPart.getSchemaVersion(), // METADATA_SCHEMA_CHECKSUM
    new SchemaId(metadataPart.getSchemaDigest()), CORRECT_METADATA_SCHEMA, // preserve original string
    true);
    // now create the decoder and use it to extract and decode the event's metadata
    DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
    try {
        GenericRecord reuse = null;
        GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
        Assert.assertNotNull(decodedMetadata, "getMetadata() returned null GenericRecord;");
        Utf8 etag = (Utf8) decodedMetadata.get("etag");
        Assert.assertEquals(etag.toString(), "dunno what an etag is");
        Integer flags = (Integer) decodedMetadata.get("flags");
        Assert.assertEquals(flags, null, "expected flags to be null");
        Long expires = (Long) decodedMetadata.get("expires");
        Assert.assertNotNull(expires, "expected expires to have a value;");
        Assert.assertEquals(expires.longValue(), 1366150681);
        Utf8 nonexistentField = (Utf8) decodedMetadata.get("nonexistentField");
        Assert.assertNull(nonexistentField, "unexpected value for 'nonexistentField';");
    } catch (Exception ex) {
        Assert.fail("unexpected error decoding metadata: " + ex);
    }
    LOG.info("leaving testGetMetadata_HappyPath()");
}
Also used : DbusEventPart(com.linkedin.databus.core.DbusEventPart) DbusEvent(com.linkedin.databus.core.DbusEvent) DbusEventAvroDecoder(com.linkedin.databus.client.DbusEventAvroDecoder) SchemaId(com.linkedin.databus2.schemas.SchemaId) Utf8(org.apache.avro.util.Utf8) VersionedSchemaSet(com.linkedin.databus2.schemas.VersionedSchemaSet) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Aggregations

VersionedSchemaSet (com.linkedin.databus2.schemas.VersionedSchemaSet)8 DbusEventAvroDecoder (com.linkedin.databus.client.DbusEventAvroDecoder)6 SchemaId (com.linkedin.databus2.schemas.SchemaId)5 Test (org.testng.annotations.Test)5 DbusEvent (com.linkedin.databus.core.DbusEvent)4 GenericRecord (org.apache.avro.generic.GenericRecord)4 DbusEventPart (com.linkedin.databus.core.DbusEventPart)3 SchemaRegistryService (com.linkedin.databus2.schemas.SchemaRegistryService)3 VersionedSchema (com.linkedin.databus2.schemas.VersionedSchema)3 RegisterResponseMetadataEntry (com.linkedin.databus2.core.container.request.RegisterResponseMetadataEntry)2 FileSystemSchemaRegistryService (com.linkedin.databus2.schemas.FileSystemSchemaRegistryService)2 ResultSetEntry (com.linkedin.databus.bootstrap.utils.BootstrapAuditTableReader.ResultSetEntry)1 RegisterRequestProcessor (com.linkedin.databus.container.request.RegisterRequestProcessor)1 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)1 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 ChunkedWritableByteChannel (com.linkedin.databus2.core.container.ChunkedWritableByteChannel)1 HttpStatisticsCollector (com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector)1 DatabusRequest (com.linkedin.databus2.core.container.request.DatabusRequest)1 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)1