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