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;
}
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);
}
Aggregations