use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext 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);
});
}
use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext 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);
});
}
use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext 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.SchemaVersionLifecycleContext in project registry by hortonworks.
the class SchemaVersionLifecycleManager method createSchemaVersionLifeCycleContextAndState.
private ImmutablePair<SchemaVersionLifecycleContext, SchemaVersionLifecycleState> createSchemaVersionLifeCycleContextAndState(Long schemaVersionId) throws SchemaNotFoundException {
// get the current state from storage for the given versionID
// we can use a query to get max value for the column for a given schema-version-id but StorageManager does not
// have API to take custom queries.
Collection<SchemaVersionStateStorable> schemaVersionStates = storageManager.find(SchemaVersionStateStorable.NAME_SPACE, Collections.singletonList(new QueryParam(SchemaVersionStateStorable.SCHEMA_VERSION_ID, schemaVersionId.toString())), Collections.singletonList(OrderByField.of(SchemaVersionStateStorable.SEQUENCE, true)));
if (schemaVersionStates.isEmpty()) {
throw new SchemaNotFoundException("No schema versions found with id " + schemaVersionId);
}
SchemaVersionStateStorable stateStorable = schemaVersionStates.iterator().next();
SchemaVersionLifecycleState schemaVersionLifecycleState = schemaVersionLifecycleStateMachine.getStates().get(stateStorable.getStateId());
SchemaVersionService schemaVersionService = createSchemaVersionService();
SchemaVersionLifecycleContext context = new SchemaVersionLifecycleContext(stateStorable.getSchemaVersionId(), stateStorable.getSequence(), schemaVersionService, schemaVersionLifecycleStateMachine, customSchemaStateExecutor);
return new ImmutablePair<>(context, schemaVersionLifecycleState);
}
use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext 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