Search in sources :

Example 21 with ClassType

use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.

the class MemRepository method defineTypes.

public void defineTypes(List<HierarchicalType> types) throws RepositoryException {
    List<TraitType> tTypes = new ArrayList<>();
    List<ClassType> cTypes = new ArrayList<>();
    for (HierarchicalType h : types) {
        if (h.getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
            tTypes.add((TraitType) h);
        } else {
            cTypes.add((ClassType) h);
        }
    }
    tTypes = HierarchicalTypeDependencySorter.sortTypes(tTypes);
    cTypes = HierarchicalTypeDependencySorter.sortTypes(cTypes);
    for (TraitType tT : tTypes) {
        defineTrait(tT);
    }
    for (ClassType cT : cTypes) {
        defineClass(cT);
    }
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType)

Example 22 with ClassType

use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.

the class EntityDiscoveryJerseyResourceIT method createTypes.

private void createTypes() throws Exception {
    HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil.createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
    HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil.createTraitTypeDef("Classification", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
    createType(typesDef);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 23 with ClassType

use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.

the class GraphHelper method getCompositeVertices.

/**
     * 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<VertexInfo> getCompositeVertices(AtlasVertex entityVertex) throws AtlasException {
    Set<VertexInfo> result = new HashSet<>();
    Stack<AtlasVertex> vertices = new Stack<>();
    vertices.push(entityVertex);
    while (vertices.size() > 0) {
        AtlasVertex vertex = vertices.pop();
        String typeName = GraphHelper.getTypeName(vertex);
        String guid = GraphHelper.getGuid(vertex);
        Id.EntityState state = GraphHelper.getState(vertex);
        if (state == Id.EntityState.DELETED) {
            //If the reference vertex is marked for deletion, skip it
            continue;
        }
        result.add(new VertexInfo(guid, vertex, typeName));
        ClassType classType = typeSystem.getDataType(ClassType.class, typeName);
        for (AttributeInfo attributeInfo : classType.fieldMapping().fields.values()) {
            if (!attributeInfo.isComposite) {
                continue;
            }
            String edgeLabel = GraphHelper.getEdgeLabel(classType, attributeInfo);
            switch(attributeInfo.dataType().getTypeCategory()) {
                case CLASS:
                    AtlasEdge edge = getEdgeForLabel(vertex, edgeLabel);
                    if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
                        AtlasVertex compositeVertex = edge.getInVertex();
                        vertices.push(compositeVertex);
                    }
                    break;
                case ARRAY:
                    IDataType elementType = ((DataTypes.ArrayType) attributeInfo.dataType()).getElemType();
                    DataTypes.TypeCategory elementTypeCategory = elementType.getTypeCategory();
                    if (elementTypeCategory != TypeCategory.CLASS) {
                        continue;
                    }
                    Iterator<AtlasEdge> edges = getOutGoingEdgesByLabel(vertex, edgeLabel);
                    if (edges != null) {
                        while (edges.hasNext()) {
                            edge = edges.next();
                            if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                case MAP:
                    DataTypes.MapType mapType = (DataTypes.MapType) attributeInfo.dataType();
                    DataTypes.TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
                    if (valueTypeCategory != TypeCategory.CLASS) {
                        continue;
                    }
                    String propertyName = GraphHelper.getQualifiedFieldName(classType, attributeInfo.name);
                    List<String> keys = vertex.getProperty(propertyName, List.class);
                    if (keys != null) {
                        for (String key : keys) {
                            String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
                            edge = getEdgeForLabel(vertex, mapEdgeLabel);
                            if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
                                AtlasVertex compositeVertex = edge.getInVertex();
                                vertices.push(compositeVertex);
                            }
                        }
                    }
                    break;
                default:
            }
        }
    }
    return result;
}
Also used : TypeCategory(org.apache.atlas.typesystem.types.DataTypes.TypeCategory) ClassType(org.apache.atlas.typesystem.types.ClassType) IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Stack(java.util.Stack) AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) Id(org.apache.atlas.typesystem.persistence.Id) HashSet(java.util.HashSet) DataTypes(org.apache.atlas.typesystem.types.DataTypes)

Example 24 with ClassType

use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.

the class GraphToTypedInstanceMapper method mapGraphToTypedInstance.

public ITypedReferenceableInstance mapGraphToTypedInstance(String guid, AtlasVertex instanceVertex) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        //place to add a check to see if there are any places that were missed.
        if (RequestContext.get().getInstanceV1(guid) != null) {
            LOG.warn("Looking up previously cached guid at: ", new Exception());
        }
        LOG.debug("Mapping graph root vertex {} to typed instance for guid {}", instanceVertex, guid);
    }
    String typeName = GraphHelper.getSingleValuedProperty(instanceVertex, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class);
    List<String> traits = GraphHelper.getTraitNames(instanceVertex);
    String state = GraphHelper.getStateAsString(instanceVertex);
    String createdBy = GraphHelper.getCreatedByAsString(instanceVertex);
    String modifiedBy = GraphHelper.getModifiedByAsString(instanceVertex);
    Date createdTime = new Date(GraphHelper.getCreatedTime(instanceVertex));
    Date modifiedTime = new Date(GraphHelper.getModifiedTime(instanceVertex));
    AtlasSystemAttributes systemAttributes = new AtlasSystemAttributes(createdBy, modifiedBy, createdTime, modifiedTime);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime);
    }
    Id id = new Id(guid, Integer.parseInt(String.valueOf(GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY))), typeName, state);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created id {} for instance type {}", id, typeName);
    }
    ClassType classType = typeSystem.getDataType(ClassType.class, typeName);
    ITypedReferenceableInstance typedInstance = classType.createInstance(id, systemAttributes, traits.toArray(new String[traits.size()]));
    mapVertexToInstance(instanceVertex, typedInstance, classType.fieldMapping().fields);
    mapVertexToInstanceTraits(instanceVertex, typedInstance, traits);
    RequestContext.get().cache(typedInstance);
    return typedInstance;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasSystemAttributes(org.apache.atlas.typesystem.persistence.AtlasSystemAttributes) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasException(org.apache.atlas.AtlasException) Date(java.util.Date)

Example 25 with ClassType

use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.

the class StoreBackedTypeCacheTest method testGetClassType.

@Test
public void testGetClassType() throws Exception {
    for (Map.Entry<String, ClassType> typeEntry : classTypesToTest.entrySet()) {
        // Not cached yet
        Assert.assertFalse(typeCache.isCachedInMemory(typeEntry.getKey()));
        IDataType dataType = ts.getDataType(IDataType.class, typeEntry.getKey());
        // Verify the type is now cached.
        Assert.assertTrue(typeCache.isCachedInMemory(typeEntry.getKey()));
        Assert.assertTrue(dataType instanceof ClassType);
        ClassType cachedType = (ClassType) dataType;
        // Verify that get() also loaded and cached any dependencies of this type from the type store.
        verifyHierarchicalType(cachedType, typeEntry.getValue());
    }
}
Also used : ClassType(org.apache.atlas.typesystem.types.ClassType) IDataType(org.apache.atlas.typesystem.types.IDataType) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

ClassType (org.apache.atlas.typesystem.types.ClassType)54 Test (org.testng.annotations.Test)26 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)19 TraitType (org.apache.atlas.typesystem.types.TraitType)19 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)17 Referenceable (org.apache.atlas.typesystem.Referenceable)16 TypesDef (org.apache.atlas.typesystem.TypesDef)15 ArrayList (java.util.ArrayList)12 Id (org.apache.atlas.typesystem.persistence.Id)8 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)8 Date (java.util.Date)5 HashMap (java.util.HashMap)5 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)5 BeforeTest (org.testng.annotations.BeforeTest)5 AtlasException (org.apache.atlas.AtlasException)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)3 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3