Search in sources :

Example 16 with SchemaVersion

use of com.hortonworks.registries.schemaregistry.SchemaVersion in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testIncompatibleSchemas.

@Test(expected = IncompatibleSchemaException.class)
public void testIncompatibleSchemas() throws Exception {
    String schema = AvroSchemaRegistryClientUtil.getSchema("/device.avsc");
    String incompatSchema = AvroSchemaRegistryClientUtil.getSchema("/device-incompat.avsc");
    SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    // registering a new schema
    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");
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, incompatSchemaInfo);
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Example 17 with SchemaVersion

use of com.hortonworks.registries.schemaregistry.SchemaVersion in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testInvalidSchema.

@Test(expected = InvalidSchemaException.class)
public void testInvalidSchema() throws Exception {
    String schema = "--- invalid schema ---";
    SchemaMetadata schemaMetadata = createSchemaMetadata(TEST_NAME_RULE.getMethodName(), SchemaCompatibility.BACKWARD);
    SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(schema, "Initial version of the schema"));
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Example 18 with SchemaVersion

use of com.hortonworks.registries.schemaregistry.SchemaVersion 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 19 with SchemaVersion

use of com.hortonworks.registries.schemaregistry.SchemaVersion in project registry by hortonworks.

the class SchemaRegistryResource method uploadSchemaVersion.

@POST
@Path("/schemas/{name}/versions/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Register a new version of the schema by uploading schema version text", notes = "Registers the given schema version to schema with name if the given file content is not registered as a version for this schema, " + "and returns respective version number." + "In case of incompatible schema errors, it throws error message like 'Unable to read schema: <> using schema <>' ", response = Integer.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response uploadSchemaVersion(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @ApiParam(value = "Schema version text file to be uploaded", required = true) @FormDataParam("file") final InputStream inputStream, @ApiParam(value = "Description about the schema version to be uploaded", required = true) @FormDataParam("description") final String description, @Context UriInfo uriInfo) {
    return handleLeaderAction(uriInfo, () -> {
        Response response;
        SchemaVersion schemaVersion = null;
        try {
            schemaVersion = new SchemaVersion(IOUtils.toString(inputStream, "UTF-8"), description);
            response = addSchemaVersion(schemaBranchName, schemaName, schemaVersion, uriInfo);
        } catch (IOException ex) {
            LOG.error("Encountered error while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex, 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) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) IOException(java.io.IOException) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Example 20 with SchemaVersion

use of com.hortonworks.registries.schemaregistry.SchemaVersion 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

SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)27 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)25 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)18 Test (org.junit.Test)16 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)7 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)6 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)6 SchemaVersionKey (com.hortonworks.registries.schemaregistry.SchemaVersionKey)6 SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)4 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)4 IOException (java.io.IOException)4 Timed (com.codahale.metrics.annotation.Timed)3 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)3 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)3 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)3 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)3 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Response (javax.ws.rs.core.Response)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2