Search in sources :

Example 26 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method deleteEntities.

@Override
@GraphTransaction
public EntityResult deleteEntities(List<String> guids) throws RepositoryException {
    if (guids == null || guids.size() == 0) {
        throw new IllegalArgumentException("guids must be non-null and non-empty");
    }
    // Retrieve vertices for requested guids.
    Map<String, AtlasVertex> vertices = graphHelper.getVerticesForGUIDs(guids);
    Collection<AtlasVertex> deletionCandidates = vertices.values();
    if (LOG.isDebugEnabled()) {
        for (String guid : guids) {
            if (!vertices.containsKey(guid)) {
                // Entity does not exist - treat as non-error, since the caller
                // wanted to delete the entity and it's already gone.
                LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
            }
        }
    }
    if (deletionCandidates.isEmpty()) {
        LOG.info("No deletion candidate entities were found for guids %s", guids);
        return new EntityResult(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
    }
    try {
        deleteHandler.deleteEntities(deletionCandidates);
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
    RequestContext requestContext = RequestContext.get();
    return createEntityResultFromContext(requestContext);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 27 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method deleteTrait.

/**
 * Deletes a given trait from an existing entity represented by a guid.
 *
 * @param guid      globally unique identifier for the entity
 * @param traitNameToBeDeleted name of the trait
 * @throws RepositoryException
 */
@Override
@GraphTransaction
public void deleteTrait(String guid, String traitNameToBeDeleted) throws TraitNotFoundException, EntityNotFoundException, RepositoryException {
    LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, guid);
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid);
    List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);
    if (!traitNames.contains(traitNameToBeDeleted)) {
        throw new TraitNotFoundException("Could not find trait=" + traitNameToBeDeleted + " in the repository for entity: " + guid);
    }
    try {
        final String entityTypeName = GraphHelper.getTypeName(instanceVertex);
        String relationshipLabel = GraphHelper.getTraitLabel(entityTypeName, traitNameToBeDeleted);
        AtlasEdge edge = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);
        if (edge != null) {
            deleteHandler.deleteEdgeReference(edge, DataTypes.TypeCategory.TRAIT, false, true);
        }
        // update the traits in entity once trait removal is successful
        traitNames.remove(traitNameToBeDeleted);
        updateTraits(instanceVertex, traitNames);
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) RepositoryException(org.apache.atlas.repository.RepositoryException) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 28 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method createEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("adding entities={}", entities);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
        List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        EntityResult entityResult = new EntityResult(createdGuids, null, null);
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(entityResult);
        result.setGuidMapping(mapping);
        return result;
    } catch (EntityExistsException e) {
        throw e;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 29 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class TypedInstanceToGraphMapper method walkClassInstances.

private Collection<IReferenceableInstance> walkClassInstances(ITypedReferenceableInstance typedInstance) throws RepositoryException {
    EntityProcessor entityProcessor = new EntityProcessor();
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Walking the object graph for instance {}", typedInstance.toShortString());
        }
        new ObjectGraphWalker(typeSystem, entityProcessor, typedInstance).walk();
    } catch (AtlasException me) {
        throw new RepositoryException("TypeSystem error when walking the ObjectGraph", me);
    }
    entityProcessor.addInstanceIfNotExists(typedInstance);
    return entityProcessor.getInstances();
}
Also used : RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasException(org.apache.atlas.AtlasException)

Example 30 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityProcessor method processNode.

@Override
public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
    IReferenceableInstance ref = null;
    Id id = null;
    if (nd.attributeName == null) {
        ref = (IReferenceableInstance) nd.instance;
        id = ref.getId();
    } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
        if (nd.value != null && (nd.value instanceof Id)) {
            id = (Id) nd.value;
        }
    }
    if (id != null) {
        if (id.isUnassigned()) {
            if (ref != null) {
                if (idToInstanceMap.containsKey(id)) {
                    // Oops
                    throw new RepositoryException(String.format("Unexpected internal error: Id %s processed again", id));
                }
                idToInstanceMap.put(id, ref);
            }
        }
    }
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) RepositoryException(org.apache.atlas.repository.RepositoryException) Id(org.apache.atlas.typesystem.persistence.Id)

Aggregations

RepositoryException (org.apache.atlas.repository.RepositoryException)31 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasException (org.apache.atlas.AtlasException)11 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)10 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)5 RequestContext (org.apache.atlas.RequestContext)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)3 GuidMapping (org.apache.atlas.model.instance.GuidMapping)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)3 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)2