Search in sources :

Example 51 with AtlasEdge

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

the class AtlasRelationshipStoreV1 method getById.

@Override
@GraphTransaction
public AtlasRelationship getById(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getById({})", guid);
    }
    AtlasRelationship ret;
    try {
        AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
        ret = mapEdgeToAtlasRelationship(edge);
    } catch (EntityNotFoundException ex) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getById({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 52 with AtlasEdge

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

the class AtlasRelationshipStoreV1 method getRelationshipEdge.

public AtlasEdge getRelationshipEdge(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) {
    String relationshipLabel = getRelationshipEdgeLabel(fromVertex, toVertex, relationship);
    AtlasEdge ret = graphHelper.getEdgeForLabel(fromVertex, relationshipLabel);
    if (ret != null) {
        AtlasVertex inVertex = ret.getInVertex();
        if (inVertex != null) {
            if (!StringUtils.equals(AtlasGraphUtilsV1.getIdFromVertex(inVertex), AtlasGraphUtilsV1.getIdFromVertex(toVertex))) {
                ret = null;
            }
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 53 with AtlasEdge

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

the class AtlasTypeDefGraphStoreV1 method hasIncomingEdgesWithLabel.

/**
 * Look to see if there are any IN edges with the supplied label
 * @param vertex
 * @param label
 * @return
 * @throws AtlasBaseException
 */
boolean hasIncomingEdgesWithLabel(AtlasVertex vertex, String label) throws AtlasBaseException {
    boolean foundEdges = false;
    Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();
    while (inEdges.hasNext()) {
        AtlasEdge edge = inEdges.next();
        if (label.equals(edge.getLabel())) {
            foundEdges = true;
            break;
        }
    }
    return foundEdges;
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 54 with AtlasEdge

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

the class DeleteHandlerV1 method getOwnedVertices.

/**
 * Get the GUIDs and vertices for all composite entities owned/contained by the specified root entity AtlasVertex.
 * The graph is traversed from the root entity through to the leaf nodes of the containment graph.
 *
 * @param entityVertex the root entity vertex
 * @return set of VertexInfo for all composite entities
 * @throws AtlasException
 */
public Set<GraphHelper.VertexInfo> getOwnedVertices(AtlasVertex entityVertex) throws AtlasBaseException {
    Set<GraphHelper.VertexInfo> result = new LinkedHashSet<>();
    Stack<AtlasVertex> vertices = new Stack<>();
    vertices.push(entityVertex);
    while (vertices.size() > 0) {
        AtlasVertex vertex = vertices.pop();
        AtlasEntity.Status state = AtlasGraphUtilsV1.getState(vertex);
        if (state == AtlasEntity.Status.DELETED) {
            // If the reference vertex is marked for deletion, skip it
            continue;
        }
        String typeName = GraphHelper.getTypeName(vertex);
        String guid = GraphHelper.getGuid(vertex);
        result.add(new GraphHelper.VertexInfo(guid, vertex, typeName));
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), typeName);
        }
        for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getAllAttributes().values()) {
            if (!attributeInfo.isOwnedRef()) {
                continue;
            }
            String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getName());
            AtlasType attrType = attributeInfo.getAttributeType();
            switch(attrType.getTypeCategory()) {
                case OBJECT_ID_TYPE:
                    AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
                    if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                        AtlasVertex compositeVertex = edge.getInVertex();
                        vertices.push(compositeVertex);
                    }
                    break;
                case ARRAY:
                    AtlasArrayType arrType = (AtlasArrayType) attrType;
                    if (arrType.getElementType().getTypeCategory() != TypeCategory.OBJECT_ID_TYPE) {
                        continue;
                    }
                    Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(vertex, edgeLabel);
                    if (edges != null) {
                        while (edges.hasNext()) {
                            edge = edges.next();
                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    AtlasMapType mapType = (AtlasMapType) attrType;
                    TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    if (valueTypeCategory != TypeCategory.OBJECT_ID_TYPE) {
                        continue;
                    }
                    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getName());
                    List<String> keys = vertex.getProperty(propertyName, List.class);
                    if (keys != null) {
                        for (String key : keys) {
                            String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
                            edge = graphHelper.getEdgeForLabel(vertex, mapEdgeLabel);
                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                default:
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) GraphHelper(org.apache.atlas.repository.graph.GraphHelper) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasType(org.apache.atlas.type.AtlasType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasMapType(org.apache.atlas.type.AtlasMapType) Stack(java.util.Stack) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) TypeCategory(org.apache.atlas.model.TypeCategory) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 55 with AtlasEdge

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

the class DeleteHandlerV1 method deleteVertex.

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);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)138 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)60 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)28 AtlasType (org.apache.atlas.type.AtlasType)15 ArrayList (java.util.ArrayList)13 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)13 AtlasStructType (org.apache.atlas.type.AtlasStructType)12 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)12 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)11 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)8 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)8 AtlasMapType (org.apache.atlas.type.AtlasMapType)8 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)7 HashSet (java.util.HashSet)6 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasException (org.apache.atlas.AtlasException)5 Iterator (java.util.Iterator)4