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