Search in sources :

Example 26 with SchemaIdVersion

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());
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion)

Example 27 with SchemaIdVersion

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;
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionKey(com.hortonworks.registries.schemaregistry.SchemaVersionKey)

Example 28 with SchemaIdVersion

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)));
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Example 29 with SchemaIdVersion

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;
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) FileNotFoundException(java.io.FileNotFoundException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 30 with SchemaIdVersion

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();
}
Also used : SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) Test(org.junit.Test)

Aggregations

SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)45 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)32 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)22 Test (org.junit.Test)21 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)15 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)15 IOException (java.io.IOException)11 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)10 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)10 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)9 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)9 Timed (com.codahale.metrics.annotation.Timed)5 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)5 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)5 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)5 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)5 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)5 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)5 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)5 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)4