Search in sources :

Example 31 with TraitType

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

the class GraphBackedMetadataRepositoryTest method testAddTrait.

@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTrait() throws Exception {
    final String aGUID = getGUID();
    AtlasVertex AtlasVertex = GraphHelper.getInstance().getVertexForGUID(aGUID);
    Long modificationTimestampPreUpdate = GraphHelper.getSingleValuedProperty(AtlasVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPreUpdate);
    List<String> traitNames = repositoryService.getTraitNames(aGUID);
    System.out.println("traitNames = " + traitNames);
    Assert.assertEquals(traitNames.size(), 1);
    Assert.assertTrue(traitNames.contains(TestUtils.CLASSIFICATION));
    Assert.assertFalse(traitNames.contains(TestUtils.PII));
    TraitType traitType = typeSystem.getDataType(TraitType.class, TestUtils.PII);
    ITypedStruct traitInstance = traitType.createInstance();
    repositoryService.addTrait(aGUID, traitInstance);
    // refresh trait names
    traitNames = repositoryService.getTraitNames(aGUID);
    Assert.assertEquals(traitNames.size(), 2);
    Assert.assertTrue(traitNames.contains(TestUtils.PII));
    Assert.assertTrue(traitNames.contains(TestUtils.CLASSIFICATION));
    // Verify modification timestamp was updated.
    GraphHelper.getInstance().getVertexForGUID(aGUID);
    Long modificationTimestampPostUpdate = GraphHelper.getSingleValuedProperty(AtlasVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPostUpdate);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Test(org.testng.annotations.Test)

Example 32 with TraitType

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

the class GraphBackedMetadataRepositoryTest method testAddTraitForBadEntity.

@Test(dependsOnMethods = "testAddTrait", expectedExceptions = RepositoryException.class)
public void testAddTraitForBadEntity() throws Exception {
    TraitType traitType = typeSystem.getDataType(TraitType.class, TestUtils.PII);
    ITypedStruct traitInstance = traitType.createInstance();
    repositoryService.addTrait(UUID.randomUUID().toString(), traitInstance);
    Assert.fail();
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) Test(org.testng.annotations.Test)

Example 33 with TraitType

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

the class RestUtilsTest method convertV1toV2.

private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types) throws AtlasBaseException {
    ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList.<HierarchicalTypeDefinition<ClassType>>builder().addAll(types).build();
    TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), classTypeList);
    String json = TypesSerialization.toJson(toConvert);
    AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry();
    AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry);
    List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs();
    return convertedEntityDefs;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 34 with TraitType

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

the class EntityJerseyResourceIT method testAddTrait.

@Test
public void testAddTrait() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
    String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    createType(traitDefinitionAsJSON);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) TraitType(org.apache.atlas.typesystem.types.TraitType) Id(org.apache.atlas.typesystem.persistence.Id) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 35 with TraitType

use of org.apache.atlas.typesystem.types.TraitType 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"));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Aggregations

TraitType (org.apache.atlas.typesystem.types.TraitType)40 Test (org.testng.annotations.Test)22 ClassType (org.apache.atlas.typesystem.types.ClassType)19 TypesDef (org.apache.atlas.typesystem.TypesDef)13 Referenceable (org.apache.atlas.typesystem.Referenceable)12 Struct (org.apache.atlas.typesystem.Struct)12 Id (org.apache.atlas.typesystem.persistence.Id)10 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)10 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)7 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)7 IStruct (org.apache.atlas.typesystem.IStruct)6 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)6 ArrayList (java.util.ArrayList)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)4 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)3 BeforeTest (org.testng.annotations.BeforeTest)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 HashMap (java.util.HashMap)2