Search in sources :

Example 1 with SchemaVersionLifecycleStateAction

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

the class SchemaVersionLifecycleManager method executeState.

public void executeState(Long schemaVersionId, Byte targetState, byte[] transitionDetails) throws SchemaLifecycleException, SchemaNotFoundException {
    ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> schemaLifeCycleContextAndState = createSchemaVersionLifeCycleContextAndState(schemaVersionId);
    SchemaVersionLifecycleContext schemaVersionLifecycleContext = schemaLifeCycleContextAndState.getLeft();
    SchemaVersionLifecycleState currentState = schemaLifeCycleContextAndState.getRight();
    schemaVersionLifecycleContext.setState(currentState);
    schemaVersionLifecycleContext.setDetails(transitionDetails);
    SchemaVersionLifecycleStateTransition transition = new SchemaVersionLifecycleStateTransition(currentState.getId(), targetState);
    SchemaVersionLifecycleStateAction action = schemaVersionLifecycleContext.getSchemaLifeCycleStatesMachine().getTransitions().get(transition);
    try {
        List<SchemaVersionLifecycleStateTransitionListener> listeners = schemaVersionLifecycleContext.getSchemaLifeCycleStatesMachine().getListeners().getOrDefault(transition, DEFAULT_LISTENERS);
        listeners.stream().forEach(listener -> listener.preStateTransition(schemaVersionLifecycleContext));
        action.execute(schemaVersionLifecycleContext);
        listeners.stream().forEach(listener -> listener.postStateTransition(schemaVersionLifecycleContext));
    } catch (SchemaLifecycleException e) {
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof SchemaNotFoundException) {
            throw (SchemaNotFoundException) cause;
        }
        throw e;
    }
}
Also used : InbuiltSchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState) SchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState) SchemaVersionLifecycleStateTransitionListener(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener) SchemaVersionLifecycleStateAction(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateAction) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Aggregations

SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 InbuiltSchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState)1 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)1 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)1 SchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState)1 SchemaVersionLifecycleStateAction (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateAction)1 SchemaVersionLifecycleStateTransition (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)1 SchemaVersionLifecycleStateTransitionListener (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener)1