default void archive(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
@Override public void enableSchemaVersion(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException, IncompatibleSchemaException { try { transitionSchemaVersionState(schemaVersionId, "enable", null); } catch (SchemaLifecycleException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof IncompatibleSchemaException) { throw (IncompatibleSchemaException) cause; } throw e; } }
@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; }
@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; }
@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; }
@POST @Path("/schemas/versions/{id}/state/startReview") @ApiOperation(value = "Disables version of the schema identified by the given version id", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response startReviewSchema(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) { Response response; try { schemaRegistry.startSchemaVersionReview(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; }
default void startReview(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
public void executeState(Long schemaVersionId, Byte targetState, byte[] transitionDetails) throws SchemaLifecycleException, SchemaNotFoundException { ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> schemaLifeCycleContextAndState = createSchemaVersionLifeCycleContextAndState(schemaVersionId); SchemaVersionLifecycleContext schemaVersionLifecycleContext = schemaLifeCycleContextAndState.getLeft(); SchemaVersionLifecycleState currentState = schemaLifeCycleContextAndState.getRight(); schemaVersionLifecycleContext.setState(currentState); schemaVersionLifecycleContext.setDetails(transitionDetails); SchemaVersionLifecycleStateTransition transition = new SchemaVersionLifecycleStateTransition(currentState.getId(), targetState); SchemaVersionLifecycleStateAction action = schemaVersionLifecycleContext.getSchemaLifeCycleStatesMachine() .getTransitions() .get(transition); try { List<SchemaVersionLifecycleStateTransitionListener> listeners = schemaVersionLifecycleContext.getSchemaLifeCycleStatesMachine() .getListeners() .getOrDefault(transition, DEFAULT_LISTENERS); listeners.stream().forEach(listener -> listener.preStateTransition(schemaVersionLifecycleContext)); action.execute(schemaVersionLifecycleContext); listeners.stream().forEach(listener -> listener.postStateTransition(schemaVersionLifecycleContext)); } catch (SchemaLifecycleException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof SchemaNotFoundException) { throw (SchemaNotFoundException) cause; } throw e; } }
@POST @Path("/schemas/versions/{id}/state/delete") @ApiOperation(value = "Disables version of the schema identified by the given version id", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response deleteSchema(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) { Response response; try { schemaRegistry.deleteSchemaVersion(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_WITH_MESSAGE, 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; }
default void enable(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
@DELETE @Path("/schemas/{name}/versions/{version}") @ApiOperation(value = "Delete a schema version given its schema name and version id", tags = OPERATION_GROUP_SCHEMA) @UnitOfWork public Response deleteSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "version of the schema", required = true) @PathParam("version") Integer versionNumber, @Context UriInfo uriInfo) { SchemaVersionKey schemaVersionKey = null; try { schemaVersionKey = new SchemaVersionKey(schemaName, versionNumber); schemaRegistry.deleteSchemaVersion(schemaVersionKey); return WSUtils.respond(Response.Status.OK); } catch (SchemaNotFoundException e) { LOG.error("No schemaVersion found with name: [{}], version : [{}]", schemaName, versionNumber); return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaVersionKey.toString()); } catch (SchemaLifecycleException e) { LOG.error("Failed to delete schema name: [{}], version : [{}]", schemaName, versionNumber, e); return WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.BAD_REQUEST_WITH_MESSAGE, e.getMessage()); } catch (Exception ex) { LOG.error("Encountered error while deleting schemaVersion with name: [{}], version : [{}]", schemaName, versionNumber, ex); return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } }
default void enable(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
@DELETE @Path("/schemas/{name}/versions/{version}") @ApiOperation(value = "Delete a schema version given its schema name and version id", tags = OPERATION_GROUP_SCHEMA) @UnitOfWork public Response deleteSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "version of the schema", required = true) @PathParam("version") Integer versionNumber, @Context UriInfo uriInfo) { SchemaVersionKey schemaVersionKey = null; try { schemaVersionKey = new SchemaVersionKey(schemaName, versionNumber); schemaRegistry.deleteSchemaVersion(schemaVersionKey); return WSUtils.respond(Response.Status.OK); } catch (SchemaNotFoundException e) { LOG.error("No schemaVersion found with name: [{}], version : [{}]", schemaName, versionNumber); return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaVersionKey.toString()); } catch (SchemaLifecycleException e) { LOG.error("Failed to delete schema name: [{}], version : [{}]", schemaName, versionNumber, e); return WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.BAD_REQUEST_WITH_MESSAGE, e.getMessage()); } catch (Exception ex) { LOG.error("Encountered error while deleting schemaVersion with name: [{}], version : [{}]", schemaName, versionNumber, ex); return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } }
default void archive(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
@POST @Path("/schemas/versions/{id}/state/disable") @ApiOperation(value = "Disables version of the schema identified by the given version id", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response disableSchema(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) { Response response; try { schemaRegistry.disableSchemaVersion(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; }
default void delete(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
@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; }
default void disable(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }
@POST @Path("/schemas/versions/{id}/state/startReview") @ApiOperation(value = "Disables version of the schema identified by the given version id", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response startReviewSchema(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) { Response response; try { schemaRegistry.startSchemaVersionReview(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; }
default void delete(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { throw new SchemaLifecycleException(" This operation is not supported for this instance: " + this); }