Search in sources :

Example 1 with SchemaVersionService

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionService 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 2 with SchemaVersionService

use of com.hortonworks.registries.schemaregistry.state.SchemaVersionService 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)

Aggregations

QueryParam (com.hortonworks.registries.common.QueryParam)2 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)2 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)2 SchemaVersionService (com.hortonworks.registries.schemaregistry.state.SchemaVersionService)2 InbuiltSchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState)1 SchemaVersionLifecycleState (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState)1 ArrayList (java.util.ArrayList)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1