Search in sources :

Example 1 with SchemaBranch

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

the class CustomStateTransitionTest method testTransitionToRejectedState.

@Test
public void testTransitionToRejectedState() throws IOException, SchemaNotFoundException, InvalidSchemaException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException, SchemaLifecycleException {
    SchemaMetadata schemaMetadata = createSchemaMetadata("test", SchemaCompatibility.NONE);
    SchemaBranch branch1 = new SchemaBranch("BRANCH1", schemaMetadata.getName());
    String schema1 = getSchema("/device.avsc");
    schemaRegistryClient.addSchemaMetadata(schemaMetadata);
    SchemaIdVersion schemaIdVersion1 = schemaRegistryClient.addSchemaVersion(schemaMetadata, new SchemaVersion(schema1, "initial version"));
    schemaRegistryClient.createSchemaBranch(schemaIdVersion1.getSchemaVersionId(), branch1);
    String schema2 = AvroSchemaRegistryClientUtil.getSchema("/device1.avsc");
    SchemaIdVersion schemaIdVersion2 = schemaRegistryClient.addSchemaVersion(branch1.getName(), schemaMetadata, new SchemaVersion(schema2, "modify version"));
    schemaRegistryClient.startSchemaVersionReview(schemaIdVersion2.getSchemaVersionId());
    SchemaVersionInfo schemaVersionInfoAtReviewState = schemaRegistryClient.getSchemaVersionInfo(new SchemaIdVersion(schemaIdVersion2.getSchemaVersionId()));
    Assert.assertTrue(schemaVersionInfoAtReviewState.getStateId().equals(CustomReviewCycleStates.PEER_REVIEW_STATE.getId()));
    schemaRegistryClient.transitionState(schemaIdVersion2.getSchemaVersionId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId(), "Rejected by X".getBytes());
    SchemaVersionInfo schemaVersionInfoAtRejectedState = schemaRegistryClient.getSchemaVersionInfo(new SchemaIdVersion(schemaIdVersion2.getSchemaVersionId()));
    Assert.assertTrue(schemaVersionInfoAtRejectedState.getStateId().equals(CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId()));
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 2 with SchemaBranch

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

the class SchemaRegistryClient method createSchemaBranch.

@Override
public SchemaBranch createSchemaBranch(Long schemaVersionId, SchemaBranch schemaBranch) throws SchemaBranchAlreadyExistsException, SchemaNotFoundException {
    WebTarget target = currentSchemaRegistryTargets().schemasTarget.path("versionsById/" + schemaVersionId + "/branch");
    Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {

        @Override
        public Response run() {
            return target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(schemaBranch), Response.class);
        }
    });
    int status = response.getStatus();
    if (status == Response.Status.OK.getStatusCode()) {
        String msg = response.readEntity(String.class);
        SchemaBranch returnedSchemaBranch = readEntity(msg, SchemaBranch.class);
        return returnedSchemaBranch;
    } else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
        throw new SchemaNotFoundException(response.readEntity(String.class));
    } else if (status == Response.Status.CONFLICT.getStatusCode()) {
        throw new SchemaBranchAlreadyExistsException(response.readEntity(String.class));
    } else {
        throw new RuntimeException(response.readEntity(String.class));
    }
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) WebTarget(javax.ws.rs.client.WebTarget) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)

Example 3 with SchemaBranch

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

the class SchemaBranchLifeCycleTest method addSchemaVersionToBranch.

@Test
public void addSchemaVersionToBranch() 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());
    addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
    addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc");
    Collection<SchemaVersionInfo> schemaBranch1VersionInfos = schemaRegistryClient.getAllVersions(schemaBranch1.getName(), schemaMetadata.getName());
    Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaMetadata.getName());
    Assert.assertTrue(masterSchemaVersionInfos.size() == 1);
    Assert.assertTrue(schemaBranch1VersionInfos.size() == 3);
    Long versionsInInitiatedState = schemaBranch1VersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.INITIATED.getId())).count();
    Long versionsInEnabledState = schemaBranch1VersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.ENABLED.getId())).count();
    Assert.assertTrue(versionsInInitiatedState == 2);
    Assert.assertTrue(versionsInEnabledState == 1);
}
Also used : Arrays(java.util.Arrays) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) SchemaRegistryTestProfileType(com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) SchemaRegistryTestServerClientWrapper(com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper) RunWith(org.junit.runner.RunWith) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) AvroSchemaRegistryClientUtil(com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TestName(org.junit.rules.TestName) After(org.junit.After) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) Before(org.junit.Before) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) SchemaCompatibility(com.hortonworks.registries.schemaregistry.SchemaCompatibility) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SetUtils(org.apache.commons.collections.SetUtils) Collection(java.util.Collection) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) Set(java.util.Set) SchemaRegistryClient(com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) Rule(org.junit.Rule) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) CustomParameterizedRunner(com.hortonworks.registries.schemaregistry.avro.util.CustomParameterizedRunner) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) Assert(org.junit.Assert) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 4 with SchemaBranch

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

the class SchemaBranchLifeCycleTest method deleteBranchWithRootVersionOfAnotherBranch.

@Test(expected = InvalidSchemaBranchDeletionException.class)
public void deleteBranchWithRootVersionOfAnotherBranch() throws InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, IOException, SchemaBranchAlreadyExistsException, SchemaLifecycleException, InvalidSchemaBranchDeletionException {
    SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), 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");
    addSchemaBranch("CHILD-BRANCH", schemaMetadata, schemaBranch1Version1.getSchemaVersionId());
    schemaRegistryClient.enableSchemaVersion(schemaBranch1Version1.getSchemaVersionId());
    schemaRegistryClient.archiveSchemaVersion(schemaBranch1Version1.getSchemaVersionId());
    schemaRegistryClient.deleteSchemaBranch(schemaBranch1.getId());
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Example 5 with SchemaBranch

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

the class SchemaBranchLifeCycleTest method mergeSchemaWithInvalidSchemaVersion.

@Test(expected = SchemaNotFoundException.class)
public void mergeSchemaWithInvalidSchemaVersion() 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 schemaBranch1Version1 = addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
    schemaRegistryClient.mergeSchemaVersion(schemaBranch1Version1.getSchemaVersionId() + 1);
}
Also used : SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) Test(org.junit.Test)

Aggregations

SchemaBranch (com.hortonworks.registries.schemaregistry.SchemaBranch)16 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)15 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)15 Test (org.junit.Test)15 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)6 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)5 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)4 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)4 Lists (com.google.common.collect.Lists)3 SchemaCompatibility (com.hortonworks.registries.schemaregistry.SchemaCompatibility)3 SchemaRegistryTestProfileType (com.hortonworks.registries.schemaregistry.avro.conf.SchemaRegistryTestProfileType)3 SchemaRegistryTestServerClientWrapper (com.hortonworks.registries.schemaregistry.avro.helper.SchemaRegistryTestServerClientWrapper)3 AvroSchemaRegistryClientUtil (com.hortonworks.registries.schemaregistry.avro.util.AvroSchemaRegistryClientUtil)3 CustomParameterizedRunner (com.hortonworks.registries.schemaregistry.avro.util.CustomParameterizedRunner)3 SchemaRegistryClient (com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient)3 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)3 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)3 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)3 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)3 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)3