use of com.hortonworks.registries.schemaregistry.SchemaIdVersion 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.SchemaIdVersion in project registry by hortonworks.
the class AvroSchemaRegistryClientTest method addAndDeleteSchemaVersion.
private SchemaVersionKey addAndDeleteSchemaVersion(String schemaName) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, IOException, SchemaBranchNotFoundException, SchemaLifecycleException {
SchemaMetadata schemaMetadata = createSchemaMetadata(schemaName, SchemaCompatibility.BOTH);
SchemaIdVersion schemaIdVersion = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/device.avsc"), "Initial version of the schema"));
SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaMetadata.getName(), schemaIdVersion.getVersion());
SCHEMA_REGISTRY_CLIENT.deleteSchemaVersion(schemaVersionKey);
return schemaVersionKey;
}
use of com.hortonworks.registries.schemaregistry.SchemaIdVersion in project registry by hortonworks.
the class AvroSchemaRegistryClientTest method testGetSchemaVersionFromStates.
@Test
public void testGetSchemaVersionFromStates() throws IOException, SchemaNotFoundException, InvalidSchemaException, IncompatibleSchemaException, SchemaLifecycleException, SchemaBranchAlreadyExistsException {
SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.NONE);
String schemaName = schemaMetadata.getName();
Long id = SCHEMA_REGISTRY_CLIENT.registerSchemaMetadata(schemaMetadata);
SchemaIdVersion v1 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-1.avsc"), "Initial version of the schema"));
SchemaIdVersion v2 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-2.avsc"), "Second version of the schema"));
SchemaIdVersion v3 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-3.avsc"), "Third version of the schema, removes name field"));
SchemaBranch schemaBranch = SCHEMA_REGISTRY_CLIENT.createSchemaBranch(v3.getSchemaVersionId(), new SchemaBranch("Branch-1", schemaName));
SchemaIdVersion v4 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaBranch.getName(), schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-4.avsc"), "Forth version of the schema, adds back name field, but different type"));
SCHEMA_REGISTRY_CLIENT.startSchemaVersionReview(v4.getSchemaVersionId());
SCHEMA_REGISTRY_CLIENT.transitionState(v4.getSchemaVersionId(), SchemaVersionLifecycleStates.REVIEWED.getId(), null);
SCHEMA_REGISTRY_CLIENT.archiveSchemaVersion(v2.getSchemaVersionId());
SCHEMA_REGISTRY_CLIENT.archiveSchemaVersion(v3.getSchemaVersionId());
Assert.assertEquals(transformToSchemaIdVersions(SCHEMA_REGISTRY_CLIENT.getAllVersions(SchemaBranch.MASTER_BRANCH, schemaName, Collections.singletonList(SchemaVersionLifecycleStates.ENABLED.getId()))), new HashSet<>(Arrays.asList(v1)));
Assert.assertEquals(transformToSchemaIdVersions(SCHEMA_REGISTRY_CLIENT.getAllVersions(SchemaBranch.MASTER_BRANCH, schemaName, Collections.singletonList(SchemaVersionLifecycleStates.ARCHIVED.getId()))), new HashSet<>(Arrays.asList(v2, v3)));
Assert.assertEquals(transformToSchemaIdVersions(SCHEMA_REGISTRY_CLIENT.getAllVersions(schemaBranch.getName(), schemaName, Collections.singletonList(SchemaVersionLifecycleStates.REVIEWED.getId()))), new HashSet<>(Arrays.asList(v4)));
SCHEMA_REGISTRY_CLIENT.disableSchemaVersion(v1.getSchemaVersionId());
Assert.assertEquals(transformToSchemaIdVersions(SCHEMA_REGISTRY_CLIENT.getAllVersions(SchemaBranch.MASTER_BRANCH, schemaName, Arrays.asList(SchemaVersionLifecycleStates.ARCHIVED.getId(), SchemaVersionLifecycleStates.DISABLED.getId()))), new HashSet<>(Arrays.asList(v1, v2, v3)));
}
use of com.hortonworks.registries.schemaregistry.SchemaIdVersion 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.SchemaIdVersion in project registry by hortonworks.
the class LocalRegistryServerTest method testSanity.
@Test
public void testSanity() throws Exception {
SchemaRegistryTestServerClientWrapper schemaRegistryTestServerClientWrapper = new SchemaRegistryTestServerClientWrapper(SCHEMA_REGISTRY_TEST_CONFIGURATION);
schemaRegistryTestServerClientWrapper.startTestServer();
SchemaRegistryClient schemaRegistryClient = schemaRegistryTestServerClientWrapper.getClient();
// registering schema metadata
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder("foo").type("avro").build();
Long schemaId = schemaRegistryClient.registerSchemaMetadata(schemaMetadata);
Assert.assertNotNull(schemaId);
// registering a new schema
String schemaName = schemaMetadata.getName();
String schema1 = IOUtils.toString(LocalRegistryServerTest.class.getResourceAsStream("/schema-1.avsc"), "UTF-8");
SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaName, new SchemaVersion(schema1, "Initial version of the schema"));
schemaRegistryTestServerClientWrapper.stopTestServer();
}
Aggregations