Search in sources :

Example 1 with SchemaBranchNotFoundException

use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.

the class SchemaVersionLifecycleManager method createSchemaVersion.

private SchemaVersionInfo createSchemaVersion(String schemaBranchName, SchemaMetadata schemaMetadata, Long schemaMetadataId, SchemaVersion schemaVersion) throws IncompatibleSchemaException, InvalidSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException {
    Preconditions.checkNotNull(schemaBranchName, "schemaBranchName must not be null");
    Preconditions.checkNotNull(schemaMetadataId, "schemaMetadataId must not be null");
    String type = schemaMetadata.getType();
    if (getSchemaProvider(type) == null) {
        throw new UnsupportedSchemaTypeException("Given schema type " + type + " not supported");
    }
    SchemaBranch schemaBranch = null;
    try {
        schemaBranch = schemaBranchCache.get(SchemaBranchCache.Key.of(new SchemaBranchKey(schemaBranchName, schemaMetadata.getName())));
    } catch (SchemaBranchNotFoundException e) {
    // Ignore this error
    }
    if (schemaBranch == null) {
        if (getAllVersions(schemaBranchName, schemaMetadata.getName()).size() != 0)
            throw new RuntimeException(String.format("Schema name : '%s' and branch name : '%s' has schema version, yet failed to obtain schema branch instance", schemaMetadata.getName(), schemaBranchName));
    }
    // generate fingerprint, it parses the schema and checks for semantic validation.
    // throws InvalidSchemaException for invalid schemas.
    final String fingerprint = getFingerprint(type, schemaVersion.getSchemaText());
    final String schemaName = schemaMetadata.getName();
    SchemaVersionStorable schemaVersionStorable = new SchemaVersionStorable();
    final Long schemaVersionStorableId = storageManager.nextId(schemaVersionStorable.getNameSpace());
    schemaVersionStorable.setId(schemaVersionStorableId);
    schemaVersionStorable.setSchemaMetadataId(schemaMetadataId);
    schemaVersionStorable.setFingerprint(fingerprint);
    schemaVersionStorable.setName(schemaName);
    schemaVersionStorable.setSchemaText(schemaVersion.getSchemaText());
    schemaVersionStorable.setDescription(schemaVersion.getDescription());
    schemaVersionStorable.setTimestamp(System.currentTimeMillis());
    schemaVersionStorable.setState(DEFAULT_VERSION_STATE.getId());
    if (!schemaBranchName.equals(SchemaBranch.MASTER_BRANCH)) {
        schemaVersion.setState(SchemaVersionLifecycleStates.INITIATED.getId());
        schemaVersion.setStateDetails(null);
    }
    // take a lock for a schema with same name.
    int retryCt = 0;
    while (true) {
        try {
            Integer version = 0;
            Byte initialState = schemaVersion.getInitialState();
            if (schemaMetadata.isEvolve()) {
                // if the given version is added with enabled or initiated state then only check for compatibility
                if (SchemaVersionLifecycleStates.ENABLED.getId().equals(initialState) || SchemaVersionLifecycleStates.INITIATED.getId().equals(initialState)) {
                    CompatibilityResult compatibilityResult = checkCompatibility(schemaBranchName, schemaName, schemaVersion.getSchemaText());
                    if (!compatibilityResult.isCompatible()) {
                        String errMsg = String.format("Given schema is not compatible with latest schema versions. \n" + "Error location: [%s] \n" + "Error encountered is: [%s]", compatibilityResult.getErrorLocation(), compatibilityResult.getErrorMessage());
                        LOG.error(errMsg);
                        throw new IncompatibleSchemaException(errMsg);
                    }
                }
                SchemaVersionInfo latestSchemaVersionInfo = getLatestSchemaVersionInfo(schemaName);
                if (latestSchemaVersionInfo != null) {
                    version = latestSchemaVersionInfo.getVersion();
                }
            }
            schemaVersionStorable.setVersion(version + 1);
            storageManager.add(schemaVersionStorable);
            updateSchemaVersionState(schemaVersionStorable.getId(), 1, initialState, schemaVersion.getStateDetails());
            break;
        } catch (StorageException e) {
            // optimistic to try the next try would be successful. When retry attempts are exhausted, throw error back to invoker.
            if (++retryCt == DEFAULT_RETRY_CT) {
                LOG.error("Giving up after retry attempts [{}] while trying to add new version of schema with metadata [{}]", retryCt, schemaMetadata, e);
                throw e;
            }
            LOG.debug("Encountered storage exception while trying to add a new version, attempting again : [{}] with error: [{}]", retryCt, e);
        }
    }
    // fetching this as the ID may have been set by storage manager.
    Long schemaInstanceId = schemaVersionStorable.getId();
    SchemaBranchVersionMapping schemaBranchVersionMapping = new SchemaBranchVersionMapping(schemaBranch.getId(), schemaInstanceId);
    storageManager.add(schemaBranchVersionMapping);
    String storableNamespace = new SchemaFieldInfoStorable().getNameSpace();
    List<SchemaFieldInfo> schemaFieldInfos = getSchemaProvider(type).generateFields(schemaVersionStorable.getSchemaText());
    for (SchemaFieldInfo schemaFieldInfo : schemaFieldInfos) {
        final Long fieldInstanceId = storageManager.nextId(storableNamespace);
        SchemaFieldInfoStorable schemaFieldInfoStorable = SchemaFieldInfoStorable.fromSchemaFieldInfo(schemaFieldInfo, fieldInstanceId);
        schemaFieldInfoStorable.setSchemaInstanceId(schemaInstanceId);
        schemaFieldInfoStorable.setTimestamp(System.currentTimeMillis());
        storageManager.add(schemaFieldInfoStorable);
    }
    return schemaVersionStorable.toSchemaVersionInfo();
}
Also used : SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) InvalidSchemaBranchVersionMapping(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping) StorageException(com.hortonworks.registries.storage.exception.StorageException)

Example 2 with SchemaBranchNotFoundException

use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.

the class SchemaVersionLifecycleManager method mergeSchemaVersion.

public SchemaVersionMergeResult mergeSchemaVersion(Long schemaVersionId, SchemaVersionMergeStrategy schemaVersionMergeStrategy) throws SchemaNotFoundException, IncompatibleSchemaException {
    try {
        SchemaVersionInfo schemaVersionInfo = getSchemaVersionInfo(new SchemaIdVersion(schemaVersionId));
        SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaVersionInfo.getName());
        Set<SchemaBranch> schemaBranches = getSchemaBranches(schemaVersionId).stream().filter(schemaBranch -> {
            try {
                return !getRootVersion(schemaBranch).getId().equals(schemaVersionId);
            } catch (SchemaNotFoundException e) {
                throw new RuntimeException(e);
            }
        }).collect(Collectors.toSet());
        if (schemaBranches.size() > 1) {
            throw new SchemaVersionMergeException(String.format("Can't determine a unique schema branch for schema version id : '%s'", schemaVersionId));
        } else if (schemaBranches.size() == 0) {
            throw new SchemaVersionMergeException(String.format("Schema version id : '%s' is not associated with any branch", schemaVersionId));
        }
        Long schemaBranchId = schemaBranches.iterator().next().getId();
        SchemaBranch schemaBranch = schemaBranchCache.get(SchemaBranchCache.Key.of(schemaBranchId));
        if (schemaVersionMergeStrategy.equals(SchemaVersionMergeStrategy.PESSIMISTIC)) {
            SchemaVersionInfo latestSchemaVersion = getLatestEnabledSchemaVersionInfo(SchemaBranch.MASTER_BRANCH, schemaMetadataInfo.getSchemaMetadata().getName());
            SchemaVersionInfo rootSchemaVersion = getRootVersion(schemaBranch);
            if (!latestSchemaVersion.getId().equals(rootSchemaVersion.getId())) {
                throw new SchemaVersionMergeException(String.format("The latest version of '%s' is different from the root version of the branch : '%s'", SchemaBranch.MASTER_BRANCH, schemaMetadataInfo.getSchemaMetadata().getName()));
            }
        }
        byte[] initializedStateDetails;
        try {
            initializedStateDetails = ObjectMapperUtils.serialize(new InitializedStateDetails(schemaBranch.getName(), schemaVersionInfo.getId()));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(String.format("Failed to serialize initializedState for %s and %s", schemaBranch.getName(), schemaVersionInfo.getId()));
        }
        SchemaVersionInfo createdSchemaVersionInfo;
        try {
            SchemaVersionInfo existingSchemaVersionInfo = findSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadataInfo.getSchemaMetadata().getType(), schemaVersionInfo.getSchemaText(), schemaMetadataInfo.getSchemaMetadata().getName());
            if (existingSchemaVersionInfo != null) {
                String mergeMessage = String.format("Given version %d is already merged to master with version %d", schemaVersionId, existingSchemaVersionInfo.getVersion());
                LOG.info(mergeMessage);
                return new SchemaVersionMergeResult(new SchemaIdVersion(schemaMetadataInfo.getId(), existingSchemaVersionInfo.getVersion(), existingSchemaVersionInfo.getId()), mergeMessage);
            }
            createdSchemaVersionInfo = createSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadataInfo.getSchemaMetadata(), schemaMetadataInfo.getId(), new SchemaVersion(schemaVersionInfo.getSchemaText(), schemaVersionInfo.getDescription(), SchemaVersionLifecycleStates.INITIATED.getId(), initializedStateDetails));
        } catch (InvalidSchemaException e) {
            throw new SchemaVersionMergeException(String.format("Failed to merge schema version : '%s'", schemaVersionId.toString()), e);
        }
        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 == null || schemaVersionStates.isEmpty()) {
            throw new RuntimeException(String.format("The database doesn't have any state transition recorded for the schema version id : '%s'", schemaVersionId));
        }
        updateSchemaVersionState(createdSchemaVersionInfo.getId(), schemaVersionStates.iterator().next().getSequence(), SchemaVersionLifecycleStates.ENABLED.getId(), null);
        String mergeMessage = String.format("Given version %d is merged successfully to master with version %d", schemaVersionId, createdSchemaVersionInfo.getVersion());
        LOG.info(mergeMessage);
        return new SchemaVersionMergeResult(new SchemaIdVersion(schemaMetadataInfo.getId(), createdSchemaVersionInfo.getVersion(), createdSchemaVersionInfo.getId()), mergeMessage);
    } catch (SchemaBranchNotFoundException e) {
        throw new SchemaVersionMergeException(String.format("Failed to merge schema version : '%s'", schemaVersionId.toString()), e);
    }
}
Also used : ObjectMapperUtils(com.hortonworks.registries.schemaregistry.utils.ObjectMapperUtils) SchemaBranchCache(com.hortonworks.registries.schemaregistry.cache.SchemaBranchCache) Arrays(java.util.Arrays) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) InitializedStateDetails(com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) QueryParam(com.hortonworks.registries.common.QueryParam) InbuiltSchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.InbuiltSchemaVersionLifecycleState) LoggerFactory(org.slf4j.LoggerFactory) Storable(com.hortonworks.registries.storage.Storable) OrderByField(com.hortonworks.registries.storage.OrderByField) Hex(org.apache.commons.codec.binary.Hex) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) SchemaVersionLifecycleStateTransitionListener(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransitionListener) Map(java.util.Map) SchemaVersionLifecycleStateTransition(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateTransition) InvalidSchemaBranchVersionMapping(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) Logger(org.slf4j.Logger) SchemaVersionLifecycleStateAction(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateAction) SchemaVersionService(com.hortonworks.registries.schemaregistry.state.SchemaVersionService) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) Collection(java.util.Collection) SchemaVersionMergeException(com.hortonworks.registries.schemaregistry.errors.SchemaVersionMergeException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CustomSchemaStateExecutor(com.hortonworks.registries.schemaregistry.state.CustomSchemaStateExecutor) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) Collectors(java.util.stream.Collectors) StorageException(com.hortonworks.registries.storage.exception.StorageException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) List(java.util.List) SchemaVersionInfoCache(com.hortonworks.registries.schemaregistry.cache.SchemaVersionInfoCache) SchemaVersionLifecycleStateMachine(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachine) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) Preconditions(com.google.common.base.Preconditions) SchemaVersionLifecycleState(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleState) StorableKey(com.hortonworks.registries.storage.StorableKey) StorageManager(com.hortonworks.registries.storage.StorageManager) Collections(java.util.Collections) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InitializedStateDetails(com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) QueryParam(com.hortonworks.registries.common.QueryParam) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionMergeException(com.hortonworks.registries.schemaregistry.errors.SchemaVersionMergeException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with SchemaBranchNotFoundException

use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.

the class SchemaRegistryResource method findAggregatedSchemas.

@GET
@Path("/search/schemas/aggregated")
@ApiOperation(value = "Search for schemas containing the given name and description", notes = "Search the schemas for given name and description, return a list of schemas that contain the field.", response = AggregatedSchemaMetadataInfo.class, responseContainer = "Collection", tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response findAggregatedSchemas(@Context UriInfo uriInfo) {
    MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    try {
        Collection<SchemaMetadataInfo> schemaMetadataInfos = findSchemaMetadataInfos(uriInfo.getQueryParameters());
        List<AggregatedSchemaMetadataInfo> aggregatedSchemaMetadataInfos = new ArrayList<>();
        for (SchemaMetadataInfo schemaMetadataInfo : schemaMetadataInfos) {
            SchemaMetadata schemaMetadata = schemaMetadataInfo.getSchemaMetadata();
            List<SerDesInfo> serDesInfos = new ArrayList<>(schemaRegistry.getSerDes(schemaMetadataInfo.getSchemaMetadata().getName()));
            aggregatedSchemaMetadataInfos.add(new AggregatedSchemaMetadataInfo(schemaMetadata, schemaMetadataInfo.getId(), schemaMetadataInfo.getTimestamp(), schemaRegistry.getAggregatedSchemaBranch(schemaMetadata.getName()), serDesInfos));
        }
        return WSUtils.respondEntities(aggregatedSchemaMetadataInfos, Response.Status.OK);
    } catch (SchemaBranchNotFoundException e) {
        return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
    } catch (Exception ex) {
        LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex);
        return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
    }
}
Also used : SchemaMetadata(com.hortonworks.registries.schemaregistry.SchemaMetadata) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) ArrayList(java.util.ArrayList) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SerDesInfo(com.hortonworks.registries.schemaregistry.SerDesInfo) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) FileNotFoundException(java.io.FileNotFoundException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException) AggregatedSchemaMetadataInfo(com.hortonworks.registries.schemaregistry.AggregatedSchemaMetadataInfo) SchemaMetadataInfo(com.hortonworks.registries.schemaregistry.SchemaMetadataInfo) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with SchemaBranchNotFoundException

use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.

the class SchemaRegistryResource method addSchemaVersion.

@POST
@Path("/schemas/{name}/versions")
@ApiOperation(value = "Register a new version of the schema", notes = "Registers the given schema version to schema with name if the given schemaText is not registered as a version for this schema, " + "and returns respective version number." + "In case of incompatible schema errors, it throws error message like 'Unable to read schema: <> using schema <>' ", response = Integer.class, tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response addSchemaVersion(@QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "Details about the schema", required = true) SchemaVersion schemaVersion, @Context UriInfo uriInfo) {
    return handleLeaderAction(uriInfo, () -> {
        Response response;
        try {
            LOG.info("adding schema version for name [{}] with [{}]", schemaName, schemaVersion);
            SchemaIdVersion version = schemaRegistry.addSchemaVersion(schemaBranchName, schemaName, schemaVersion);
            response = WSUtils.respondEntity(version.getVersion(), Response.Status.CREATED);
        } catch (InvalidSchemaException ex) {
            LOG.error("Invalid schema error encountered while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex);
            response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.INVALID_SCHEMA, ex.getMessage());
        } catch (IncompatibleSchemaException ex) {
            LOG.error("Incompatible schema error encountered while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex);
            response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA, ex.getMessage());
        } catch (UnsupportedSchemaTypeException ex) {
            LOG.error("Unsupported schema type encountered while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex);
            response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.UNSUPPORTED_SCHEMA_TYPE, ex.getMessage());
        } catch (SchemaBranchNotFoundException e) {
            return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
        } catch (Exception ex) {
            LOG.error("Encountered error while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex, ex);
            response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
        }
        return response;
    });
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) SchemaIdVersion(com.hortonworks.registries.schemaregistry.SchemaIdVersion) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) FileNotFoundException(java.io.FileNotFoundException) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException) Path(javax.ws.rs.Path) UnitOfWork(com.hortonworks.registries.common.transaction.UnitOfWork) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with SchemaBranchNotFoundException

use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.

the class DefaultSchemaRegistry method getSchemaBranch.

private SchemaBranch getSchemaBranch(Long id) throws SchemaBranchNotFoundException {
    List<QueryParam> schemaBranchQueryParam = new ArrayList<>();
    schemaBranchQueryParam.add(new QueryParam(SchemaBranchStorable.ID, id.toString()));
    Collection<SchemaBranchStorable> schemaBranchStorables = storageManager.find(SchemaBranchStorable.NAME_SPACE, schemaBranchQueryParam);
    if (schemaBranchStorables == null || schemaBranchStorables.isEmpty())
        throw new SchemaBranchNotFoundException(String.format("Schema branch with id : '%s' not found", id.toString()));
    // size of the collection will always be less than 2, as ID is a primary key, so no need handle the case where size > 1
    return schemaBranchStorables.iterator().next().toSchemaBranch();
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) ArrayList(java.util.ArrayList)

Aggregations

SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)16 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)12 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)11 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)10 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)10 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)10 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)10 IOException (java.io.IOException)9 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)8 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)6 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 Collectors (java.util.stream.Collectors)6 Timed (com.codahale.metrics.annotation.Timed)5 Lists (com.google.common.collect.Lists)5 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)5 UnitOfWork (com.hortonworks.registries.common.transaction.UnitOfWork)5 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)5 SchemaVersionLifecycleStates (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates)5 ApiOperation (io.swagger.annotations.ApiOperation)5