Search in sources :

Example 51 with ClassType

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

the class VertexLookupContext method addInstance.

/**
 * Adds an instance to be loaded.
 */
public void addInstance(IReferenceableInstance instance) throws AtlasException {
    ClassType classType = typeSystem.getDataType(ClassType.class, instance.getTypeName());
    ITypedReferenceableInstance newInstance = classType.convert(instance, Multiplicity.REQUIRED);
    findReferencedInstancesToPreLoad(newInstance);
    Id id = instance.getId();
    if (mapper.lookupVertex(id) == null) {
        if (id.isAssigned()) {
            guidsToLookup.add(id);
        } else {
            addToClassMap(classType, instance);
        }
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 52 with ClassType

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

the class ReverseReferenceUpdateTestBase method setUp.

@BeforeClass
public void setUp() throws Exception {
    typeSystem = TypeSystem.getInstance();
    typeSystem.reset();
    HierarchicalTypeDefinition<ClassType> aDef = TypesUtil.createClassTypeDef("A", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), // 1-1
    new AttributeDefinition("b", "B", Multiplicity.OPTIONAL, false, "a"), // 1-*
    new AttributeDefinition("oneB", "B", Multiplicity.OPTIONAL, false, "manyA"), // *-*
    new AttributeDefinition("manyB", DataTypes.arrayTypeName("B"), Multiplicity.OPTIONAL, false, "manyToManyA"), new AttributeDefinition("map", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), "B"), Multiplicity.OPTIONAL, false, "backToMap"));
    HierarchicalTypeDefinition<ClassType> bDef = TypesUtil.createClassTypeDef("B", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), new AttributeDefinition("a", "A", Multiplicity.OPTIONAL, false, "b"), new AttributeDefinition("manyA", DataTypes.arrayTypeName("A"), Multiplicity.OPTIONAL, false, "oneB"), new AttributeDefinition("manyToManyA", DataTypes.arrayTypeName("A"), Multiplicity.OPTIONAL, false, "manyB"), new AttributeDefinition("backToMap", "A", Multiplicity.OPTIONAL, false, "map"));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(aDef, bDef));
    typeSystem.defineTypes(typesDef);
    typeA = typeSystem.getDataType(ClassType.class, "A");
    typeB = typeSystem.getDataType(ClassType.class, "B");
    repositoryService = TestUtils.addTransactionWrapper(repositoryService);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) BeforeClass(org.testng.annotations.BeforeClass)

Example 53 with ClassType

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

the class GraphRepoMapperScaleTest method createHiveTableInstance.

private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance, int uberIndex) throws Exception {
    Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE);
    tableInstance.set("name", TABLE_NAME + "-" + uberIndex);
    tableInstance.set("description", "bar table" + "-" + uberIndex);
    tableInstance.set("type", "managed");
    tableInstance.set("created", new Date(TestUtils.TEST_DATE_IN_LONG));
    // enum
    tableInstance.set("tableType", 1);
    // refer to an existing class
    tableInstance.set("database", databaseInstance);
    ArrayList<String> columnNames = new ArrayList<>();
    columnNames.add("first_name" + "-" + uberIndex);
    columnNames.add("last_name" + "-" + uberIndex);
    tableInstance.set("columnNames", columnNames);
    Struct serde1Instance = new Struct("serdeType");
    serde1Instance.set("name", "serde1" + "-" + uberIndex);
    serde1Instance.set("serde", "serde1" + "-" + uberIndex);
    tableInstance.set("serde1", serde1Instance);
    Struct serde2Instance = new Struct("serdeType");
    serde2Instance.set("name", "serde2" + "-" + uberIndex);
    serde2Instance.set("serde", "serde2" + "-" + uberIndex);
    tableInstance.set("serde2", serde2Instance);
    ArrayList<Referenceable> columns = new ArrayList<>();
    for (int index = 0; index < 5; index++) {
        Referenceable columnInstance = new Referenceable("column_type");
        columnInstance.set("name", "column_" + "-" + uberIndex + "-" + index);
        columnInstance.set("type", "string");
        columns.add(columnInstance);
    }
    tableInstance.set("columns", columns);
    ArrayList<Struct> partitions = new ArrayList<>();
    for (int index = 0; index < 5; index++) {
        Struct partitionInstance = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
        partitionInstance.set("name", "partition_" + "-" + uberIndex + "-" + index);
        partitions.add(partitionInstance);
    }
    tableInstance.set("partitions", partitions);
    ClassType tableType = typeSystem.getDataType(ClassType.class, TestUtils.TABLE_TYPE);
    return tableType.convert(tableInstance, Multiplicity.REQUIRED);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Date(java.util.Date) Struct(org.apache.atlas.typesystem.Struct)

Example 54 with ClassType

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

the class StoreBackedTypeCacheTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    // force graph to be initialized up front
    TestUtils.getGraph();
    ts = TypeSystem.getInstance();
    ts.reset();
    ts.setTypeCache(typeCache);
    // Populate the type store for testing.
    TestUtils.defineDeptEmployeeTypes(ts);
    TestUtils.createHiveTypes(ts);
    ImmutableList<String> typeNames = ts.getTypeNames();
    typeStore.store(ts, typeNames);
    ClassType type = ts.getDataType(ClassType.class, "Manager");
    classTypesToTest.put("Manager", type);
    type = ts.getDataType(ClassType.class, TestUtils.TABLE_TYPE);
    classTypesToTest.put(TestUtils.TABLE_TYPE, type);
}
Also used : ClassType(org.apache.atlas.typesystem.types.ClassType) BeforeClass(org.testng.annotations.BeforeClass)

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