Search in sources :

Example 1 with RequestContextV1

use of org.apache.atlas.RequestContextV1 in project atlas by apache.

the class AtlasEntityStoreV1 method deleteVertices.

private EntityMutationResponse deleteVertices(Collection<AtlasVertex> deletionCandidates) throws AtlasBaseException {
    EntityMutationResponse response = new EntityMutationResponse();
    RequestContextV1 req = RequestContextV1.get();
    // this will update req with list of deleted/updated entities
    deleteHandler.deleteEntities(deletionCandidates);
    for (AtlasObjectId entity : req.getDeletedEntities()) {
        response.addEntity(DELETE, entity);
    }
    for (AtlasObjectId entity : req.getUpdatedEntities()) {
        response.addEntity(UPDATE, entity);
    }
    return response;
}
Also used : RequestContextV1(org.apache.atlas.RequestContextV1)

Example 2 with RequestContextV1

use of org.apache.atlas.RequestContextV1 in project atlas by apache.

the class EntityGraphMapper method addInverseReference.

private void addInverseReference(AtlasAttribute inverseAttribute, AtlasEdge edge, Map<String, Object> relationshipAttributes) throws AtlasBaseException {
    AtlasStructType inverseType = inverseAttribute.getDefinedInType();
    AtlasVertex inverseVertex = edge.getInVertex();
    String inverseEdgeLabel = inverseAttribute.getRelationshipEdgeLabel();
    AtlasEdge inverseEdge = graphHelper.getEdgeForLabel(inverseVertex, inverseEdgeLabel);
    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseType, inverseAttribute.getName());
    // create new inverse reference
    AtlasEdge newEdge = createInverseReferenceUsingRelationship(inverseAttribute, edge, relationshipAttributes);
    boolean inverseUpdated = true;
    switch(inverseAttribute.getAttributeType().getTypeCategory()) {
        case OBJECT_ID_TYPE:
            if (inverseEdge != null) {
                if (!inverseEdge.equals(newEdge)) {
                    // Disconnect old reference
                    deleteHandler.deleteEdgeReference(inverseEdge, inverseAttribute.getAttributeType().getTypeCategory(), inverseAttribute.isOwnedRef(), true, inverseVertex);
                } else {
                    // Edge already exists for this attribute between these vertices.
                    inverseUpdated = false;
                }
            }
            break;
        case ARRAY:
            // Add edge ID to property value
            List<String> elements = inverseVertex.getProperty(propertyName, List.class);
            if (newEdge != null && elements == null) {
                elements = new ArrayList<>();
                elements.add(newEdge.getId().toString());
                inverseVertex.setProperty(propertyName, elements);
            } else {
                if (newEdge != null && !elements.contains(newEdge.getId().toString())) {
                    elements.add(newEdge.getId().toString());
                    inverseVertex.setProperty(propertyName, elements);
                } else {
                    // Property value list already contains the edge ID.
                    inverseUpdated = false;
                }
            }
            break;
        default:
            break;
    }
    if (inverseUpdated) {
        RequestContextV1 requestContext = RequestContextV1.get();
        if (!requestContext.isDeletedEntity(GraphHelper.getGuid(inverseVertex))) {
            updateModificationMetadata(inverseVertex);
            requestContext.recordEntityUpdate(entityRetriever.toAtlasObjectId(inverseVertex));
        }
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RequestContextV1(org.apache.atlas.RequestContextV1) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 3 with RequestContextV1

use of org.apache.atlas.RequestContextV1 in project atlas by apache.

the class EntityGraphMapper method mapAttributesAndClassifications.

public EntityMutationResponse mapAttributesAndClassifications(EntityMutationContext context, final boolean isPartialUpdate, final boolean replaceClassifications) throws AtlasBaseException {
    EntityMutationResponse resp = new EntityMutationResponse();
    Collection<AtlasEntity> createdEntities = context.getCreatedEntities();
    Collection<AtlasEntity> updatedEntities = context.getUpdatedEntities();
    if (CollectionUtils.isNotEmpty(createdEntities)) {
        for (AtlasEntity createdEntity : createdEntities) {
            String guid = createdEntity.getGuid();
            AtlasVertex vertex = context.getVertex(guid);
            AtlasEntityType entityType = context.getType(guid);
            compactAttributes(createdEntity);
            mapRelationshipAttributes(createdEntity, vertex, CREATE, context);
            mapAttributes(createdEntity, vertex, CREATE, context);
            resp.addEntity(CREATE, constructHeader(createdEntity, entityType, vertex));
            addClassifications(context, guid, createdEntity.getClassifications());
        }
    }
    if (CollectionUtils.isNotEmpty(updatedEntities)) {
        for (AtlasEntity updatedEntity : updatedEntities) {
            String guid = updatedEntity.getGuid();
            AtlasVertex vertex = context.getVertex(guid);
            AtlasEntityType entityType = context.getType(guid);
            compactAttributes(updatedEntity);
            mapRelationshipAttributes(updatedEntity, vertex, UPDATE, context);
            mapAttributes(updatedEntity, vertex, UPDATE, context);
            if (isPartialUpdate) {
                resp.addEntity(PARTIAL_UPDATE, constructHeader(updatedEntity, entityType, vertex));
            } else {
                resp.addEntity(UPDATE, constructHeader(updatedEntity, entityType, vertex));
            }
            if (replaceClassifications) {
                deleteClassifications(guid);
                addClassifications(context, guid, updatedEntity.getClassifications());
            }
        }
    }
    RequestContextV1 req = RequestContextV1.get();
    for (AtlasObjectId entity : req.getDeletedEntities()) {
        resp.addEntity(DELETE, entity);
    }
    for (AtlasObjectId entity : req.getUpdatedEntities()) {
        if (isPartialUpdate) {
            resp.addEntity(PARTIAL_UPDATE, entity);
        } else {
            resp.addEntity(UPDATE, entity);
        }
    }
    return resp;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RequestContextV1(org.apache.atlas.RequestContextV1) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 4 with RequestContextV1

use of org.apache.atlas.RequestContextV1 in project atlas by apache.

the class EntityGraphMapper method recordEntityUpdate.

private void recordEntityUpdate(AtlasVertex vertex) throws AtlasBaseException {
    RequestContextV1 req = RequestContextV1.get();
    if (!req.isUpdatedEntity(GraphHelper.getGuid(vertex))) {
        updateModificationMetadata(vertex);
        req.recordEntityUpdate(entityRetriever.toAtlasObjectId(vertex));
    }
}
Also used : RequestContextV1(org.apache.atlas.RequestContextV1)

Example 5 with RequestContextV1

use of org.apache.atlas.RequestContextV1 in project atlas by apache.

the class DeleteHandlerV1 method deleteEntities.

/**
 * Deletes the specified entity vertices.
 * Deletes any traits, composite entities, and structs owned by each entity.
 * Also deletes all the references from/to the entity.
 *
 * @param instanceVertices
 * @throws AtlasException
 */
public void deleteEntities(Collection<AtlasVertex> instanceVertices) throws AtlasBaseException {
    RequestContextV1 requestContext = RequestContextV1.get();
    Set<AtlasVertex> deletionCandidateVertices = new HashSet<>();
    for (AtlasVertex instanceVertex : instanceVertices) {
        String guid = AtlasGraphUtilsV1.getIdFromVertex(instanceVertex);
        AtlasEntity.Status state = getState(instanceVertex);
        if (state == DELETED || requestContext.isDeletedEntity(guid)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Skipping deletion of {} as it is already deleted", guid);
            }
            continue;
        }
        // and gather deletion candidate vertices.
        for (GraphHelper.VertexInfo vertexInfo : getOwnedVertices(instanceVertex)) {
            requestContext.recordEntityDelete(vertexInfo.getEntity());
            deletionCandidateVertices.add(vertexInfo.getVertex());
        }
    }
    // Delete traits and vertices.
    for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) {
        deleteAllClassifications(deletionCandidateVertex);
        deleteTypeVertex(deletionCandidateVertex, false);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RequestContextV1(org.apache.atlas.RequestContextV1) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) GraphHelper(org.apache.atlas.repository.graph.GraphHelper)

Aggregations

RequestContextV1 (org.apache.atlas.RequestContextV1)15 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)6 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)3 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)3 AtlasStructType (org.apache.atlas.type.AtlasStructType)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)2 GraphHelper (org.apache.atlas.repository.graph.GraphHelper)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 AtlasType (org.apache.atlas.type.AtlasType)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1