@Override public void executeReviewState(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { schemaVersionLifecycleContext.setState(inReviewState); schemaVersionLifecycleContext.updateSchemaVersionState(); }
private void transitionToState(SchemaVersionLifecycleContext context, SchemaVersionLifecycleState targetState) throws SchemaLifecycleException { if (context.getDetails() == null || context.getDetails().length == 0) throw new RuntimeException("This state transition should not be triggered through UI"); context.setState(targetState); try { context.updateSchemaVersionState(); } catch (SchemaNotFoundException e) { throw new SchemaLifecycleException(e); } }
private static void transitionToDeleteState(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(DELETED); context.updateSchemaVersionState(); context.getSchemaVersionService().deleteSchemaVersion(context.getSchemaVersionId()); }
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); } }
private void storeSchemaVersionState(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaNotFoundException { // store versions state, sequence SchemaVersionStateStorable stateStorable = new SchemaVersionStateStorable(); Long schemaVersionId = schemaVersionLifecycleContext.getSchemaVersionId(); byte stateId = schemaVersionLifecycleContext.getState().getId(); stateStorable.setSchemaVersionId(schemaVersionId); stateStorable.setSequence(schemaVersionLifecycleContext.getSequence() + 1); stateStorable.setStateId(stateId); stateStorable.setTimestamp(System.currentTimeMillis()); stateStorable.setDetails(schemaVersionLifecycleContext.getDetails()); stateStorable.setId(storageManager.nextId(SchemaVersionStateStorable.NAME_SPACE)); storageManager.add(stateStorable); // store latest state in versions entity StorableKey storableKey = new StorableKey(SchemaVersionStorable.NAME_SPACE, SchemaVersionStorable.getPrimaryKey(schemaVersionId)); SchemaVersionStorable versionedSchema = storageManager.get(storableKey); if (versionedSchema == null) { throw new SchemaNotFoundException("No Schema version exists with id " + schemaVersionId); } versionedSchema.setState(stateId); storageManager.update(versionedSchema); // invalidate schema version from cache SchemaVersionInfoCache.Key schemaVersionCacheKey = SchemaVersionInfoCache.Key.of(new SchemaIdVersion(schemaVersionId)); invalidateSchemaInAllHAServer(schemaVersionCacheKey); }
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; } }
private static void transitionToStartReview(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(START_REVIEW); // execute start review process, updation of the state should be done by schemaReviewExecutor context.getCustomSchemaStateExecutor().executeReviewState(context); }
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);
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; }
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); }
private static void transitionToStartReview(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(START_REVIEW); // execute start review process, updation of the state should be done by schemaReviewExecutor context.getCustomSchemaStateExecutor().executeReviewState(context); }
@Override public void executeReviewState(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { schemaVersionLifecycleContext.setState(CustomReviewCycleStates.PEER_REVIEW_STATE); schemaVersionLifecycleContext.updateSchemaVersionState(); } }
private static void transitionToDeleteState(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(DELETED); context.updateSchemaVersionState(); context.getSchemaVersionService().deleteSchemaVersion(context.getSchemaVersionId()); }
@Override public void executeReviewState(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaLifecycleException, SchemaNotFoundException { schemaVersionLifecycleContext.setState(inReviewState); schemaVersionLifecycleContext.updateSchemaVersionState(); }
public static void transitionToEnableState(SchemaVersionLifecycleContext context) throws SchemaNotFoundException, IncompatibleSchemaException, SchemaLifecycleException, SchemaBranchNotFoundException { Long schemaVersionId = context.getSchemaVersionId(); SchemaVersionService schemaVersionService = context.getSchemaVersionService(); context.setState(ENABLED); context.updateSchemaVersionState();
private static void transitionToArchiveState(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(ARCHIVED); context.updateSchemaVersionState(); }
public static void transitionToEnableState(SchemaVersionLifecycleContext context) throws SchemaNotFoundException, IncompatibleSchemaException, SchemaLifecycleException, SchemaBranchNotFoundException { Long schemaVersionId = context.getSchemaVersionId(); SchemaVersionService schemaVersionService = context.getSchemaVersionService(); context.setState(ENABLED); context.updateSchemaVersionState();
private static void transitionToDisableState(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(DISABLED); context.updateSchemaVersionState(); }
private static void transitionToArchiveState(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(ARCHIVED); context.updateSchemaVersionState(); }
private static void transitionToDisableState(SchemaVersionLifecycleContext context) throws SchemaLifecycleException, SchemaNotFoundException { context.setState(DISABLED); context.updateSchemaVersionState(); }