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