Search in sources :

Example 41 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class EntityLineageServiceTest method testGetOutputLineageInfo.

@Test
public void testGetOutputLineageInfo() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact");
    AtlasLineageInfo outputLineage = getOutputLineageInfo(entityGuid, 4);
    assertNotNull(outputLineage);
    System.out.println("output lineage = " + outputLineage);
    Map<String, AtlasEntityHeader> entities = outputLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = outputLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 5);
    Assert.assertEquals(relations.size(), 4);
    Assert.assertEquals(outputLineage.getLineageDepth(), 4);
    Assert.assertEquals(outputLineage.getLineageDirection(), LineageDirection.OUTPUT);
    assertTrue(entities.containsKey(outputLineage.getBaseEntityGuid()));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 42 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class EntityLineageServiceTest method testGetInputLineageInfo.

@Test
public void testGetInputLineageInfo() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact_monthly_mv");
    AtlasLineageInfo inputLineage = getInputLineageInfo(entityGuid, 4);
    assertNotNull(inputLineage);
    System.out.println("input lineage = " + inputLineage);
    Map<String, AtlasEntityHeader> entities = inputLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = inputLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(inputLineage.getLineageDepth(), 4);
    Assert.assertEquals(inputLineage.getLineageDirection(), LineageDirection.INPUT);
    assertTrue(entities.containsKey(inputLineage.getBaseEntityGuid()));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 43 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonCompositeManyToOne.

@Test
public void testInverseReferenceAutoUpdate_NonCompositeManyToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(a3);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream, false);
    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.manyA reference to a1 and a2
    // * set inverse a1.oneB reference to b
    // * set inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceList(storedEntity, "manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a3)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set b.manyA reference to a3
    // * set inverse a3.oneB reference to b
    // * disconnect inverse a1.oneB reference to b
    // * disconnect inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 4);
    init();
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), a3.getGuid(), b.getGuid()));
    verifyReferenceValue(storedEntities.getEntity(a3.getGuid()), "oneB", b.getGuid());
    verify_testInverseReferenceAutoUpdate_NonCompositeManyToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(a2.getGuid()), storedEntities.getEntity(a3.getGuid()), storedEntities.getEntity(b.getGuid()));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 44 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class InverseReferenceUpdateV1Test method setUp.

@BeforeClass
public void setUp() throws Exception {
    metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
    AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineInverseReferenceTestTypes() };
    for (AtlasTypesDef typesDef : testTypesDefs) {
        AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
        if (!typesToCreate.isEmpty()) {
            typeDefStore.createTypesDef(typesToCreate);
        }
    }
    deptEntity = TestUtilsV2.createDeptEg2();
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);
    for (AtlasEntityHeader entityHeader : response.getCreatedEntities()) {
        nameIdMap.put((String) entityHeader.getAttribute(NAME), AtlasTypeUtil.getAtlasObjectId(entityHeader));
    }
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 45 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader in project incubator-atlas by apache.

the class EntityLineageJerseyResourceIT method testLineageInfo.

@Test
public void testLineageInfo() throws Exception {
    String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
    queryParams.add(DEPTH_PARAM, "5");
    JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
    Assert.assertNotNull(response);
    System.out.println("both lineage info = " + response);
    AtlasLineageInfo bothLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
    Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
    Assert.assertNotNull(entities);
    Set<AtlasLineageInfo.LineageRelation> relations = bothLineageInfo.getRelations();
    Assert.assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(bothLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
    Assert.assertEquals(bothLineageInfo.getLineageDepth(), 5);
    Assert.assertEquals(bothLineageInfo.getBaseEntityGuid(), tableId);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)65 Test (org.testng.annotations.Test)46 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)38 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)15 ArrayList (java.util.ArrayList)14 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)14 HashMap (java.util.HashMap)12 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)12 List (java.util.List)10 Map (java.util.Map)8 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)6 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)5