private void registerInBuiltStates() { List<Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction>> transitionActions = new ArrayList<>(); Field[] declaredFields = SchemaVersionLifecycleStates.class.getDeclaredFields(); for (Field field : declaredFields) { if (Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && InbuiltSchemaVersionLifecycleState.class.isAssignableFrom(field.getType())) { InbuiltSchemaVersionLifecycleState state = null; try { state = (InbuiltSchemaVersionLifecycleState) field.get(null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } register(state); transitionActions.addAll(state.getTransitionActions()); } } // register transitions for inbuilt states for (Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> transitionAction : transitionActions) { transition(transitionAction.getLeft(), transitionAction.getRight()); } }
/** * Registers the given state with REGISTRY. * * @param state state to be registered. * * @throws IllegalArgumentException if the given state is already registered. */ public void register(SchemaVersionLifecycleState state) { checkForInbuiltStateIds(state); SchemaVersionLifecycleState prevState = states.putIfAbsent(state.getId(), state); if (prevState != null) { throw new IllegalArgumentException("Given state is already registered as " + prevState); } }
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 void registerInBuiltStates() { List<Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction>> transitionActions = new ArrayList<>(); Field[] declaredFields = SchemaVersionLifecycleStates.class.getDeclaredFields(); for (Field field : declaredFields) { if (Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && InbuiltSchemaVersionLifecycleState.class.isAssignableFrom(field.getType())) { InbuiltSchemaVersionLifecycleState state = null; try { state = (InbuiltSchemaVersionLifecycleState) field.get(null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } register(state); transitionActions.addAll(state.getTransitionActions()); } } // register transitions for inbuilt states for (Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> transitionAction : transitionActions) { transition(transitionAction.getLeft(), transitionAction.getRight()); } }
public SchemaVersionLifecycleManager(StorageManager storageManager, Map<String, Object> props, DefaultSchemaRegistry.SchemaMetadataFetcher schemaMetadataFetcher, SchemaBranchCache schemaBranchCache, HAServerNotificationManager haServerNotificationManager) { this.storageManager = storageManager; this.schemaMetadataFetcher = schemaMetadataFetcher; this.schemaBranchCache = schemaBranchCache; this.haServerNotificationManager = haServerNotificationManager; SchemaVersionLifecycleStateMachine.Builder builder = SchemaVersionLifecycleStateMachine.newBuilder(); DefaultSchemaRegistry.Options options = new DefaultSchemaRegistry.Options(props); schemaVersionRetriever = createSchemaVersionRetriever(); schemaVersionInfoCache = new SchemaVersionInfoCache( schemaVersionRetriever, options.getMaxSchemaCacheSize(), options.getSchemaExpiryInSecs() * 1000L); customSchemaStateExecutor = createSchemaReviewExecutor(props, builder); schemaVersionLifecycleStateMachine = builder.build(); }
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); } })); }
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 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); }); }
public void registerPeerReviewState(SchemaVersionLifecycleStateMachine.Builder builder) { builder.register(CustomReviewCycleStates.PEER_REVIEW_STATE); }
public static Builder newBuilder() { return new Builder(); }
public Builder() { registerInBuiltStates(); }
public Builder() { registerInBuiltStates(); }
public static Builder newBuilder() { return new Builder(); }
@Override public void init(SchemaVersionLifecycleStateMachine.Builder builder, Byte successStateId, Byte retryStateId, Map<String, ?> props) { this.successState = builder.getStates().get(successStateId); this.retryState = builder.getStates().get(retryStateId); inReviewState = new InReviewState(successState); builder.register(inReviewState); for (Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> pair : inReviewState .getTransitionActions()) { builder.transition(pair.getLeft(), pair.getRight()); } }
@Override public void init(SchemaVersionLifecycleStateMachine.Builder builder, Byte successStateId, Byte retryStateId, Map<String, ?> props) { this.successState = builder.getStates().get(successStateId); this.retryState = builder.getStates().get(retryStateId); inReviewState = new InReviewState(successState); builder.register(inReviewState); for (Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> pair : inReviewState .getTransitionActions()) { builder.transition(pair.getLeft(), pair.getRight()); } }
/** * Registers the given state with REGISTRY. * * @param state state to be registered. * * @throws IllegalArgumentException if the given state is already registered. */ public void register(SchemaVersionLifecycleState state) { checkForInbuiltStateIds(state); SchemaVersionLifecycleState prevState = states.putIfAbsent(state.getId(), state); if (prevState != null) { throw new IllegalArgumentException("Given state is already registered as " + prevState); } }
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 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 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; }