use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.
the class ConfluentSchemaRegistryCompatibleResource method registerSchemaVersion.
@POST
@Path("/subjects/{subject}/versions")
@ApiOperation(value = "Register a new version of the schema", notes = "Registers the given schema version to schema with subject if the given schemaText is not registered as a version for this schema, " + "and returns respective unique id." + "In case of incompatible schema errors, it throws error message like 'Unable to read schema: <> using schema <>' ", response = Id.class, tags = OPERATION_GROUP_CONFLUENT_SR)
@Timed
@UnitOfWork
public Response registerSchemaVersion(@ApiParam(value = "subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "Details about the schema", required = true) String schema, @Context UriInfo uriInfo) {
LOG.info("registerSchema for [{}] is [{}]", subject);
return handleLeaderAction(uriInfo, () -> {
Response response;
try {
LOG.info("registerSchema for [{}] is [{}]", subject);
SchemaMetadataInfo schemaMetadataInfo = schemaRegistry.getSchemaMetadataInfo(subject);
if (schemaMetadataInfo == null) {
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(subject).type(AvroSchemaProvider.TYPE).schemaGroup("Kafka").build();
schemaRegistry.addSchemaMetadata(schemaMetadata);
schemaMetadataInfo = schemaRegistry.getSchemaMetadataInfo(subject);
}
SchemaIdVersion schemaVersionInfo = schemaRegistry.addSchemaVersion(schemaMetadataInfo.getSchemaMetadata(), new SchemaVersion(schemaStringFromJson(schema).getSchema(), null));
Id id = new Id();
id.setId(schemaVersionInfo.getSchemaVersionId());
response = WSUtils.respondEntity(id, Response.Status.OK);
} catch (InvalidSchemaException ex) {
LOG.error("Invalid schema error encountered while adding subject [{}]", subject, ex);
response = invalidSchemaError();
} catch (IncompatibleSchemaException ex) {
LOG.error("Incompatible schema error encountered while adding subject [{}]", subject, ex);
response = incompatibleSchemaError();
} catch (UnsupportedSchemaTypeException ex) {
LOG.error("Unsupported schema type encountered while adding subject [{}]", subject, ex);
response = incompatibleSchemaError();
} catch (Exception ex) {
LOG.error("Encountered error while adding subject [{}]", subject, ex);
response = serverError();
}
return response;
});
}
use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.
the class ConfluentSchemaRegistryCompatibleResource method getSchemaById.
@GET
@Path("/schemas/ids/{id}")
@ApiOperation(value = "Get schema version by id", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR)
@Timed
@UnitOfWork
public Response getSchemaById(@ApiParam(value = "schema version id", required = true) @PathParam("id") Long id) {
Response response;
try {
SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(new SchemaIdVersion(id));
SchemaString schema = new SchemaString();
schema.setSchema(schemaVersionInfo.getSchemaText());
response = WSUtils.respondEntity(schema, Response.Status.OK);
} catch (SchemaNotFoundException ex) {
LOG.error("No schema version found with id [{}]", id, ex);
response = schemaNotFoundError();
} catch (Exception ex) {
LOG.error("Encountered error while retrieving Schema with id: [{}]", id, ex);
response = serverError();
}
return response;
}
use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.
the class ConfluentSchemaRegistryCompatibleResource method getSubjects.
@GET
@Path("/subjects")
@ApiOperation(value = "Get all registered subjects", response = String.class, responseContainer = "Collection", tags = OPERATION_GROUP_CONFLUENT_SR)
@Timed
@UnitOfWork
public Response getSubjects() {
Response response;
try {
List<String> registeredSubjects = schemaRegistry.findSchemaMetadata(Collections.emptyMap()).stream().map(x -> x.getSchemaMetadata().getName()).collect(Collectors.toList());
response = WSUtils.respondEntity(registeredSubjects, Response.Status.OK);
} catch (Exception ex) {
LOG.error("Encountered error while retrieving all subjects", ex);
response = serverError();
}
return response;
}
use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.
the class ConfluentSchemaRegistryCompatibleResource method getAllVersions.
@GET
@Path("/subjects/{subject}/versions")
@ApiOperation(value = "Get all schema versions of given subject", response = Integer.class, responseContainer = "Collection", tags = OPERATION_GROUP_CONFLUENT_SR)
@Timed
@UnitOfWork
public Response getAllVersions(@ApiParam(value = "subject", required = true) @PathParam("subject") String subject) {
Response response;
try {
List<Integer> registeredSubjects = schemaRegistry.getAllVersions(subject).stream().map(SchemaVersionInfo::getVersion).collect(Collectors.toList());
response = WSUtils.respondEntity(registeredSubjects, 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;
}
use of com.hortonworks.registries.common.transaction.UnitOfWork 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());
}
}
Aggregations