Search in sources :

Example 6 with AttributeDefinition

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

the class TypeConverterUtil method toAtlasClassificationDefs.

private static List<AtlasClassificationDef> toAtlasClassificationDefs(List<HierarchicalTypeDefinition<TraitType>> traitTypeDefinitions) throws AtlasBaseException {
    List<AtlasClassificationDef> ret = new ArrayList<AtlasClassificationDef>();
    for (HierarchicalTypeDefinition<TraitType> traitType : traitTypeDefinitions) {
        AtlasClassificationDef classifDef = new AtlasClassificationDef();
        List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
        classifDef.setName(traitType.typeName);
        classifDef.setDescription(traitType.typeDescription);
        classifDef.setTypeVersion(traitType.typeVersion);
        classifDef.setSuperTypes(traitType.superTypes);
        AttributeDefinition[] attrDefinitions = traitType.attributeDefinitions;
        for (AttributeDefinition attrDefinition : attrDefinitions) {
            attrDefs.add(toAtlasAttributeDef(attrDefinition));
        }
        classifDef.setAttributeDefs(attrDefs);
        ret.add(classifDef);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition)

Example 7 with AttributeDefinition

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

the class GraphBackedMetadataRepositoryTest method testConcurrentCalls.

@Test
public //In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104
void testConcurrentCalls() throws Exception {
    final HierarchicalTypeDefinition<ClassType> refType = createClassTypeDef(randomString(), ImmutableSet.<String>of());
    HierarchicalTypeDefinition<ClassType> type = createClassTypeDef(randomString(), ImmutableSet.<String>of(), new AttributeDefinition("ref", refType.typeName, Multiplicity.OPTIONAL, true, null));
    typeSystem.defineClassType(refType);
    typeSystem.defineClassType(type);
    String refId1 = createEntity(new Referenceable(refType.typeName)).get(0);
    String refId2 = createEntity(new Referenceable(refType.typeName)).get(0);
    final Referenceable instance1 = new Referenceable(type.typeName);
    instance1.set("ref", new Referenceable(refId1, refType.typeName, null));
    final Referenceable instance2 = new Referenceable(type.typeName);
    instance2.set("ref", new Referenceable(refId2, refType.typeName, null));
    ExecutorService executor = Executors.newFixedThreadPool(3);
    List<Future<Object>> futures = new ArrayList<>();
    futures.add(executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return createEntity(instance1).get(0);
        }
    }));
    futures.add(executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return createEntity(instance2).get(0);
        }
    }));
    futures.add(executor.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return discoveryService.searchByDSL(TestUtils.TABLE_TYPE, new QueryParams(10, 0));
        }
    }));
    String id1 = (String) futures.get(0).get();
    String id2 = (String) futures.get(1).get();
    futures.get(2).get();
    executor.shutdown();
    boolean validated1 = assertEdge(id1, type.typeName);
    boolean validated2 = assertEdge(id2, type.typeName);
    assertTrue(validated1 | validated2);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) Future(java.util.concurrent.Future) QueryParams(org.apache.atlas.query.QueryParams) ClassType(org.apache.atlas.typesystem.types.ClassType) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test)

Example 8 with AttributeDefinition

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

the class QuickStart method createTypeDefinitions.

TypesDef createTypeDefinitions() throws Exception {
    HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil.createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), attrDef("description", DataTypes.STRING_TYPE), attrDef("locationUri", DataTypes.STRING_TYPE), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE));
    HierarchicalTypeDefinition<ClassType> storageDescClsDef = TypesUtil.createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", DataTypes.STRING_TYPE), attrDef("inputFormat", DataTypes.STRING_TYPE), attrDef("outputFormat", DataTypes.STRING_TYPE), attrDef("compressed", DataTypes.STRING_TYPE, Multiplicity.REQUIRED, false, null));
    HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
    HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("retention", DataTypes.LONG_TYPE), attrDef("viewOriginalText", DataTypes.STRING_TYPE), attrDef("viewExpandedText", DataTypes.STRING_TYPE), attrDef("tableType", DataTypes.STRING_TYPE), attrDef("temporary", DataTypes.BOOLEAN_TYPE), new AttributeDefinition(COLUMNS_ATTRIBUTE, DataTypes.arrayTypeName(COLUMN_TYPE), Multiplicity.COLLECTION, true, null));
    HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableSet.of("Process"), attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE), attrDef("endTime", DataTypes.LONG_TYPE), attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
    HierarchicalTypeDefinition<ClassType> viewClsDef = TypesUtil.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("inputTables", DataTypes.arrayTypeName(TABLE_TYPE), Multiplicity.COLLECTION, false, null));
    HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null);
    HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null);
    HierarchicalTypeDefinition<TraitType> piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null);
    HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null);
    HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null);
    HierarchicalTypeDefinition<TraitType> jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null);
    HierarchicalTypeDefinition<TraitType> logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null);
    return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef), ImmutableList.of(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef));
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 9 with AttributeDefinition

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

the class FieldMappingTest method testOutputStruct.

@Test
public void testOutputStruct() throws Exception {
    // ATLAS-645: verify that FieldMapping.output(IStruct) does not infinitely recurse
    // when an IStruct and ITypedReferenceableInstance reference each other.
    HierarchicalTypeDefinition<ClassType> valueDef = TypesUtil.createClassTypeDef("Value", ImmutableSet.<String>of(), new AttributeDefinition("owner", "Owner", Multiplicity.OPTIONAL, false, null));
    // Define struct type with reference, where the value is a class reference to Value.
    StructTypeDefinition ownerDef = TypesUtil.createStructTypeDef("Owner", new AttributeDefinition("value", "Value", Multiplicity.OPTIONAL, false, null));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(ownerDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(valueDef));
    TypeSystem typeSystem = TypeSystem.getInstance();
    typeSystem.reset();
    typeSystem.defineTypes(typesDef);
    StructType ownerType = typeSystem.getDataType(StructType.class, "Owner");
    ClassType valueType = typeSystem.getDataType(ClassType.class, "Value");
    // Prior to fix for ATLAS-645, this call would throw a StackOverflowError
    try {
        ownerType.toString();
    } catch (StackOverflowError e) {
        Assert.fail("Infinite recursion in StructType.toString() caused StackOverflowError");
    }
    // Create instances of Owner and Value that reference each other.
    ITypedStruct ownerInstance = ownerType.createInstance();
    ITypedReferenceableInstance valueInstance = valueType.createInstance();
    // Set Owner.value reference to Value instance.
    ownerInstance.set("value", valueInstance);
    // Set Value.owner reference on Owner instance.
    valueInstance.set("owner", ownerInstance);
    // Prior to fix for ATLAS-645, this call would throw a StackOverflowError
    try {
        ownerInstance.fieldMapping().output(ownerInstance, new StringBuilder(), "", null);
    } catch (StackOverflowError e) {
        Assert.fail("Infinite recursion in FieldMapping.output() caused StackOverflowError");
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with AttributeDefinition

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

the class AbstractGremlinQueryOptimizerTest method getTestFieldInfo.

private FieldInfo getTestFieldInfo() throws AtlasException {
    AttributeDefinition def = new AttributeDefinition("foo", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null);
    AttributeInfo attrInfo = new AttributeInfo(TypeSystem.getInstance(), def, null);
    return new FieldInfo(DataTypes.STRING_TYPE, attrInfo, null, null);
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) FieldInfo(org.apache.atlas.query.TypeUtils.FieldInfo)

Aggregations

AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)27 ClassType (org.apache.atlas.typesystem.types.ClassType)17 Test (org.testng.annotations.Test)13 TraitType (org.apache.atlas.typesystem.types.TraitType)10 ArrayList (java.util.ArrayList)7 TypesDef (org.apache.atlas.typesystem.TypesDef)7 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)4 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Referenceable (org.apache.atlas.typesystem.Referenceable)3 StructTypeDefinition (org.apache.atlas.typesystem.types.StructTypeDefinition)3 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)3 BeforeTest (org.testng.annotations.BeforeTest)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 QueryParams (org.apache.atlas.query.QueryParams)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Callable (java.util.concurrent.Callable)1