Java Code Examples for org.apache.atlas.AtlasErrorCode#INVALID_PARAMETERS

The following examples show how to use org.apache.atlas.AtlasErrorCode#INVALID_PARAMETERS . 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 void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValueForUpdate(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValueForUpdate(classification);
}
 
Example 2
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Validate if classification is not already associated with the entities
 *
 * @param guid            unique entity id
 * @param classifications list of classifications to be associated
 */
private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    List<String>    entityClassifications = getClassificationNames(guid);
    String          entityTypeName        = AtlasGraphUtilsV2.getTypeNameFromGuid(graph, guid);
    AtlasEntityType entityType            = typeRegistry.getEntityTypeByName(entityTypeName);

    for (AtlasClassification classification : classifications) {
        String newClassification = classification.getTypeName();

        if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid +
                    ", already associated with classification: " + newClassification);
        }

        // for each classification, check whether there are entities it should be restricted to
        AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(newClassification);

        if (!classificationType.canApplyToEntityType(entityType)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_ENTITY_FOR_CLASSIFICATION, guid, entityTypeName, newClassification);
        }
    }
}
 
Example 3
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }

    List<String> messages = new ArrayList<>();

    type.validateValue(classification, classification.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }

    type.getNormalizedValue(classification);
}
 
Example 4
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
@GraphTransaction
public void deleteClassifications(final String guid, final List<String> classificationNames) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (CollectionUtils.isEmpty(classificationNames)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting classifications={} from entity={}", classificationNames, guid);
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);

    entityGraphMapper.deleteClassifications(guid, classificationNames);

    // notify listeners on classification deletion
    entityChangeNotifier.onClassificationDeletedFromEntity(guid, classificationNames);
}
 
Example 5
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 6
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public EntityMutationResponse purgeByIds(Set<String> guids) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(guids)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }

    AtlasAuthorizationUtils.verifyAccess(new AtlasAdminAccessRequest(AtlasPrivilege.ADMIN_PURGE), "purge entity: guids=", guids);
    Collection<AtlasVertex> purgeCandidates = new ArrayList<>();

    for (String guid : guids) {
        AtlasVertex vertex = AtlasGraphUtilsV2.findDeletedByGuid(graph, guid);

        if (vertex == null) {
            // Entity does not exist - treat as non-error, since the caller
            // wanted to delete the entity and it's already gone.
            LOG.warn("Purge request ignored for non-existent/active entity with guid " + guid);

            continue;
        }

        purgeCandidates.add(vertex);
    }

    if (purgeCandidates.isEmpty()) {
        LOG.info("No purge candidate entities were found for guids: " + guids + " which is already deleted");
    }

    EntityMutationResponse ret = purgeVertices(purgeCandidates);

    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, false);

    return ret;
}
 
Example 7
Source File: EntityREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Bulk API to associate a tag to multiple entities
 */
@POST
@Path("/bulk/classification")
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassification(" + request  + ")");
        }

        AtlasClassification classification = request == null ? null : request.getClassification();
        List<String>        entityGuids    = request == null ? null : request.getEntityGuids();

        if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
        }

        if (CollectionUtils.isEmpty(entityGuids)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty guid list");
        }

        entitiesStore.addClassification(entityGuids, classification);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 8
Source File: AtlasRelationshipStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void validateRelationship(AtlasRelationship relationship) throws AtlasBaseException {
    if (relationship == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "AtlasRelationship is null");
    }

    String                relationshipName = relationship.getTypeName();
    String                end1TypeName     = getTypeNameFromObjectId(relationship.getEnd1());
    String                end2TypeName     = getTypeNameFromObjectId(relationship.getEnd2());
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);

    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }

    if (relationship.getEnd1() == null || relationship.getEnd2() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "end1/end2 is null");
    }

    if (!relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName) &&
            !relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {

        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName,
                                     relationshipType.getEnd2Type().getTypeName(), end1TypeName);
    }

    if (!relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName) &&
            !relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName)) {

        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName,
                                     relationshipType.getEnd1Type().getTypeName(), end2TypeName);
    }

    validateEnd(relationship.getEnd1());

    validateEnd(relationship.getEnd2());

    validateAndNormalize(relationship);
}
 
Example 9
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public void addLabels(String guid, Set<String> labels) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> addLabels()");
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "guid is null/empty");
    }

    if (CollectionUtils.isEmpty(labels)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "labels is null/empty");
    }

    AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(graph, guid);

    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    AtlasEntityHeader               entityHeader   = entityRetriever.toAtlasEntityHeaderWithClassifications(entityVertex);
    AtlasEntityAccessRequestBuilder requestBuilder = new AtlasEntityAccessRequestBuilder(typeRegistry, AtlasPrivilege.ENTITY_ADD_LABEL, entityHeader);

    for (String label : labels) {
        requestBuilder.setLabel(label);

        AtlasAuthorizationUtils.verifyAccess(requestBuilder.build(), "add/update label: guid=", guid, ", label=", label);
    }

    validateLabels(labels);

    entityGraphMapper.addLabels(entityVertex, labels);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== addLabels()");
    }
}
 
Example 10
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public void removeLabels(String guid, Set<String> labels) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> removeLabels()");
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "guid is null/empty");
    }

    if (CollectionUtils.isEmpty(labels)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "labels is null/empty");
    }

    AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(graph, guid);

    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }

    AtlasEntityHeader               entityHeader   = entityRetriever.toAtlasEntityHeaderWithClassifications(entityVertex);
    AtlasEntityAccessRequestBuilder requestBuilder = new AtlasEntityAccessRequestBuilder(typeRegistry, AtlasPrivilege.ENTITY_REMOVE_LABEL, entityHeader);

    for (String label : labels) {
        requestBuilder.setLabel(label);

        AtlasAuthorizationUtils.verifyAccess(requestBuilder.build(), "remove label: guid=", guid, ", label=", label);
    }

    validateLabels(labels);

    entityGraphMapper.removeLabels(entityVertex, labels);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== removeLabels()");
    }
}
 
Example 11
Source File: EntityResource.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static WebApplicationException toWebApplicationException(AtlasBaseException e) {
    if (e.getAtlasErrorCode() == AtlasErrorCode.CLASSIFICATION_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    }

    if (e.getAtlasErrorCode() == AtlasErrorCode.INVALID_PARAMETERS
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    }

    return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
 
Example 12
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public void addClassifications(final String guid, final List<AtlasClassification> classifications) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (CollectionUtils.isEmpty(classifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding classifications={} to entity={}", classifications, guid);
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    for (AtlasClassification classification : classifications) {
        validateAndNormalize(classification);
    }

    // validate if entity, not already associated with classifications
    validateEntityAssociations(guid, classifications);

    entityGraphMapper.addClassifications(new EntityMutationContext(), guid, classifications);

    // notify listeners on classification addition
    entityChangeNotifier.onClassificationAddedToEntity(guid, classifications);
}
 
Example 13
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public EntityMutationResponse updateEntity(AtlasObjectId objectId, AtlasEntityWithExtInfo updatedEntityInfo, boolean isPartialUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateEntity({}, {}, {})", objectId, updatedEntityInfo, isPartialUpdate);
    }

    if (objectId == null || updatedEntityInfo == null || updatedEntityInfo.getEntity() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "null entity-id/entity");
    }

    final String guid;

    if (AtlasTypeUtil.isAssignedGuid(objectId.getGuid())) {
        guid = objectId.getGuid();
    } else {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objectId.getTypeName());

        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, objectId.getTypeName());
        }

        guid = AtlasGraphUtilsV2.getGuidByUniqueAttributes(graph, typeRegistry.getEntityTypeByName(objectId.getTypeName()), objectId.getUniqueAttributes());
    }

    AtlasEntity entity = updatedEntityInfo.getEntity();

    entity.setGuid(guid);

    return createOrUpdate(new AtlasEntityStream(updatedEntityInfo), isPartialUpdate, false, false);
}
 
Example 14
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Validate if classification is not already associated with the entities
 *
 * @param guid            unique entity id
 * @param classifications list of classifications to be associated
 */
private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    List<String> entityClassifications = getClassificationNames(guid);

    for (AtlasClassification classification : classifications) {
        String newClassification = classification.getTypeName();

        if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid +
                    ", already associated with classification: " + newClassification);
        }
    }
}
 
Example 15
Source File: MigrationImport.java    From atlas with Apache License 2.0 5 votes vote down vote up
public EntityMutationResponse run(EntityImportStream entityStream, AtlasImportResult importResult) throws AtlasBaseException {
    if (entityStream == null || !entityStream.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no entities to create/update.");
    }

    if (importResult.getRequest() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "importResult should contain request");
    }

    DataMigrationStatusService dataMigrationStatusService = createMigrationStatusService(importResult);

    long index = 0;
    int streamSize = entityStream.size();
    EntityMutationResponse ret = new EntityMutationResponse();
    EntityCreationManager creationManager = createEntityCreationManager(importResult, dataMigrationStatusService);

    try {
        LOG.info("Migration Import: Size: {}: Starting...", streamSize);
        index = creationManager.read(entityStream);
        creationManager.drain();
        creationManager.extractResults();
    } catch (Exception ex) {
        LOG.error("Migration Import: Error: Current position: {}", index, ex);
    } finally {
        shutdownEntityCreationManager(creationManager);
    }

    LOG.info("Migration Import: Size: {}: Done!", streamSize);
    return ret;
}
 
Example 16
Source File: AtlasAuditService.java    From atlas with Apache License 2.0 5 votes vote down vote up
public List<AtlasAuditEntry> get(AuditSearchParameters auditSearchParameters) throws AtlasBaseException {
    if (auditSearchParameters == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Audit Search Parameters not specified");
    }

    SearchParameters searchParameters = getSearchParameters(auditSearchParameters);

    searchParameters.setAttributes(getAuditEntityAttributes());

    AtlasSearchResult result = discoveryService.searchWithParameters(searchParameters);
    return toAtlasAuditEntries(result);
}
 
Example 17
Source File: EntityREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Bulk API to associate a tag to multiple entities
 */
@POST
@Path("/bulk/classification")
public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassification(" + request  + ")");
        }

        AtlasClassification classification = request == null ? null : request.getClassification();
        List<String>        entityGuids    = request == null ? null : request.getEntityGuids();

        if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
        }

        if (CollectionUtils.isEmpty(entityGuids)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty guid list");
        }

        entitiesStore.addClassification(entityGuids, classification);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 18
Source File: AtlasEntityStoreV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Override
@GraphTransaction
public void updateClassifications(String guid, List<AtlasClassification> newClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classifications={} for entity={}", newClassifications, guid);
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid not specified");
    }

    if (CollectionUtils.isEmpty(newClassifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }

    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    List<AtlasClassification> updatedClassifications = new ArrayList<>();

    for (AtlasClassification newClassification : newClassifications) {
        String              classificationName = newClassification.getTypeName();
        AtlasClassification oldClassification  = getClassification(guid, classificationName);

        if (oldClassification == null) {
            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
        }

        validateAndNormalizeForUpdate(newClassification);

        Map<String, Object> newAttrs = newClassification.getAttributes();

        if (MapUtils.isNotEmpty(newAttrs)) {
            for (String attrName : newAttrs.keySet()) {
                oldClassification.setAttribute(attrName, newAttrs.get(attrName));
            }
        }

        entityGraphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);

        updatedClassifications.add(oldClassification);
    }

    // notify listeners on update to classifications
    entityChangeNotifier.onClassificationUpdatedToEntity(guid, updatedClassifications);
}
 
Example 19
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;
}
 
Example 20
Source File: DiscoveryREST.java    From atlas with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve data for the specified attribute search query
 *
 * @param attrName        Attribute name
 * @param attrValuePrefix Attibute value to search on
 * @param typeName        limit the result to only entities of specified type or its sub-types
 * @param limit           limit the result set to only include the specified number of entries
 * @param offset          start offset of the result set (useful for pagination)
 * @return Search results
 * @throws AtlasBaseException
 * @HTTP 200 On successful FullText lookup with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid wildcard or query parameters
 */
@GET
@Path("/attribute")
public AtlasSearchResult searchUsingAttribute(@QueryParam("attrName")        String attrName,
                                              @QueryParam("attrValuePrefix") String attrValuePrefix,
                                              @QueryParam("typeName")        String typeName,
                                              @QueryParam("limit")           int    limit,
                                              @QueryParam("offset")          int    offset) throws AtlasBaseException {
    Servlets.validateQueryParamLength("attrName", attrName);
    Servlets.validateQueryParamLength("attrValuePrefix", attrValuePrefix);
    Servlets.validateQueryParamLength("typeName", typeName);

    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingAttribute(" + attrName + "," +
                    attrValuePrefix + "," + typeName + "," + limit + "," + offset + ")");
        }

        if (StringUtils.isEmpty(attrName) && StringUtils.isEmpty(attrValuePrefix)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS,
                    String.format("attrName : %s, attrValue: %s for attribute search.", attrName, attrValuePrefix));
        }

        if (StringUtils.isEmpty(attrName)) {
            AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

            if (entityType != null) {
                String[] defaultAttrNames = new String[] { AtlasClient.QUALIFIED_NAME, AtlasClient.NAME };

                for (String defaultAttrName : defaultAttrNames) {
                    AtlasStructType.AtlasAttribute attribute = entityType.getAttribute(defaultAttrName);

                    if (attribute != null) {
                        attrName = defaultAttrName;

                        break;
                    }
                }
            }

            if (StringUtils.isEmpty(attrName)) {
                attrName = AtlasClient.QUALIFIED_NAME;
            }
        }

        SearchParameters searchParams = new SearchParameters();
        FilterCriteria   attrFilter   = new FilterCriteria();

        attrFilter.setAttributeName(StringUtils.isEmpty(attrName) ? AtlasClient.QUALIFIED_NAME : attrName);
        attrFilter.setOperator(SearchParameters.Operator.STARTS_WITH);
        attrFilter.setAttributeValue(attrValuePrefix);

        searchParams.setTypeName(typeName);
        searchParams.setEntityFilters(attrFilter);
        searchParams.setOffset(offset);
        searchParams.setLimit(limit);

        return searchWithParameters(searchParams);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}