Search in sources :

Example 71 with AtlasException

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

the class BaseSecurityTest method getSSLClientFile.

private static File getSSLClientFile() throws AtlasException {
    File sslDir;
    try {
        String persistDir = null;
        URL resource = BaseSecurityTest.class.getResource("/");
        if (resource != null) {
            persistDir = resource.toURI().getPath();
        }
        assert persistDir != null;
        sslDir = new File(persistDir);
    // LOG.info("ssl-client.xml will be created in {}", sslDir);
    } catch (Exception e) {
        throw new AtlasException("Failed to find client configuration directory", e);
    }
    return new File(sslDir, SSL_CLIENT_PROPERTIES);
}
Also used : AtlasException(org.apache.atlas.AtlasException) File(java.io.File) URL(java.net.URL) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 72 with AtlasException

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

the class AtlasObjectIdConverter method hasAnyAssignedAttribute.

private boolean hasAnyAssignedAttribute(IReferenceableInstance rInstance) {
    boolean ret = false;
    if (rInstance instanceof StructInstance) {
        StructInstance sInstance = (StructInstance) rInstance;
        Map<String, Object> attributes = null;
        try {
            attributes = sInstance.getValuesMap();
        } catch (AtlasException e) {
        // ignore
        }
        if (MapUtils.isNotEmpty(attributes)) {
            for (String attrName : attributes.keySet()) {
                try {
                    if (sInstance.isValueSet(attrName)) {
                        ret = true;
                        break;
                    }
                } catch (AtlasException e) {
                // ignore
                }
            }
        }
    } else if (rInstance instanceof Referenceable) {
        Referenceable referenceable = (Referenceable) rInstance;
        ret = MapUtils.isNotEmpty(referenceable.getValuesMap());
    }
    return ret;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) AtlasException(org.apache.atlas.AtlasException)

Example 73 with AtlasException

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

the class AtlasClassificationFormatConverter method fromV1ToV2.

@Override
public AtlasClassification fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    AtlasClassification ret = null;
    if (v1Obj != null) {
        AtlasClassificationType classificationType = (AtlasClassificationType) type;
        if (v1Obj instanceof Map) {
            final Map v1Map = (Map) v1Obj;
            final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isNotEmpty(v1Attribs)) {
                ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
            } else {
                ret = new AtlasClassification(type.getTypeName());
            }
        } else if (v1Obj instanceof IStruct) {
            IStruct struct = (IStruct) v1Obj;
            Map<String, Object> v1Attribs = null;
            try {
                v1Attribs = struct.getValuesMap();
            } catch (AtlasException excp) {
                LOG.error("IStruct.getValuesMap() failed", excp);
            }
            ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasException(org.apache.atlas.AtlasException) Map(java.util.Map) IStruct(org.apache.atlas.typesystem.IStruct)

Example 74 with AtlasException

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

the class AtlasEntityFormatConverter method fromV1ToV2.

@Override
public AtlasEntity fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext context) throws AtlasBaseException {
    AtlasEntity entity = null;
    if (v1Obj != null) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        if (v1Obj instanceof IReferenceableInstance) {
            IReferenceableInstance entRef = (IReferenceableInstance) v1Obj;
            String guid = entRef.getId()._getId();
            if (!context.entityExists(guid)) {
                Map<String, Object> v1Attribs = null;
                try {
                    v1Attribs = entRef.getValuesMap();
                } catch (AtlasException excp) {
                    LOG.error("IReferenceableInstance.getValuesMap() failed", excp);
                }
                entity = new AtlasEntity(entRef.getTypeName(), super.fromV1ToV2(entityType, v1Attribs, context));
                entity.setGuid(entRef.getId()._getId());
                entity.setStatus(convertState(entRef.getId().getState()));
                entity.setCreatedBy(entRef.getSystemAttributes().createdBy);
                entity.setCreateTime(entRef.getSystemAttributes().createdTime);
                entity.setUpdatedBy(entRef.getSystemAttributes().modifiedBy);
                entity.setUpdateTime(entRef.getSystemAttributes().modifiedTime);
                entity.setVersion((long) entRef.getId().version);
                if (CollectionUtils.isNotEmpty(entRef.getTraits())) {
                    List<AtlasClassification> classifications = new ArrayList<>();
                    AtlasFormatConverter traitConverter = converterRegistry.getConverter(TypeCategory.CLASSIFICATION);
                    for (String traitName : entRef.getTraits()) {
                        IStruct trait = entRef.getTrait(traitName);
                        AtlasType classifiType = typeRegistry.getType(traitName);
                        AtlasClassification classification = (AtlasClassification) traitConverter.fromV1ToV2(trait, classifiType, context);
                        classifications.add(classification);
                    }
                    entity.setClassifications(classifications);
                }
            } else {
                entity = context.getById(guid);
            }
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "IReferenceableInstance", v1Obj.getClass().getCanonicalName());
        }
    }
    return entity;
}
Also used : ArrayList(java.util.ArrayList) AtlasType(org.apache.atlas.type.AtlasType) AtlasException(org.apache.atlas.AtlasException) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) IStruct(org.apache.atlas.typesystem.IStruct)

Example 75 with AtlasException

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

the class AtlasInstanceConverter method getTrait.

public ITypedStruct getTrait(AtlasClassification classification) throws AtlasBaseException {
    AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.CLASSIFICATION);
    AtlasType classificationType = typeRegistry.getType(classification.getTypeName());
    Struct trait = (Struct) converter.fromV2ToV1(classification, classificationType, new ConverterContext());
    try {
        return metadataService.createTraitInstance(trait);
    } catch (AtlasException e) {
        LOG.error("Exception while getting a typed reference for the entity ", e);
        throw toAtlasBaseException(e);
    }
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasType(org.apache.atlas.type.AtlasType) AtlasException(org.apache.atlas.AtlasException) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

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