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;
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations