Search in sources :

Example 66 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class ExportService method addType.

private void addType(String typeName, ExportContext context) {
    AtlasType type = null;
    try {
        type = typeRegistry.getType(typeName);
        addType(type, context);
    } catch (AtlasBaseException excp) {
        LOG.error("unknown type {}", typeName);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType)

Example 67 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project 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.lineageToProcess.isEmpty()) {
                context.guidsToProcess.addAll(context.lineageToProcess);
                context.lineageProcessed.addAll(context.lineageToProcess.getList());
                context.lineageToProcess.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 68 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class ImportTransformer method getTransformer.

public static ImportTransformer getTransformer(String transformerSpec) throws AtlasBaseException {
    String[] params = StringUtils.split(transformerSpec, TRANSFORMER_PARAMETER_SEPARATOR);
    String key = (params == null || params.length < 1) ? transformerSpec : params[0];
    final ImportTransformer ret;
    if (StringUtils.isEmpty(key)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "Error creating ImportTransformer. Invalid transformer-specification: {}.", transformerSpec);
    } else if (key.equals("replace")) {
        String toFindStr = (params == null || params.length < 2) ? "" : params[1];
        String replaceStr = (params == null || params.length < 3) ? "" : params[2];
        ret = new Replace(toFindStr, replaceStr);
    } else if (key.equals("lowercase")) {
        ret = new Lowercase();
    } else if (key.equals("uppercase")) {
        ret = new Uppercase();
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "Error creating ImportTransformer. Unknown transformer: {}.", transformerSpec);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 69 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasMapFormatConverter method fromV1ToV2.

@Override
public Map fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    Map ret = null;
    if (v1Obj != null) {
        if (v1Obj instanceof Map) {
            AtlasMapType mapType = (AtlasMapType) type;
            AtlasType keyType = mapType.getKeyType();
            AtlasType valueType = mapType.getValueType();
            AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory());
            AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory());
            Map v1Map = (Map) v1Obj;
            ret = new HashMap<>();
            for (Object key : v1Map.keySet()) {
                Object value = v1Map.get(key);
                Object v2Key = keyConverter.fromV1ToV2(key, keyType, ctx);
                Object v2Value = valueConverter.fromV1ToV2(value, valueType, ctx);
                ret.put(v2Key, v2Value);
            }
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType) Map(java.util.Map) HashMap(java.util.HashMap) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Example 70 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class TypeConverterUtil method toAtlasTypesDef.

public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    try {
        if (StringUtils.isEmpty(typeDefinition)) {
            throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
        }
        TypesDef typesDef = AtlasType.fromV1Json(typeDefinition, TypesDef.class);
        if (CollectionUtils.isNotEmpty(typesDef.getEnumTypes())) {
            List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.getEnumTypes());
            ret.setEnumDefs(enumDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.getStructTypes())) {
            List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.getStructTypes());
            ret.setStructDefs(structDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.getClassTypes())) {
            List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.getClassTypes(), registry);
            ret.setEntityDefs(entityDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.getTraitTypes())) {
            List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.getTraitTypes());
            ret.setClassificationDefs(classificationDefs);
        }
    } catch (Exception e) {
        LOG.error("Invalid type definition = {}", typeDefinition, e);
        throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 ArrayList (java.util.ArrayList)60 Test (org.testng.annotations.Test)60 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24