Java Code Examples for org.apache.atlas.model.instance.AtlasEntity#Status

The following examples show how to use org.apache.atlas.model.instance.AtlasEntity#Status . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteHandlerV1.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean skipVertexForDelete(AtlasVertex vertex) {
    boolean ret = true;

    if(vertex != null) {
        try {
            final RequestContext reqContext = RequestContext.get();
            final String guid = AtlasGraphUtilsV2.getIdFromVertex(vertex);

            if(guid != null && !reqContext.isDeletedEntity(guid)) {
                final AtlasEntity.Status vertexState = getState(vertex);
                if (reqContext.isPurgeRequested()) {
                    ret = vertexState == ACTIVE; // skip purging ACTIVE vertices
                } else {
                    ret = vertexState == DELETED; // skip deleting DELETED vertices
                }
            }
        } catch (IllegalStateException excp) {
            LOG.warn("skipVertexForDelete(): failed guid/state for the vertex", excp);
        }
    }

    return ret;
}
 
Example 2
Source File: DeleteHandlerV1.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Setting the external references to {} to null(removing edges)", string(instanceVertex));
    }

    // Delete external references to this vertex - incoming edges from lineage or glossary term edges
    final Iterable<AtlasEdge> incomingEdges    = instanceVertex.getEdges(AtlasEdgeDirection.IN);
    final boolean             isPurgeRequested = RequestContext.get().isPurgeRequested();

    for (AtlasEdge edge : incomingEdges) {
        AtlasEntity.Status edgeStatus = getStatus(edge);
        boolean            isProceed   = edgeStatus == (isPurgeRequested ? DELETED : ACTIVE);

        if (isProceed) {
            if (isRelationshipEdge(edge)) {
                deleteRelationship(edge);
            } else {
                AtlasVertex    outVertex = edge.getOutVertex();
                AtlasVertex    inVertex  = edge.getInVertex();
                AtlasAttribute attribute = getAttributeForEdge(edge.getLabel());

                deleteEdgeBetweenVertices(outVertex, inVertex, attribute);
            }
        }
    }

    _deleteVertex(instanceVertex, force);
}
 
Example 3
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasRelatedObjectId mapVertexToRelatedObjectId(AtlasVertex entityVertex, AtlasEdge edge, boolean isOwnedRef, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) throws AtlasBaseException {
    AtlasRelatedObjectId ret = null;

    if (GraphHelper.elementExists(edge)) {
        AtlasVertex referenceVertex = edge.getInVertex();

        if (StringUtils.equals(getIdFromVertex(referenceVertex), getIdFromVertex(entityVertex))) {
            referenceVertex = edge.getOutVertex();
        }

        if (referenceVertex != null) {
            String             entityTypeName = getTypeName(referenceVertex);
            String             entityGuid     = getGuid(referenceVertex);
            AtlasEntity.Status entityStatus   = GraphHelper.getStatus(referenceVertex);
            AtlasRelationship  relationship   = mapEdgeToAtlasRelationship(edge);

            ret = new AtlasRelatedObjectId(entityGuid, entityTypeName, entityStatus,
                                           relationship.getGuid(), relationship.getStatus(),
                                           new AtlasStruct(relationship.getTypeName(), relationship.getAttributes()));

            Object displayText = getDisplayText(referenceVertex, entityTypeName);

            if (displayText != null) {
                ret.setDisplayText(displayText.toString());
            }

            if (isOwnedRef && entityExtInfo != null) {
                if (isMinExtInfo) {
                    mapVertexToAtlasEntityMin(referenceVertex, entityExtInfo);
                } else {
                    mapVertexToAtlasEntity(referenceVertex, entityExtInfo);
                }
            }

        }
    }

    return ret;
}
 
Example 4
Source File: DeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * 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 = AtlasGraphUtilsV1.getState(instanceVertex);

        if (state == AtlasEntity.Status.DELETED) {
            LOG.debug("Skipping deletion of {} as it is already deleted", guid);
            continue;
        }

        String typeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
        AtlasObjectId objId = new AtlasObjectId(guid, typeName);

        if (requestContext.getDeletedEntityIds().contains(objId)) {
            LOG.debug("Skipping deletion of {} as it is already deleted", guid);
            continue;
        }

        // Get GUIDs and vertices for all deletion candidates.
        Set<GraphHelper.VertexInfo> compositeVertices = getOwnedVertices(instanceVertex);

        // Record all deletion candidate GUIDs in RequestContext
        // and gather deletion candidate vertices.
        for (GraphHelper.VertexInfo vertexInfo : compositeVertices) {
            requestContext.recordEntityDelete(new AtlasObjectId(vertexInfo.getGuid(), vertexInfo.getTypeName()));
            deletionCandidateVertices.add(vertexInfo.getVertex());
        }
    }

    // Delete traits and vertices.
    for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) {
        deleteAllTraits(deletionCandidateVertex);
        deleteTypeVertex(deletionCandidateVertex, false);
    }
}
 
Example 5
Source File: DeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException {
    //Update external references(incoming edges) to this vertex
    LOG.debug("Setting the external references to {} to null(removing edges)", string(instanceVertex));

    for (AtlasEdge edge : (Iterable<AtlasEdge>) instanceVertex.getEdges(AtlasEdgeDirection.IN)) {
        AtlasEntity.Status edgeState = AtlasGraphUtilsV1.getState(edge);
        if (edgeState == AtlasEntity.Status.ACTIVE) {
            //Delete only the active edge references
            AtlasAttribute attribute = getAttributeForEdge(edge.getLabel());
            //TODO use delete edge instead??
            deleteEdgeBetweenVertices(edge.getOutVertex(), edge.getInVertex(), attribute);
        }
    }
    _deleteVertex(instanceVertex, force);
}
 
Example 6
Source File: SoftDeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected void _deleteVertex(AtlasVertex instanceVertex, boolean force) {
    if (force) {
        graphHelper.removeVertex(instanceVertex);
    } else {
        AtlasEntity.Status state = AtlasGraphUtilsV1.getState(instanceVertex);
        if (state != AtlasEntity.Status.DELETED) {
            GraphHelper.setProperty(instanceVertex, STATE_PROPERTY_KEY, AtlasEntity.Status.DELETED.name());
            GraphHelper.setProperty(instanceVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY,
                RequestContextV1.get().getRequestTime());
            GraphHelper.setProperty(instanceVertex, MODIFIED_BY_KEY, RequestContextV1.get().getUser());
        }
    }
}
 
Example 7
Source File: SoftDeleteHandlerV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseException {
    if (force) {
        graphHelper.removeEdge(edge);
    } else {
        AtlasEntity.Status state = AtlasGraphUtilsV1.getState(edge);
        if (state != AtlasEntity.Status.DELETED) {
            GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.DELETED.name());
            GraphHelper
                .setProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime());
            GraphHelper.setProperty(edge, MODIFIED_BY_KEY, RequestContextV1.get().getUser());
        }
    }
}
 
Example 8
Source File: AtlasGraphUtilsV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasEntity.Status getState(AtlasElement element) {
    String state = getStateAsString(element);
    return state == null ? null : AtlasEntity.Status.valueOf(state);
}
 
Example 9
Source File: AtlasGraphUtilsV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasEntity.Status getState(AtlasElement element) {
    String state = getStateAsString(element);
    return state == null ? null : AtlasEntity.Status.valueOf(state);
}