Search in sources :

Example 76 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasInstanceConverter method toAtlasEntity.

public AtlasEntitiesWithExtInfo toAtlasEntity(IReferenceableInstance referenceable) throws AtlasBaseException {
    AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());
    if (entityType == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
    }
    // validate
    try {
        metadataService.validateAndConvertToTypedInstance(referenceable, entityType.getTypeName());
    } catch (AtlasException excp) {
        throw toAtlasBaseException(excp);
    }
    ConverterContext ctx = new ConverterContext();
    AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, ctx);
    ctx.addEntity(entity);
    return ctx.getEntities();
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasException(org.apache.atlas.AtlasException) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 77 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructType method output.

@Override
public void output(Appendable buf, Set<String> typesInProcess) throws AtlasException {
    if (typesInProcess == null) {
        typesInProcess = new HashSet<>();
    } else if (typesInProcess.contains(name)) {
        // Avoid infinite recursion on bi-directional reference attributes.
        try {
            buf.append(name);
        } catch (IOException e) {
            throw new AtlasException(e);
        }
        return;
    }
    typesInProcess.add(name);
    try {
        buf.append(getClass().getSimpleName());
        buf.append("{name=").append(name);
        buf.append(", description=").append(description);
        buf.append(", fieldMapping.fields=[");
        Iterator<AttributeInfo> it = fieldMapping.fields.values().iterator();
        while (it.hasNext()) {
            AttributeInfo attrInfo = it.next();
            attrInfo.output(buf, typesInProcess);
            if (it.hasNext()) {
                buf.append(", ");
            } else {
                buf.append(']');
            }
        }
        buf.append("}");
    } catch (IOException e) {
        throw new AtlasException(e);
    } finally {
        typesInProcess.remove(name);
    }
}
Also used : IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException)

Example 78 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class HierarchicalType method constructFieldMapping.

protected Pair<FieldMapping, ImmutableMap<String, String>> constructFieldMapping(ImmutableSet<String> superTypes, AttributeInfo... fields) throws AtlasException {
    Map<String, AttributeInfo> fieldsMap = new LinkedHashMap();
    Map<String, Integer> fieldPos = new HashMap();
    Map<String, Integer> fieldNullPos = new HashMap();
    Map<String, String> attributeNameToType = new HashMap<>();
    int numBools = 0;
    int numBytes = 0;
    int numShorts = 0;
    int numInts = 0;
    int numLongs = 0;
    int numFloats = 0;
    int numDoubles = 0;
    int numBigInts = 0;
    int numBigDecimals = 0;
    int numDates = 0;
    int numStrings = 0;
    int numArrays = 0;
    int numMaps = 0;
    int numStructs = 0;
    int numReferenceables = 0;
    setupSuperTypesGraph(superTypes);
    Iterator<Path> pathItr = pathIterator();
    while (pathItr.hasNext()) {
        Path currentPath = pathItr.next();
        ST superType = Objects.equals(currentPath.typeName, getName()) ? (ST) this : typeSystem.getDataType(superTypeClass, currentPath.typeName);
        ImmutableList<AttributeInfo> superTypeFields = superType == this ? ImmutableList.copyOf(fields) : superType.immediateAttrs;
        Set<String> immediateFields = new HashSet<>();
        for (AttributeInfo i : superTypeFields) {
            if (superType == this) {
                if (immediateFields.contains(i.name)) {
                    throw new AtlasException(String.format("Struct defintion cannot contain multiple fields with the" + " same name %s", i.name));
                }
                immediateFields.add(i.name);
            }
            String attrName = i.name;
            if (fieldsMap.containsKey(attrName)) {
                attrName = currentPath.addOverrideAttr(attrName);
            }
            attributeNameToType.put(attrName, superType.getName());
            fieldsMap.put(attrName, i);
            fieldNullPos.put(attrName, fieldNullPos.size());
            if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
                fieldPos.put(attrName, numBools);
                numBools++;
            } else if (i.dataType() == DataTypes.BYTE_TYPE) {
                fieldPos.put(attrName, numBytes);
                numBytes++;
            } else if (i.dataType() == DataTypes.SHORT_TYPE) {
                fieldPos.put(attrName, numShorts);
                numShorts++;
            } else if (i.dataType() == DataTypes.INT_TYPE) {
                fieldPos.put(attrName, numInts);
                numInts++;
            } else if (i.dataType() == DataTypes.LONG_TYPE) {
                fieldPos.put(attrName, numLongs);
                numLongs++;
            } else if (i.dataType() == DataTypes.FLOAT_TYPE) {
                fieldPos.put(attrName, numFloats);
                numFloats++;
            } else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
                fieldPos.put(attrName, numDoubles);
                numDoubles++;
            } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
                fieldPos.put(attrName, numBigInts);
                numBigInts++;
            } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
                fieldPos.put(attrName, numBigDecimals);
                numBigDecimals++;
            } else if (i.dataType() == DataTypes.DATE_TYPE) {
                fieldPos.put(attrName, numDates);
                numDates++;
            } else if (i.dataType() == DataTypes.STRING_TYPE) {
                fieldPos.put(attrName, numStrings);
                numStrings++;
            } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
                fieldPos.put(i.name, numInts);
                numInts++;
            } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
                fieldPos.put(attrName, numArrays);
                numArrays++;
            } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
                fieldPos.put(attrName, numMaps);
                numMaps++;
            } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
                fieldPos.put(attrName, numStructs);
                numStructs++;
            } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
                fieldPos.put(attrName, numReferenceables);
                numReferenceables++;
            } else {
                throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
            }
        }
    }
    this.superTypePaths = ImmutableMap.copyOf(superTypePaths);
    this.pathNameToPathMap = ImmutableMap.copyOf(pathNameToPathMap);
    FieldMapping fm = new FieldMapping(fieldsMap, fieldPos, fieldNullPos, numBools, numBytes, numShorts, numInts, numLongs, numFloats, numDoubles, numBigInts, numBigDecimals, numDates, numStrings, numArrays, numMaps, numStructs, numReferenceables);
    return new Pair(fm, ImmutableMap.copyOf(attributeNameToType));
}
Also used : AtlasException(org.apache.atlas.AtlasException) Pair(org.apache.atlas.typesystem.types.TypeUtils.Pair)

Example 79 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class HierarchicalType method output.

@Override
public void output(Appendable buf, Set<String> typesInProcess) throws AtlasException {
    if (typesInProcess == null) {
        typesInProcess = new HashSet<>();
    } else if (typesInProcess.contains(name)) {
        // Avoid infinite recursion on bi-directional reference attributes.
        try {
            buf.append(name);
        } catch (IOException e) {
            throw new AtlasException(e);
        }
        return;
    }
    typesInProcess.add(name);
    try {
        buf.append(getClass().getSimpleName()).append('{');
        buf.append("name=").append(name);
        buf.append(", description=").append(description);
        buf.append(", superTypes=").append(superTypes.toString());
        buf.append(", immediateAttrs=[");
        UnmodifiableIterator<AttributeInfo> it = immediateAttrs.iterator();
        while (it.hasNext()) {
            AttributeInfo attrInfo = it.next();
            attrInfo.output(buf, typesInProcess);
            if (it.hasNext()) {
                buf.append(", ");
            } else {
                buf.append(']');
            }
        }
        buf.append("}");
    } catch (IOException e) {
        throw new AtlasException(e);
    } finally {
        typesInProcess.remove(name);
    }
}
Also used : IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException)

Example 80 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructType method constructFieldMapping.

protected FieldMapping constructFieldMapping(AttributeInfo... fields) throws AtlasException {
    Map<String, AttributeInfo> fieldsMap = new LinkedHashMap<>();
    Map<String, Integer> fieldPos = new HashMap<>();
    Map<String, Integer> fieldNullPos = new HashMap<>();
    int numBools = 0;
    int numBytes = 0;
    int numShorts = 0;
    int numInts = 0;
    int numLongs = 0;
    int numFloats = 0;
    int numDoubles = 0;
    int numBigInts = 0;
    int numBigDecimals = 0;
    int numDates = 0;
    int numStrings = 0;
    int numArrays = 0;
    int numMaps = 0;
    int numStructs = 0;
    int numReferenceables = 0;
    for (AttributeInfo i : fields) {
        if (fieldsMap.containsKey(i.name)) {
            throw new AtlasException(String.format("Struct defintion cannot contain multiple fields with the same " + "name %s", i.name));
        }
        fieldsMap.put(i.name, i);
        fieldNullPos.put(i.name, fieldNullPos.size());
        if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
            fieldPos.put(i.name, numBools);
            numBools++;
        } else if (i.dataType() == DataTypes.BYTE_TYPE) {
            fieldPos.put(i.name, numBytes);
            numBytes++;
        } else if (i.dataType() == DataTypes.SHORT_TYPE) {
            fieldPos.put(i.name, numShorts);
            numShorts++;
        } else if (i.dataType() == DataTypes.INT_TYPE) {
            fieldPos.put(i.name, numInts);
            numInts++;
        } else if (i.dataType() == DataTypes.LONG_TYPE) {
            fieldPos.put(i.name, numLongs);
            numLongs++;
        } else if (i.dataType() == DataTypes.FLOAT_TYPE) {
            fieldPos.put(i.name, numFloats);
            numFloats++;
        } else if (i.dataType() == DataTypes.DOUBLE_TYPE) {
            fieldPos.put(i.name, numDoubles);
            numDoubles++;
        } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
            fieldPos.put(i.name, numBigInts);
            numBigInts++;
        } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
            fieldPos.put(i.name, numBigDecimals);
            numBigDecimals++;
        } else if (i.dataType() == DataTypes.DATE_TYPE) {
            fieldPos.put(i.name, numDates);
            numDates++;
        } else if (i.dataType() == DataTypes.STRING_TYPE) {
            fieldPos.put(i.name, numStrings);
            numStrings++;
        } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
            fieldPos.put(i.name, numInts);
            numInts++;
        } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
            fieldPos.put(i.name, numArrays);
            numArrays++;
        } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
            fieldPos.put(i.name, numMaps);
            numMaps++;
        } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
            fieldPos.put(i.name, numStructs);
            numStructs++;
        } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
            fieldPos.put(i.name, numReferenceables);
            numReferenceables++;
        } else {
            throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
        }
    }
    return new FieldMapping(fieldsMap, fieldPos, fieldNullPos, numBools, numBytes, numShorts, numInts, numLongs, numFloats, numDoubles, numBigInts, numBigDecimals, numDates, numStrings, numArrays, numMaps, numStructs, numReferenceables);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AtlasException(org.apache.atlas.AtlasException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

AtlasException (org.apache.atlas.AtlasException)101 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)19 IOException (java.io.IOException)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 Configuration (org.apache.commons.configuration.Configuration)9 ArrayList (java.util.ArrayList)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)6 HashMap (java.util.HashMap)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)5 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)5 Referenceable (org.apache.atlas.typesystem.Referenceable)5 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)5