Search in sources :

Example 21 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction 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 {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, 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 22 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method deleteByIds.

@Override
@GraphTransaction
public EntityMutationResponse deleteByIds(final List<String> guids) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(guids)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    for (String guid : guids) {
        // Retrieve vertices for requested guids.
        AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (vertex != null) {
            deletionCandidates.add(vertex);
        } else {
            if (LOG.isDebugEnabled()) {
                // 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);
    }
    EntityMutationResponse ret = deleteVertices(deletionCandidates);
    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, false);
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 23 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method getByIds.

@Override
@GraphTransaction
public AtlasEntitiesWithExtInfo getByIds(List<String> guids) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getByIds({})", guids);
    }
    EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry);
    AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getByIds({}): {}", guids, ret);
    }
    return ret;
}
Also used : AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 24 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method deleteById.

@Override
@GraphTransaction
public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    // Retrieve vertices for requested guids.
    AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    if (vertex != null) {
        deletionCandidates.add(vertex);
    } else {
        if (LOG.isDebugEnabled()) {
            // 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);
        }
    }
    EntityMutationResponse ret = deleteVertices(deletionCandidates);
    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, false);
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 25 with GraphTransaction

use of org.apache.atlas.annotation.GraphTransaction in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method updateClassifications.

@Override
@GraphTransaction
public void updateClassifications(String guid, List<AtlasClassification> newClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classifications={} for entity={}", newClassifications, guid);
    }
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid not specified");
    }
    if (CollectionUtils.isEmpty(newClassifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }
    List<AtlasClassification> updatedClassifications = new ArrayList<>();
    for (AtlasClassification newClassification : newClassifications) {
        String classificationName = newClassification.getTypeName();
        AtlasClassification oldClassification = getClassification(guid, classificationName);
        if (oldClassification == null) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }
        validateAndNormalizeForUpdate(newClassification);
        Map<String, Object> newAttrs = newClassification.getAttributes();
        if (MapUtils.isNotEmpty(newAttrs)) {
            for (String attrName : newAttrs.keySet()) {
                oldClassification.setAttribute(attrName, newAttrs.get(attrName));
            }
        }
        entityGraphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);
        updatedClassifications.add(oldClassification);
    }
    // notify listeners on update to classifications
    entityChangeNotifier.onClassificationUpdatedToEntity(guid, updatedClassifications);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

GraphTransaction (org.apache.atlas.annotation.GraphTransaction)34 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)12 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)11 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)11 AtlasException (org.apache.atlas.AtlasException)6 RepositoryException (org.apache.atlas.repository.RepositoryException)6 ArrayList (java.util.ArrayList)5 RequestContext (org.apache.atlas.RequestContext)4 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)4 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)3 GuidMapping (org.apache.atlas.model.instance.GuidMapping)3 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)3 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2