use of com.hortonworks.registries.common.transaction.UnitOfWork in project registry by hortonworks.
the class SchemaRegistryResource method getSchemaVersion.
@GET
@Path("/schemas/{name}/versions/{version}")
@ApiOperation(value = "Get a version of the schema identified by the schema name", response = SchemaVersionInfo.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaMetadata, @ApiParam(value = "version of the schema", required = true) @PathParam("version") Integer versionNumber) {
SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaMetadata, versionNumber);
Response response;
try {
SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(schemaVersionKey);
response = WSUtils.respondEntity(schemaVersionInfo, Response.Status.OK);
} catch (SchemaNotFoundException e) {
LOG.info("No schemas found with schemaVersionKey: [{}]", schemaVersionKey);
response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaVersionKey.toString());
} catch (Exception ex) {
LOG.error("Encountered error while getting all schema versions for schemakey [{}]", schemaMetadata, 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 addSchemaVersion.
@POST
@Path("/schemas/{name}/versions")
@ApiOperation(value = "Register a new version of the schema", notes = "Registers the given schema version to schema with name if the given schemaText 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 addSchemaVersion(@QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "Details about the schema", required = true) SchemaVersion schemaVersion, @Context UriInfo uriInfo) {
return handleLeaderAction(uriInfo, () -> {
Response response;
try {
LOG.info("adding schema version for name [{}] with [{}]", schemaName, schemaVersion);
SchemaIdVersion version = schemaRegistry.addSchemaVersion(schemaBranchName, schemaName, schemaVersion);
response = WSUtils.respondEntity(version.getVersion(), Response.Status.CREATED);
} catch (InvalidSchemaException ex) {
LOG.error("Invalid schema error encountered while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex);
response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.INVALID_SCHEMA, ex.getMessage());
} catch (IncompatibleSchemaException ex) {
LOG.error("Incompatible schema error encountered while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex);
response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA, ex.getMessage());
} catch (UnsupportedSchemaTypeException ex) {
LOG.error("Unsupported schema type encountered while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex);
response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE, ex.getMessage());
} 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 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 executeState.
@POST
@Path("/schemas/versions/{id}/state/{stateId}")
@ApiOperation(value = "Runs the state execution for schema version identified by the given version id and executes action associated with target state id", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response executeState(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId, @ApiParam(value = "", required = true) @PathParam("stateId") Byte stateId, byte[] transitionDetails) {
Response response;
try {
schemaRegistry.transitionState(versionId, stateId, transitionDetails);
response = WSUtils.respondEntity(true, 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 (SchemaLifecycleException e) {
LOG.error("Encountered error while disabling schema version with id [{}]", versionId, e);
CatalogResponse.ResponseMessage badRequestResponse = e.getCause() != null && e.getCause() instanceof IncompatibleSchemaException ? CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA : CatalogResponse.ResponseMessage.BAD_REQUEST;
response = WSUtils.respond(Response.Status.BAD_REQUEST, badRequestResponse, e.getMessage());
} 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 archiveSchema.
@POST
@Path("/schemas/versions/{id}/state/archive")
@ApiOperation(value = "Disables version of the schema identified by the given version id", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response archiveSchema(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) {
Response response;
try {
schemaRegistry.archiveSchemaVersion(versionId);
response = WSUtils.respondEntity(true, 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 (SchemaLifecycleException e) {
LOG.error("Encountered error while disabling schema version with id [{}]", versionId, e);
response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.BAD_REQUEST, e.getMessage());
} 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 getSerializers.
@GET
@Path("/schemas/{name}/serdes")
@ApiOperation(value = "Get list of Serializers registered for the given schema name", response = SerDesInfo.class, responseContainer = "List", tags = OPERATION_GROUP_SERDE)
@Timed
@UnitOfWork
public Response getSerializers(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName) {
Response response;
try {
SchemaMetadataInfo schemaMetadataInfoStorable = schemaRegistry.getSchemaMetadataInfo(schemaName);
if (schemaMetadataInfoStorable != null) {
Collection<SerDesInfo> schemaSerializers = schemaRegistry.getSerDes(schemaMetadataInfoStorable.getSchemaMetadata().getName());
response = WSUtils.respondEntities(schemaSerializers, 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 (Exception ex) {
LOG.error("Encountered error while getting serializers for schemaKey [{}]", schemaName, ex);
response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
}
return response;
}
Aggregations