Search in sources :

Example 6 with SchemaVersionLifecycleContext

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);
    });
}
Also used : SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Example 7 with SchemaVersionLifecycleContext

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);
    });
}
Also used : SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Example 8 with SchemaVersionLifecycleContext

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);
        }
    }));
}
Also used : Logger(org.slf4j.Logger) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) LoggerFactory(org.slf4j.LoggerFactory) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) CustomSchemaStateExecutor(com.hortonworks.registries.schemaregistry.state.CustomSchemaStateExecutor) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) ClientBuilder(javax.ws.rs.client.ClientBuilder) SchemaVersionLifecycleStateMachine(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachine) SchemaVersionLifecycleStateTransitionListener(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener) CustomReviewCycleStates(com.hortonworks.registries.examples.schema.lifecycle.state.CustomReviewCycleStates) Map(java.util.Map) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition) WebTarget(javax.ws.rs.client.WebTarget) SchemaVersionLifecycleStateTransitionListener(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener) WebTarget(javax.ws.rs.client.WebTarget) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Example 9 with SchemaVersionLifecycleContext

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);
}
Also used : InbuiltSchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState) SchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) QueryParam(com.hortonworks.registries.common.QueryParam) SchemaVersionService(com.hortonworks.registries.schemaregistry.state.SchemaVersionService) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Example 10 with SchemaVersionLifecycleContext

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;
    }
}
Also used : InbuiltSchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState) SchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState) SchemaVersionLifecycleStateTransitionListener(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener) SchemaVersionLifecycleStateAction(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateAction) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)

Aggregations

SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)10 SchemaVersionLifecycleStateTransition (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition)6 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)5 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)3 SchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState)3 QueryParam (com.hortonworks.registries.common.QueryParam)2 InbuiltSchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState)2 SchemaVersionLifecycleStateTransitionListener (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener)2 SchemaVersionService (com.hortonworks.registries.schemaregistry.state.SchemaVersionService)2 ArrayList (java.util.ArrayList)2 CustomReviewCycleStates (com.hortonworks.registries.examples.schema.lifecycle.state.CustomReviewCycleStates)1 CustomSchemaStateExecutor (com.hortonworks.registries.schemaregistry.state.CustomSchemaStateExecutor)1 SchemaVersionLifecycleStateAction (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateAction)1 SchemaVersionLifecycleStateMachine (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachine)1 SchemaVersionLifecycleStates (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates)1 InitializedStateDetails (com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails)1 MergeInfo (com.hortonworks.registries.schemaregistry.state.details.MergeInfo)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1