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