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());
}
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;
}
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());
}
Aggregations