use of com.hortonworks.registries.schemaregistry.SchemaVersionInfo in project registry by hortonworks.
the class AvroSchemaRegistryClientTest method doTestSchemaVersionEnableState.
public void doTestSchemaVersionEnableState(String schemaName) throws Exception {
String schema = AvroSchemaRegistryClientUtil.getSchema("/device.avsc");
String incompatSchema = AvroSchemaRegistryClientUtil.getSchema("/device-compat.avsc");
SchemaMetadata schemaMetadata = createSchemaMetadata(schemaName, SchemaCompatibility.BACKWARD);
// registering a new schema
SchemaIdVersion schemaIdVersion_1 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema"));
// adding a new version of the schema
SchemaVersion incompatSchemaInfo = new SchemaVersion(incompatSchema, "second version");
SchemaIdVersion schemaIdVersion_2 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, incompatSchemaInfo);
Long schemaVersionId_2 = schemaIdVersion_2.getSchemaVersionId();
SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(schemaVersionId_2);
SchemaVersionInfo schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
System.out.println("disable :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
Assert.assertEquals(SchemaVersionLifecycleStates.DISABLED.getId(), schemaVersionInfo.getStateId());
SCHEMA_REGISTRY_CLIENT.enableSchemaVersion(schemaVersionId_2);
schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
System.out.println("enable :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
Assert.assertEquals(SchemaVersionLifecycleStates.ENABLED.getId(), schemaVersionInfo.getStateId());
SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(schemaVersionId_2);
schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
System.out.println("disable :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
Assert.assertEquals(SchemaVersionLifecycleStates.DISABLED.getId(), schemaVersionInfo.getStateId());
SCHEMA_REGISTRY_CLIENT.archiveSchemaVersion(schemaVersionId_2);
schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
System.out.println("archive :: schemaVersionInfo.getStateId() = " + schemaVersionInfo.getStateId());
Assert.assertEquals(SchemaVersionLifecycleStates.ARCHIVED.getId(), schemaVersionInfo.getStateId());
}
use of com.hortonworks.registries.schemaregistry.SchemaVersionInfo in project registry by hortonworks.
the class SchemaRegistryResource method getSchemaVersionById.
@GET
@Path("/schemas/versionsById/{id}")
@ApiOperation(value = "Get a version of the schema identified by the given versionid", response = SchemaVersionInfo.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getSchemaVersionById(@ApiParam(value = "version identifier of the schema", required = true) @PathParam("id") Long versionId) {
SchemaIdVersion schemaIdVersion = new SchemaIdVersion(versionId);
Response response;
try {
SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(schemaIdVersion);
response = WSUtils.respondEntity(schemaVersionInfo, 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 (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.SchemaVersionInfo in project registry by hortonworks.
the class SchemaRegistryResource method getAllSchemaVersions.
@GET
@Path("/schemas/{name}/versions")
@ApiOperation(value = "Get all the versions of the schema for the given schema name)", response = SchemaVersionInfo.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getAllSchemaVersions(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @QueryParam("states") List<Byte> stateIds) {
Response response;
try {
Collection<SchemaVersionInfo> schemaVersionInfos = schemaRegistry.getAllVersions(schemaBranchName, schemaName, stateIds);
if (schemaVersionInfos != null) {
response = WSUtils.respondEntities(schemaVersionInfos, 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 (SchemaBranchNotFoundException e) {
return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
} catch (Exception ex) {
LOG.error("Encountered error while getting all schema versions for schemakey [{}]", schemaName, ex);
response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
}
return response;
}
use of com.hortonworks.registries.schemaregistry.SchemaVersionInfo in project registry by hortonworks.
the class SchemaRegistryResource method getLatestSchemaVersion.
@GET
@Path("/schemas/{name}/versions/latest")
@ApiOperation(value = "Get the latest version of the schema for the given schema name", response = SchemaVersionInfo.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getLatestSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName) {
Response response;
try {
SchemaVersionInfo schemaVersionInfo = schemaRegistry.getLatestSchemaVersionInfo(schemaBranchName, schemaName);
if (schemaVersionInfo != null) {
response = WSUtils.respondEntity(schemaVersionInfo, 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 (SchemaBranchNotFoundException e) {
return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
} catch (Exception ex) {
LOG.error("Encountered error while getting latest schema version for schemakey [{}]", schemaName, ex);
response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
}
return response;
}
use of com.hortonworks.registries.schemaregistry.SchemaVersionInfo 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);
}
Aggregations