Search in sources :

Example 6 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test method testMapOfPrimitivesUpdate.

@Test(dependsOnMethods = "testCreate")
public void testMapOfPrimitivesUpdate() throws Exception {
    AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
    entitiesInfo.addReferredEntity(tableEntity);
    //Add a new entry
    Map<String, String> paramsMap = (Map<String, String>) tableEntity.getAttribute("parametersMap");
    paramsMap.put("newParam", "value");
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1);
    AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    //Remove an entry
    paramsMap.remove("key1");
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
}
Also used : 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) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 7 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test method testArrayOfStructs.

@Test(dependsOnMethods = "testCreate")
public void testArrayOfStructs() throws Exception {
    //Modify array of structs
    AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
    List<AtlasStruct> partitions = new ArrayList<AtlasStruct>() {

        {
            add(new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part1"));
            add(new AtlasStruct(TestUtilsV2.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part2"));
        }
    };
    tableEntity.setAttribute("partitions", partitions);
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    //add a new element to array of struct
    partitions.add(new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part3"));
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    //remove one of the struct values
    init();
    partitions.remove(1);
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    //Update struct value within array of struct
    init();
    partitions.get(0).setAttribute(TestUtilsV2.NAME, "part4");
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    //add a repeated element to array of struct
    partitions.add(new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "part4"));
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
    // Remove all elements. Should set array attribute to null
    partitions.clear();
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    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) ArrayList(java.util.ArrayList) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with AtlasEntitiesWithExtInfo

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

the class TestEntityREST method createTestEntity.

private void createTestEntity() throws Exception {
    AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    final EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
    Assert.assertNotNull(response);
    List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
    Assert.assertNotNull(entitiesMutated);
    Assert.assertEquals(entitiesMutated.size(), 1);
    Assert.assertNotNull(entitiesMutated.get(0));
    dbEntity.setGuid(entitiesMutated.get(0).getGuid());
    this.dbEntity = dbEntity;
}
Also used : 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)

Example 9 with AtlasEntitiesWithExtInfo

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

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonComposite_OneToMany.

@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);
}
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) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 10 with AtlasEntitiesWithExtInfo

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

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_Map.

@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);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test)

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