Search in sources :

Example 1 with SerDesInfo

use of com.hortonworks.registries.schemaregistry.SerDesInfo in project registry by hortonworks.

the class SampleSchemaRegistryClientApp method getSnapshotDeserializer.

private SnapshotDeserializer<byte[], Object, Integer> getSnapshotDeserializer(SchemaMetadata schemaMetadata) {
    Collection<SerDesInfo> deserializers = schemaRegistryClient.getSerDes(schemaMetadata.getName());
    if (deserializers.isEmpty()) {
        throw new RuntimeException("Serializer for schemaKey:" + schemaMetadata + " must exist");
    }
    SerDesInfo serdesInfo = deserializers.iterator().next();
    return schemaRegistryClient.createDeserializerInstance(serdesInfo);
}
Also used : SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo)

Example 2 with SerDesInfo

use of com.hortonworks.registries.schemaregistry.SerDesInfo in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testSerializerOps.

@Test
public void testSerializerOps() throws Exception {
    String fileId = uploadFile();
    SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BOTH);
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/device.avsc"), "Initial version of the schema"));
    SerDesPair serDesPair = createSerDesInfo(fileId);
    Long serDesId = SCHEMA_REGISTRY_CLIENT.addSerDes(serDesPair);
    Assert.assertNotNull("Returned serDesId can not be null", serDesId);
    String schemaName = schemaMetadata.getName();
    SCHEMA_REGISTRY_CLIENT.mapSchemaWithSerDes(schemaName, serDesId);
    Collection<SerDesInfo> serializers = SCHEMA_REGISTRY_CLIENT.getSerDes(schemaName);
    Assert.assertTrue(serializers.stream().map(x -> x.getSerDesPair()).collect(Collectors.toList()).contains(serDesPair));
}
Also used : Arrays(java.util.Arrays) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) SchemaRegistryTestProfileType(com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType) SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) SERDES_PROTOCOL_VERSION(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer.SERDES_PROTOCOL_VERSION) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) AvroSnapshotSerializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotSerializer) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) Utf8(org.apache.avro.util.Utf8) SerDesProtocolHandlerRegistry(com.hortonworks.registries.schemaregistry.serdes.avro.SerDesProtocolHandlerRegistry) AvroSnapshotDeserializer(com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer) SchemaRegistryTestName(com.hortonworks.registries.schemaregistry.avro.util.SchemaRegistryTestName) Collection(java.util.Collection) BAD_REQUEST_PARAM_MISSING(com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.BAD_REQUEST_PARAM_MISSING) Set(java.util.Set) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) Response(javax.ws.rs.core.Response) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) CustomParameterizedRunner(com.hortonworks.registries.schemaregistry.avro.util.CustomParameterizedRunner) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) UNSUPPORTED_SCHEMA_TYPE(com.hortonworks.registries.common.catalog.CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE) IntStream(java.util.stream.IntStream) SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) AvroSchemaRegistryClientUtil(com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SchemaValidationLevel(com.hortonworks.registries.schemaregistry.SchemaValidationLevel) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) Files(java.nio.file.Files) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) FileOutputStream(java.io.FileOutputStream) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) Test(org.junit.Test) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Maps(com.google.common.collect.Maps) File(java.io.File) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Rule(org.junit.Rule) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) Assert(org.junit.Assert) Collections(java.util.Collections) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) InputStream(java.io.InputStream) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SerDesPair(com.hortonworks.registries.schemaregistry.SerDesPair) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Example 3 with SerDesInfo

use of com.hortonworks.registries.schemaregistry.SerDesInfo in project registry by hortonworks.

the class SchemaRegistryResource method findAggregatedSchemas.

@GET
@Path("/search/schemas/aggregated")
@ApiOperation(value = "Search for schemas containing the given name and description", notes = "Search the schemas for given name and description, return a list of schemas that contain the field.", response = AggregatedSchemaMetadataInfo.class, responseContainer = "Collection", tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response findAggregatedSchemas(@Context UriInfo uriInfo) {
    MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    try {
        Collection<SchemaMetadataInfo> schemaMetadataInfos = findSchemaMetadataInfos(uriInfo.getQueryParameters());
        List<AggregatedSchemaMetadataInfo> aggregatedSchemaMetadataInfos = new ArrayList<>();
        for (SchemaMetadataInfo schemaMetadataInfo : schemaMetadataInfos) {
            SchemaMetadata schemaMetadata = schemaMetadataInfo.getSchemaMetadata();
            List<SerDesInfo> serDesInfos = new ArrayList<>(schemaRegistry.getSerDes(schemaMetadataInfo.getSchemaMetadata().getName()));
            aggregatedSchemaMetadataInfos.add(new AggregatedSchemaMetadataInfo(schemaMetadata, schemaMetadataInfo.getId(), schemaMetadataInfo.getTimestamp(), schemaRegistry.getAggregatedSchemaBranch(schemaMetadata.getName()), serDesInfos));
        }
        return WSUtils.respondEntities(aggregatedSchemaMetadataInfos, Response.Status.OK);
    } catch (SchemaBranchNotFoundException e) {
        return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
    } catch (Exception ex) {
        LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex);
        return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
    }
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) ArrayList(java.util.ArrayList) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) FileNotFoundException(java.io.FileNotFoundException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with SerDesInfo

use of com.hortonworks.registries.schemaregistry.SerDesInfo in project registry by hortonworks.

the class SchemaRegistryResource method _getSerDesInfo.

private Response _getSerDesInfo(Long serializerId) {
    Response response;
    try {
        SerDesInfo serializerInfo = schemaRegistry.getSerDes(serializerId);
        response = WSUtils.respondEntity(serializerInfo, Response.Status.OK);
    } catch (Exception ex) {
        LOG.error("Encountered error while getting serializer/deserializer [{}]", serializerId, ex);
        response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) FileNotFoundException(java.io.FileNotFoundException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException)

Example 5 with SerDesInfo

use of com.hortonworks.registries.schemaregistry.SerDesInfo in project registry by hortonworks.

the class SampleSchemaRegistryClientApp method getSnapshotSerializer.

private SnapshotSerializer<Object, byte[], SchemaMetadata> getSnapshotSerializer(SchemaMetadata schemaMetadata) {
    Collection<SerDesInfo> serializers = schemaRegistryClient.getSerDes(schemaMetadata.getName());
    if (serializers.isEmpty()) {
        throw new RuntimeException("Serializer for schemaKey:" + schemaMetadata + " must exist");
    }
    SerDesInfo serdesInfo = serializers.iterator().next();
    return schemaRegistryClient.createSerializerInstance(serdesInfo);
}
Also used : SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo)

Aggregations

SerDesInfo (com.hortonworks.registries.schemaregistry.SerDesInfo)6 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)4 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)4 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)4 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)4 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)4 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)4 IOException (java.io.IOException)4 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)3 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)3 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)3 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)3 FileNotFoundException (java.io.FileNotFoundException)3 Response (javax.ws.rs.core.Response)3 Timed (com.codahale.metrics.annotation.Timed)2 UnitOfWork (com.hortonworks.registries.common.transaction.UnitOfWork)2 AggregatedSchemaMetadataInfo (com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo)2 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1