Search in sources :

Example 91 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasRelationshipStoreHardDeleteV2Test method verifyRelationshipAttributeUpdate_ManyToMany_Friends.

@Override
protected void verifyRelationshipAttributeUpdate_ManyToMany_Friends(AtlasEntity max, AtlasEntity julius, AtlasEntity mike, AtlasEntity john) throws Exception {
    AtlasObjectId johnId = employeeNameIdMap.get("John");
    AtlasObjectId mikeId = employeeNameIdMap.get("Mike");
    AtlasObjectId juliusId = employeeNameIdMap.get("Julius");
    AtlasObjectId maxId = employeeNameIdMap.get("Max");
    List<AtlasObjectId> maxFriendsIds = toAtlasObjectIds(max.getRelationshipAttribute("friends"));
    assertNotNull(maxFriendsIds);
    assertEquals(maxFriendsIds.size(), 2);
    assertObjectIdsContains(maxFriendsIds, johnId);
    assertObjectIdsContains(maxFriendsIds, juliusId);
    // Julius's updated friends: [Max]
    List<AtlasObjectId> juliusFriendsIds = toAtlasObjectIds(julius.getRelationshipAttribute("friends"));
    assertNotNull(juliusFriendsIds);
    assertEquals(juliusFriendsIds.size(), 1);
    assertObjectIdsContains(juliusFriendsIds, maxId);
    // Mike's updated friends: [John]
    List<AtlasObjectId> mikeFriendsIds = toAtlasObjectIds(mike.getRelationshipAttribute("friends"));
    assertNotNull(mikeFriendsIds);
    assertEquals(mikeFriendsIds.size(), 1);
    assertObjectIdsContains(mikeFriendsIds, johnId);
    // John's updated friends: [Max, Mike]
    List<AtlasObjectId> johnFriendsIds = toAtlasObjectIds(john.getRelationshipAttribute("friends"));
    assertNotNull(johnFriendsIds);
    assertEquals(johnFriendsIds.size(), 2);
    assertObjectIdsContains(johnFriendsIds, maxId);
    assertObjectIdsContains(johnFriendsIds, mikeId);
}
Also used : AtlasTypeUtil.getAtlasObjectId(org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 92 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasRelationshipStoreV2Test method testRelationshipAttributeOnPartialUpdate.

@Test
public void testRelationshipAttributeOnPartialUpdate() throws Exception {
    AtlasObjectId maxId = employeeNameIdMap.get("Max");
    AtlasObjectId janeId = employeeNameIdMap.get("Jane");
    AtlasObjectId mikeId = employeeNameIdMap.get("Mike");
    AtlasObjectId johnId = employeeNameIdMap.get("John");
    // Partial Update Max's Employee.friends reference with Jane and apply the change as a partial update.
    // This should also update friends list of Max and Jane.
    AtlasEntity maxEntityForUpdate = new AtlasEntity(EMPLOYEE_TYPE);
    maxEntityForUpdate.setRelationshipAttribute("friends", Arrays.asList(janeId));
    AtlasEntityType employeeType = typeRegistry.getEntityTypeByName(EMPLOYEE_TYPE);
    Map<String, Object> uniqAttributes = Collections.<String, Object>singletonMap("name", "Max");
    init();
    EntityMutationResponse updateResponse = entityStore.updateByUniqueAttributes(employeeType, uniqAttributes, new AtlasEntityWithExtInfo(maxEntityForUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = updateResponse.getPartialUpdatedEntities();
    assertEquals(partialUpdatedEntities.size(), 2);
    // 2 entities should have been updated:
    // * Max to add  Employee.friends reference
    // * Jane to add Max from Employee.friends
    AtlasEntitiesWithExtInfo updatedEntities = entityStore.getByIds(ImmutableList.of(maxId.getGuid(), janeId.getGuid()));
    AtlasEntity maxEntity = updatedEntities.getEntity(maxId.getGuid());
    verifyRelationshipAttributeList(maxEntity, "friends", ImmutableList.of(mikeId, johnId, janeId));
    AtlasEntity janeEntity = updatedEntities.getEntity(janeId.getGuid());
    verifyRelationshipAttributeList(janeEntity, "friends", ImmutableList.of(maxId));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypeUtil.getAtlasObjectId(org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 93 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasRelationshipStoreV2Test method testDepartmentEmployeeEntitiesUsingRelationship.

@Test
public void testDepartmentEmployeeEntitiesUsingRelationship() throws Exception {
    AtlasObjectId hrId = employeeNameIdMap.get("hr");
    AtlasObjectId maxId = employeeNameIdMap.get("Max");
    AtlasObjectId johnId = employeeNameIdMap.get("John");
    AtlasObjectId juliusId = employeeNameIdMap.get("Julius");
    AtlasObjectId janeId = employeeNameIdMap.get("Jane");
    AtlasObjectId mikeId = employeeNameIdMap.get("Mike");
    AtlasEntity hrDept = getEntityFromStore(hrId.getGuid());
    AtlasEntity max = getEntityFromStore(maxId.getGuid());
    AtlasEntity john = getEntityFromStore(johnId.getGuid());
    AtlasEntity julius = getEntityFromStore(juliusId.getGuid());
    AtlasEntity jane = getEntityFromStore(janeId.getGuid());
    AtlasEntity mike = getEntityFromStore(mikeId.getGuid());
    // Department relationship attributes
    List<AtlasObjectId> deptEmployees = toAtlasObjectIds(hrDept.getRelationshipAttribute("employees"));
    assertNotNull(deptEmployees);
    assertEquals(deptEmployees.size(), 5);
    assertObjectIdsContains(deptEmployees, maxId);
    assertObjectIdsContains(deptEmployees, johnId);
    assertObjectIdsContains(deptEmployees, juliusId);
    assertObjectIdsContains(deptEmployees, janeId);
    assertObjectIdsContains(deptEmployees, mikeId);
    // Max employee validation
    AtlasObjectId maxDepartmentId = toAtlasObjectId(max.getRelationshipAttribute("department"));
    assertNotNull(maxDepartmentId);
    assertObjectIdEquals(maxDepartmentId, hrId);
    AtlasObjectId maxManagerId = toAtlasObjectId(max.getRelationshipAttribute("manager"));
    assertNotNull(maxManagerId);
    assertObjectIdEquals(maxManagerId, janeId);
    List<AtlasObjectId> maxMentorsId = toAtlasObjectIds(max.getRelationshipAttribute("mentors"));
    assertNotNull(maxMentorsId);
    assertEquals(maxMentorsId.size(), 1);
    assertObjectIdEquals(maxMentorsId.get(0), juliusId);
    List<AtlasObjectId> maxMenteesId = toAtlasObjectIds(max.getRelationshipAttribute("mentees"));
    assertNotNull(maxMenteesId);
    assertEquals(maxMenteesId.size(), 1);
    assertObjectIdEquals(maxMenteesId.get(0), johnId);
    List<AtlasObjectId> maxFriendsIds = toAtlasObjectIds(max.getRelationshipAttribute("friends"));
    assertNotNull(maxFriendsIds);
    assertEquals(maxFriendsIds.size(), 2);
    assertObjectIdsContains(maxFriendsIds, mikeId);
    assertObjectIdsContains(maxFriendsIds, johnId);
    // John Employee validation
    AtlasObjectId johnDepartmentId = toAtlasObjectId(john.getRelationshipAttribute("department"));
    assertNotNull(johnDepartmentId);
    assertObjectIdEquals(johnDepartmentId, hrId);
    AtlasObjectId johnManagerId = toAtlasObjectId(john.getRelationshipAttribute("manager"));
    assertNotNull(johnManagerId);
    assertObjectIdEquals(johnManagerId, janeId);
    List<AtlasObjectId> johnMentorIds = toAtlasObjectIds(john.getRelationshipAttribute("mentors"));
    assertNotNull(johnMentorIds);
    assertEquals(johnMentorIds.size(), 2);
    assertObjectIdsContains(johnMentorIds, maxId);
    assertObjectIdsContains(johnMentorIds, juliusId);
    List<AtlasObjectId> johnMenteesId = toAtlasObjectIds(john.getRelationshipAttribute("mentees"));
    assertEmpty(johnMenteesId);
    List<AtlasObjectId> johnFriendsIds = toAtlasObjectIds(john.getRelationshipAttribute("friends"));
    assertNotNull(johnFriendsIds);
    assertEquals(johnFriendsIds.size(), 2);
    assertObjectIdsContains(johnFriendsIds, mikeId);
    assertObjectIdsContains(johnFriendsIds, maxId);
    // Mike Employee validation
    AtlasObjectId mikeDepartmentId = toAtlasObjectId(mike.getRelationshipAttribute("department"));
    assertNotNull(mikeDepartmentId);
    assertObjectIdEquals(mikeDepartmentId, hrId);
    AtlasObjectId mikeManagerId = toAtlasObjectId(mike.getRelationshipAttribute("manager"));
    assertNotNull(mikeManagerId);
    assertObjectIdEquals(mikeManagerId, juliusId);
    List<AtlasObjectId> mikeMentorIds = toAtlasObjectIds(mike.getRelationshipAttribute("mentors"));
    assertEmpty(mikeMentorIds);
    List<AtlasObjectId> mikeMenteesId = toAtlasObjectIds(mike.getRelationshipAttribute("mentees"));
    assertEmpty(mikeMenteesId);
    List<AtlasObjectId> mikeFriendsIds = toAtlasObjectIds(mike.getRelationshipAttribute("friends"));
    assertNotNull(mikeFriendsIds);
    assertEquals(mikeFriendsIds.size(), 2);
    assertObjectIdsContains(mikeFriendsIds, maxId);
    assertObjectIdsContains(mikeFriendsIds, johnId);
    // Jane Manager validation
    AtlasObjectId janeDepartmentId = toAtlasObjectId(jane.getRelationshipAttribute("department"));
    assertNotNull(janeDepartmentId);
    assertObjectIdEquals(janeDepartmentId, hrId);
    AtlasObjectId janeManagerId = toAtlasObjectId(jane.getRelationshipAttribute("manager"));
    assertNull(janeManagerId);
    List<AtlasObjectId> janeMentorIds = toAtlasObjectIds(jane.getRelationshipAttribute("mentors"));
    assertEmpty(janeMentorIds);
    List<AtlasObjectId> janeMenteesId = toAtlasObjectIds(jane.getRelationshipAttribute("mentees"));
    assertEmpty(janeMenteesId);
    List<AtlasObjectId> janeSubordinateIds = toAtlasObjectIds(jane.getRelationshipAttribute("subordinates"));
    assertNotNull(janeSubordinateIds);
    assertEquals(janeSubordinateIds.size(), 2);
    assertObjectIdsContains(janeSubordinateIds, maxId);
    assertObjectIdsContains(janeSubordinateIds, johnId);
    List<AtlasObjectId> janeFriendsIds = toAtlasObjectIds(jane.getRelationshipAttribute("friends"));
    assertEmpty(janeFriendsIds);
    AtlasObjectId janeSiblingId = toAtlasObjectId(jane.getRelationshipAttribute("sibling"));
    assertNotNull(janeSiblingId);
    assertObjectIdEquals(janeSiblingId, juliusId);
    // Julius Manager validation
    AtlasObjectId juliusDepartmentId = toAtlasObjectId(julius.getRelationshipAttribute("department"));
    assertNotNull(juliusDepartmentId);
    assertObjectIdEquals(juliusDepartmentId, hrId);
    AtlasObjectId juliusManagerId = toAtlasObjectId(julius.getRelationshipAttribute("manager"));
    assertNull(juliusManagerId);
    List<AtlasObjectId> juliusMentorIds = toAtlasObjectIds(julius.getRelationshipAttribute("mentors"));
    assertEmpty(juliusMentorIds);
    List<AtlasObjectId> juliusMenteesId = toAtlasObjectIds(julius.getRelationshipAttribute("mentees"));
    assertNotNull(juliusMenteesId);
    assertEquals(juliusMenteesId.size(), 2);
    assertObjectIdsContains(juliusMenteesId, maxId);
    assertObjectIdsContains(juliusMenteesId, johnId);
    List<AtlasObjectId> juliusSubordinateIds = toAtlasObjectIds(julius.getRelationshipAttribute("subordinates"));
    assertNotNull(juliusSubordinateIds);
    assertEquals(juliusSubordinateIds.size(), 1);
    assertObjectIdsContains(juliusSubordinateIds, mikeId);
    List<AtlasObjectId> juliusFriendsIds = toAtlasObjectIds(julius.getRelationshipAttribute("friends"));
    assertEmpty(juliusFriendsIds);
    AtlasObjectId juliusSiblingId = toAtlasObjectId(julius.getRelationshipAttribute("sibling"));
    assertNotNull(juliusSiblingId);
    assertObjectIdEquals(juliusSiblingId, janeId);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasTypeUtil.getAtlasObjectId(org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 94 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasEntityStoreV2Test method testStructs.

@Test(dependsOnMethods = "testCreate")
public void testStructs() throws Exception {
    AtlasEntity databaseEntity = dbEntity.getEntity();
    AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
    AtlasStruct serdeInstance = new AtlasStruct(TestUtilsV2.SERDE_TYPE, NAME, "serde1Name");
    serdeInstance.setAttribute("serde", "test");
    serdeInstance.setAttribute("description", "testDesc");
    tableEntity.setAttribute("serde1", serdeInstance);
    tableEntity.setAttribute("database", new AtlasObjectId(databaseEntity.getTypeName(), NAME, databaseEntity.getAttribute(NAME)));
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    // update struct attribute
    serdeInstance.setAttribute("serde", "testUpdated");
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    // set to null
    tableEntity.setAttribute("description", null);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    Object updatedDescription = ObjectUtils.defaultIfNull(updatedTable.getAttribute("description"), StringUtils.EMPTY);
    Assert.assertTrue(StringUtils.isEmpty(updatedDescription.toString()));
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) 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) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 95 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasEntityStoreV2Test method testClassUpdate.

@Test(dependsOnMethods = "testCreate")
public void testClassUpdate() throws Exception {
    init();
    // Create new db instance
    final AtlasEntity databaseInstance = TestUtilsV2.createDBEntity();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(databaseInstance), false);
    final AtlasEntityHeader dbCreated = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE);
    init();
    Map<String, AtlasEntity> tableCloneMap = new HashMap<>();
    AtlasEntity tableClone = new AtlasEntity(tblEntity.getEntity());
    tableClone.setAttribute("database", new AtlasObjectId(dbCreated.getGuid(), TestUtilsV2.DATABASE_TYPE));
    tableCloneMap.put(dbCreated.getGuid(), databaseInstance);
    tableCloneMap.put(tableClone.getGuid(), tableClone);
    response = entityStore.createOrUpdate(new InMemoryMapEntityStream(tableCloneMap), false);
    final AtlasEntityHeader tableDefinition = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    AtlasEntity updatedTableDefinition = getEntityFromStore(tableDefinition);
    assertNotNull(updatedTableDefinition.getAttribute("database"));
    Assert.assertEquals(((AtlasObjectId) updatedTableDefinition.getAttribute("database")).getGuid(), dbCreated.getGuid());
}
Also used : HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)255 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)70 ArrayList (java.util.ArrayList)69 Map (java.util.Map)47 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)44 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)41 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)41 HashMap (java.util.HashMap)40 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)38 List (java.util.List)36 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)33 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)32 BeforeTest (org.testng.annotations.BeforeTest)32 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)29 AtlasTypeUtil.getAtlasObjectId (org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId)24 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)22 AtlasExportRequest (org.apache.atlas.model.impexp.AtlasExportRequest)14 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)13 AtlasType (org.apache.atlas.type.AtlasType)11