Search in sources :

Example 1 with SchemaVersionLifecycleStateMachineInfo

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testSchemaVersionLifeCycleStateMachineConfig.

@Test
public void testSchemaVersionLifeCycleStateMachineConfig() throws Exception {
    SchemaVersionLifecycleStateMachineInfo stateMachineInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionLifecycleStateMachineInfo();
    ObjectMapper objectMapper = new ObjectMapper();
    String stateMachineAsStr = objectMapper.writeValueAsString(stateMachineInfo);
    SchemaVersionLifecycleStateMachineInfo readStateMachineInfo = objectMapper.readValue(stateMachineAsStr, SchemaVersionLifecycleStateMachineInfo.class);
    Assert.assertEquals(readStateMachineInfo, stateMachineInfo);
    // check for duplicate state/transitions
    checkDuplicateEntries(stateMachineInfo.getStates());
    checkDuplicateEntries(stateMachineInfo.getTransitions());
}
Also used : SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Example 2 with SchemaVersionLifecycleStateMachineInfo

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo in project registry by hortonworks.

the class SchemaRegistryResource method getSchemaVersionLifeCycleStates.

@GET
@Path("/schemas/versions/statemachine")
@ApiOperation(value = "Get schema version life cycle states", response = SchemaVersionInfo.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
public Response getSchemaVersionLifeCycleStates() {
    Response response;
    try {
        SchemaVersionLifecycleStateMachineInfo states = schemaRegistry.getSchemaVersionLifecycleStateMachineInfo();
        response = WSUtils.respondEntity(states, Response.Status.OK);
    } catch (Exception ex) {
        LOG.error("Encountered error while getting schema version lifecycle states", 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) SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) 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) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with SchemaVersionLifecycleStateMachineInfo

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo in project registry by hortonworks.

the class AvroSchemaRegistryClientTest method testSchemaVersionStatesThroughIds.

@Test
public void testSchemaVersionStatesThroughIds() throws Exception {
    SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(TEST_NAME_RULE.getMethodName() + "-schema").type(AvroSchemaProvider.TYPE).schemaGroup("group").compatibility(SchemaCompatibility.BOTH).build();
    String schemaName = schemaMetadata.getName();
    // build nextTransitions from state machine
    SchemaVersionLifecycleStateMachineInfo stateMachine = SCHEMA_REGISTRY_CLIENT.getSchemaVersionLifecycleStateMachineInfo();
    Map<Byte, List<SchemaVersionLifecycleStateTransition>> nextTransitionsForStateIds = new HashMap<>();
    for (SchemaVersionLifecycleStateTransition transition : stateMachine.getTransitions()) {
        List<SchemaVersionLifecycleStateTransition> nextTransitions = nextTransitionsForStateIds.computeIfAbsent(transition.getSourceStateId(), aByte -> new ArrayList<>());
        nextTransitions.add(transition);
    }
    Long id = SCHEMA_REGISTRY_CLIENT.registerSchemaMetadata(schemaMetadata);
    SchemaIdVersion schemaIdVersion_1 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-1.avsc"), "Initial version of the schema"));
    SchemaIdVersion schemaIdVersion_2 = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaName, new SchemaVersion(AvroSchemaRegistryClientUtil.getSchema("/schema-2.avsc"), "Second version of the schema"));
    // disable version 2
    SchemaVersionInfo schemaVersionInfo = SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2);
    Byte stateId = schemaVersionInfo.getStateId();
    List<SchemaVersionLifecycleStateTransition> nextTransitions = nextTransitionsForStateIds.get(stateId);
    Byte targetStateId = nextTransitions.get(0).getTargetStateId();
    SCHEMA_REGISTRY_CLIENT.transitionState(schemaVersionInfo.getId(), targetStateId, null);
    Assert.assertEquals(targetStateId, SCHEMA_REGISTRY_CLIENT.getSchemaVersionInfo(schemaIdVersion_2).getStateId());
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaVersion(com.hortonworks.registries.schemaregistry.SchemaVersion) SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) HashMap(java.util.HashMap) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition) SchemaVersionInfo(com.hortonworks.registries.schemaregistry.SchemaVersionInfo) List(java.util.List) ArrayList(java.util.ArrayList) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest) Test(org.junit.Test)

Aggregations

SchemaVersionLifecycleStateMachineInfo (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo)3 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)2 Test (org.junit.Test)2 Timed (com.codahale.metrics.annotation.Timed)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)1 SchemaIdVersion (com.hortonworks.registries.schemaregistry.SchemaIdVersion)1 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)1 SchemaVersion (com.hortonworks.registries.schemaregistry.SchemaVersion)1 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)1 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)1 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)1 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)1 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)1 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)1 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)1 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)1 SchemaVersionLifecycleStateTransition (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)1 ApiOperation (io.swagger.annotations.ApiOperation)1