Search in sources :

Example 1 with VertexInfo

use of org.apache.atlas.repository.graph.GraphHelper.VertexInfo in project incubator-atlas by apache.

the class DeleteHandler method deleteEntities.

/**
     * Deletes the specified entity vertices.
     * Deletes any traits, composite entities, and structs owned by each entity.
     * Also deletes all the references from/to the entity.
     *
     * @param instanceVertices
     * @throws AtlasException
     */
public void deleteEntities(Collection<AtlasVertex> instanceVertices) throws AtlasException {
    RequestContext requestContext = RequestContext.get();
    Set<AtlasVertex> deletionCandidateVertices = new HashSet<>();
    for (AtlasVertex instanceVertex : instanceVertices) {
        String guid = GraphHelper.getGuid(instanceVertex);
        Id.EntityState state = GraphHelper.getState(instanceVertex);
        if (requestContext.getDeletedEntityIds().contains(guid) || state == Id.EntityState.DELETED) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Skipping deletion of {} as it is already deleted", guid);
            }
            continue;
        }
        // Get GUIDs and vertices for all deletion candidates.
        Set<VertexInfo> compositeVertices = graphHelper.getCompositeVertices(instanceVertex);
        // and gather deletion candidate vertices.
        for (VertexInfo vertexInfo : compositeVertices) {
            requestContext.recordEntityDelete(vertexInfo.getGuid(), vertexInfo.getTypeName());
            deletionCandidateVertices.add(vertexInfo.getVertex());
        }
    }
    // Delete traits and vertices.
    for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) {
        deleteAllTraits(deletionCandidateVertex);
        deleteTypeVertex(deletionCandidateVertex, false);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) VertexInfo(org.apache.atlas.repository.graph.GraphHelper.VertexInfo) RequestContext(org.apache.atlas.RequestContext) Id(org.apache.atlas.typesystem.persistence.Id) HashSet(java.util.HashSet)

Example 2 with VertexInfo

use of org.apache.atlas.repository.graph.GraphHelper.VertexInfo in project incubator-atlas by apache.

the class GraphHelperTest method testGetCompositeGuidsAndVertices.

@Test
public void testGetCompositeGuidsAndVertices() throws Exception {
    ITypedReferenceableInstance hrDept = TestUtils.createDeptEg1(typeSystem);
    List<String> createdGuids = repositoryService.createEntities(hrDept).getCreatedEntities();
    String deptGuid = null;
    Set<String> expectedGuids = new HashSet<>();
    for (String guid : createdGuids) {
        ITypedReferenceableInstance entityDefinition = repositoryService.getEntityDefinition(guid);
        expectedGuids.add(guid);
        if (entityDefinition.getId().getTypeName().equals(TestUtils.DEPARTMENT_TYPE)) {
            deptGuid = guid;
        }
    }
    AtlasVertex deptVertex = GraphHelper.getInstance().getVertexForGUID(deptGuid);
    Set<VertexInfo> compositeVertices = GraphHelper.getInstance().getCompositeVertices(deptVertex);
    HashMap<String, VertexInfo> verticesByGuid = new HashMap<>();
    for (VertexInfo vertexInfo : compositeVertices) {
        verticesByGuid.put(vertexInfo.getGuid(), vertexInfo);
    }
    // Verify compositeVertices has entries for all expected guids.
    Assert.assertEquals(compositeVertices.size(), expectedGuids.size());
    for (String expectedGuid : expectedGuids) {
        Assert.assertTrue(verticesByGuid.containsKey(expectedGuid));
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) VertexInfo(org.apache.atlas.repository.graph.GraphHelper.VertexInfo) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

HashSet (java.util.HashSet)2 VertexInfo (org.apache.atlas.repository.graph.GraphHelper.VertexInfo)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 HashMap (java.util.HashMap)1 RequestContext (org.apache.atlas.RequestContext)1 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)1 Id (org.apache.atlas.typesystem.persistence.Id)1 Test (org.testng.annotations.Test)1