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