Search in sources :

Example 51 with AtlasException

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

the class GraphSandboxUtil method create.

public static void create(String sandboxName) {
    Configuration configuration;
    try {
        configuration = ApplicationProperties.get();
        String newStorageDir = System.getProperty("atlas.data") + File.separatorChar + "storage" + File.separatorChar + sandboxName;
        configuration.setProperty("atlas.graph.storage.directory", newStorageDir);
        String newIndexerDir = System.getProperty("atlas.data") + File.separatorChar + "index" + File.separatorChar + sandboxName;
        configuration.setProperty("atlas.graph.index.search.directory", newIndexerDir);
        LOG.debug("New Storage dir : {}", newStorageDir);
        LOG.debug("New Indexer dir : {}", newIndexerDir);
    } catch (AtlasException ignored) {
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasException(org.apache.atlas.AtlasException)

Example 52 with AtlasException

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

the class DefaultGraphPersistenceStrategy method constructInstance.

@Override
public <U> U constructInstance(IDataType<U> dataType, Object value) {
    try {
        switch(dataType.getTypeCategory()) {
            case PRIMITIVE:
            case ENUM:
                return dataType.convert(value, Multiplicity.OPTIONAL);
            case ARRAY:
                DataTypes.ArrayType arrType = (DataTypes.ArrayType) dataType;
                IDataType<?> elemType = arrType.getElemType();
                ImmutableCollection.Builder result = ImmutableList.builder();
                List list = (List) value;
                for (Object listElement : list) {
                    Object collectionEntry = constructCollectionEntry(elemType, listElement);
                    if (collectionEntry != null) {
                        result.add(collectionEntry);
                    }
                }
                return (U) result.build();
            case MAP:
                // todo
                break;
            case STRUCT:
                AtlasVertex structVertex = (AtlasVertex) value;
                StructType structType = (StructType) dataType;
                ITypedStruct structInstance = structType.createInstance();
                TypeSystem.IdType idType = TypeSystem.getInstance().getIdType();
                if (dataType.getName().equals(idType.getName())) {
                    structInstance.set(idType.typeNameAttrName(), GraphHelper.getSingleValuedProperty(structVertex, typeAttributeName(), String.class));
                    structInstance.set(idType.idAttrName(), GraphHelper.getSingleValuedProperty(structVertex, idAttributeName(), String.class));
                    String stateValue = GraphHelper.getSingleValuedProperty(structVertex, stateAttributeName(), String.class);
                    if (stateValue != null) {
                        structInstance.set(idType.stateAttrName(), stateValue);
                    }
                    structInstance.set(idType.versionAttrName(), structVertex.getProperty(versionAttributeName(), Integer.class));
                } else {
                    metadataRepository.getGraphToInstanceMapper().mapVertexToInstance(structVertex, structInstance, structType.fieldMapping().fields);
                }
                return dataType.convert(structInstance, Multiplicity.OPTIONAL);
            case TRAIT:
                AtlasVertex traitVertex = (AtlasVertex) value;
                TraitType traitType = (TraitType) dataType;
                ITypedStruct traitInstance = traitType.createInstance();
                // todo - this is not right, we should load the Instance associated with this
                // trait. for now just loading the trait struct.
                // metadataRepository.getGraphToInstanceMapper().mapVertexToTraitInstance(
                //        traitVertex, dataType.getName(), , traitType, traitInstance);
                metadataRepository.getGraphToInstanceMapper().mapVertexToInstance(traitVertex, traitInstance, traitType.fieldMapping().fields);
                break;
            case CLASS:
                AtlasVertex classVertex = (AtlasVertex) value;
                String guid = classVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
                // Check if the instance we need was previously loaded.
                ITypedReferenceableInstance classInstance = RequestContext.get().getInstanceV1(guid);
                if (classInstance == null) {
                    classInstance = metadataRepository.getGraphToInstanceMapper().mapGraphToTypedInstance(guid, classVertex);
                }
                return dataType.convert(classInstance, Multiplicity.OPTIONAL);
            default:
                throw new UnsupportedOperationException("Load for type " + dataType + "is not supported");
        }
    } catch (AtlasException e) {
        LOG.error("error while constructing an instance", e);
    }
    return null;
}
Also used : ImmutableCollection(com.google.common.collect.ImmutableCollection) TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) StructType(org.apache.atlas.typesystem.types.StructType) TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) AtlasException(org.apache.atlas.AtlasException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DataTypes(org.apache.atlas.typesystem.types.DataTypes)

Example 53 with AtlasException

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

the class EntityGraphMapper method mapMapValue.

private Map<String, Object> mapMapValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapMapValue({})", ctx);
    }
    @SuppressWarnings("unchecked") Map<Object, Object> newVal = (Map<Object, Object>) ctx.getValue();
    Map<String, Object> newMap = new HashMap<>();
    AtlasMapType mapType = (AtlasMapType) ctx.getAttrType();
    try {
        AtlasAttribute attribute = ctx.getAttribute();
        List<String> currentKeys = GraphHelper.getListProperty(ctx.getReferringVertex(), ctx.getVertexProperty());
        Map<String, Object> currentMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(currentKeys)) {
            for (String key : currentKeys) {
                String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), GraphHelper.encodePropertyKey(key));
                Object propertyValueForKey = getMapValueProperty(mapType.getValueType(), ctx.getReferringVertex(), propertyNameForKey);
                currentMap.put(key, propertyValueForKey);
            }
        }
        if (MapUtils.isNotEmpty(newVal)) {
            boolean isReference = AtlasGraphUtilsV1.isReference(mapType.getValueType());
            AtlasAttribute inverseRefAttribute = attribute.getInverseRefAttribute();
            for (Map.Entry<Object, Object> entry : newVal.entrySet()) {
                String key = entry.getKey().toString();
                String propertyName = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), GraphHelper.encodePropertyKey(key));
                AtlasEdge existingEdge = getEdgeIfExists(mapType, currentMap, key);
                AttributeMutationContext mapCtx = new AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), attribute, entry.getValue(), propertyName, mapType.getValueType(), existingEdge);
                //Add/Update/Remove property value
                Object newEntry = mapCollectionElementsToVertex(mapCtx, context);
                setMapValueProperty(mapType.getValueType(), ctx.getReferringVertex(), propertyName, newEntry);
                newMap.put(key, newEntry);
                // update the inverse reference value.
                if (isReference && newEntry instanceof AtlasEdge && inverseRefAttribute != null) {
                    AtlasEdge newEdge = (AtlasEdge) newEntry;
                    addInverseReference(mapCtx, inverseRefAttribute, newEdge);
                }
            }
        }
        Map<String, Object> finalMap = removeUnusedMapEntries(attribute, ctx.getReferringVertex(), ctx.getVertexProperty(), currentMap, newMap);
        for (Object newEntry : newMap.values()) {
            updateInConsistentOwnedMapVertices(ctx, mapType, newEntry);
        }
        Set<String> newKeys = new LinkedHashSet<>(newMap.keySet());
        newKeys.addAll(finalMap.keySet());
        // for dereference on way out
        GraphHelper.setListProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), new ArrayList<>(newKeys));
    } catch (AtlasException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapMapValue({})", ctx);
    }
    return newMap;
}
Also used : AtlasException(org.apache.atlas.AtlasException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasMapType(org.apache.atlas.type.AtlasMapType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 54 with AtlasException

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

the class UserDao method loadFileLoginsDetails.

void loadFileLoginsDetails() {
    InputStream inStr = null;
    try {
        Configuration configuration = ApplicationProperties.get();
        inStr = ApplicationProperties.getFileAsInputStream(configuration, "atlas.authentication.method.file.filename", DEFAULT_USER_CREDENTIALS_PROPERTIES);
        userLogins = new Properties();
        userLogins.load(inStr);
    } catch (IOException | AtlasException e) {
        LOG.error("Error while reading user.properties file", e);
        throw new RuntimeException(e);
    } finally {
        if (inStr != null) {
            try {
                inStr.close();
            } catch (Exception excp) {
            // ignore
            }
        }
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) ApplicationProperties(org.apache.atlas.ApplicationProperties) AtlasException(org.apache.atlas.AtlasException) AtlasAuthenticationException(org.apache.atlas.web.security.AtlasAuthenticationException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 55 with AtlasException

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

the class BaseResourceDefinition method registerProperty.

protected void registerProperty(AttributeDefinition propertyDefinition) {
    try {
        propertyDefs.put(propertyDefinition.name, propertyDefinition);
        properties.put(propertyDefinition.name, new AttributeInfo(typeSystem, propertyDefinition, null));
    } catch (AtlasException e) {
        throw new CatalogRuntimeException("Unable to create attribute: " + propertyDefinition.name, e);
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) 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