Java Code Examples for org.apache.atlas.model.instance.EntityMutationResponse#setGuidAssignments()

The following examples show how to use org.apache.atlas.model.instance.EntityMutationResponse#setGuidAssignments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createOrUpdate()");
    }

    if (entityStream == null || !entityStream.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no entities to create/update.");
    }

    // Create/Update entities
    EntityMutationContext context = preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate);

    EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications);

    ret.setGuidAssignments(context.getGuidAssignments());

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== createOrUpdate()");
    }

    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, entityStream instanceof EntityImportStream);

    return ret;
}
 
Example 2
Source File: AtlasAPIV2ServerEmulator.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    final AtlasEntity.AtlasEntitiesWithExtInfo withExtInfo = readInputJSON(req, AtlasEntity.AtlasEntitiesWithExtInfo.class);
    final Map<String, String> guidAssignments = new HashMap<>();
    withExtInfo.getEntities().forEach(entity -> {
        atlasEntitiesByTypedQname.put(toTypedQname(entity), entity);
        String guid = entity.getGuid();
        if (!AtlasUtils.isGuidAssigned(guid)) {
            final String _guid = String.valueOf(guidSeq.getAndIncrement());
            guidAssignments.put(guid, _guid);
            entity.setGuid(_guid);
            guid = _guid;
        }
        atlasEntitiesByGuid.put(guid, entity);
    });
    final EntityMutationResponse mutationResponse = new EntityMutationResponse();
    mutationResponse.setGuidAssignments(guidAssignments);
    respondWithJson(resp, mutationResponse);
}
 
Example 3
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
@GraphTransaction
public EntityMutationResponse bulkImport(EntityImportStream entityStream, AtlasImportResult importResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> bulkImport()");
    }

    if (entityStream == null || !entityStream.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no entities to create/update.");
    }

    EntityMutationResponse ret = new EntityMutationResponse();
    ret.setGuidAssignments(new HashMap<String, String>());

    Set<String> processedGuids = new HashSet<>();
    float       currentPercent = 0f;

    List<String> residualList = new ArrayList<>();
    EntityImportStreamWithResidualList entityImportStreamWithResidualList = new EntityImportStreamWithResidualList(entityStream, residualList);
    while (entityImportStreamWithResidualList.hasNext()) {
        AtlasEntityWithExtInfo entityWithExtInfo = entityImportStreamWithResidualList.getNextEntityWithExtInfo();
        AtlasEntity            entity            = entityWithExtInfo != null ? entityWithExtInfo.getEntity() : null;

        if (entity == null || processedGuids.contains(entity.getGuid())) {
            continue;
        }

        AtlasEntityStreamForImport oneEntityStream = new AtlasEntityStreamForImport(entityWithExtInfo, entityStream);
        try {
            EntityMutationResponse resp = createOrUpdate(oneEntityStream, false, true);

            if (resp.getGuidAssignments() != null) {
                ret.getGuidAssignments().putAll(resp.getGuidAssignments());
            }

            currentPercent = updateImportMetrics(entityWithExtInfo, resp, importResult, processedGuids, entityStream.getPosition(),
                                                 entityImportStreamWithResidualList.getStreamSize(), currentPercent);

            entityStream.onImportComplete(entity.getGuid());
        } catch (AtlasBaseException e) {
            if (!updateResidualList(e, residualList, entityWithExtInfo.getEntity().getGuid())) {
                throw e;
            }
        }
    }

    importResult.getProcessedEntities().addAll(processedGuids);
    LOG.info("bulkImport(): done. Total number of entities (including referred entities) imported: {}", processedGuids.size());

    return ret;
}