Search in sources :

Example 21 with AtlasEntityWithExtInfo

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

the class ExportService method processObjectId.

private AtlasExportResult.OperationStatus processObjectId(AtlasObjectId item, ExportContext context) throws AtlasServiceException, AtlasException, AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> processObjectId({})", item);
    }
    try {
        List<AtlasEntityWithExtInfo> entities = getStartingEntity(item, context);
        if (entities.size() == 0) {
            return AtlasExportResult.OperationStatus.FAIL;
        }
        for (AtlasEntityWithExtInfo entityWithExtInfo : entities) {
            processEntity(entityWithExtInfo.getEntity().getGuid(), context);
        }
        while (!context.guidsToProcess.isEmpty()) {
            while (!context.guidsToProcess.isEmpty()) {
                String guid = context.guidsToProcess.remove(0);
                processEntity(guid, context);
            }
            if (!context.guidsLineageToProcess.isEmpty()) {
                context.guidsToProcess.addAll(context.guidsLineageToProcess);
                context.guidsLineageToProcess.clear();
            }
        }
    } catch (AtlasBaseException excp) {
        LOG.error("Fetching entity failed for: {}", item, excp);
        return AtlasExportResult.OperationStatus.FAIL;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== processObjectId({})", item);
    }
    return AtlasExportResult.OperationStatus.SUCCESS;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)

Example 22 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo 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 23 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo 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 24 with AtlasEntityWithExtInfo

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

Example 25 with AtlasEntityWithExtInfo

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

the class FullTextMapperV2 method getIndexTextForClassifications.

/**
     * Map newly associated/defined classifications for the entity with given GUID
     * @param guid Entity guid
     * @param classifications new classifications added to the entity
     * @return Full text string ONLY for the added classifications
     * @throws AtlasBaseException
     */
public String getIndexTextForClassifications(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    String ret = null;
    AtlasEntityWithExtInfo entityWithExtInfo = getAndCacheEntity(guid);
    if (entityWithExtInfo != null) {
        StringBuilder sb = new StringBuilder();
        if (CollectionUtils.isNotEmpty(classifications)) {
            for (AtlasClassification classification : classifications) {
                sb.append(classification.getTypeName()).append(FULL_TEXT_DELIMITER);
                mapAttributes(classification.getAttributes(), entityWithExtInfo, sb, new HashSet<String>());
            }
        }
        ret = sb.toString();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("FullTextMapperV2.map({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Aggregations

AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)34 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)24 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)18 Test (org.testng.annotations.Test)17 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 HashMap (java.util.HashMap)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)4 BeforeTest (org.testng.annotations.BeforeTest)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)2 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2