Search in sources :

Example 71 with AtlasEdge

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

the class DeleteHandlerV1 method deleteTypeVertex.

/**
 * Deleting any type vertex. Goes over the complex attributes and removes the references
 * @param instanceVertex
 * @throws AtlasException
 */
protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting {}", string(instanceVertex));
    }
    String typeName = GraphHelper.getTypeName(instanceVertex);
    AtlasType parentType = typeRegistry.getType(typeName);
    if (parentType instanceof AtlasStructType) {
        AtlasStructType structType = (AtlasStructType) parentType;
        boolean isEntityType = (parentType instanceof AtlasEntityType);
        for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex));
            }
            boolean isOwned = isEntityType && attributeInfo.isOwnedRef();
            AtlasType attrType = attributeInfo.getAttributeType();
            String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(structType, attributeInfo.getName());
            switch(attrType.getTypeCategory()) {
                case OBJECT_ID_TYPE:
                    // If its class attribute, delete the reference
                    deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned);
                    break;
                case STRUCT:
                    // If its struct attribute, delete the reference
                    deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false);
                    break;
                case ARRAY:
                    // For array attribute, if the element is struct/class, delete all the references
                    AtlasArrayType arrType = (AtlasArrayType) attrType;
                    AtlasType elemType = arrType.getElementType();
                    if (AtlasGraphUtilsV1.isReference(elemType.getTypeCategory())) {
                        Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(instanceVertex, edgeLabel);
                        if (edges != null) {
                            while (edges.hasNext()) {
                                AtlasEdge edge = edges.next();
                                deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    // For map attribute, if the value type is struct/class, delete all the references
                    AtlasMapType mapType = (AtlasMapType) attrType;
                    AtlasType keyType = mapType.getKeyType();
                    TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(structType, attributeInfo.getName());
                    if (AtlasGraphUtilsV1.isReference(valueTypeCategory)) {
                        List<Object> keys = EntityGraphMapper.getArrayElementsProperty(keyType, instanceVertex, propertyName);
                        if (keys != null) {
                            for (Object key : keys) {
                                String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, (String) key);
                                deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, isOwned);
                            }
                        }
                    }
                    break;
            }
        }
    }
    deleteVertex(instanceVertex, force);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasMapType(org.apache.atlas.type.AtlasMapType) TypeCategory(org.apache.atlas.model.TypeCategory) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 72 with AtlasEdge

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

the class EntityGraphRetriever method mapClassifications.

private void mapClassifications(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException {
    List<AtlasEdge> edges = getAllClassificationEdges(entityVertex);
    if (CollectionUtils.isNotEmpty(edges)) {
        List<AtlasClassification> allClassifications = new ArrayList<>();
        List<AtlasClassification> propagationDisabledClassifications = new ArrayList<>();
        for (AtlasEdge edge : edges) {
            PropagationState edgeState = getClassificationEdgeState(edge);
            AtlasVertex classificationVertex = edge.getInVertex();
            if (edgeState == ACTIVE) {
                allClassifications.add(toAtlasClassification(classificationVertex));
            } else if (edgeState == DELETED && isPropagatedClassificationEdge(edge)) {
                propagationDisabledClassifications.add(toAtlasClassification(classificationVertex));
            }
        }
        entity.setClassifications(allClassifications);
        entity.setPropagationDisabledClassifications(propagationDisabledClassifications);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ArrayList(java.util.ArrayList) PropagationState(org.apache.atlas.model.instance.AtlasClassification.PropagationState) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 73 with AtlasEdge

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

the class EntityGraphRetriever method removeTagPropagation.

private void removeTagPropagation(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasEdge edge) throws AtlasBaseException {
    final List<AtlasVertex> classificationVertices = getPropagationEnabledClassificationVertices(fromVertex);
    final List<AtlasVertex> impactedEntityVertices = CollectionUtils.isNotEmpty(classificationVertices) ? graphHelper.getIncludedImpactedVerticesWithReferences(toVertex, getRelationshipGuid(edge)) : null;
    if (CollectionUtils.isNotEmpty(impactedEntityVertices)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Removing {} propagated tags: for {} from {} entities", classificationVertices.size(), getTypeName(fromVertex), impactedEntityVertices.size());
        }
        for (AtlasVertex classificationVertex : classificationVertices) {
            String classificationName = getTypeName(classificationVertex);
            AtlasVertex associatedEntityVertex = getAssociatedEntityVertex(classificationVertex);
            List<AtlasVertex> referrals = graphHelper.getIncludedImpactedVerticesWithReferences(associatedEntityVertex, getRelationshipGuid(edge));
            for (AtlasVertex impactedEntityVertex : impactedEntityVertices) {
                if (referrals.contains(impactedEntityVertex)) {
                    if (LOG.isDebugEnabled()) {
                        if (StringUtils.equals(getGuid(impactedEntityVertex), getGuid(associatedEntityVertex))) {
                            LOG.debug(" --> Not removing propagated classification edge from [{}] --> [{}][{}] with edge label: [{}], since [{}] is associated with [{}]", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), CLASSIFICATION_LABEL, classificationName, getTypeName(associatedEntityVertex));
                        } else {
                            LOG.debug(" --> Not removing propagated classification edge from [{}] --> [{}][{}] with edge label: [{}], since [{}] is propagated through other path", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), CLASSIFICATION_LABEL, classificationName);
                        }
                    }
                    continue;
                }
                // remove propagated classification edge and classificationName from propagatedTraitNames vertex property
                AtlasEdge propagatedEdge = getPropagatedClassificationEdge(impactedEntityVertex, classificationVertex);
                if (propagatedEdge != null) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(" --> Removing propagated classification edge from [{}] --> [{}][{}] with edge label: [{}]", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), CLASSIFICATION_LABEL);
                    }
                    graphHelper.removeEdge(propagatedEdge);
                    if (getClassificationEdgeState(propagatedEdge) == ACTIVE) {
                        removeFromPropagatedTraitNames(impactedEntityVertex, classificationName);
                    }
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(" --> Not removing propagated classification edge from [{}] --> [{}][{}] using edge label: [{}], since edge doesn't exist", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), CLASSIFICATION_LABEL);
                    }
                }
            }
        }
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 74 with AtlasEdge

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

the class GraphHelper method getClassificationEdges.

public static List<AtlasEdge> getClassificationEdges(AtlasVertex entityVertex, Boolean propagated) {
    List<AtlasEdge> ret = new ArrayList<>();
    AtlasVertexQuery query = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL);
    if (propagated != null) {
        query = query.has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, propagated);
    }
    Iterable edges = query.edges();
    if (edges != null) {
        Iterator<AtlasEdge> iterator = edges.iterator();
        while (iterator.hasNext()) {
            AtlasEdge edge = iterator.next();
            if (edge != null) {
                ret.add(edge);
            }
        }
    }
    return ret;
}
Also used : AtlasVertexQuery(org.apache.atlas.repository.graphdb.AtlasVertexQuery) ArrayList(java.util.ArrayList) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 75 with AtlasEdge

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

the class GraphHelper method dumpToLog.

public static void dumpToLog(final AtlasGraph<?, ?> graph) {
    LOG.debug("*******************Graph Dump****************************");
    LOG.debug("Vertices of {}", graph);
    for (AtlasVertex vertex : graph.getVertices()) {
        LOG.debug(vertexString(vertex));
    }
    LOG.debug("Edges of {}", graph);
    for (AtlasEdge edge : graph.getEdges()) {
        LOG.debug(edgeString(edge));
    }
    LOG.debug("*******************Graph Dump****************************");
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) 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