Search in sources :

Example 1 with SchemaVersionLifecycleStateTransitionListener

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);
        }
    }));
}
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 2 with SchemaVersionLifecycleStateTransitionListener

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;
    }
}
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

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