Search in sources :

Example 1 with AggregatedSchemaMetadataInfo

use of com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo 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 2 with AggregatedSchemaMetadataInfo

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

the class AvroSchemaRegistryTest method testRegistrySchemaOps.

@Test
public void testRegistrySchemaOps() throws Exception {
    SchemaCompatibility compatibility = SchemaCompatibility.BOTH;
    SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(schemaName).type(AvroSchemaProvider.TYPE).description("devices schema").compatibility(compatibility).schemaGroup(SCHEMA_GROUP).build();
    Long schemaMetadataId = schemaRegistry.registerSchemaMetadata(schemaMetadata);
    SchemaMetadata schemaMetadataReturned = schemaRegistry.getSchemaMetadataInfo(schemaMetadataId).getSchemaMetadata();
    Assert.assertEquals(schemaMetadata, schemaMetadataReturned);
    Integer v1 = schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(schema1, "initial version of the schema")).getVersion();
    Integer v2 = schemaRegistry.addSchemaVersion(schemaName, new SchemaVersion(schema2, "second version of the the schema")).getVersion();
    Assert.assertTrue(v2 == v1 + 1);
    Collection<SchemaVersionInfo> allSchemaVersions = schemaRegistry.getAllVersions(schemaName);
    Assert.assertTrue(allSchemaVersions.size() == 2);
    SchemaMetadataInfo schemaMetadataInfo = schemaRegistry.getSchemaMetadataInfo(schemaName);
    Assert.assertEquals(schemaMetadata, schemaMetadataInfo.getSchemaMetadata());
    Integer schemaVersion = schemaRegistry.getSchemaVersionInfo(schemaName, schema1).getVersion();
    Assert.assertEquals(v1, schemaVersion);
    SchemaVersionInfo schemaVersionInfo1 = schemaRegistry.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v1));
    Assert.assertEquals(schemaVersionInfo1.getSchemaText(), schema1);
    SchemaVersionInfo schemaVersionInfo2 = schemaRegistry.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v2));
    Assert.assertEquals(schemaVersionInfo2.getSchemaText(), schema2);
    // receive the same version as earlier without adding a new schema entry as it exists in the same schema group.
    Integer version = schemaRegistry.addSchemaVersion(schemaMetadata, new SchemaVersion(schema1, "already added schema")).getVersion();
    Assert.assertEquals(version, v1);
    // aggregate apis
    AggregatedSchemaMetadataInfo aggregatedSchemaMetadata = schemaRegistry.getAggregatedSchemaMetadataInfo(schemaName);
    Assert.assertEquals(allSchemaVersions.size(), aggregatedSchemaMetadata.getSchemaBranches().iterator().next().getSchemaVersionInfos().size());
    Assert.assertTrue(aggregatedSchemaMetadata.getSerDesInfos().isEmpty());
    Collection<AggregatedSchemaMetadataInfo> aggregatedSchemaMetadataCollection = schemaRegistry.findAggregatedSchemaMetadata(Collections.emptyMap());
    Assert.assertEquals(1, aggregatedSchemaMetadataCollection.size());
    // Serializing and deserializing AggregatedSchemaMetadataInfo should not throw any errors
    String aggregateSchemaMetadataStr = new ObjectMapper().writeValueAsString(aggregatedSchemaMetadataCollection);
    Collection<AggregatedSchemaMetadataInfo> returnedResult = new ObjectMapper().readValue(aggregateSchemaMetadataStr, new TypeReference<Collection<AggregatedSchemaMetadataInfo>>() {
    });
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) Collection(java.util.Collection) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Test(org.junit.Test)

Aggregations

AggregatedSchemaMetadataInfo (com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo)2 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)2 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)2 Timed (com.codahale.metrics.annotation.Timed)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 UnitOfWork (com.hortonworks.registries.common.transaction.UnitOfWork)1 SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)1 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)1 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)1 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)1 SerDesInfo (com.hortonworks.registries.schemaregistry.SerDesInfo)1 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)1 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)1 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)1 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)1 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)1 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)1 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)1 ApiOperation (io.swagger.annotations.ApiOperation)1