private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createStartReviewTransitionActionPair(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, START_REVIEW.getId(), "StartReview", "Starts review state"), context -> { try { transitionToStartReview(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
public Builder transition(SchemaVersionLifecycleStateTransition transition, SchemaVersionLifecycleStateAction action) { Byte sourceStateId = transition.getSourceStateId(); Byte targetStateId = transition.getTargetStateId(); checkStatesRegistered(sourceStateId, targetStateId); SchemaVersionLifecycleStateAction existingTransitionAction = transitionsWithActions.putIfAbsent(transition, action); if (existingTransitionAction != null) { throw new IllegalArgumentException("Given transition already exists, from: [" + sourceStateId + "] to: [" + targetStateId + "]"); } return this; }
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); } })); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createStartReviewTransitionActionPair(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, START_REVIEW.getId(), "StartReview", "Starts review state"), context -> { try { transitionToStartReview(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
public Builder transition(SchemaVersionLifecycleStateTransition transition, SchemaVersionLifecycleStateAction action) { Byte sourceStateId = transition.getSourceStateId(); Byte targetStateId = transition.getTargetStateId(); checkStatesRegistered(sourceStateId, targetStateId); SchemaVersionLifecycleStateAction existingTransitionAction = transitionsWithActions.putIfAbsent(transition, action); if (existingTransitionAction != null) { throw new IllegalArgumentException("Given transition already exists, from: [" + sourceStateId + "] to: [" + targetStateId + "]"); } return this; }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDisableAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DISABLED.getId(), "Disable", "Disables the schema version"), context -> { try { transitionToDisableState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
for (SchemaVersionLifecycleStateTransition transition : stateMachine.getTransitions()) { List<SchemaVersionLifecycleStateTransition> nextTransitions = nextTransitionsForStateIds.computeIfAbsent(transition .getSourceStateId(), aByte -> new ArrayList<>()); nextTransitions.add(transition); List<SchemaVersionLifecycleStateTransition> nextTransitions = nextTransitionsForStateIds.get(stateId); Byte targetStateId = nextTransitions.get(0).getTargetStateId(); SCHEMA_REGISTRY_CLIENT.transitionState(schemaVersionInfo.getId(), targetStateId, null);
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createArchiveTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ARCHIVED.getId(), "Archive", "Archives the schema version"), context -> { try { transitionToArchiveState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createEnableTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ENABLED.getId(), "Enable", "Enables the schema version"), context -> { try { transitionToEnableState(context); } catch (SchemaNotFoundException | IncompatibleSchemaException | SchemaBranchNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDisableAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DISABLED.getId(), "Disable", "Disables the schema version"), context -> { try { transitionToDisableState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createArchiveTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ARCHIVED.getId(), "Archive", "Archives the schema version"), context -> { try { transitionToArchiveState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createEnableTransitionAction(Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, ENABLED.getId(), "Enable", "Enables the schema version"), context -> { try { transitionToEnableState(context); } catch (SchemaNotFoundException | IncompatibleSchemaException | SchemaBranchNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDeleteTransitionActionPair( Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DELETED.getId(), "Delete", "Deletes the schema version"), context -> { try { transitionToDeleteState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private static Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> createDeleteTransitionActionPair( Byte sourceStateId) { return Pair.of(new SchemaVersionLifecycleStateTransition(sourceStateId, DELETED.getId(), "Delete", "Deletes the schema version"), context -> { try { transitionToDeleteState(context); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }); }
private InReviewState(final SchemaVersionLifecycleState targetState) { super("InReview", (byte) 32, "Finish the schema version." ); SchemaVersionLifecycleStateTransition stateTransition = new SchemaVersionLifecycleStateTransition(getId(), targetState.getId(), "FinishReview", "Finish schema review process"); SchemaVersionLifecycleStateAction stateAction = context -> { context.setState(targetState); try { context.updateSchemaVersionState(); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }; transitionActionPair = Collections.singletonList(Pair.of(stateTransition, stateAction)); }
private InReviewState(final SchemaVersionLifecycleState targetState) { super("InReview", (byte) 32, "Finish the schema version." ); SchemaVersionLifecycleStateTransition stateTransition = new SchemaVersionLifecycleStateTransition(getId(), targetState.getId(), "FinishReview", "Finish schema review process"); SchemaVersionLifecycleStateAction stateAction = context -> { context.setState(targetState); try { context.updateSchemaVersionState(); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }; transitionActionPair = Collections.singletonList(Pair.of(stateTransition, stateAction)); }
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); }); }
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); }); }
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); }); }
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); }); }