Search in sources :

Example 1 with AtlasVertex

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

the class DeleteHandlerV1 method deleteEdgeReference.

/**
     * Force delete is used to remove struct/trait in case of entity updates
     * @param edge
     * @param typeCategory
     * @param isOwned
     * @param forceDeleteStructTrait
     * @return returns true if the edge reference is hard deleted
     * @throws AtlasException
     */
public boolean deleteEdgeReference(AtlasEdge edge, TypeCategory typeCategory, boolean isOwned, boolean forceDeleteStructTrait) throws AtlasBaseException {
    LOG.debug("Deleting {}", string(edge));
    boolean forceDelete = (typeCategory == TypeCategory.STRUCT || typeCategory == TypeCategory.CLASSIFICATION) && forceDeleteStructTrait;
    if (typeCategory == TypeCategory.STRUCT || typeCategory == TypeCategory.CLASSIFICATION || (typeCategory == TypeCategory.OBJECT_ID_TYPE && isOwned)) {
        //If the vertex is of type struct/trait, delete the edge and then the reference vertex as the vertex is not shared by any other entities.
        //If the vertex is of type class, and its composite attribute, this reference vertex' lifecycle is controlled
        //through this delete, hence delete the edge and the reference vertex.
        AtlasVertex vertexForDelete = edge.getInVertex();
        //If deleting the edge and then the in vertex, reverse attribute shouldn't be updated
        deleteEdge(edge, false, forceDelete);
        deleteTypeVertex(vertexForDelete, typeCategory, forceDelete);
    } else {
        //If the vertex is of type class, and its not a composite attributes, the reference AtlasVertex' lifecycle is not controlled
        //through this delete. Hence just remove the reference edge. Leave the reference AtlasVertex as is
        //If deleting just the edge, reverse attribute should be updated for any references
        //For example, for the department type system, if the person's manager edge is deleted, subordinates of manager should be updated
        deleteEdge(edge, true, false);
    }
    return !softDelete || forceDelete;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 2 with AtlasVertex

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

the class TitanGraphQuery method vertices.

@Override
public Iterable<AtlasVertex<V, E>> vertices() {
    LOG.debug("Executing: ");
    LOG.debug(queryCondition.toString());
    //compute the overall result by unioning the results from all of the
    //AndConditions together.
    Set<AtlasVertex<V, E>> result = new HashSet<>();
    for (AndCondition andExpr : queryCondition.getAndTerms()) {
        NativeTitanGraphQuery<V, E> andQuery = andExpr.create(getQueryFactory());
        for (AtlasVertex<V, E> vertex : andQuery.vertices()) {
            result.add(vertex);
        }
    }
    return result;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashSet(java.util.HashSet) AndCondition(org.apache.atlas.repository.graphdb.titan.query.expr.AndCondition)

Example 3 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project atlas by apache.

the class AtlasEntityStoreV1 method getByUniqueAttributes.

@Override
@GraphTransaction
public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes);
    }
    AtlasVertex entityVertex = AtlasGraphUtilsV1.getVertexByUniqueAttributes(entityType, uniqAttributes);
    AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getByUniqueAttribute({}, {}): {}", entityType.getTypeName(), uniqAttributes, ret);
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 4 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project 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) {
        AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (vertex == null) {
            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);
            }
            continue;
        }
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex);
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: guid=", guid);
        deletionCandidates.add(vertex);
    }
    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) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 5 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project atlas by apache.

the class AtlasEntityStoreV1 method createOrUpdate.

private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createOrUpdate()");
    }
    if (entityStream == null || !entityStream.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no entities to create/update.");
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "createOrUpdate()");
    }
    try {
        final boolean isImport = entityStream instanceof EntityImportStream;
        final EntityMutationContext context = preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate);
        // Check if authorized to create entities
        if (!isImport && CollectionUtils.isNotEmpty(context.getCreatedEntities())) {
            for (AtlasEntity entity : context.getCreatedEntities()) {
                AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)), "create entity: type=", entity.getTypeName());
            }
        }
        // for existing entities, skip update if incoming entity doesn't have any change
        if (CollectionUtils.isNotEmpty(context.getUpdatedEntities())) {
            List<AtlasEntity> entitiesToSkipUpdate = null;
            for (AtlasEntity entity : context.getUpdatedEntities()) {
                String guid = entity.getGuid();
                AtlasVertex vertex = context.getVertex(guid);
                AtlasEntity entityInStore = entityRetriever.toAtlasEntity(vertex);
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
                if (!AtlasEntityUtil.hasAnyAttributeUpdate(entityType, entity, entityInStore)) {
                    // if classifications are to be replaced as well, then skip updates only when no change in classifications as well
                    if (!replaceClassifications || Objects.equals(entity.getClassifications(), entityInStore.getClassifications())) {
                        if (entitiesToSkipUpdate == null) {
                            entitiesToSkipUpdate = new ArrayList<>();
                        }
                        entitiesToSkipUpdate.add(entity);
                    }
                }
            }
            if (entitiesToSkipUpdate != null) {
                context.getUpdatedEntities().removeAll(entitiesToSkipUpdate);
            }
            // Check if authorized to update entities
            if (!isImport) {
                for (AtlasEntity entity : context.getUpdatedEntities()) {
                    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new AtlasEntityHeader(entity)), "update entity: type=", entity.getTypeName());
                }
            }
        }
        EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications);
        ret.setGuidAssignments(context.getGuidAssignments());
        // Notify the change listeners
        entityChangeNotifier.onEntitiesMutated(ret, isImport);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== createOrUpdate()");
        }
        return ret;
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)323 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)128 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)60 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)34 ArrayList (java.util.ArrayList)33 AtlasType (org.apache.atlas.type.AtlasType)33 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)29 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)26 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)25 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)22 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)21 Test (org.testng.annotations.Test)19 AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)18 HashMap (java.util.HashMap)17 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)15 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)14 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)14 RepositoryException (org.apache.atlas.repository.RepositoryException)14 HashSet (java.util.HashSet)13 List (java.util.List)13