Search in sources :

Example 11 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test method testArrayOfEntityUpdate.

@Test(dependsOnMethods = "testCreate")
public void testArrayOfEntityUpdate() throws Exception {
    AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
    List<AtlasObjectId> columns = new ArrayList<>();
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
    AtlasEntity col1 = TestUtilsV2.createColumnEntity(tableEntity);
    col1.setAttribute(TestUtilsV2.NAME, "col1");
    AtlasEntity col2 = TestUtilsV2.createColumnEntity(tableEntity);
    col2.setAttribute(TestUtilsV2.NAME, "col2");
    columns.add(AtlasTypeUtil.getAtlasObjectId(col1));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col2));
    tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
    entitiesInfo.addReferredEntity(dbEntity.getEntity());
    entitiesInfo.addReferredEntity(col1);
    entitiesInfo.addReferredEntity(col2);
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName());
    validateEntity(entitiesInfo, getEntityFromStore(updatedTableHeader));
    //Complete update. Add  array elements - col3,col4
    AtlasEntity col3 = TestUtilsV2.createColumnEntity(tableEntity);
    col3.setAttribute(TestUtilsV2.NAME, "col3");
    AtlasEntity col4 = TestUtilsV2.createColumnEntity(tableEntity);
    col4.setAttribute(TestUtilsV2.NAME, "col4");
    columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col4));
    tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
    entitiesInfo.addReferredEntity(col3);
    entitiesInfo.addReferredEntity(col4);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName());
    validateEntity(entitiesInfo, getEntityFromStore(updatedTableHeader));
    //Swap elements
    columns.clear();
    columns.add(AtlasTypeUtil.getAtlasObjectId(col4));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
    tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName());
    AtlasEntity updatedEntity = getEntityFromStore(updatedTableHeader);
    // deleted columns are also included in "columns" attribute
    Assert.assertTrue(((List<AtlasObjectId>) updatedEntity.getAttribute(COLUMNS_ATTR_NAME)).size() >= 2);
    // col1, col2 are deleted
    assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
    //Update array column to null
    tableEntity.setAttribute(COLUMNS_ATTR_NAME, null);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTableHeader = response.getFirstUpdatedEntityByTypeName(tableEntity.getTypeName());
    validateEntity(entitiesInfo, getEntityFromStore(updatedTableHeader));
    assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with AtlasEntitiesWithExtInfo

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

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonComposite_OneToOne.

@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()));
}
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 13 with AtlasEntitiesWithExtInfo

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

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonComposite_ManyToMany.

@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)));
}
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 14 with AtlasEntitiesWithExtInfo

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

the class TestUtilsV2 method createDeptEg2.

public static AtlasEntitiesWithExtInfo createDeptEg2() {
    AtlasEntitiesWithExtInfo entitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    /******* Department - HR *******/
    AtlasEntity hrDept = new AtlasEntity(DEPARTMENT_TYPE, "name", "hr");
    AtlasObjectId hrDeptId = AtlasTypeUtil.getAtlasObjectId(hrDept);
    /******* Address Entities *******/
    AtlasStruct janeAddr = new AtlasStruct(ADDRESS_TYPE);
    janeAddr.setAttribute("street", "Great America Parkway");
    janeAddr.setAttribute("city", "Santa Clara");
    AtlasStruct juliusAddr = new AtlasStruct(ADDRESS_TYPE);
    juliusAddr.setAttribute("street", "Madison Ave");
    juliusAddr.setAttribute("city", "Newtonville");
    AtlasStruct maxAddr = new AtlasStruct(ADDRESS_TYPE);
    maxAddr.setAttribute("street", "Ripley St");
    maxAddr.setAttribute("city", "Newton");
    AtlasStruct johnAddr = new AtlasStruct(ADDRESS_TYPE);
    johnAddr.setAttribute("street", "Stewart Drive");
    johnAddr.setAttribute("city", "Sunnyvale");
    /******* Manager - Jane (John and Max subordinates) *******/
    AtlasEntity jane = new AtlasEntity(MANAGER_TYPE);
    AtlasObjectId janeId = AtlasTypeUtil.getAtlasObjectId(jane);
    jane.setAttribute("name", "Jane");
    jane.setAttribute("department", hrDeptId);
    jane.setAttribute("address", janeAddr);
    /******* Manager - Julius (no subordinates) *******/
    AtlasEntity julius = new AtlasEntity(MANAGER_TYPE);
    AtlasObjectId juliusId = AtlasTypeUtil.getAtlasObjectId(julius);
    julius.setAttribute("name", "Julius");
    julius.setAttribute("department", hrDeptId);
    julius.setAttribute("address", juliusAddr);
    julius.setAttribute("subordinates", ImmutableList.of());
    /******* Employee - Max (Manager: Jane, Mentor: Julius) *******/
    AtlasEntity max = new AtlasEntity(EMPLOYEE_TYPE);
    AtlasObjectId maxId = AtlasTypeUtil.getAtlasObjectId(max);
    max.setAttribute("name", "Max");
    max.setAttribute("department", hrDeptId);
    max.setAttribute("address", maxAddr);
    max.setAttribute("manager", janeId);
    max.setAttribute("mentor", juliusId);
    max.setAttribute("birthday", new Date(1979, 3, 15));
    max.setAttribute("hasPets", true);
    max.setAttribute("age", 36);
    max.setAttribute("numberOfCars", 2);
    max.setAttribute("houseNumber", 17);
    max.setAttribute("carMileage", 13);
    max.setAttribute("shares", Long.MAX_VALUE);
    max.setAttribute("salary", Double.MAX_VALUE);
    max.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000000000000"));
    max.setAttribute("approximationOfPi", new BigDecimal("3.1415926535897932"));
    /******* Employee - John (Manager: Jane, Mentor: Max) *******/
    AtlasEntity john = new AtlasEntity(EMPLOYEE_TYPE);
    AtlasObjectId johnId = AtlasTypeUtil.getAtlasObjectId(john);
    john.setAttribute("name", "John");
    john.setAttribute("department", hrDeptId);
    john.setAttribute("address", johnAddr);
    john.setAttribute("manager", janeId);
    john.setAttribute("mentor", maxId);
    john.setAttribute("birthday", new Date(1950, 5, 15));
    john.setAttribute("hasPets", true);
    john.setAttribute("numberOfCars", 1);
    john.setAttribute("houseNumber", 153);
    john.setAttribute("carMileage", 13364);
    john.setAttribute("shares", 15000);
    john.setAttribute("salary", 123345.678);
    john.setAttribute("age", 50);
    john.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000"));
    john.setAttribute("approximationOfPi", new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286"));
    jane.setAttribute("subordinates", ImmutableList.of(johnId, maxId));
    hrDept.setAttribute("employees", ImmutableList.of(janeId, juliusId, maxId, johnId));
    entitiesWithExtInfo.addEntity(hrDept);
    entitiesWithExtInfo.addEntity(jane);
    entitiesWithExtInfo.addEntity(julius);
    entitiesWithExtInfo.addEntity(max);
    entitiesWithExtInfo.addEntity(john);
    return entitiesWithExtInfo;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) BigInteger(java.math.BigInteger) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 15 with AtlasEntitiesWithExtInfo

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

the class EntityGraphRetriever method toAtlasEntitiesWithExtInfo.

public AtlasEntitiesWithExtInfo toAtlasEntitiesWithExtInfo(List<String> guids) throws AtlasBaseException {
    AtlasEntitiesWithExtInfo ret = new AtlasEntitiesWithExtInfo();
    for (String guid : guids) {
        AtlasVertex vertex = getEntityVertex(guid);
        AtlasEntity entity = mapVertexToAtlasEntity(vertex, ret);
        ret.addEntity(entity);
    }
    ret.compact();
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)

Aggregations

AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)26 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)21 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)21 Test (org.testng.annotations.Test)17 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)15 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 BeforeTest (org.testng.annotations.BeforeTest)7 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AtlasException (org.apache.atlas.AtlasException)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)4 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 Map (java.util.Map)3 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)3 ValueConversionException (org.apache.atlas.typesystem.types.ValueConversionException)3 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)3