use of com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException 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;
}
use of com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException in project registry by hortonworks.
the class SchemaRegistryResource method enableSchema.
@POST
@Path("/schemas/versions/{id}/state/enable")
@ApiOperation(value = "Enables version of the schema identified by the given versionid", response = Boolean.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response enableSchema(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) {
Response response;
try {
schemaRegistry.enableSchemaVersion(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 (IncompatibleSchemaException e) {
LOG.error("Encountered error while enabling schema version with id [{}]", versionId, e);
response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA, e.getMessage());
} catch (SchemaLifecycleException e) {
LOG.error("Encountered error while enabling 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.IncompatibleSchemaException in project registry by hortonworks.
the class SchemaBranchLifeCycleTest method getAllBranches.
@Test
public void getAllBranches() 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());
SchemaIdVersion masterSchemaIdVersion2 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device-incompat.avsc");
SchemaBranch schemaBranch2 = addSchemaBranch("BRANCH2", schemaMetadata, masterSchemaIdVersion2.getSchemaVersionId());
Set<String> actualSchemaBranches = schemaRegistryClient.getSchemaBranches(schemaMetadata.getName()).stream().map(branch -> branch.getName()).collect(Collectors.toSet());
Set<String> expectedSchemaBranches = new HashSet<>(Lists.newArrayList("MASTER", schemaBranch1.getName(), schemaBranch2.getName()));
Assert.assertTrue(SetUtils.isEqualSet(actualSchemaBranches, expectedSchemaBranches));
}
use of com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException in project registry by hortonworks.
the class SchemaBranchLifeCycleTest method mergeSchemaWithDefaultMergeStrategy.
@Test
public void mergeSchemaWithDefaultMergeStrategy() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException {
SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.toString(), SchemaCompatibility.NONE);
SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc");
SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId());
SchemaIdVersion schemaBranch1Version1 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
SchemaIdVersion schemaBranch1Version2 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc");
schemaRegistryClient.mergeSchemaVersion(schemaBranch1Version2.getSchemaVersionId());
Collection<SchemaVersionInfo> branchSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaBranch1.getName(), schemaMetadata.getName());
Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaMetadata.getName());
Assert.assertTrue(masterSchemaVersionInfos.size() == 2);
Assert.assertTrue(branchSchemaVersionInfos.size() == 3);
Long branchVersionsInInitiatedState = branchSchemaVersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.INITIATED.getId())).count();
Long masterVersionsInEnabledState = masterSchemaVersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.ENABLED.getId())).count();
Assert.assertTrue(branchVersionsInInitiatedState == 2);
Assert.assertTrue(masterVersionsInEnabledState == 2);
}
use of com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException in project registry by hortonworks.
the class SchemaVersionLifecycleStates method transitionToEnableState.
public static void transitionToEnableState(SchemaVersionLifecycleContext context) throws SchemaNotFoundException, IncompatibleSchemaException, SchemaLifecycleException, SchemaBranchNotFoundException {
Long schemaVersionId = context.getSchemaVersionId();
SchemaVersionService schemaVersionService = context.getSchemaVersionService();
SchemaMetadataInfo schemaMetadataInfo = schemaVersionService.getSchemaMetadata(schemaVersionId);
SchemaMetadata schemaMetadata = schemaMetadataInfo.getSchemaMetadata();
String schemaName = schemaMetadata.getName();
SchemaValidationLevel validationLevel = schemaMetadata.getValidationLevel();
SchemaVersionInfo schemaVersionInfo = schemaVersionService.getSchemaVersionInfo(schemaVersionId);
int schemaVersion = schemaVersionInfo.getVersion();
String schemaText = schemaVersionInfo.getSchemaText();
List<SchemaVersionInfo> allEnabledSchemaVersions = schemaVersionService.getAllSchemaVersions(SchemaBranch.MASTER_BRANCH, schemaName).stream().filter(x -> SchemaVersionLifecycleStates.ENABLED.getId().equals(x.getStateId())).collect(Collectors.toList());
if (!allEnabledSchemaVersions.isEmpty()) {
if (validationLevel.equals(SchemaValidationLevel.ALL)) {
for (SchemaVersionInfo curSchemaVersionInfo : allEnabledSchemaVersions) {
int curVersion = curSchemaVersionInfo.getVersion();
if (curVersion < schemaVersion) {
checkCompatibility(schemaVersionService, schemaMetadata, schemaText, curSchemaVersionInfo.getSchemaText());
} else {
checkCompatibility(schemaVersionService, schemaMetadata, curSchemaVersionInfo.getSchemaText(), schemaText);
}
}
} else if (validationLevel.equals(SchemaValidationLevel.LATEST)) {
List<SchemaVersionInfo> sortedSchemaVersionInfos = new ArrayList<>(allEnabledSchemaVersions);
sortedSchemaVersionInfos.sort(Comparator.comparingInt(SchemaVersionInfo::getVersion));
int i = 0;
int size = sortedSchemaVersionInfos.size();
for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() < schemaVersion; i++) {
String fromSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText();
checkCompatibility(schemaVersionService, schemaMetadata, schemaText, fromSchemaText);
}
for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() > schemaVersion; i++) {
String toSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText();
checkCompatibility(schemaVersionService, schemaMetadata, toSchemaText, schemaText);
}
}
}
context.setState(ENABLED);
context.updateSchemaVersionState();
}
Aggregations