public SchemaVersionLifecycleStateMachine build() { return new SchemaVersionLifecycleStateMachine(states, transitionsWithActions , transitionsWithListeners); } }
public SchemaVersionLifecycleStateMachineInfo getSchemaVersionLifecycleStateMachineInfo() { return schemaVersionLifecycleManager.getSchemaVersionLifecycleStateMachine().toConfig(); }
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 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); } }
public SchemaVersionLifecycleManager(StorageManager storageManager, Map<String, Object> props, DefaultSchemaRegistry.SchemaMetadataFetcher schemaMetadataFetcher, SchemaBranchCache schemaBranchCache, HAServerNotificationManager haServerNotificationManager) { this.storageManager = storageManager; this.schemaMetadataFetcher = schemaMetadataFetcher; this.schemaBranchCache = schemaBranchCache; this.haServerNotificationManager = haServerNotificationManager; SchemaVersionLifecycleStateMachine.Builder builder = SchemaVersionLifecycleStateMachine.newBuilder(); DefaultSchemaRegistry.Options options = new DefaultSchemaRegistry.Options(props); schemaVersionRetriever = createSchemaVersionRetriever(); schemaVersionInfoCache = new SchemaVersionInfoCache( schemaVersionRetriever, options.getMaxSchemaCacheSize(), options.getSchemaExpiryInSecs() * 1000L); customSchemaStateExecutor = createSchemaReviewExecutor(props, builder); schemaVersionLifecycleStateMachine = builder.build(); }
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); }
public SchemaVersionLifecycleStateMachine build() { return new SchemaVersionLifecycleStateMachine(states, transitionsWithActions , transitionsWithListeners); } }