Search in sources :

Example 31 with EntityMutationResponse

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

the class BaseResourceIT method modifyEntity.

protected AtlasEntityHeader modifyEntity(AtlasEntity atlasEntity, boolean update) {
    EntityMutationResponse entity = null;
    try {
        if (!update) {
            entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity));
            assertNotNull(entity);
            assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
            assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size() > 0);
            return entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0);
        } else {
            entity = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity));
            assertNotNull(entity);
            assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
            assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
            return entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0);
        }
    } catch (AtlasServiceException e) {
        LOG.error("Entity {} failed", update ? "update" : "creation", entity);
    }
    return null;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasServiceException(org.apache.atlas.AtlasServiceException) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse)

Example 32 with EntityMutationResponse

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

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

the class InverseReferenceUpdateV1Test method setUp.

@BeforeClass
public void setUp() throws Exception {
    metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
    AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineInverseReferenceTestTypes() };
    for (AtlasTypesDef typesDef : testTypesDefs) {
        AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
        if (!typesToCreate.isEmpty()) {
            typeDefStore.createTypesDef(typesToCreate);
        }
    }
    deptEntity = TestUtilsV2.createDeptEg2();
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);
    for (AtlasEntityHeader entityHeader : response.getCreatedEntities()) {
        nameIdMap.put((String) entityHeader.getAttribute(NAME), AtlasTypeUtil.getAtlasObjectId(entityHeader));
    }
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 34 with EntityMutationResponse

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

the class EntityV2JerseyResourceIT method testEntityDeduping.

@Test
public void testEntityDeduping() throws Exception {
    JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
    assertEquals(results.length(), 1);
    final AtlasEntity hiveDBInstanceV2 = createHiveDB();
    // Do the notification thing here
    waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {

        @Override
        public boolean evaluate(EntityNotification notification) throws Exception {
            return notification != null && notification.getEntity().getId()._getId().equals(hiveDBInstanceV2.getGuid());
        }
    });
    results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
    assertEquals(results.length(), 1);
    //Test the same across references
    final String tableName = randomString();
    AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(hiveDBInstanceV2, tableName);
    hiveTableInstanceV2.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
    EntityMutationResponse entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(hiveTableInstanceV2));
    assertNotNull(entity);
    assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
    results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
    assertEquals(results.length(), 1);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityNotification(org.apache.atlas.notification.entity.EntityNotification) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) JSONArray(org.codehaus.jettison.json.JSONArray) AtlasServiceException(org.apache.atlas.AtlasServiceException) Test(org.testng.annotations.Test)

Example 35 with EntityMutationResponse

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

the class EntityV2JerseyResourceIT method addProperty.

private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
    AtlasEntity entityByGuid = getEntityByGuid(guid);
    entityByGuid.setAttribute(property, value);
    EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
    assertNotNull(response);
    assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse)

Aggregations

EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)60 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)44 Test (org.testng.annotations.Test)40 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)21 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)17 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)17 ArrayList (java.util.ArrayList)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 HashMap (java.util.HashMap)12 List (java.util.List)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)7 ImmutableList (com.google.common.collect.ImmutableList)6 AtlasException (org.apache.atlas.AtlasException)6 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)6 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 Map (java.util.Map)5