Search in sources :

Example 61 with AtlasException

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

the class GraphHelper method deserializeClassInstances.

public static ITypedReferenceableInstance[] deserializeClassInstances(TypeSystem typeSystem, String entityInstanceDefinition) throws AtlasException {
    try {
        JSONArray referableInstances = new JSONArray(entityInstanceDefinition);
        ITypedReferenceableInstance[] instances = new ITypedReferenceableInstance[referableInstances.length()];
        for (int index = 0; index < referableInstances.length(); index++) {
            Referenceable entityInstance = InstanceSerialization.fromJsonReferenceable(referableInstances.getString(index), true);
            ITypedReferenceableInstance typedInstrance = getTypedReferenceableInstance(typeSystem, entityInstance);
            instances[index] = typedInstrance;
        }
        return instances;
    } catch (ValueConversionException | TypeNotFoundException e) {
        throw e;
    } catch (Exception e) {
        // exception from deserializer
        LOG.error("Unable to deserialize json={}", entityInstanceDefinition, e);
        throw new IllegalArgumentException("Unable to deserialize json", e);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) TypeNotFoundException(org.apache.atlas.typesystem.exception.TypeNotFoundException) JSONArray(org.codehaus.jettison.json.JSONArray) ValueConversionException(org.apache.atlas.typesystem.types.ValueConversionException) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) TypeNotFoundException(org.apache.atlas.typesystem.exception.TypeNotFoundException) AtlasException(org.apache.atlas.AtlasException) ValueConversionException(org.apache.atlas.typesystem.types.ValueConversionException)

Example 62 with AtlasException

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

the class GraphBackedMetadataRepository method deleteEntities.

@Override
@GraphTransaction
public EntityResult deleteEntities(List<String> guids) throws RepositoryException {
    if (guids == null || guids.size() == 0) {
        throw new IllegalArgumentException("guids must be non-null and non-empty");
    }
    // Retrieve vertices for requested guids.
    Map<String, AtlasVertex> vertices = graphHelper.getVerticesForGUIDs(guids);
    Collection<AtlasVertex> deletionCandidates = vertices.values();
    if (LOG.isDebugEnabled()) {
        for (String guid : guids) {
            if (!vertices.containsKey(guid)) {
                // Entity does not exist - treat as non-error, since the caller
                // wanted to delete the entity and it's already gone.
                LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
            }
        }
    }
    if (deletionCandidates.isEmpty()) {
        LOG.info("No deletion candidate entities were found for guids %s", guids);
        return new EntityResult(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
    }
    try {
        deleteHandler.deleteEntities(deletionCandidates);
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
    RequestContext requestContext = RequestContext.get();
    return createEntityResultFromContext(requestContext);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 63 with AtlasException

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

the class GraphBackedMetadataRepository method createEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("adding entities={}", entities);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
        List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        EntityResult entityResult = new EntityResult(createdGuids, null, null);
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(entityResult);
        result.setGuidMapping(mapping);
        return result;
    } catch (EntityExistsException e) {
        throw e;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 64 with AtlasException

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

the class DefaultMetadataService method validateAndConvertToTypedInstance.

@Override
public ITypedReferenceableInstance validateAndConvertToTypedInstance(IReferenceableInstance updatedEntity, String typeName) throws AtlasException {
    ClassType type = typeSystem.getDataType(ClassType.class, typeName);
    ITypedReferenceableInstance newInstance = type.createInstance(updatedEntity.getId());
    for (String attributeName : updatedEntity.getValuesMap().keySet()) {
        AttributeInfo attributeInfo = type.fieldMapping.fields.get(attributeName);
        if (attributeInfo == null) {
            throw new AtlasException("Invalid property " + attributeName + " for entity " + updatedEntity);
        }
        DataTypes.TypeCategory attrTypeCategory = attributeInfo.dataType().getTypeCategory();
        Object value = updatedEntity.get(attributeName);
        switch(attrTypeCategory) {
            case CLASS:
                if (value != null) {
                    if (value instanceof Referenceable) {
                        newInstance.set(attributeName, value);
                    } else {
                        Id id = new Id((String) value, 0, attributeInfo.dataType().getName());
                        newInstance.set(attributeName, id);
                    }
                }
                break;
            case ENUM:
            case PRIMITIVE:
            case ARRAY:
            case STRUCT:
            case MAP:
                newInstance.set(attributeName, value);
                break;
            case TRAIT:
            //TODO - handle trait updates as well?
            default:
                throw new AtlasException("Update of " + attrTypeCategory + " is not supported");
        }
    }
    return newInstance;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) JSONObject(org.codehaus.jettison.json.JSONObject) Id(org.apache.atlas.typesystem.persistence.Id) AtlasException(org.apache.atlas.AtlasException)

Example 65 with AtlasException

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

the class DefaultMetadataService method createTraitInstance.

@Override
public ITypedStruct createTraitInstance(Struct traitInstance) throws AtlasException {
    try {
        final String entityTypeName = ParamChecker.notEmpty(traitInstance.getTypeName(), "entity type");
        TraitType traitType = typeSystem.getDataType(TraitType.class, entityTypeName);
        return traitType.convert(traitInstance, Multiplicity.REQUIRED);
    } catch (TypeNotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new AtlasException("Error deserializing trait instance", e);
    }
}
Also used : TypeNotFoundException(org.apache.atlas.typesystem.exception.TypeNotFoundException) AtlasException(org.apache.atlas.AtlasException) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) TypeNotFoundException(org.apache.atlas.typesystem.exception.TypeNotFoundException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONException(org.codehaus.jettison.json.JSONException) AtlasException(org.apache.atlas.AtlasException)

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