Search in sources :

Example 86 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class AtlasJanusGraph method addEdge.

@Override
public AtlasEdge<AtlasJanusVertex, AtlasJanusEdge> addEdge(AtlasVertex<AtlasJanusVertex, AtlasJanusEdge> outVertex, AtlasVertex<AtlasJanusVertex, AtlasJanusEdge> inVertex, String edgeLabel) {
    try {
        Vertex oV = outVertex.getV().getWrappedElement();
        Vertex iV = inVertex.getV().getWrappedElement();
        Edge edge = oV.addEdge(edgeLabel, iV);
        return GraphDbObjectFactory.createEdge(this, edge);
    } catch (SchemaViolationException e) {
        throw new AtlasSchemaViolationException(e);
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasSchemaViolationException(org.apache.atlas.repository.graphdb.AtlasSchemaViolationException) SchemaViolationException(org.janusgraph.core.SchemaViolationException) AtlasSchemaViolationException(org.apache.atlas.repository.graphdb.AtlasSchemaViolationException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 87 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class AtlasRelationshipStoreV1 method getOrCreate.

@Override
public AtlasRelationship getOrCreate(AtlasRelationship relationship) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getOrCreate({})", relationship);
    }
    validateRelationship(relationship);
    AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
    AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2());
    AtlasRelationship ret = null;
    // check if relationship exists
    AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName());
    if (relationshipEdge == null) {
        validateRelationship(relationship);
        relationshipEdge = createRelationship(end1Vertex, end2Vertex, relationship);
    }
    if (relationshipEdge != null) {
        ret = entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getOrCreate({}): {}", relationship, ret);
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 88 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class AtlasRelationshipStoreV1 method deleteById.

@Override
@GraphTransaction
public void deleteById(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> deleteById({})", guid);
    }
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, " empty/null guid");
    }
    AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
    if (edge == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
    }
    if (getState(edge) == DELETED) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_DELETED, guid);
    }
    deleteHandler.deleteRelationships(Collections.singleton(edge));
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== deleteById({}): {}", guid);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 89 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class AtlasRelationshipStoreV1 method update.

@Override
@GraphTransaction
public AtlasRelationship update(AtlasRelationship relationship) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> update({})", relationship);
    }
    String guid = relationship.getGuid();
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
    }
    AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
    String edgeType = AtlasGraphUtilsV1.getTypeName(edge);
    AtlasVertex end1Vertex = edge.getOutVertex();
    AtlasVertex end2Vertex = edge.getInVertex();
    // update shouldn't change endType
    if (StringUtils.isNotEmpty(relationship.getTypeName()) && !StringUtils.equalsIgnoreCase(edgeType, relationship.getTypeName())) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_TYPE_CHANGE_NOT_ALLOWED, guid, edgeType, relationship.getTypeName());
    }
    // update shouldn't change ends
    if (relationship.getEnd1() != null) {
        String updatedEnd1Guid = relationship.getEnd1().getGuid();
        if (updatedEnd1Guid == null) {
            AtlasVertex updatedEnd1Vertex = getVertexFromEndPoint(relationship.getEnd1());
            updatedEnd1Guid = updatedEnd1Vertex == null ? null : AtlasGraphUtilsV1.getIdFromVertex(updatedEnd1Vertex);
        }
        if (updatedEnd1Guid != null) {
            String end1Guid = AtlasGraphUtilsV1.getIdFromVertex(end1Vertex);
            if (!StringUtils.equalsIgnoreCase(relationship.getEnd1().getGuid(), end1Guid)) {
                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_END_CHANGE_NOT_ALLOWED, edgeType, guid, end1Guid, relationship.getEnd1().getGuid());
            }
        }
    }
    // update shouldn't change ends
    if (relationship.getEnd2() != null) {
        String updatedEnd2Guid = relationship.getEnd2().getGuid();
        if (updatedEnd2Guid == null) {
            AtlasVertex updatedEnd2Vertex = getVertexFromEndPoint(relationship.getEnd2());
            updatedEnd2Guid = updatedEnd2Vertex == null ? null : AtlasGraphUtilsV1.getIdFromVertex(updatedEnd2Vertex);
        }
        if (updatedEnd2Guid != null) {
            String end2Guid = AtlasGraphUtilsV1.getIdFromVertex(end2Vertex);
            if (!StringUtils.equalsIgnoreCase(relationship.getEnd2().getGuid(), end2Guid)) {
                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_END_CHANGE_NOT_ALLOWED, AtlasGraphUtilsV1.getTypeName(edge), guid, end2Guid, relationship.getEnd2().getGuid());
            }
        }
    }
    validateRelationship(end1Vertex, end2Vertex, edgeType, relationship.getAttributes());
    AtlasRelationship ret = updateRelationship(edge, relationship);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== update({}): {}", relationship, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 90 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.

the class AtlasRelationshipStoreV1 method createRelationshipEdge.

private AtlasEdge createRelationshipEdge(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) throws RepositoryException, AtlasBaseException {
    String relationshipLabel = getRelationshipEdgeLabel(fromVertex, toVertex, relationship.getTypeName());
    PropagateTags tagPropagation = getRelationshipTagPropagation(fromVertex, toVertex, relationship);
    AtlasEdge ret = graphHelper.getOrCreateEdge(fromVertex, toVertex, relationshipLabel);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created relationship edge from [{}] --> [{}] using edge label: [{}]", getTypeName(fromVertex), getTypeName(toVertex), relationshipLabel);
    }
    // map additional properties to relationship edge
    if (ret != null) {
        final String guid = UUID.randomUUID().toString();
        AtlasGraphUtilsV1.setProperty(ret, Constants.ENTITY_TYPE_PROPERTY_KEY, relationship.getTypeName());
        AtlasGraphUtilsV1.setProperty(ret, Constants.RELATIONSHIP_GUID_PROPERTY_KEY, guid);
        AtlasGraphUtilsV1.setProperty(ret, Constants.VERSION_PROPERTY_KEY, getRelationshipVersion(relationship));
        AtlasGraphUtilsV1.setProperty(ret, Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, tagPropagation.name());
        // propagate tags
        entityRetriever.addTagPropagation(ret, tagPropagation);
    }
    return ret;
}
Also used : PropagateTags(org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags) GraphHelper.getPropagateTags(org.apache.atlas.repository.graph.GraphHelper.getPropagateTags) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)138 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)60 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)28 AtlasType (org.apache.atlas.type.AtlasType)15 ArrayList (java.util.ArrayList)13 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)13 AtlasStructType (org.apache.atlas.type.AtlasStructType)12 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)12 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)11 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)8 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)8 AtlasMapType (org.apache.atlas.type.AtlasMapType)8 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)7 HashSet (java.util.HashSet)6 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasException (org.apache.atlas.AtlasException)5 Iterator (java.util.Iterator)4