Search in sources :

Example 1 with MergeInfo

use of com.hortonworks.registries.schemaregistry.state.details.MergeInfo 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;
}
Also used : MergeInfo(com.hortonworks.registries.schemaregistry.state.details.MergeInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InitializedStateDetails(com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Aggregations

SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)1 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)1 InitializedStateDetails (com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails)1 MergeInfo (com.hortonworks.registries.schemaregistry.state.details.MergeInfo)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1