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()));
}
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()));
}
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()));
}
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));
}
}
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);
}
Aggregations