Search in sources :

Example 6 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class LineageUtils method isDataSet.

private static boolean isDataSet(String typeName, AtlasTypeRegistry registry) throws AtlasBaseException {
    boolean ret = false;
    AtlasType type = registry.getType(typeName);
    if (type instanceof AtlasEntityType) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        ret = entityType.getAllSuperTypes().contains(AtlasBaseTypeDef.ATLAS_TYPE_DATASET);
    }
    return ret;
}
Also used : AtlasType(org.apache.atlas.type.AtlasType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 7 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class ModelTestUtil method newEntity.

public static AtlasEntity newEntity(AtlasEntityDef entityDef, AtlasTypeRegistry typesRegistry) {
    AtlasEntity ret = null;
    AtlasEntityType entityType = typesRegistry.getEntityTypeByName(entityDef.getName());
    if (entityType != null) {
        ret = entityType.createDefaultValue();
    } else {
        LOG.error("failed to get entity-type {}", entityDef.getName());
    }
    return ret;
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 8 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class DeleteHandlerV1 method deleteEdge.

protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolean force) throws AtlasBaseException {
    //update inverse attribute
    if (updateInverseAttribute) {
        AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edge.getLabel());
        AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
        if (parentType instanceof AtlasEntityType) {
            AtlasEntityType parentEntityType = (AtlasEntityType) parentType;
            AtlasStructType.AtlasAttribute attribute = parentEntityType.getAttribute(atlasEdgeLabel.getAttributeName());
            if (attribute.getInverseRefAttribute() != null) {
                deleteEdgeBetweenVertices(edge.getInVertex(), edge.getOutVertex(), attribute.getInverseRefAttribute());
            }
        }
    }
    deleteEdge(edge, force);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasEdgeLabel(org.apache.atlas.repository.graph.AtlasEdgeLabel) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 9 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType 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 10 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class EntityGraphMapper method getInstanceType.

private AtlasEntityType getInstanceType(Object val) throws AtlasBaseException {
    AtlasEntityType ret = null;
    if (val != null) {
        String typeName = null;
        if (val instanceof AtlasObjectId) {
            typeName = ((AtlasObjectId) val).getTypeName();
        } else if (val instanceof Map) {
            Object typeNameVal = ((Map) val).get(AtlasObjectId.KEY_TYPENAME);
            if (typeNameVal != null) {
                typeName = typeNameVal.toString();
            }
        }
        ret = typeName != null ? typeRegistry.getEntityTypeByName(typeName) : null;
        if (ret == null) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, val.toString());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

AtlasEntityType (org.apache.atlas.type.AtlasEntityType)45 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)6 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)6 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)6 AtlasType (org.apache.atlas.type.AtlasType)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)5 HashMap (java.util.HashMap)4 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)4 List (java.util.List)3 Map (java.util.Map)3 Consumes (javax.ws.rs.Consumes)3