Search in sources :

Example 26 with AtlasEntityHeader

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

the class AtlasEntityStoreV1Test method testSetObjectIdAttrToNull.

@Test
public void testSetObjectIdAttrToNull() throws Exception {
    final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    final AtlasEntity db2Entity = TestUtilsV2.createDBEntity();
    entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    entityStore.createOrUpdate(new AtlasEntityStream(db2Entity), false);
    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);
    tableEntity.setAttribute("databaseComposite", AtlasTypeUtil.getAtlasObjectId(db2Entity));
    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableEntity), false);
    final AtlasEntityHeader createdTblHeader = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    final AtlasEntity createdTblEntity = getEntityFromStore(createdTblHeader);
    init();
    createdTblEntity.setAttribute("databaseComposite", null);
    final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(createdTblEntity), true);
    final AtlasEntityHeader updatedTblHeader = tblUpdateResponse.getFirstEntityPartialUpdated();
    final AtlasEntity updatedTblEntity = getEntityFromStore(updatedTblHeader);
    final AtlasEntity deletedDb2Entity = getEntityFromStore(db2Entity.getGuid());
    assertEquals(deletedDb2Entity.getStatus(), AtlasEntity.Status.DELETED);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 27 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader 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 28 with AtlasEntityHeader

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

the class AtlasEntityStoreV1Test method testCreate.

@Test
public void testCreate() throws Exception {
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);
    validateMutationResponse(response, EntityOperation.CREATE, 5);
    AtlasEntityHeader dept1 = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DEPARTMENT_TYPE);
    validateEntity(deptEntity, getEntityFromStore(dept1), deptEntity.getEntities().get(0));
    final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities();
    List<AtlasEntityHeader> entitiesCreated = entitiesMutated.get(EntityOperation.CREATE);
    Assert.assertTrue(entitiesCreated.size() >= deptEntity.getEntities().size());
    for (int i = 0; i < deptEntity.getEntities().size(); i++) {
        AtlasEntity expected = deptEntity.getEntities().get(i);
        AtlasEntity actual = getEntityFromStore(entitiesCreated.get(i));
        validateEntity(deptEntity, actual, expected);
    }
    //Create DB
    init();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    validateMutationResponse(dbCreationResponse, EntityOperation.CREATE, 1);
    AtlasEntityHeader db1 = dbCreationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE);
    validateEntity(dbEntity, getEntityFromStore(db1));
    //Create Table
    //Update DB guid
    AtlasObjectId dbObjectId = (AtlasObjectId) tblEntity.getEntity().getAttribute("database");
    dbObjectId.setGuid(db1.getGuid());
    tblEntity.addReferredEntity(dbEntity.getEntity());
    init();
    EntityMutationResponse tableCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tblEntity), false);
    validateMutationResponse(tableCreationResponse, EntityOperation.CREATE, 1);
    AtlasEntityHeader tableEntity = tableCreationResponse.getFirstCreatedEntityByTypeName(TABLE_TYPE);
    validateEntity(tblEntity, getEntityFromStore(tableEntity));
}
Also used : EntityOperation(org.apache.atlas.model.instance.EntityMutations.EntityOperation) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) List(java.util.List) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 29 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader 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 30 with AtlasEntityHeader

use of org.apache.atlas.model.instance.AtlasEntityHeader 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)

Aggregations

AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)65 Test (org.testng.annotations.Test)46 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)38 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)15 ArrayList (java.util.ArrayList)14 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)14 HashMap (java.util.HashMap)12 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)12 List (java.util.List)10 Map (java.util.Map)8 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)6 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)5