Search in sources :

Example 21 with UnitOfWork

use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.

the class SchemaRegistryResource method checkCompatibilityWithSchema.

@POST
@Path("/schemas/{name}/compatibility")
@ApiOperation(value = "Checks if the given schema text is compatible with all the versions of the schema identified by the name", response = CompatibilityResult.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response checkCompatibilityWithSchema(@QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "schema text", required = true) String schemaText) {
    Response response;
    try {
        CompatibilityResult compatibilityResult = schemaRegistry.checkCompatibility(schemaBranchName, schemaName, schemaText);
        response = WSUtils.respondEntity(compatibilityResult, Response.Status.OK);
    } catch (SchemaNotFoundException e) {
        LOG.error("No schemas found with schemakey: [{}]", schemaName, e);
        response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaName);
    } 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 checking compatibility with versions of schema with [{}] for given schema text [{}]", schemaName, schemaText, 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) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) CompatibilityResult(com.hortonworks.registries.schemaregistry.CompatibilityResult) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) 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) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Example 22 with UnitOfWork

use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.

the class SchemaRegistryResource method getLatestSchemaVersion.

@GET
@Path("/schemas/{name}/versions/latest")
@ApiOperation(value = "Get the latest version of the schema for the given schema name", response = SchemaVersionInfo.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getLatestSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName) {
    Response response;
    try {
        SchemaVersionInfo schemaVersionInfo = schemaRegistry.getLatestSchemaVersionInfo(schemaBranchName, schemaName);
        if (schemaVersionInfo != null) {
            response = WSUtils.respondEntity(schemaVersionInfo, Response.Status.OK);
        } else {
            LOG.info("No schemas found with schemakey: [{}]", schemaName);
            response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaName);
        }
    } 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 getting latest schema version for schemakey [{}]", schemaName, 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) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) 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) 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 23 with UnitOfWork

use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.

the class ConfluentSchemaRegistryCompatibleResource method getSchemaVersion.

@GET
@Path("/subjects/{subject}/versions/{versionId}")
@ApiOperation(value = "Get the schema information for given subject and versionId", response = Integer.class, responseContainer = "Collection", tags = OPERATION_GROUP_CONFLUENT_SR)
@Timed
@UnitOfWork
public Response getSchemaVersion(@ApiParam(value = "subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "versionId", required = true) @PathParam("versionId") String versionId) {
    Response response;
    try {
        SchemaVersionInfo schemaVersionInfo = null;
        if ("latest".equals(versionId)) {
            schemaVersionInfo = schemaRegistry.getLatestSchemaVersionInfo(subject);
        } else {
            SchemaMetadataInfo schemaMetadataInfo = schemaRegistry.getSchemaMetadataInfo(subject);
            if (schemaMetadataInfo == null) {
                throw new SchemaNotFoundException();
            }
            SchemaVersionInfo fetchedSchemaVersionInfo = null;
            try {
                Integer version = Integer.valueOf(versionId);
                if (version > 0 && version <= Integer.MAX_VALUE) {
                    fetchedSchemaVersionInfo = schemaRegistry.getSchemaVersionInfo(new SchemaVersionKey(subject, version));
                } else {
                    LOG.error("versionId is not in valid range [{}, {}] ", 1, Integer.MAX_VALUE);
                }
            } catch (NumberFormatException e) {
                LOG.error("Invalid version id string ", versionId, e);
            } catch (SchemaNotFoundException e) {
                LOG.error("Schema version not found with version id [{}]", versionId, e);
            }
            if (fetchedSchemaVersionInfo != null) {
                if (subject.equals(fetchedSchemaVersionInfo.getName())) {
                    schemaVersionInfo = fetchedSchemaVersionInfo;
                } else {
                    LOG.error("Received schema version for id [{}] belongs to subject [{}] which is different from requested subject [{}]", versionId, fetchedSchemaVersionInfo.getName(), subject);
                }
            }
        }
        if (schemaVersionInfo == null) {
            response = versionNotFoundError();
        } else {
            Schema schema = new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText());
            response = WSUtils.respondEntity(schema, Response.Status.OK);
        }
    } catch (SchemaNotFoundException ex) {
        LOG.error("No schema found with subject [{}]", subject, ex);
        response = subjectNotFoundError();
    } catch (Exception ex) {
        LOG.error("Encountered error while retrieving all subjects", ex);
        response = serverError();
    }
    return response;
}
Also used : CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) Response(javax.ws.rs.core.Response) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) IOException(java.io.IOException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) 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)

Aggregations

UnitOfWork (com.hortonworks.registries.common.transaction.UnitOfWork)23 ApiOperation (io.swagger.annotations.ApiOperation)23 IOException (java.io.IOException)23 Path (javax.ws.rs.Path)23 Timed (com.codahale.metrics.annotation.Timed)22 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)22 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)22 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)22 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)22 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)21 Response (javax.ws.rs.core.Response)21 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)17 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)17 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)17 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)17 FileNotFoundException (java.io.FileNotFoundException)17 POST (javax.ws.rs.POST)13 GET (javax.ws.rs.GET)10 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)7 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)5