Search in sources :

Example 6 with SchemaNotFoundException

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

the class SchemaRegistryClient method createSchemaBranch.

@Override
public SchemaBranch createSchemaBranch(Long schemaVersionId, SchemaBranch schemaBranch) throws SchemaBranchAlreadyExistsException, SchemaNotFoundException {
    WebTarget target = currentSchemaRegistryTargets().schemasTarget.path("versionsById/" + schemaVersionId + "/branch");
    Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {

        @Override
        public Response run() {
            return target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(schemaBranch), Response.class);
        }
    });
    int status = response.getStatus();
    if (status == Response.Status.OK.getStatusCode()) {
        String msg = response.readEntity(String.class);
        SchemaBranch returnedSchemaBranch = readEntity(msg, SchemaBranch.class);
        return returnedSchemaBranch;
    } else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
        throw new SchemaNotFoundException(response.readEntity(String.class));
    } else if (status == Response.Status.CONFLICT.getStatusCode()) {
        throw new SchemaBranchAlreadyExistsException(response.readEntity(String.class));
    } else {
        throw new RuntimeException(response.readEntity(String.class));
    }
}
Also used : Response(javax.ws.rs.core.Response) CatalogResponse(com.hortonworks.registries.common.catalog.CatalogResponse) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) SchemaBranch(com.hortonworks.registries.schemaregistry.SchemaBranch) WebTarget(javax.ws.rs.client.WebTarget) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)

Example 7 with SchemaNotFoundException

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

the class SchemaVersionLifecycleManager method createSchemaVersionLifeCycleContext.

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;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) SchemaVersionService(com.hortonworks.registries.schemaregistry.state.SchemaVersionService) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)

Example 8 with SchemaNotFoundException

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

the class SchemaVersionLifecycleManager method storeSchemaVersionState.

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.addOrUpdate(versionedSchema);
    // invalidate schema version from cache
    SchemaVersionInfoCache.Key schemaVersionCacheKey = SchemaVersionInfoCache.Key.of(new SchemaIdVersion(schemaVersionId));
    invalidateSchemaInAllHAServer(schemaVersionCacheKey);
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) SchemaVersionInfoCache(com.hortonworks.registries.schemaregistry.cache.SchemaVersionInfoCache)

Example 9 with SchemaNotFoundException

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

the class SchemaVersionLifecycleManager method deleteSchemaVersionBranchMapping.

private void deleteSchemaVersionBranchMapping(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException {
    List<QueryParam> schemaVersionMappingStorableQueryParams = Lists.newArrayList();
    schemaVersionMappingStorableQueryParams.add(new QueryParam(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, schemaVersionId.toString()));
    List<OrderByField> orderByFields = new ArrayList<>();
    orderByFields.add(OrderByField.of(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, false));
    Collection<SchemaBranchVersionMapping> storables = storageManager.find(SchemaBranchVersionMapping.NAMESPACE, schemaVersionMappingStorableQueryParams, orderByFields);
    if (storables == null || storables.isEmpty()) {
        LOG.debug("No need to delete schema version mapping as the database did a cascade delete");
        return;
    }
    if (storables.size() > 1) {
        List<String> branchNamesTiedToSchema = storables.stream().map(storable -> schemaBranchCache.get(SchemaBranchCache.Key.of(storable.getSchemaBranchId())).getName()).collect(Collectors.toList());
        throw new SchemaLifecycleException(String.format("Schema version with id : '%s' is tied with more than one branch : '%s' ", schemaVersionId.toString(), Arrays.toString(branchNamesTiedToSchema.toArray())));
    }
    storageManager.remove(new StorableKey(SchemaBranchVersionMapping.NAMESPACE, storables.iterator().next().getPrimaryKey()));
}
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) QueryParam(com.hortonworks.registries.common.QueryParam) OrderByField(com.hortonworks.registries.storage.OrderByField) StorableKey(com.hortonworks.registries.storage.StorableKey) ArrayList(java.util.ArrayList) InvalidSchemaBranchVersionMapping(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)

Example 10 with SchemaNotFoundException

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

the class SchemaVersionLifecycleManager method getAllVersions.

public Collection<SchemaVersionInfo> getAllVersions(final String schemaName) throws SchemaNotFoundException {
    List<QueryParam> queryParams = Collections.singletonList(new QueryParam(SchemaVersionStorable.NAME, schemaName));
    SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
    if (schemaMetadataInfo == null) {
        throw new SchemaNotFoundException("Schema not found with name " + schemaName);
    }
    Collection<SchemaVersionStorable> storables = storageManager.find(SchemaVersionStorable.NAME_SPACE, queryParams, Collections.singletonList(OrderByField.of(SchemaVersionStorable.VERSION, true)));
    List<SchemaVersionInfo> schemaVersionInfos;
    if (storables != null && !storables.isEmpty()) {
        schemaVersionInfos = storables.stream().map(SchemaVersionStorable::toSchemaVersionInfo).collect(Collectors.toList());
    } else {
        schemaVersionInfos = Collections.emptyList();
    }
    return schemaVersionInfos;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)

Aggregations

SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)40 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)24 InvalidSchemaException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException)21 IOException (java.io.IOException)20 CatalogResponse (com.hortonworks.registries.common.catalog.CatalogResponse)18 SchemaLifecycleException (com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException)18 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)17 Response (javax.ws.rs.core.Response)17 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)16 SchemaBranchAlreadyExistsException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException)15 Timed (com.codahale.metrics.annotation.Timed)14 InvalidSchemaBranchDeletionException (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException)14 Path (javax.ws.rs.Path)14 UnitOfWork (com.hortonworks.registries.common.transaction.UnitOfWork)13 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)13 ApiOperation (io.swagger.annotations.ApiOperation)13 FileNotFoundException (java.io.FileNotFoundException)10 QueryParam (com.hortonworks.registries.common.QueryParam)7 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)7 Collection (java.util.Collection)7