Search in sources :

Example 1 with RegistryException

use of com.hortonworks.registries.schemaregistry.exceptions.RegistryException in project registry by hortonworks.

the class AbstractAvroSnapshotDeserializer method buildDeserializedObject.

/**
 * Builds the deserialized object from the given {@code payloadInputStream} and applying writer and reader schemas
 * from the respective given versions.
 *
 * @param protocolId          protocol id
 * @param payloadInputStream  payload
 * @param schemaMetadata      metadata about schema
 * @param writerSchemaVersion schema version of the writer
 * @param readerSchemaVersion schema version to be applied for reading or projection
 * @return the deserialized object
 * @throws SerDesException when any ser/des error occurs
 */
protected Object buildDeserializedObject(byte protocolId, InputStream payloadInputStream, SchemaMetadata schemaMetadata, Integer writerSchemaVersion, Integer readerSchemaVersion) throws SerDesException {
    Object deserializedObj;
    String schemaName = schemaMetadata.getName();
    SchemaVersionKey writerSchemaVersionKey = new SchemaVersionKey(schemaName, writerSchemaVersion);
    LOG.debug("SchemaKey: [{}] for the received payload", writerSchemaVersionKey);
    Schema writerSchema = getSchema(writerSchemaVersionKey);
    if (writerSchema == null) {
        throw new RegistryException("No schema exists with metadata-key: " + schemaMetadata + " and writerSchemaVersion: " + writerSchemaVersion);
    }
    Schema readerSchema = readerSchemaVersion != null ? getSchema(new SchemaVersionKey(schemaName, readerSchemaVersion)) : null;
    deserializedObj = deserializePayloadForProtocol(protocolId, payloadInputStream, writerSchema, readerSchema);
    return deserializedObj;
}
Also used : Schema(org.apache.avro.Schema) RegistryException(com.hortonworks.registries.schemaregistry.exceptions.RegistryException) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey)

Example 2 with RegistryException

use of com.hortonworks.registries.schemaregistry.exceptions.RegistryException in project registry by hortonworks.

the class AbstractSnapshotDeserializer method deserialize.

@Override
public O deserialize(I input, Integer readerSchemaVersion) throws SerDesException {
    if (!initialized) {
        throw new IllegalStateException("init should be invoked before invoking deserialize operation");
    }
    if (closed) {
        throw new IllegalStateException("This deserializer is already closed");
    }
    // it can be enhanced to have respective protocol handlers for different versions
    byte protocolId = retrieveProtocolId(input);
    SchemaIdVersion schemaIdVersion = retrieveSchemaIdVersion(protocolId, input);
    SchemaVersionInfo schemaVersionInfo = null;
    SchemaMetadata schemaMetadata = null;
    try {
        schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(schemaIdVersion);
        schemaMetadata = schemaRegistryClient.getSchemaMetadataInfo(schemaVersionInfo.getName()).getSchemaMetadata();
    } catch (Exception e) {
        throw new RegistryException(e);
    }
    return doDeserialize(input, protocolId, schemaMetadata, schemaVersionInfo.getVersion(), readerSchemaVersion);
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) RegistryException(com.hortonworks.registries.schemaregistry.exceptions.RegistryException) RegistryException(com.hortonworks.registries.schemaregistry.exceptions.RegistryException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) ExecutionException(java.util.concurrent.ExecutionException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)

Aggregations

RegistryException (com.hortonworks.registries.schemaregistry.exceptions.RegistryException)2 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)1 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)1 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)1 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)1 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)1 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Schema (org.apache.avro.Schema)1