use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class TypesJerseyResourceIT method testDuplicateSubmit.
@Test
public void testDuplicateSubmit() throws Exception {
HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(), ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type));
atlasClientV1.createType(typesDef);
try {
atlasClientV1.createType(typesDef);
fail("Expected 409");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
}
}
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);
}
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);
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.
@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
//create type
HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil.createClassTypeDef(randomString(), ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE));
atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
//create entity for the type
Referenceable instance = new Referenceable(typeDefinition.typeName);
instance.set("name", randomString());
String guid = atlasClientV1.createEntity(instance).get(0);
//update type - add attribute
typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE));
TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(typeDefinition));
atlasClientV1.updateType(typeDef);
//Get definition after type update - new attributes should be null
Referenceable entity = atlasClientV1.getEntity(guid);
Assert.assertNull(entity.get("description"));
Assert.assertEquals(entity.get("name"), instance.get("name"));
}
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);
}
}
}
Aggregations