use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException 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.errors.SchemaNotFoundException 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.errors.SchemaNotFoundException in project registry by hortonworks.
the class DefaultSchemaRegistry method getAggregatedSchemaBranch.
@Override
public Collection<AggregatedSchemaBranch> getAggregatedSchemaBranch(String schemaName) throws SchemaNotFoundException, SchemaBranchNotFoundException {
Collection<AggregatedSchemaBranch> aggregatedSchemaBranches = new ArrayList<>();
for (SchemaBranch schemaBranch : getSchemaBranches(schemaName)) {
Long rootVersion = schemaBranch.getName().equals(SchemaBranch.MASTER_BRANCH) ? null : schemaVersionLifecycleManager.getRootVersion(schemaBranch).getId();
Collection<SchemaVersionInfo> schemaVersionInfos = getAllVersions(schemaBranch.getName(), schemaName);
schemaVersionInfos.stream().forEach(schemaVersionInfo -> {
SchemaVersionLifecycleContext context = null;
try {
context = schemaVersionLifecycleManager.createSchemaVersionLifeCycleContext(schemaVersionInfo.getId(), SchemaVersionLifecycleStates.INITIATED);
MergeInfo mergeInfo = null;
if (context.getDetails() == null) {
mergeInfo = null;
} else {
try {
InitializedStateDetails details = ObjectMapperUtils.deserialize(context.getDetails(), InitializedStateDetails.class);
mergeInfo = details.getMergeInfo();
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to serialize state details of schema version : '%s'", context.getSchemaVersionId()), e);
}
}
schemaVersionInfo.setMergeInfo(mergeInfo);
} catch (SchemaNotFoundException e) {
// If the schema version has never been in 'INITIATED' state, then SchemaNotFoundException error is thrown which is expected
schemaVersionInfo.setMergeInfo(null);
}
});
aggregatedSchemaBranches.add(new AggregatedSchemaBranch(schemaBranch, rootVersion, schemaVersionInfos));
}
return aggregatedSchemaBranches;
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaBranchLifeCycleTest method addSchemaVersionToBranch.
@Test
public void addSchemaVersionToBranch() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException {
SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE);
SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc");
SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId());
addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc");
Collection<SchemaVersionInfo> schemaBranch1VersionInfos = schemaRegistryClient.getAllVersions(schemaBranch1.getName(), schemaMetadata.getName());
Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaMetadata.getName());
Assert.assertTrue(masterSchemaVersionInfos.size() == 1);
Assert.assertTrue(schemaBranch1VersionInfos.size() == 3);
Long versionsInInitiatedState = schemaBranch1VersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.INITIATED.getId())).count();
Long versionsInEnabledState = schemaBranch1VersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.ENABLED.getId())).count();
Assert.assertTrue(versionsInInitiatedState == 2);
Assert.assertTrue(versionsInEnabledState == 1);
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project streamline by hortonworks.
the class SchemaResource method postStreamsSchema.
@POST
@Timed
@Produces(MediaType.APPLICATION_JSON)
public Response postStreamsSchema(StreamsSchemaInfo streamsSchemaInfo, @Context SecurityContext securityContext) throws IOException {
Preconditions.checkNotNull(streamsSchemaInfo, "streamsSchemaInfo can not be null");
SchemaIdVersion schemaIdVersion = null;
SchemaMetadata schemaMetadata = streamsSchemaInfo.getSchemaMetadata();
String schemaName = schemaMetadata.getName();
Long schemaMetadataId = schemaRegistryClient.registerSchemaMetadata(schemaMetadata);
LOG.info("Registered schemaMetadataId [{}] for schema with name:[{}]", schemaMetadataId, schemaName);
String streamsSchemaText = streamsSchemaInfo.getSchemaVersion().getSchemaText();
try {
// convert streams schema to avro schema.
String avroSchemaText = AvroStreamlineSchemaConverter.convertStreamlineSchemaToAvroSchema(streamsSchemaText);
SchemaVersion avroSchemaVersion = new SchemaVersion(avroSchemaText, streamsSchemaInfo.getSchemaVersion().getDescription());
schemaIdVersion = schemaRegistryClient.addSchemaVersion(schemaName, avroSchemaVersion);
} catch (InvalidSchemaException e) {
String errMsg = String.format("Invalid schema received for schema with name [%s] : [%s]", schemaName, streamsSchemaText);
LOG.error(errMsg, e);
throw BadRequestException.message(errMsg, e);
} catch (SchemaNotFoundException e) {
String errMsg = String.format("Schema not found for topic: [%s]", schemaName);
LOG.error(errMsg, e);
throw EntityNotFoundException.byId(schemaName);
} catch (IncompatibleSchemaException e) {
String errMsg = String.format("Incompatible schema received for schema with name [%s] : [%s]", schemaName, streamsSchemaText);
LOG.error(errMsg, e);
throw BadRequestException.message(errMsg, e);
} catch (Exception e) {
throw new RuntimeException(e);
}
return WSUtils.respondEntity(schemaIdVersion, OK);
}
Aggregations