Search in sources :

Example 21 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testAddTraitWithAttribute.

@Test
public void testAddTraitWithAttribute() 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);
    }
    final String traitName = "PII_Trait" + randomString();
    HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
    String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    createType(traitDefinitionAsJSON);
    Struct traitInstance = new Struct(traitName);
    traitInstance.set("type", "SSN");
    atlasClientV1.addTrait(guid, traitInstance);
    // verify the response
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNotNull(entity);
    Assert.assertEquals(entity.getId()._getId(), guid);
    assertNotNull(entity.getTrait(traitName));
    assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type"));
}
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 22 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testSubmitEntity.

@Test
public void testSubmitEntity() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(referenceable);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 23 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testGetTraitDefinitionForEntity.

@Test
public void testGetTraitDefinitionForEntity() 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);
    Struct traitDef = atlasClientV1.getTraitDefinition(guid, traitName);
    Assert.assertEquals(traitDef.getTypeName(), traitName);
    List<Struct> allTraitDefs = atlasClientV1.listTraitDefinitions(guid);
    System.out.println(allTraitDefs.toString());
    Assert.assertEquals(allTraitDefs.size(), 8);
}
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 24 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.

@Test
public void testDeleteExistentTraitNonExistentForEntity() 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);
    }
    final String traitName = "PII_Trait" + randomString();
    HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
    String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
    createType(traitDefinitionAsJSON);
    try {
        atlasClientV1.deleteTrait(guid, traitName);
        fail("Call should've failed for deletion of invalid trait");
    } catch (AtlasServiceException e) {
        assertNotNull(e);
        assertNotNull(e.getStatus());
        assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) TraitType(org.apache.atlas.typesystem.types.TraitType) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 25 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testEntityDeduping.

@Test
public void testEntityDeduping() throws Exception {
    final String dbName = "db" + randomString();
    Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbIdReference = createInstance(HiveDBInstance);
    final String dbId = dbIdReference._getId();
    assertEntityAudit(dbId, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
    waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {

        @Override
        public boolean evaluate(EntityNotification notification) throws Exception {
            return notification != null && notification.getEntity().getId()._getId().equals(dbId);
        }
    });
    JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
    assertEquals(results.length(), 1);
    //create entity again shouldn't create another instance with same unique attribute value
    List<String> entityResults = atlasClientV1.createEntity(HiveDBInstance);
    assertEquals(entityResults.size(), 0);
    try {
        waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {

            @Override
            public boolean evaluate(EntityNotification notification) throws Exception {
                return notification != null && notification.getEntity().getId()._getId().equals(dbId);
            }
        });
    } catch (Exception e) {
    //expected timeout
    }
    results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
    assertEquals(results.length(), 1);
    //Test the same across references
    Referenceable table = new Referenceable(HIVE_TABLE_TYPE_BUILTIN);
    final String tableName = randomString();
    Referenceable tableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbIdReference);
    atlasClientV1.createEntity(tableInstance);
    results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
    assertEquals(results.length(), 1);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) EntityNotification(org.apache.atlas.notification.entity.EntityNotification) JSONArray(org.codehaus.jettison.json.JSONArray) Id(org.apache.atlas.typesystem.persistence.Id) AtlasServiceException(org.apache.atlas.AtlasServiceException) Test(org.testng.annotations.Test)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5