Search in sources :

Example 16 with AtlasEntitiesWithExtInfo

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

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonCompositeManyToOne.

@Test
public void testInverseReferenceAutoUpdate_NonCompositeManyToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(a3);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream, false);
    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.manyA reference to a1 and a2
    // * set inverse a1.oneB reference to b
    // * set inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceList(storedEntity, "manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a3)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set b.manyA reference to a3
    // * set inverse a3.oneB reference to b
    // * disconnect inverse a1.oneB reference to b
    // * disconnect inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 4);
    init();
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), a3.getGuid(), b.getGuid()));
    verifyReferenceValue(storedEntities.getEntity(a3.getGuid()), "oneB", b.getGuid());
    verify_testInverseReferenceAutoUpdate_NonCompositeManyToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(a2.getGuid()), storedEntities.getEntity(a3.getGuid()), storedEntities.getEntity(b.getGuid()));
}
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 17 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test method testPartialUpdateArrayAttr.

@Test
public void testPartialUpdateArrayAttr() throws Exception {
    // Create a table entity, with 3 reference column entities
    init();
    final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
    final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity1.setAttribute("description", "desc for col1");
    entitiesInfo.addReferredEntity(columnEntity1);
    final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity2.setAttribute("description", "desc for col2");
    entitiesInfo.addReferredEntity(columnEntity2);
    final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity3.setAttribute("description", "desc for col3");
    entitiesInfo.addReferredEntity(columnEntity3);
    tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1), AtlasTypeUtil.getAtlasObjectId(columnEntity2), AtlasTypeUtil.getAtlasObjectId(columnEntity3)));
    init();
    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    final AtlasEntityHeader createdTblHeader = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    final AtlasEntity createdTblEntity = getEntityFromStore(createdTblHeader);
    final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME));
    final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME));
    final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME));
    // update only description attribute of all 3 columns
    AtlasEntity col1 = new AtlasEntity(COLUMN_TYPE);
    col1.setGuid(column1Created.getGuid());
    col1.setAttribute("description", "desc for col1:updated");
    AtlasEntity col2 = new AtlasEntity(COLUMN_TYPE);
    col2.setGuid(column2Created.getGuid());
    col2.setAttribute("description", "desc for col2:updated");
    AtlasEntity col3 = new AtlasEntity(COLUMN_TYPE);
    col3.setGuid(column3Created.getGuid());
    col3.setAttribute("description", "desc for col3:updated");
    final AtlasEntity tableEntity1 = new AtlasEntity(TABLE_TYPE);
    tableEntity1.setGuid(createdTblHeader.getGuid());
    tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(col1), AtlasTypeUtil.getAtlasObjectId(col2), AtlasTypeUtil.getAtlasObjectId(col3)));
    AtlasEntitiesWithExtInfo tableInfo = new AtlasEntitiesWithExtInfo(tableEntity1);
    tableInfo.addReferredEntity(col1.getGuid(), col1);
    tableInfo.addReferredEntity(col2.getGuid(), col2);
    tableInfo.addReferredEntity(col3.getGuid(), col3);
    init();
    final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableInfo), true);
    final AtlasEntityHeader updatedTblHeader = tblUpdateResponse.getFirstEntityPartialUpdated();
    final AtlasEntity updatedTblEntity2 = getEntityFromStore(updatedTblHeader);
    List<AtlasEntityHeader> updatedColHeaders = tblUpdateResponse.getPartialUpdatedEntitiesByTypeName(COLUMN_TYPE);
    final AtlasEntity updatedCol1Entity = getEntityFromStore(updatedColHeaders.get(0));
    final AtlasEntity updatedCol2Entity = getEntityFromStore(updatedColHeaders.get(1));
    final AtlasEntity updatedCol3Entity = getEntityFromStore(updatedColHeaders.get(2));
    assertEquals(col1.getAttribute("description"), updatedCol1Entity.getAttribute("description"));
    assertEquals(col2.getAttribute("description"), updatedCol2Entity.getAttribute("description"));
    assertEquals(col3.getAttribute("description"), updatedCol3Entity.getAttribute("description"));
}
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) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 18 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test method testPartialUpdateAttr.

@Test
public void testPartialUpdateAttr() throws Exception {
    //Update optional attribute
    init();
    AtlasEntity dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE);
    dbEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10));
    dbEntity.setAttribute("description", "us db");
    dbEntity.setAttribute("isReplicated", false);
    dbEntity.setAttribute("created", "09081988");
    dbEntity.setAttribute("namespace", "db namespace");
    dbEntity.setAttribute("cluster", "Fenton_Cluster");
    dbEntity.setAttribute("colo", "10001");
    EntityStream dbStream = new AtlasEntityStream(new AtlasEntitiesWithExtInfo(dbEntity));
    EntityMutationResponse response = entityStore.createOrUpdate(dbStream, false);
    AtlasEntityHeader dbHeader = response.getFirstEntityCreated();
    AtlasEntity createdDbEntity = getEntityFromStore(dbHeader);
    // update the db entity
    dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE);
    dbEntity.setGuid(createdDbEntity.getGuid());
    // dbEntity.setAttribute("name", createdDbEntity.getAttribute("name"));
    // dbEntity.setAttribute("description", "another db"); // required attr
    // optional attr
    dbEntity.setAttribute("created", "08151947");
    // optional attr
    dbEntity.setAttribute("isReplicated", true);
    dbStream = new AtlasEntityStream(new AtlasEntitiesWithExtInfo(dbEntity));
    // fail full update if required attributes are not specified.
    try {
        entityStore.createOrUpdate(dbStream, false);
    } catch (AtlasBaseException ex) {
        Assert.assertEquals(ex.getAtlasErrorCode(), AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS);
    }
    // do partial update without providing required attributes
    dbStream.reset();
    response = entityStore.createOrUpdate(dbStream, true);
    dbHeader = response.getFirstEntityPartialUpdated();
    AtlasEntity updatedDbEntity = getEntityFromStore(dbHeader);
    assertEquals(updatedDbEntity.getAttribute("name"), createdDbEntity.getAttribute("name"));
    assertEquals(updatedDbEntity.getAttribute("description"), createdDbEntity.getAttribute("description"));
    assertEquals(updatedDbEntity.getAttribute("isReplicated"), true);
    assertEquals(updatedDbEntity.getAttribute("created"), "08151947");
    assertEquals(updatedDbEntity.getAttribute("namespace"), createdDbEntity.getAttribute("namespace"));
    assertEquals(updatedDbEntity.getAttribute("cluster"), createdDbEntity.getAttribute("cluster"));
    assertEquals(updatedDbEntity.getAttribute("colo"), createdDbEntity.getAttribute("colo"));
    // create a new table type
    AtlasEntity tblEntity = new AtlasEntity(TABLE_TYPE);
    tblEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10));
    tblEntity.setAttribute("type", "type");
    tblEntity.setAttribute("tableType", "MANAGED");
    tblEntity.setAttribute("database", AtlasTypeUtil.getAtlasObjectId(updatedDbEntity));
    // create new column entity
    AtlasEntity col1 = TestUtilsV2.createColumnEntity(tblEntity);
    AtlasEntity col2 = TestUtilsV2.createColumnEntity(tblEntity);
    col1.setAttribute(TestUtilsV2.NAME, "col1");
    col2.setAttribute(TestUtilsV2.NAME, "col2");
    List<AtlasObjectId> columns = new ArrayList<>();
    columns.add(AtlasTypeUtil.getAtlasObjectId(col1));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col2));
    tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
    AtlasEntitiesWithExtInfo tableEntityInfo = new AtlasEntitiesWithExtInfo(tblEntity);
    tableEntityInfo.addReferredEntity(col1.getGuid(), col1);
    tableEntityInfo.addReferredEntity(col2.getGuid(), col2);
    EntityStream tblStream = new AtlasEntityStream(tableEntityInfo);
    response = entityStore.createOrUpdate(tblStream, false);
    AtlasEntityHeader tblHeader = response.getFirstEntityCreated();
    AtlasEntity createdTblEntity = getEntityFromStore(tblHeader);
    columns = (List<AtlasObjectId>) createdTblEntity.getAttribute(TestUtilsV2.COLUMNS_ATTR_NAME);
    assertEquals(columns.size(), 2);
    // update - add 2 more columns to table
    AtlasEntity col3 = TestUtilsV2.createColumnEntity(createdTblEntity);
    col3.setAttribute(TestUtilsV2.NAME, "col3");
    col3.setAttribute("description", "description col3");
    AtlasEntity col4 = TestUtilsV2.createColumnEntity(createdTblEntity);
    col4.setAttribute(TestUtilsV2.NAME, "col4");
    col4.setAttribute("description", "description col4");
    columns.clear();
    columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
    columns.add(AtlasTypeUtil.getAtlasObjectId(col4));
    tblEntity = new AtlasEntity(TABLE_TYPE);
    tblEntity.setGuid(createdTblEntity.getGuid());
    tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
    tableEntityInfo = new AtlasEntitiesWithExtInfo(tblEntity);
    tableEntityInfo.addReferredEntity(col3.getGuid(), col3);
    tableEntityInfo.addReferredEntity(col4.getGuid(), col4);
    tblStream = new AtlasEntityStream(tableEntityInfo);
    response = entityStore.createOrUpdate(tblStream, true);
    tblHeader = response.getFirstEntityPartialUpdated();
    AtlasEntity updatedTblEntity = getEntityFromStore(tblHeader);
    columns = (List<AtlasObjectId>) updatedTblEntity.getAttribute(TestUtilsV2.COLUMNS_ATTR_NAME);
    // deleted columns are included in the attribute; hence use >=
    assertTrue(columns.size() >= 2);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) 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) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 19 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test method testUpdateEntityWithMap.

@Test(dependsOnMethods = "testCreate")
public void testUpdateEntityWithMap() throws Exception {
    AtlasEntity tableEntity = new AtlasEntity(tblEntity.getEntity());
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);
    Map<String, AtlasStruct> partsMap = new HashMap<>();
    partsMap.put("part0", new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test"));
    tableEntity.setAttribute("partitionsMap", partsMap);
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition1 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    AtlasEntity updatedTableDef1 = getEntityFromStore(tableDefinition1);
    validateEntity(entitiesInfo, updatedTableDef1);
    Assert.assertTrue(partsMap.get("part0").equals(((Map<String, AtlasStruct>) updatedTableDef1.getAttribute("partitionsMap")).get("part0")));
    //update map - add a map key
    partsMap.put("part1", new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test1"));
    tableEntity.setAttribute("partitionsMap", partsMap);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition2 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    AtlasEntity updatedTableDef2 = getEntityFromStore(tableDefinition2);
    validateEntity(entitiesInfo, updatedTableDef2);
    assertEquals(((Map<String, AtlasStruct>) updatedTableDef2.getAttribute("partitionsMap")).size(), 2);
    Assert.assertTrue(partsMap.get("part1").equals(((Map<String, AtlasStruct>) updatedTableDef2.getAttribute("partitionsMap")).get("part1")));
    //update map - remove a key and add another key
    partsMap.remove("part0");
    partsMap.put("part2", new AtlasStruct(TestUtils.PARTITION_STRUCT_TYPE, TestUtilsV2.NAME, "test2"));
    tableEntity.setAttribute("partitionsMap", partsMap);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition3 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    AtlasEntity updatedTableDef3 = getEntityFromStore(tableDefinition3);
    validateEntity(entitiesInfo, updatedTableDef3);
    assertEquals(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).size(), 2);
    Assert.assertNull(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).get("part0"));
    Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef3.getAttribute("partitionsMap")).get("part2")));
    //update struct value for existing map key
    AtlasStruct partition2 = partsMap.get("part2");
    partition2.setAttribute(TestUtilsV2.NAME, "test2Updated");
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition4 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    AtlasEntity updatedTableDef4 = getEntityFromStore(tableDefinition4);
    validateEntity(entitiesInfo, updatedTableDef4);
    assertEquals(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).size(), 2);
    Assert.assertNull(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).get("part0"));
    Assert.assertTrue(partsMap.get("part2").equals(((Map<String, AtlasStruct>) updatedTableDef4.getAttribute("partitionsMap")).get("part2")));
    //Test map pointing to a class
    AtlasEntity col0 = new AtlasEntity(TestUtilsV2.COLUMN_TYPE, TestUtilsV2.NAME, "test1");
    col0.setAttribute("type", "string");
    col0.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
    AtlasEntityWithExtInfo col0WithExtendedInfo = new AtlasEntityWithExtInfo(col0);
    col0WithExtendedInfo.addReferredEntity(tableEntity);
    col0WithExtendedInfo.addReferredEntity(dbEntity.getEntity());
    init();
    entityStore.createOrUpdate(new AtlasEntityStream(col0WithExtendedInfo), false);
    AtlasEntity col1 = new AtlasEntity(TestUtils.COLUMN_TYPE, TestUtilsV2.NAME, "test2");
    col1.setAttribute("type", "string");
    col1.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
    AtlasEntityWithExtInfo col1WithExtendedInfo = new AtlasEntityWithExtInfo(col1);
    col1WithExtendedInfo.addReferredEntity(tableEntity);
    col1WithExtendedInfo.addReferredEntity(dbEntity.getEntity());
    init();
    entityStore.createOrUpdate(new AtlasEntityStream(col1WithExtendedInfo), false);
    Map<String, AtlasObjectId> columnsMap = new HashMap<String, AtlasObjectId>();
    columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col0));
    columnsMap.put("col1", AtlasTypeUtil.getAtlasObjectId(col1));
    tableEntity.setAttribute(TestUtils.COLUMNS_MAP, columnsMap);
    entitiesInfo.addReferredEntity(col0);
    entitiesInfo.addReferredEntity(col1);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition5 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(tableDefinition5));
    //Swap elements
    columnsMap.clear();
    columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col1));
    columnsMap.put("col1", AtlasTypeUtil.getAtlasObjectId(col0));
    tableEntity.setAttribute(TestUtils.COLUMNS_MAP, columnsMap);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition6 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(tableDefinition6));
    Assert.assertEquals(entityStore.getById(col0.getGuid()).getEntity().getStatus(), AtlasEntity.Status.ACTIVE);
    Assert.assertEquals(entityStore.getById(col1.getGuid()).getEntity().getStatus(), AtlasEntity.Status.ACTIVE);
    //Drop the first key and change the class type as well to col0
    columnsMap.clear();
    columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col0));
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition7 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(tableDefinition7));
    //Clear state
    tableEntity.setAttribute(TestUtils.COLUMNS_MAP, null);
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    AtlasEntityHeader tableDefinition8 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(tableDefinition8));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) HashMap(java.util.HashMap) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 20 with AtlasEntitiesWithExtInfo

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

the class AtlasEntityStoreV1Test 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(TestUtils.SERDE_TYPE, TestUtilsV2.NAME, "serde1Name");
    serdeInstance.setAttribute("serde", "test");
    serdeInstance.setAttribute("description", "testDesc");
    tableEntity.setAttribute("serde1", serdeInstance);
    tableEntity.setAttribute("database", new AtlasObjectId(databaseEntity.getTypeName(), TestUtilsV2.NAME, databaseEntity.getAttribute(TestUtilsV2.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);
    Assert.assertNull(updatedTable.getAttribute("description"));
    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)

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