Search in sources :

Example 1 with SchemaVersionLifecycleStateTransition

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

the class CustomReviewCycleExecutor method registerReviewedState.

public void registerReviewedState(SchemaVersionLifecycleStateMachine.Builder builder) {
    builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), SchemaVersionLifecycleStates.REVIEWED.getId(), SchemaVersionLifecycleStates.REVIEWED.getName(), SchemaVersionLifecycleStates.REVIEWED.getDescription()), (SchemaVersionLifecycleContext context) -> {
        // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database
        LOG.debug("Making a transition from 'TECHNICAL LEAD REVIEW' to 'REVIEWED' state");
        transitionToState(context, SchemaVersionLifecycleStates.REVIEWED);
    });
}
Also used : SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Example 2 with SchemaVersionLifecycleStateTransition

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

the class CustomReviewCycleExecutor method registerTechnicalLeadReviewState.

public void registerTechnicalLeadReviewState(SchemaVersionLifecycleStateMachine.Builder builder) {
    builder.register(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE);
    builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getName(), CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getDescription()), (SchemaVersionLifecycleContext context) -> {
        // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database
        LOG.debug("Making a transition from 'PEER REVIEW' to 'TECHNICAL LEAD REVIEW' state");
        transitionToState(context, CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE);
    });
}
Also used : SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Example 3 with SchemaVersionLifecycleStateTransition

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

the class CustomReviewCycleExecutor method registerChangesRequiredState.

public void registerChangesRequiredState(SchemaVersionLifecycleStateMachine.Builder builder) {
    builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getName(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getDescription()), (SchemaVersionLifecycleContext context) -> {
        // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database
        LOG.debug("Making a transition from 'PEER REVIEW' to 'REJECTED' state");
        transitionToState(context, SchemaVersionLifecycleStates.CHANGES_REQUIRED);
    });
    builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getId(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getName(), SchemaVersionLifecycleStates.CHANGES_REQUIRED.getDescription()), (SchemaVersionLifecycleContext context) -> {
        // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database
        LOG.debug("Making a transition from 'TECHNICAL LEAD REVIEW' to 'REJECTED' state");
        transitionToState(context, SchemaVersionLifecycleStates.CHANGES_REQUIRED);
    });
}
Also used : SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Example 4 with SchemaVersionLifecycleStateTransition

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

the class CustomReviewCycleExecutor method registerRejectedState.

public void registerRejectedState(SchemaVersionLifecycleStateMachine.Builder builder) {
    builder.register(CustomReviewCycleStates.REJECTED_REVIEW_STATE);
    builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.PEER_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getName(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getDescription()), (SchemaVersionLifecycleContext context) -> {
        // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database
        LOG.debug("Making a transition from 'PEER REVIEW' to 'REJECTED' state");
        transitionToState(context, CustomReviewCycleStates.REJECTED_REVIEW_STATE);
    });
    builder.transition(new SchemaVersionLifecycleStateTransition(CustomReviewCycleStates.TECHNICAL_LEAD_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getId(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getName(), CustomReviewCycleStates.REJECTED_REVIEW_STATE.getDescription()), (SchemaVersionLifecycleContext context) -> {
        // Plugin a custom code to trigger as a part of the state transition, here we just record the state change in the database
        LOG.debug("Making a transition from 'TECHNICAL LEAD REVIEW' to 'REJECTED' state");
        transitionToState(context, CustomReviewCycleStates.REJECTED_REVIEW_STATE);
    });
}
Also used : SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Example 5 with SchemaVersionLifecycleStateTransition

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

SchemaVersionLifecycleStateTransition (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)6 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)5 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)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 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 InbuiltSchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState)1 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)1 SchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState)1 SchemaVersionLifecycleStateAction (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateAction)1 SchemaVersionLifecycleStateMachineInfo (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo)1 SchemaVersionLifecycleStateTransitionListener (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.Test)1