Search in sources :

Example 21 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class GraphBackedSearchIndexer method getVertexIndexKeys.

public Set<String> getVertexIndexKeys() {
    if (recomputeIndexedKeys) {
        AtlasGraphManagement management = null;
        try {
            management = provider.get().getManagementSystem();
        } catch (RepositoryException excp) {
            LOG.error("failed to get indexedKeys from graph", excp);
        }
        if (management != null) {
            recomputeIndexedKeys = false;
            AtlasGraphIndex vertexIndex = management.getGraphIndex(Constants.VERTEX_INDEX);
            Set<String> indexKeys = new HashSet<>();
            for (AtlasPropertyKey fieldKey : vertexIndex.getFieldKeys()) {
                indexKeys.add(fieldKey.getName());
            }
            vertexIndexKeys = indexKeys;
        }
    }
    return vertexIndexKeys;
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) AtlasGraphIndex(org.apache.atlas.repository.graphdb.AtlasGraphIndex) RepositoryException(org.apache.atlas.repository.RepositoryException) HashSet(java.util.HashSet)

Example 22 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityGraphMapper method addInverseReference.

private void addInverseReference(AttributeMutationContext ctx, AtlasAttribute inverseAttribute, AtlasEdge edge) throws AtlasBaseException {
    AtlasStructType inverseType = inverseAttribute.getDefinedInType();
    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseType, inverseAttribute.getName());
    AtlasVertex vertex = edge.getOutVertex();
    AtlasVertex inverseVertex = edge.getInVertex();
    String inverseEdgeLabel = AtlasGraphUtilsV1.getEdgeLabel(propertyName);
    AtlasEdge inverseEdge = graphHelper.getEdgeForLabel(inverseVertex, inverseEdgeLabel);
    AtlasEdge newEdge;
    try {
        newEdge = graphHelper.getOrCreateEdge(inverseVertex, vertex, inverseEdgeLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    boolean inverseUpdated = true;
    switch(inverseAttribute.getAttributeType().getTypeCategory()) {
        case OBJECT_ID_TYPE:
            if (inverseEdge != null) {
                if (!inverseEdge.equals(newEdge)) {
                    // Disconnect old reference
                    deleteHandler.deleteEdgeReference(inverseEdge, inverseAttribute.getAttributeType().getTypeCategory(), inverseAttribute.isOwnedRef(), true);
                } else {
                    // Edge already exists for this attribute between these vertices.
                    inverseUpdated = false;
                }
            }
            break;
        case ARRAY:
            // Add edge ID to property value
            List<String> elements = inverseVertex.getProperty(propertyName, List.class);
            if (elements == null) {
                elements = new ArrayList<>();
                elements.add(newEdge.getId().toString());
                inverseVertex.setProperty(propertyName, elements);
            } else {
                if (!elements.contains(newEdge.getId().toString())) {
                    elements.add(newEdge.getId().toString());
                    inverseVertex.setProperty(propertyName, elements);
                } else {
                    // Property value list already contains the edge ID.
                    inverseUpdated = false;
                }
            }
            break;
        default:
            break;
    }
    if (inverseUpdated) {
        updateModificationMetadata(inverseVertex);
        AtlasObjectId inverseEntityId = new AtlasObjectId(AtlasGraphUtilsV1.getIdFromVertex(inverseVertex), inverseType.getTypeName());
        RequestContextV1.get().recordEntityUpdate(inverseEntityId);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasStructType(org.apache.atlas.type.AtlasStructType) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 23 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project atlas by apache.

the class AtlasRelationshipStoreV1 method createRelationship.

private AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException {
    AtlasEdge ret = null;
    try {
        ret = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName());
        if (ret == null) {
            ret = createRelationshipEdge(end1Vertex, end2Vertex, relationship);
            AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
            if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
                for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
                    String attrName = attr.getName();
                    String attrVertexProperty = attr.getVertexPropertyName();
                    Object attrValue = relationship.getAttribute(attrName);
                    AtlasGraphUtilsV1.setProperty(ret, attrVertexProperty, attrValue);
                }
            }
        } else {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), AtlasGraphUtilsV1.getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getIdFromVertex(end2Vertex));
        }
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 24 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project atlas by apache.

the class EntityGraphMapper method mapObjectIdValue.

private AtlasEdge mapObjectIdValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapObjectIdValue({})", ctx);
    }
    AtlasEdge ret = null;
    String guid = getGuid(ctx.getValue());
    AtlasVertex entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(guid);
    if (entityVertex == null) {
        AtlasObjectId objId = getObjectId(ctx.getValue());
        if (objId != null) {
            entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId);
        }
    }
    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString()));
    }
    if (ctx.getCurrentEdge() != null) {
        ret = updateEdge(ctx.getAttributeDef(), ctx.getValue(), ctx.getCurrentEdge(), entityVertex);
    } else if (ctx.getValue() != null) {
        String edgeLabel = AtlasGraphUtilsV1.getEdgeLabel(ctx.getVertexProperty());
        try {
            ret = graphHelper.getOrCreateEdge(ctx.getReferringVertex(), entityVertex, edgeLabel);
        } catch (RepositoryException e) {
            throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapObjectIdValue({})", ctx);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 25 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityGraphMapper method createVertex.

private AtlasEdge createVertex(AtlasStruct struct, AtlasVertex referringVertex, String edgeLabel, EntityMutationContext context) throws AtlasBaseException {
    AtlasVertex vertex = createStructVertex(struct);
    mapAttributes(struct, vertex, CREATE, context);
    try {
        // TODO - Map directly in AtlasGraphUtilsV1
        return graphHelper.getOrCreateEdge(referringVertex, vertex, edgeLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException)

Aggregations

RepositoryException (org.apache.atlas.repository.RepositoryException)31 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasException (org.apache.atlas.AtlasException)11 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)10 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)5 RequestContext (org.apache.atlas.RequestContext)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)3 GuidMapping (org.apache.atlas.model.instance.GuidMapping)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)3 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)2