Search in sources :

Example 6 with ClassType

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

the class GraphHelper method getTypedReferenceableInstance.

public static ITypedReferenceableInstance getTypedReferenceableInstance(TypeSystem typeSystem, Referenceable entityInstance) throws AtlasException {
    final String entityTypeName = ParamChecker.notEmpty(entityInstance.getTypeName(), "Entity type cannot be null");
    ClassType entityType = typeSystem.getDataType(ClassType.class, entityTypeName);
    //Both assigned id and values are required for full update
    //classtype.convert() will remove values if id is assigned. So, set temp id, convert and
    // then replace with original id
    Id origId = entityInstance.getId();
    entityInstance.replaceWithNewId(new Id(entityInstance.getTypeName()));
    ITypedReferenceableInstance typedInstrance = entityType.convert(entityInstance, Multiplicity.REQUIRED);
    ((ReferenceableInstance) typedInstrance).replaceWithNewId(origId);
    return typedInstrance;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 7 with ClassType

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

the class GraphBackedSearchIndexer method addIndexForType.

private void addIndexForType(AtlasGraphManagement management, IDataType dataType) {
    switch(dataType.getTypeCategory()) {
        case PRIMITIVE:
        case ENUM:
        case ARRAY:
        case MAP:
            // and not types like structs, traits or classes
            break;
        case STRUCT:
            StructType structType = (StructType) dataType;
            createIndexForFields(management, structType, structType.fieldMapping().fields);
            break;
        case TRAIT:
            TraitType traitType = (TraitType) dataType;
            createIndexForFields(management, traitType, traitType.fieldMapping().fields);
            break;
        case CLASS:
            ClassType classType = (ClassType) dataType;
            createIndexForFields(management, classType, classType.fieldMapping().fields);
            break;
        default:
            throw new IllegalArgumentException("bad data type" + dataType);
    }
}
Also used : StructType(org.apache.atlas.typesystem.types.StructType) AtlasStructType(org.apache.atlas.type.AtlasStructType) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 8 with ClassType

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

the class TypeConverterUtil method classificationToTypesDef.

private static TypesDef classificationToTypesDef(AtlasClassificationType classificationType, AtlasTypeRegistry registry) throws AtlasBaseException {
    String typeName = classificationType.getClassificationDef().getName();
    String typeDesc = classificationType.getClassificationDef().getDescription();
    String typeVersion = classificationType.getClassificationDef().getTypeVersion();
    ImmutableSet superTypes = ImmutableSet.copyOf(classificationType.getClassificationDef().getSuperTypes());
    AttributeDefinition[] attributes = getAttributes(classificationType, registry);
    HierarchicalTypeDefinition traitType = TypesUtil.createTraitTypeDef(typeName, typeDesc, typeVersion, superTypes, attributes);
    TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(traitType), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
    return ret;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) ImmutableSet(com.google.common.collect.ImmutableSet) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) 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)

Example 9 with ClassType

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

the class TypeConverterUtil method structToTypesDef.

private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException {
    String typeName = structType.getStructDef().getName();
    String typeDesc = structType.getStructDef().getDescription();
    String typeVersion = structType.getStructDef().getTypeVersion();
    AttributeDefinition[] attributes = getAttributes(structType, registry);
    StructTypeDefinition structTypeDef = TypesUtil.createStructTypeDef(typeName, typeDesc, typeVersion, attributes);
    TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(structTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
    return ret;
}
Also used : AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) 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) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition)

Example 10 with ClassType

use of org.apache.atlas.typesystem.types.ClassType 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)

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