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