use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener in project registry by hortonworks.
the class CustomReviewCycleExecutor method registerNotificationsWithSchemaEnabled.
public void registerNotificationsWithSchemaEnabled(SchemaVersionLifecycleStateMachine.Builder builder, Map<String, ?> props) {
builder.getTransitionsWithActions().entrySet().stream().filter(transitionAction -> transitionAction.getKey().getTargetStateId().equals(SchemaVersionLifecycleStates.ENABLED.getId())).forEach(transitionAction -> builder.registerListener(transitionAction.getKey(), new SchemaVersionLifecycleStateTransitionListener() {
@Override
public void preStateTransition(SchemaVersionLifecycleContext context) {
LOG.debug("preStateTransition() does nothing for this state transition");
}
@Override
public void postStateTransition(SchemaVersionLifecycleContext context) {
LOG.debug("postStateTransition() calling external review service to notify the state transition");
Long schemaVersionId = context.getSchemaVersionId();
WebTarget webTarget = ClientBuilder.newClient().target(props.get("review.service.url").toString()).path("/v1/transition/schema/" + schemaVersionId + "/notify");
webTarget.request().post(null);
}
}));
}
use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener 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