Java Code Examples for org.apache.atlas.model.instance.EntityMutationResponse#getPartialUpdatedEntities()

The following examples show how to use org.apache.atlas.model.instance.EntityMutationResponse#getPartialUpdatedEntities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasEntityChangeNotifier.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public void onEntitiesMutated(EntityMutationResponse entityMutationResponse, boolean isImport) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(entityChangeListeners) || instanceConverter == null) {
        return;
    }

    List<AtlasEntityHeader> createdEntities          = entityMutationResponse.getCreatedEntities();
    List<AtlasEntityHeader> updatedEntities          = entityMutationResponse.getUpdatedEntities();
    List<AtlasEntityHeader> partiallyUpdatedEntities = entityMutationResponse.getPartialUpdatedEntities();
    List<AtlasEntityHeader> deletedEntities          = entityMutationResponse.getDeletedEntities();

    // complete full text mapping before calling toITypedReferenceable(), from notifyListners(), to
    // include all vertex updates in the current graph-transaction
    doFullTextMapping(createdEntities);
    doFullTextMapping(updatedEntities);
    doFullTextMapping(partiallyUpdatedEntities);

    notifyListeners(createdEntities, EntityOperation.CREATE, isImport);
    notifyListeners(updatedEntities, EntityOperation.UPDATE, isImport);
    notifyListeners(partiallyUpdatedEntities, EntityOperation.PARTIAL_UPDATE, isImport);
    notifyListeners(deletedEntities, EntityOperation.DELETE, isImport);
}
 
Example 2
Source File: AtlasEntityChangeNotifier.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void onEntitiesMutated(EntityMutationResponse entityMutationResponse, boolean isImport) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(entityChangeListeners)) {
        return;
    }

    pruneResponse(entityMutationResponse);

    List<AtlasEntityHeader> createdEntities          = entityMutationResponse.getCreatedEntities();
    List<AtlasEntityHeader> updatedEntities          = entityMutationResponse.getUpdatedEntities();
    List<AtlasEntityHeader> partiallyUpdatedEntities = entityMutationResponse.getPartialUpdatedEntities();
    List<AtlasEntityHeader> deletedEntities          = entityMutationResponse.getDeletedEntities();
    List<AtlasEntityHeader> purgedEntities           = entityMutationResponse.getPurgedEntities();

    // complete full text mapping before calling toReferenceables(), from notifyListners(), to
    // include all vertex updates in the current graph-transaction
    doFullTextMapping(createdEntities);
    doFullTextMapping(updatedEntities);
    doFullTextMapping(partiallyUpdatedEntities);

    notifyListeners(createdEntities, EntityOperation.CREATE, isImport);
    notifyListeners(updatedEntities, EntityOperation.UPDATE, isImport);
    notifyListeners(partiallyUpdatedEntities, EntityOperation.PARTIAL_UPDATE, isImport);
    notifyListeners(deletedEntities, EntityOperation.DELETE, isImport);
    notifyListeners(purgedEntities, EntityOperation.PURGE, isImport);

    notifyPropagatedEntities();
}
 
Example 3
Source File: InverseReferenceUpdateV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_ManyToMany() 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 b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(a3);
    atlasEntitiesWithExtInfo.addEntity(b1);
    atlasEntitiesWithExtInfo.addEntity(b2);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntity b1ForPartialUpdate = new AtlasEntity("B");
    b1ForPartialUpdate.setAttribute("manyToManyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b1.getAttribute(NAME)), new AtlasEntityWithExtInfo(b1ForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b1.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(b1.getGuid());
    verifyReferenceList(storedEntity, "manyToManyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1)));
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1)));
}
 
Example 4
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_OneToMany() throws Exception {
    AtlasObjectId juliusId = nameIdMap.get("Julius");

    // Change Max's Employee.manager reference to Julius and apply the change as a partial update.
    // This should also update Julius to add Max to the inverse Manager.subordinates reference.
    AtlasEntity maxEntityForUpdate = new AtlasEntity(TestUtilsV2.EMPLOYEE_TYPE);
    maxEntityForUpdate.setAttribute("manager", juliusId);
    AtlasEntityType employeeType = typeRegistry.getEntityTypeByName(TestUtilsV2.EMPLOYEE_TYPE);
    Map<String, Object> uniqAttributes = Collections.<String, Object>singletonMap("name", "Max");
    EntityMutationResponse updateResponse = entityStore.updateByUniqueAttributes(employeeType, uniqAttributes , new AtlasEntityWithExtInfo(maxEntityForUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = updateResponse.getPartialUpdatedEntities();
    // 3 entities should have been updated:
    // * Max to change the Employee.manager reference
    // * Julius to add Max to Manager.subordinates
    // * Jane to remove Max from Manager.subordinates
    assertEquals(partialUpdatedEntities.size(), 3);

    AtlasObjectId maxId = nameIdMap.get("Max");
    String janeGuid = nameIdMap.get("Jane").getGuid();
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(maxId.getGuid(), juliusId.getGuid(), janeGuid));
    AtlasEntity storedEntity = storedEntities.getEntity(maxId.getGuid());
    verifyReferenceValue(storedEntity, "manager", juliusId.getGuid());
    storedEntity = storedEntities.getEntity(juliusId.getGuid());
    verifyReferenceList(storedEntity, "subordinates", ImmutableList.of(maxId));
    storedEntity = storedEntities.getEntity(janeGuid);
    verify_testInverseReferenceAutoUpdate_NonComposite_OneToMany(storedEntity);
}
 
Example 5
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_ManyToMany() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(a3);
    atlasEntitiesWithExtInfo.addEntity(b1);
    atlasEntitiesWithExtInfo.addEntity(b2);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntity b1ForPartialUpdate = new AtlasEntity("B");
    b1ForPartialUpdate.setAttribute("manyToManyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b1.getAttribute(NAME)), new AtlasEntityWithExtInfo(b1ForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b1.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(b1.getGuid());
    verifyReferenceList(storedEntity, "manyToManyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1)));
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1)));
}
 
Example 6
Source File: InverseReferenceUpdateV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_OneToMany() throws Exception {
    AtlasObjectId juliusId = nameIdMap.get("Julius");

    // Change Max's Employee.manager reference to Julius and apply the change as a partial update.
    // This should also update Julius to add Max to the inverse Manager.subordinates reference.
    AtlasEntity maxEntityForUpdate = new AtlasEntity(TestUtilsV2.EMPLOYEE_TYPE);
    maxEntityForUpdate.setAttribute("manager", juliusId);
    AtlasEntityType employeeType = typeRegistry.getEntityTypeByName(TestUtilsV2.EMPLOYEE_TYPE);
    Map<String, Object> uniqAttributes = Collections.<String, Object>singletonMap("name", "Max");
    EntityMutationResponse updateResponse = entityStore.updateByUniqueAttributes(employeeType, uniqAttributes , new AtlasEntityWithExtInfo(maxEntityForUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = updateResponse.getPartialUpdatedEntities();
    // 3 entities should have been updated:
    // * Max to change the Employee.manager reference
    // * Julius to add Max to Manager.subordinates
    // * Jane to remove Max from Manager.subordinates
    assertEquals(partialUpdatedEntities.size(), 3);

    AtlasObjectId maxId = nameIdMap.get("Max");
    String janeGuid = nameIdMap.get("Jane").getGuid();
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(maxId.getGuid(), juliusId.getGuid(), janeGuid));
    AtlasEntity storedEntity = storedEntities.getEntity(maxId.getGuid());
    verifyReferenceValue(storedEntity, "manager", juliusId.getGuid());
    storedEntity = storedEntities.getEntity(juliusId.getGuid());
    verifyReferenceList(storedEntity, "subordinates", ImmutableList.of(maxId));
    storedEntity = storedEntities.getEntity(janeGuid);
    verify_testInverseReferenceAutoUpdate_NonComposite_OneToMany(storedEntity);
}
 
Example 7
Source File: AtlasRelationshipStoreV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelationshipAttributeUpdate_NonComposite_OneToMany() throws Exception {
    AtlasObjectId maxId    = employeeNameIdMap.get("Max");
    AtlasObjectId juliusId = employeeNameIdMap.get("Julius");
    AtlasObjectId janeId   = employeeNameIdMap.get("Jane");

    // Change Max's Employee.manager reference to Julius and apply the change as a partial update.
    // This should also update Julius to add Max to the inverse Manager.subordinates reference.
    AtlasEntity maxEntityForUpdate = new AtlasEntity(EMPLOYEE_TYPE);
    maxEntityForUpdate.setRelationshipAttribute("manager", juliusId);

    AtlasEntityType        employeeType   = typeRegistry.getEntityTypeByName(EMPLOYEE_TYPE);
    Map<String, Object>    uniqAttributes = Collections.<String, Object>singletonMap("name", "Max");
    EntityMutationResponse updateResponse = entityStore.updateByUniqueAttributes(employeeType, uniqAttributes , new AtlasEntityWithExtInfo(maxEntityForUpdate));

    List<AtlasEntityHeader> partialUpdatedEntities = updateResponse.getPartialUpdatedEntities();
    assertEquals(partialUpdatedEntities.size(), 3);
    // 3 entities should have been updated:
    // * Max to change the Employee.manager reference
    // * Julius to add Max to Manager.subordinates
    // * Jane to remove Max from Manager.subordinates

    AtlasEntitiesWithExtInfo updatedEntities = entityStore.getByIds(ImmutableList.of(maxId.getGuid(), juliusId.getGuid(), janeId.getGuid()));

    // Max's manager updated as Julius
    AtlasEntity maxEntity = updatedEntities.getEntity(maxId.getGuid());
    verifyRelationshipAttributeValue(maxEntity, "manager", juliusId.getGuid());

    // Max added to the subordinate list of Julius
    AtlasEntity juliusEntity = updatedEntities.getEntity(juliusId.getGuid());
    verifyRelationshipAttributeList(juliusEntity, "subordinates", ImmutableList.of(maxId));

    // Max removed from the subordinate list of Julius
    AtlasEntity janeEntity = updatedEntities.getEntity(janeId.getGuid());

    // Jane's subordinates list includes John and Max for soft delete
    // Jane's subordinates list includes only John for hard delete
    verifyRelationshipAttributeUpdate_NonComposite_OneToMany(janeEntity);
}
 
Example 8
Source File: InverseReferenceUpdateV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_Map() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b3 = new AtlasEntity("B");
    b3.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(b1);
    atlasEntitiesWithExtInfo.addEntity(b2);
    atlasEntitiesWithExtInfo.addEntity(b3);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntityType aType = typeRegistry.getEntityTypeByName("A");
    AtlasEntity aForPartialUpdate = new AtlasEntity("A");
    aForPartialUpdate.setAttribute("mapToB", ImmutableMap.<String, AtlasObjectId>of("b1", AtlasTypeUtil.getAtlasObjectId(b1), "b2", AtlasTypeUtil.getAtlasObjectId(b2)));
    init();
    response = entityStore.updateByUniqueAttributes(aType, Collections.<String, Object>singletonMap(NAME, a1.getAttribute(NAME)), new AtlasEntityWithExtInfo(aForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set a1.mapToB to "b1"->b1, "b2"->b2
    // * set b1.mappedFromA to a1
    // * set b2.mappedFromA to a1
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b2.getGuid(), b1.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    Object value = storedEntity.getAttribute("mapToB");
    assertTrue(value instanceof Map);
    Map<String, AtlasObjectId> refMap = (Map<String, AtlasObjectId>) value;
    assertEquals(refMap.size(), 2);
    AtlasObjectId referencedEntityId = refMap.get("b1");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b1));
    referencedEntityId = refMap.get("b2");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b2));
    storedEntity = storedEntities.getEntity(b1.getGuid());
    verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid());
    storedEntity = storedEntities.getEntity(b2.getGuid());
    verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid());

    aForPartialUpdate.setAttribute("mapToB", ImmutableMap.<String, AtlasObjectId>of("b3", AtlasTypeUtil.getAtlasObjectId(b3)));
    init();
    response = entityStore.updateByUniqueAttributes(aType, Collections.<String, Object>singletonMap(NAME, a1.getAttribute(NAME)), new AtlasEntityWithExtInfo(aForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set a1.mapToB to "b3"->b3
    // * set b3.mappedFromA to a1
    // * disconnect b1.mappedFromA
    // * disconnect b2.mappedFromA
    assertEquals(partialUpdatedEntities.size(), 4);
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b2.getGuid(), b1.getGuid(), b3.getGuid()));
    AtlasEntity storedB3 = storedEntities.getEntity(b3.getGuid());
    verifyReferenceValue(storedB3, "mappedFromA", a1.getGuid());
    verify_testInverseReferenceAutoUpdate_Map(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b1.getGuid()), storedEntities.getEntity(b2.getGuid()), storedB3);
}
 
Example 9
Source File: InverseReferenceUpdateV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_OneToOne() 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 b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("a", AtlasTypeUtil.getAtlasObjectId(a1));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 2 entities were updated:
    // * set b.a reference to a1
    // * set inverse a1.b reference to b
    assertEquals(partialUpdatedEntities.size(), 2);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "b", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceValue(storedEntity, "a", a1.getGuid());

    // Update b.a to reference a2.
    bForPartialUpdate.setAttribute("a", AtlasTypeUtil.getAtlasObjectId(a2));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.a reference to a2
    // * set a2.b reference to b
    // * disconnect a1.b reference
    assertEquals(partialUpdatedEntities.size(), 3);
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "b", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceValue(storedEntity, "a", a2.getGuid());
    storedEntity = storedEntities.getEntity(a1.getGuid());
    Object refValue = storedEntity.getAttribute("b");
    verify_testInverseReferenceAutoUpdate_NonComposite_OneToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b.getGuid()));
}
 
Example 10
Source File: InverseReferenceUpdateV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@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()));
}
 
Example 11
Source File: AtlasRelationshipStoreV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelationshipAttributeUpdate_NonComposite_ManyToMany() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, "a1_name");

    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, "a2_name");

    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, "a3_name");

    AtlasEntity b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, "b1_name");

    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, "b2_name");

    AtlasEntitiesWithExtInfo entitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    entitiesWithExtInfo.addEntity(a1);
    entitiesWithExtInfo.addEntity(a2);
    entitiesWithExtInfo.addEntity(a3);
    entitiesWithExtInfo.addEntity(b1);
    entitiesWithExtInfo.addEntity(b2);
    entityStore.createOrUpdate(new AtlasEntityStream(entitiesWithExtInfo) , false);

    AtlasEntity b1PartialUpdate = new AtlasEntity("B");
    b1PartialUpdate.setRelationshipAttribute("manyToManyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2)));

    init();
    EntityMutationResponse response = entityStore.updateByUniqueAttributes(typeRegistry.getEntityTypeByName("B"),
                                                                           Collections.singletonMap(NAME, b1.getAttribute(NAME)),
                                                                           new AtlasEntityWithExtInfo(b1PartialUpdate));

    List<AtlasEntityHeader> updatedEntityHeaders = response.getPartialUpdatedEntities();
    assertEquals(updatedEntityHeaders.size(), 3);

    AtlasEntitiesWithExtInfo updatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b1.getGuid()));

    AtlasEntity b1Entity = updatedEntities.getEntity(b1.getGuid());
    verifyRelationshipAttributeList(b1Entity, "manyToManyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2)));

    AtlasEntity a1Entity = updatedEntities.getEntity(a1.getGuid());
    verifyRelationshipAttributeList(a1Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1)));

    AtlasEntity a2Entity = updatedEntities.getEntity(a2.getGuid());
    verifyRelationshipAttributeList(a2Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1)));
}
 
Example 12
Source File: AtlasRelationshipStoreV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelationshipAttributeUpdate_NonComposite_OneToOne() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, "a1_name");

    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, "a2_name");

    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, "b_name");

    AtlasEntitiesWithExtInfo entitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    entitiesWithExtInfo.addEntity(a1);
    entitiesWithExtInfo.addEntity(a2);
    entitiesWithExtInfo.addEntity(b);

    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesWithExtInfo) , false);

    AtlasEntity partialUpdateB = new AtlasEntity("B");
    partialUpdateB.setRelationshipAttribute("a", getAtlasObjectId(a1));

    init();
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");

    response = entityStore.updateByUniqueAttributes(bType, Collections.singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(partialUpdateB));
    List<AtlasEntityHeader> partialUpdatedEntitiesHeader = response.getPartialUpdatedEntities();
    // Verify 2 entities were updated:
    // * set b.a reference to a1
    // * set inverse a1.b reference to b
    assertEquals(partialUpdatedEntitiesHeader.size(), 2);
    AtlasEntitiesWithExtInfo partialUpdatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b.getGuid()));

    AtlasEntity a1Entity = partialUpdatedEntities.getEntity(a1.getGuid());
    verifyRelationshipAttributeValue(a1Entity, "b", b.getGuid());

    AtlasEntity bEntity = partialUpdatedEntities.getEntity(b.getGuid());
    verifyRelationshipAttributeValue(bEntity, "a", a1.getGuid());

    init();

    // Update b.a to reference a2.
    partialUpdateB.setRelationshipAttribute("a", getAtlasObjectId(a2));
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(partialUpdateB));
    partialUpdatedEntitiesHeader = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.a reference to a2
    // * set a2.b reference to b
    // * disconnect a1.b reference
    assertEquals(partialUpdatedEntitiesHeader.size(), 3);
    partialUpdatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));

    bEntity = partialUpdatedEntities.getEntity(b.getGuid());
    verifyRelationshipAttributeValue(bEntity, "a", a2.getGuid());

    AtlasEntity a2Entity = partialUpdatedEntities.getEntity(a2.getGuid());
    verifyRelationshipAttributeValue(a2Entity, "b", b.getGuid());

    a1Entity = partialUpdatedEntities.getEntity(a1.getGuid());
    verifyRelationshipAttributeUpdate_NonComposite_OneToOne(a1Entity, bEntity);
}
 
Example 13
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_Map() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b3 = new AtlasEntity("B");
    b3.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(b1);
    atlasEntitiesWithExtInfo.addEntity(b2);
    atlasEntitiesWithExtInfo.addEntity(b3);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntityType aType = typeRegistry.getEntityTypeByName("A");
    AtlasEntity aForPartialUpdate = new AtlasEntity("A");
    aForPartialUpdate.setAttribute("mapToB", ImmutableMap.<String, AtlasObjectId>of("b1", AtlasTypeUtil.getAtlasObjectId(b1), "b2", AtlasTypeUtil.getAtlasObjectId(b2)));
    init();
    response = entityStore.updateByUniqueAttributes(aType, Collections.<String, Object>singletonMap(NAME, a1.getAttribute(NAME)), new AtlasEntityWithExtInfo(aForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set a1.mapToB to "b1"->b1, "b2"->b2
    // * set b1.mappedFromA to a1
    // * set b2.mappedFromA to a1
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b2.getGuid(), b1.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    Object value = storedEntity.getAttribute("mapToB");
    assertTrue(value instanceof Map);
    Map<String, AtlasObjectId> refMap = (Map<String, AtlasObjectId>) value;
    assertEquals(refMap.size(), 2);
    AtlasObjectId referencedEntityId = refMap.get("b1");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b1));
    referencedEntityId = refMap.get("b2");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b2));
    storedEntity = storedEntities.getEntity(b1.getGuid());
    verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid());
    storedEntity = storedEntities.getEntity(b2.getGuid());
    verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid());

    aForPartialUpdate.setAttribute("mapToB", ImmutableMap.<String, AtlasObjectId>of("b3", AtlasTypeUtil.getAtlasObjectId(b3)));
    init();
    response = entityStore.updateByUniqueAttributes(aType, Collections.<String, Object>singletonMap(NAME, a1.getAttribute(NAME)), new AtlasEntityWithExtInfo(aForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set a1.mapToB to "b3"->b3
    // * set b3.mappedFromA to a1
    // * disconnect b1.mappedFromA
    // * disconnect b2.mappedFromA
    assertEquals(partialUpdatedEntities.size(), 4);
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b2.getGuid(), b1.getGuid(), b3.getGuid()));
    AtlasEntity storedB3 = storedEntities.getEntity(b3.getGuid());
    verifyReferenceValue(storedB3, "mappedFromA", a1.getGuid());
    verify_testInverseReferenceAutoUpdate_Map(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b1.getGuid()), storedEntities.getEntity(b2.getGuid()), storedB3);
}
 
Example 14
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_OneToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("a", AtlasTypeUtil.getAtlasObjectId(a1));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 2 entities were updated:
    // * set b.a reference to a1
    // * set inverse a1.b reference to b
    assertEquals(partialUpdatedEntities.size(), 2);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "b", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceValue(storedEntity, "a", a1.getGuid());

    // Update b.a to reference a2.
    bForPartialUpdate.setAttribute("a", AtlasTypeUtil.getAtlasObjectId(a2));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.a reference to a2
    // * set a2.b reference to b
    // * disconnect a1.b reference
    assertEquals(partialUpdatedEntities.size(), 3);
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "b", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceValue(storedEntity, "a", a2.getGuid());
    storedEntity = storedEntities.getEntity(a1.getGuid());
    Object refValue = storedEntity.getAttribute("b");
    verify_testInverseReferenceAutoUpdate_NonComposite_OneToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b.getGuid()));
}
 
Example 15
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonCompositeManyToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b = new AtlasEntity("B");

    b.setAttribute(NAME, TestUtilsV2.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()));
}
 
Example 16
Source File: AtlasRelationshipStoreV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelationshipAttributeUpdate_NonComposite_ManyToMany() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, "a1_name");

    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, "a2_name");

    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, "a3_name");

    AtlasEntity b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, "b1_name");

    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, "b2_name");

    AtlasEntitiesWithExtInfo entitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    entitiesWithExtInfo.addEntity(a1);
    entitiesWithExtInfo.addEntity(a2);
    entitiesWithExtInfo.addEntity(a3);
    entitiesWithExtInfo.addEntity(b1);
    entitiesWithExtInfo.addEntity(b2);
    entityStore.createOrUpdate(new AtlasEntityStream(entitiesWithExtInfo) , false);

    AtlasEntity b1PartialUpdate = new AtlasEntity("B");
    b1PartialUpdate.setRelationshipAttribute("manyToManyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2)));

    init();
    EntityMutationResponse response = entityStore.updateByUniqueAttributes(typeRegistry.getEntityTypeByName("B"),
                                                                           Collections.singletonMap(NAME, b1.getAttribute(NAME)),
                                                                           new AtlasEntityWithExtInfo(b1PartialUpdate));

    List<AtlasEntityHeader> updatedEntityHeaders = response.getPartialUpdatedEntities();
    assertEquals(updatedEntityHeaders.size(), 3);

    AtlasEntitiesWithExtInfo updatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b1.getGuid()));

    AtlasEntity b1Entity = updatedEntities.getEntity(b1.getGuid());
    verifyRelationshipAttributeList(b1Entity, "manyToManyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2)));

    AtlasEntity a1Entity = updatedEntities.getEntity(a1.getGuid());
    verifyRelationshipAttributeList(a1Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1)));

    AtlasEntity a2Entity = updatedEntities.getEntity(a2.getGuid());
    verifyRelationshipAttributeList(a2Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1)));
}
 
Example 17
Source File: AtlasRelationshipStoreV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelationshipAttributeUpdate_NonComposite_OneToOne() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, "a1_name");

    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, "a2_name");

    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, "b_name");

    AtlasEntitiesWithExtInfo entitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    entitiesWithExtInfo.addEntity(a1);
    entitiesWithExtInfo.addEntity(a2);
    entitiesWithExtInfo.addEntity(b);

    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesWithExtInfo) , false);

    AtlasEntity partialUpdateB = new AtlasEntity("B");
    partialUpdateB.setRelationshipAttribute("a", getAtlasObjectId(a1));

    init();
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");

    response = entityStore.updateByUniqueAttributes(bType, Collections.singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(partialUpdateB));
    List<AtlasEntityHeader> partialUpdatedEntitiesHeader = response.getPartialUpdatedEntities();
    // Verify 2 entities were updated:
    // * set b.a reference to a1
    // * set inverse a1.b reference to b
    assertEquals(partialUpdatedEntitiesHeader.size(), 2);
    AtlasEntitiesWithExtInfo partialUpdatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b.getGuid()));

    AtlasEntity a1Entity = partialUpdatedEntities.getEntity(a1.getGuid());
    verifyRelationshipAttributeValue(a1Entity, "b", b.getGuid());

    AtlasEntity bEntity = partialUpdatedEntities.getEntity(b.getGuid());
    verifyRelationshipAttributeValue(bEntity, "a", a1.getGuid());

    init();

    // Update b.a to reference a2.
    partialUpdateB.setRelationshipAttribute("a", getAtlasObjectId(a2));
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(partialUpdateB));
    partialUpdatedEntitiesHeader = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.a reference to a2
    // * set a2.b reference to b
    // * disconnect a1.b reference
    assertEquals(partialUpdatedEntitiesHeader.size(), 3);
    partialUpdatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));

    bEntity = partialUpdatedEntities.getEntity(b.getGuid());
    verifyRelationshipAttributeValue(bEntity, "a", a2.getGuid());

    AtlasEntity a2Entity = partialUpdatedEntities.getEntity(a2.getGuid());
    verifyRelationshipAttributeValue(a2Entity, "b", b.getGuid());

    a1Entity = partialUpdatedEntities.getEntity(a1.getGuid());
    verifyRelationshipAttributeUpdate_NonComposite_OneToOne(a1Entity, bEntity);
}