use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class TypeConverterUtil method entityToTypesDef.
private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) throws AtlasBaseException {
String typeName = entityType.getEntityDef().getName();
String typeDesc = entityType.getEntityDef().getDescription();
String typeVersion = entityType.getEntityDef().getTypeVersion();
ImmutableSet superTypes = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes());
AttributeDefinition[] attributes = getAttributes(entityType, registry);
HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion, superTypes, attributes);
TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(classType));
return ret;
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method testCreateEntity.
@Test
public void testCreateEntity() throws Exception {
Referenceable databaseInstance = new Referenceable(TestUtils.DATABASE_TYPE);
databaseInstance.set("name", TestUtils.DATABASE_NAME);
databaseInstance.set("description", "foo database");
databaseInstance.set("created", new Date(TestUtils.TEST_DATE_IN_LONG));
databaseInstance.set("namespace", "colo:cluster:hive:db");
databaseInstance.set("cluster", "cluster-1");
databaseInstance.set("colo", "colo-1");
System.out.println("databaseInstance = " + databaseInstance);
ClassType dbType = typeSystem.getDataType(ClassType.class, TestUtils.DATABASE_TYPE);
ITypedReferenceableInstance db = dbType.convert(databaseInstance, Multiplicity.REQUIRED);
System.out.println("db = " + db);
//Reuse the same database instance without id, with the same unique attribute
ITypedReferenceableInstance table = createHiveTableInstance(databaseInstance);
List<String> guids = createEntities(db, table);
//1 db + 5 columns + 1 table. Shouldn't create db again
Assert.assertEquals(guids.size(), 7);
System.out.println("added db = " + guids.get(0));
System.out.println("added table = " + guids.get(6));
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method testCreateEntityWithThreeNestingLevels.
@Test
public void testCreateEntityWithThreeNestingLevels() throws AtlasException {
List<Referenceable> toVerify = new ArrayList<>();
Referenceable dept = new Referenceable(TestUtils.DEPARTMENT_TYPE);
toVerify.add(dept);
dept.set(TestUtils.NAME, "test3");
Referenceable barry = new Referenceable(TestUtils.PERSON_TYPE);
toVerify.add(barry);
barry.set(TestUtils.NAME, "barry");
barry.set(TestUtils.DEPARTMENT_ATTR, dept);
Referenceable barryComputer = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(barryComputer);
barryComputer.set("name", "barryComputer");
barry.set(TestUtils.ASSETS_ATTR, ImmutableList.of(barryComputer));
Referenceable barryHardDrive = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(barryHardDrive);
barryHardDrive.set("name", "barryHardDrive");
Referenceable barryCpuFan = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(barryCpuFan);
barryCpuFan.set("name", "barryCpuFan");
Referenceable barryVideoCard = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(barryVideoCard);
barryVideoCard.set("name", "barryVideoCard");
barryComputer.set("childAssets", ImmutableList.of(barryHardDrive, barryVideoCard, barryCpuFan));
Referenceable jacob = new Referenceable(TestUtils.PERSON_TYPE);
toVerify.add(jacob);
jacob.set(TestUtils.NAME, "jacob");
jacob.set(TestUtils.DEPARTMENT_ATTR, dept);
Referenceable jacobComputer = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(jacobComputer);
jacobComputer.set("name", "jacobComputer");
jacob.set(TestUtils.ASSETS_ATTR, ImmutableList.of(jacobComputer));
Referenceable jacobHardDrive = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(jacobHardDrive);
jacobHardDrive.set("name", "jacobHardDrive");
Referenceable jacobCpuFan = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(jacobCpuFan);
jacobCpuFan.set("name", "jacobCpuFan");
Referenceable jacobVideoCard = new Referenceable(TestUtils.ASSET_TYPE);
toVerify.add(jacobVideoCard);
jacobVideoCard.set("name", "jacobVideoCard");
jacobComputer.set("childAssets", ImmutableList.of(jacobHardDrive, jacobVideoCard, jacobCpuFan));
dept.set(TestUtils.EMPLOYEES_ATTR, ImmutableList.of(barry, jacob));
Map<String, Referenceable> positions = new HashMap<>();
final String JANITOR = "janitor";
final String RECEPTIONIST = "receptionist";
positions.put(JANITOR, barry);
positions.put(RECEPTIONIST, jacob);
dept.set(TestUtils.POSITIONS_ATTR, positions);
ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, TestUtils.DEPARTMENT_TYPE);
ITypedReferenceableInstance deptInstance = deptType.convert(dept, Multiplicity.REQUIRED);
CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
assertEquals(result.getCreatedEntities().size(), toVerify.size());
validateGuidMapping(toVerify, result);
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method testMultipleTypesWithSameUniqueAttribute.
@Test
public void testMultipleTypesWithSameUniqueAttribute() throws Exception {
//Two entities of different types(with same supertype that has the unique attribute) with same qualified name should succeed
HierarchicalTypeDefinition<ClassType> supertype = createClassTypeDef(randomString(), ImmutableSet.<String>of(), createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> t1 = createClassTypeDef(randomString(), ImmutableSet.of(supertype.typeName));
HierarchicalTypeDefinition<ClassType> t2 = createClassTypeDef(randomString(), ImmutableSet.of(supertype.typeName));
typeSystem.defineClassTypes(supertype, t1, t2);
final String name = randomString();
String id1 = createEntity(new Referenceable(t1.typeName) {
{
set("name", name);
}
}).get(0);
String id2 = createEntity(new Referenceable(t2.typeName) {
{
set("name", name);
}
}).get(0);
assertNotEquals(id1, id2);
ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(t1.typeName, "name", name);
assertEquals(entity.getTypeName(), t1.typeName);
assertEquals(entity.getId()._getId(), id1);
entity = repositoryService.getEntityDefinition(t2.typeName, "name", name);
assertEquals(entity.getTypeName(), t2.typeName);
assertEquals(entity.getId()._getId(), id2);
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method createHiveTableInstance.
private ITypedReferenceableInstance createHiveTableInstance(Referenceable databaseInstance) throws Exception {
Referenceable tableInstance = new Referenceable(TestUtils.TABLE_TYPE, TestUtils.CLASSIFICATION);
tableInstance.set("name", TestUtils.TABLE_NAME);
tableInstance.set("description", "bar table");
tableInstance.set("type", "managed");
tableInstance.set("created", new Date(TestUtils.TEST_DATE_IN_LONG));
// enum
tableInstance.set("tableType", 1);
// super type
tableInstance.set("namespace", "colo:cluster:hive:db:table");
tableInstance.set("cluster", "cluster-1");
tableInstance.set("colo", "colo-1");
// refer to an existing class
tableInstance.set("database", databaseInstance);
ArrayList<String> columnNames = new ArrayList<>();
columnNames.add("first_name");
columnNames.add("last_name");
tableInstance.set("columnNames", columnNames);
Struct traitInstance = (Struct) tableInstance.getTrait(TestUtils.CLASSIFICATION);
traitInstance.set("tag", "foundation_etl");
Struct serde1Instance = new Struct("serdeType");
serde1Instance.set("name", "serde1");
serde1Instance.set("serde", "serde1");
tableInstance.set("serde1", serde1Instance);
Struct serde2Instance = new Struct("serdeType");
serde2Instance.set("name", "serde2");
serde2Instance.set("serde", "serde2");
tableInstance.set("serde2", serde2Instance);
// HashMap<String, Referenceable> columnsMap = new HashMap<>();
ArrayList<Referenceable> columns = new ArrayList<>();
for (int index = 0; index < 5; index++) {
Referenceable columnInstance = new Referenceable("column_type");
final String name = "column_" + index;
columnInstance.set("name", name);
columnInstance.set("type", "string");
columns.add(columnInstance);
// columnsMap.put(name, columnInstance);
}
tableInstance.set("columns", columns);
// tableInstance.set("columnsMap", columnsMap);
// HashMap<String, Struct> partitionsMap = new HashMap<>();
ArrayList<Struct> partitions = new ArrayList<>();
for (int index = 0; index < 5; index++) {
Struct partitionInstance = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
final String name = "partition_" + index;
partitionInstance.set("name", name);
partitions.add(partitionInstance);
// partitionsMap.put(name, partitionInstance);
}
tableInstance.set("partitions", partitions);
// tableInstance.set("partitionsMap", partitionsMap);
HashMap<String, String> parametersMap = new HashMap<>();
parametersMap.put("foo", "bar");
parametersMap.put("bar", "baz");
parametersMap.put("some", "thing");
tableInstance.set("parametersMap", parametersMap);
ClassType tableType = typeSystem.getDataType(ClassType.class, TestUtils.TABLE_TYPE);
return tableType.convert(tableInstance, Multiplicity.REQUIRED);
}
Aggregations