Search in sources :

Example 11 with UnitOfWork

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

the class SchemaRegistryResource method getSchemaVersionById.

@GET
@Path("/schemas/versionsById/{id}")
@ApiOperation(value = "Get a version of the schema identified by the given versionid", response = SchemaVersionInfo.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getSchemaVersionById(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) {
    SchemaIdVersion schemaIdVersion = new SchemaIdVersion(versionId);
    Response response;
    try {
        SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(schemaIdVersion);
        response = WSUtils.respondEntity(schemaVersionInfo, Response.Status.OK);
    } catch (SchemaNotFoundException e) {
        LOG.info("No schema version is found with schema version id : [{}]", versionId);
        response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, versionId.toString());
    } catch (Exception ex) {
        LOG.error("Encountered error while getting schema version with id [{}]", versionId, 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) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) 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) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with UnitOfWork

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

the class SchemaRegistryResource method uploadSchemaVersion.

@POST
@Path("/schemas/{name}/versions/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Register a new version of the schema by uploading schema version text", notes = "Registers the given schema version to schema with name if the given file content is not registered as a version for this schema, " + "and returns respective version number." + "In case of incompatible schema errors, it throws error message like 'Unable to read schema: <> using schema <>' ", response = Integer.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response uploadSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @ApiParam(value = "Schema version text file to be uploaded", required = true) @FormDataParam("file") final InputStream inputStream, @ApiParam(value = "Description about the schema version to be uploaded", required = true) @FormDataParam("description") final String description, @Context UriInfo uriInfo) {
    return handleLeaderAction(uriInfo, () -> {
        Response response;
        SchemaVersion schemaVersion = null;
        try {
            schemaVersion = new SchemaVersion(IOUtils.toString(inputStream, "UTF-8"), description);
            response = addSchemaVersion(schemaBranchName, schemaName, schemaVersion, uriInfo);
        } catch (IOException ex) {
            LOG.error("Encountered error while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex, 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) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) IOException(java.io.IOException) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Example 13 with UnitOfWork

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

the class SchemaRegistryResource method mapSchemaWithSerDes.

@POST
@Path("/schemas/{name}/mapping/{serDesId}")
@ApiOperation(value = "Bind the given Serializer/Deserializer to the schema identified by the schema name", tags = OPERATION_GROUP_SERDE)
@Timed
@UnitOfWork
public Response mapSchemaWithSerDes(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "Serializer/deserializer identifier", required = true) @PathParam("serDesId") Long serDesId, @Context UriInfo uriInfo) {
    return handleLeaderAction(uriInfo, () -> {
        Response response;
        try {
            schemaRegistry.mapSchemaWithSerDes(schemaName, serDesId);
            response = WSUtils.respondEntity(true, Response.Status.OK);
        } catch (Exception 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) 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 14 with UnitOfWork

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

the class SchemaRegistryResource method addSchemaInfo.

@POST
@Path("/schemas")
@ApiOperation(value = "Create a schema if it does not already exist", notes = "Creates a schema with the given schema information if it does not already exist." + " A unique schema identifier is returned.", response = Long.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response addSchemaInfo(@ApiParam(value = "Schema to be added to the registry", required = true) SchemaMetadata schemaMetadata, @Context UriInfo uriInfo, @Context HttpHeaders httpHeaders) {
    return handleLeaderAction(uriInfo, () -> {
        Response response;
        try {
            schemaMetadata.trim();
            checkValueAsNullOrEmpty("Schema name", schemaMetadata.getName());
            checkValueAsNullOrEmpty("Schema type", schemaMetadata.getType());
            checkValidNames(schemaMetadata.getName());
            boolean throwErrorIfExists = isThrowErrorIfExists(httpHeaders);
            Long schemaId = schemaRegistry.addSchemaMetadata(schemaMetadata, throwErrorIfExists);
            response = WSUtils.respondEntity(schemaId, Response.Status.CREATED);
        } catch (IllegalArgumentException ex) {
            LOG.error("Expected parameter is invalid", schemaMetadata, ex);
            response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.BAD_REQUEST_PARAM_MISSING, ex.getMessage());
        } catch (UnsupportedSchemaTypeException ex) {
            LOG.error("Unsupported schema type encountered while adding schema metadata [{}]", schemaMetadata, ex);
            response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE, ex.getMessage());
        } catch (Exception ex) {
            LOG.error("Error encountered while adding schema info [{}] ", schemaMetadata, ex);
            response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, String.format("Storing the given SchemaMetadata [%s] is failed", schemaMetadata.toString()));
        }
        return response;
    });
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) 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 15 with UnitOfWork

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

the class SchemaRegistryResource method getAllSchemaVersions.

@GET
@Path("/schemas/{name}/versions")
@ApiOperation(value = "Get all the versions of the schema for the given schema name)", response = SchemaVersionInfo.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getAllSchemaVersions(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @QueryParam("states") List<Byte> stateIds) {
    Response response;
    try {
        Collection<SchemaVersionInfo> schemaVersionInfos = schemaRegistry.getAllVersions(schemaBranchName, schemaName, stateIds);
        if (schemaVersionInfos != null) {
            response = WSUtils.respondEntities(schemaVersionInfos, 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 all schema versions 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)

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