use of com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException in project registry by hortonworks.
the class SchemaVersionLifecycleManager method deleteSchemaVersionBranchMapping.
private void deleteSchemaVersionBranchMapping(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException {
List<QueryParam> schemaVersionMappingStorableQueryParams = Lists.newArrayList();
schemaVersionMappingStorableQueryParams.add(new QueryParam(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, schemaVersionId.toString()));
List<OrderByField> orderByFields = new ArrayList<>();
orderByFields.add(OrderByField.of(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, false));
Collection<SchemaBranchVersionMapping> storables = storageManager.find(SchemaBranchVersionMapping.NAMESPACE, schemaVersionMappingStorableQueryParams, orderByFields);
if (storables == null || storables.isEmpty()) {
LOG.debug("No need to delete schema version mapping as the database did a cascade delete");
return;
}
if (storables.size() > 1) {
List<String> branchNamesTiedToSchema = storables.stream().map(storable -> schemaBranchCache.get(SchemaBranchCache.Key.of(storable.getSchemaBranchId())).getName()).collect(Collectors.toList());
throw new SchemaLifecycleException(String.format("Schema version with id : '%s' is tied with more than one branch : '%s' ", schemaVersionId.toString(), Arrays.toString(branchNamesTiedToSchema.toArray())));
}
storageManager.remove(new StorableKey(SchemaBranchVersionMapping.NAMESPACE, storables.iterator().next().getPrimaryKey()));
}
use of com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException in project registry by hortonworks.
the class SchemaVersionLifecycleManager method updateSchemaVersionState.
private void updateSchemaVersionState(Long schemaVersionId, Integer sequence, Byte initialState, byte[] stateDetails) throws SchemaNotFoundException {
try {
SchemaVersionLifecycleContext schemaVersionLifecycleContext = new SchemaVersionLifecycleContext(schemaVersionId, sequence, createSchemaVersionService(), schemaVersionLifecycleStateMachine, customSchemaStateExecutor);
schemaVersionLifecycleContext.setState(schemaVersionLifecycleStateMachine.getStates().get(initialState));
schemaVersionLifecycleContext.setDetails(stateDetails);
schemaVersionLifecycleContext.updateSchemaVersionState();
} catch (SchemaLifecycleException e) {
throw new RuntimeException(e);
}
}
use of com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException 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.schemaregistry.state.SchemaLifecycleException 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.schemaregistry.state.SchemaLifecycleException in project registry by hortonworks.
the class SchemaRegistryClient method handleSchemaLifeCycleResponse.
private boolean handleSchemaLifeCycleResponse(Response response) throws SchemaNotFoundException, SchemaLifecycleException {
boolean result;
int status = response.getStatus();
if (status == Response.Status.OK.getStatusCode()) {
result = response.readEntity(Boolean.class);
} else if (status == Response.Status.NOT_FOUND.getStatusCode()) {
throw new SchemaNotFoundException(response.readEntity(String.class));
} else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
CatalogResponse catalogResponse = readCatalogResponse(response.readEntity(String.class));
if (catalogResponse.getResponseCode() == CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA.getCode()) {
throw new SchemaLifecycleException(new IncompatibleSchemaException(catalogResponse.getResponseMessage()));
}
throw new SchemaLifecycleException(catalogResponse.getResponseMessage());
} else {
throw new RuntimeException(response.readEntity(String.class));
}
return result;
}
Aggregations