Search in sources :

Example 1 with SchemaVersionLifecycleContext

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext in project registry by hortonworks.

the class CustomReviewCycleExecutor method registerReviewedState.

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

Example 2 with SchemaVersionLifecycleContext

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext in project registry by hortonworks.

the class SchemaVersionLifecycleManager method createSchemaVersionLifeCycleContext.

public SchemaVersionLifecycleContext createSchemaVersionLifeCycleContext(Long schemaVersionId, SchemaVersionLifecycleState schemaVersionLifecycleState) 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.
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(SchemaVersionStateStorable.SCHEMA_VERSION_ID, schemaVersionId.toString()));
    queryParams.add(new QueryParam(SchemaVersionStateStorable.STATE, schemaVersionLifecycleState.getId().toString()));
    Collection<SchemaVersionStateStorable> schemaVersionStates = storageManager.find(SchemaVersionStateStorable.NAME_SPACE, queryParams, 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();
    SchemaVersionService schemaVersionService = createSchemaVersionService();
    SchemaVersionLifecycleContext context = new SchemaVersionLifecycleContext(stateStorable.getSchemaVersionId(), stateStorable.getSequence(), schemaVersionService, schemaVersionLifecycleStateMachine, customSchemaStateExecutor);
    context.setDetails(stateStorable.getDetails());
    return context;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) SchemaVersionService(com.hortonworks.registries.schemaregistry.state.SchemaVersionService) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Example 3 with SchemaVersionLifecycleContext

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext in project registry by hortonworks.

the class SchemaVersionLifecycleManager method updateSchemaVersionState.

private void updateSchemaVersionState(Long schemaVersionId, Integer sequence, Byte initialState, byte[] stateDetails) throws SchemaNotFoundException {
    try {
        SchemaVersionLifecycleContext schemaVersionLifecycleContext = new SchemaVersionLifecycleContext(schemaVersionId, sequence, createSchemaVersionService(), schemaVersionLifecycleStateMachine, customSchemaStateExecutor);
        schemaVersionLifecycleContext.setState(schemaVersionLifecycleStateMachine.getStates().get(initialState));
        schemaVersionLifecycleContext.setDetails(stateDetails);
        schemaVersionLifecycleContext.updateSchemaVersionState();
    } catch (SchemaLifecycleException e) {
        throw new RuntimeException(e);
    }
}
Also used : SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Example 4 with SchemaVersionLifecycleContext

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext in project registry by hortonworks.

the class DefaultSchemaRegistry method getAggregatedSchemaBranch.

@Override
public Collection<AggregatedSchemaBranch> getAggregatedSchemaBranch(String schemaName) throws SchemaNotFoundException, SchemaBranchNotFoundException {
    Collection<AggregatedSchemaBranch> aggregatedSchemaBranches = new ArrayList<>();
    for (SchemaBranch schemaBranch : getSchemaBranches(schemaName)) {
        Long rootVersion = schemaBranch.getName().equals(SchemaBranch.MASTER_BRANCH) ? null : schemaVersionLifecycleManager.getRootVersion(schemaBranch).getId();
        Collection<SchemaVersionInfo> schemaVersionInfos = getAllVersions(schemaBranch.getName(), schemaName);
        schemaVersionInfos.stream().forEach(schemaVersionInfo -> {
            SchemaVersionLifecycleContext context = null;
            try {
                context = schemaVersionLifecycleManager.createSchemaVersionLifeCycleContext(schemaVersionInfo.getId(), SchemaVersionLifecycleStates.INITIATED);
                MergeInfo mergeInfo = null;
                if (context.getDetails() == null) {
                    mergeInfo = null;
                } else {
                    try {
                        InitializedStateDetails details = ObjectMapperUtils.deserialize(context.getDetails(), InitializedStateDetails.class);
                        mergeInfo = details.getMergeInfo();
                    } catch (IOException e) {
                        throw new RuntimeException(String.format("Failed to serialize state details of schema version : '%s'", context.getSchemaVersionId()), e);
                    }
                }
                schemaVersionInfo.setMergeInfo(mergeInfo);
            } catch (SchemaNotFoundException e) {
                // If the schema version has never been in 'INITIATED' state, then SchemaNotFoundException error is thrown which is expected
                schemaVersionInfo.setMergeInfo(null);
            }
        });
        aggregatedSchemaBranches.add(new AggregatedSchemaBranch(schemaBranch, rootVersion, schemaVersionInfos));
    }
    return aggregatedSchemaBranches;
}
Also used : MergeInfo(com.hortonworks.registries.schemaregistry.state.details.MergeInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InitializedStateDetails(com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Example 5 with SchemaVersionLifecycleContext

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext in project registry by hortonworks.

the class CustomReviewCycleExecutor method registerTechnicalLeadReviewState.

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);
    });
}
Also used : 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