@Override @GraphTransaction public AtlasClient.EntityResult deleteEntities(List<String> guids) throws RepositoryException { if (guids == null || guids.size() == 0) { throw new IllegalArgumentException("guids must be non-null and non-empty"); } for (String guid : guids) { if (guid == null) { LOG.warn("deleteEntities: Ignoring null guid"); continue; } try { Vertex instanceVertex = graphHelper.getVertexForGUID(guid); deleteHandler.deleteEntity(instanceVertex); } catch (EntityNotFoundException e) { // Entity does not exist - treat as non-error, since the caller // wanted to delete the entity and it's already gone. LOG.info("Deletion request ignored for non-existent entity with guid " + guid); continue; } catch (AtlasException e) { throw new RepositoryException(e); } } RequestContext requestContext = RequestContext.get(); return new AtlasClient.EntityResult( requestContext.getCreatedEntityIds(), requestContext.getUpdatedEntityIds(), requestContext.getDeletedEntityIds()); }
/** * 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(List<AtlasVertex> instanceVertices) throws AtlasException { RequestContext requestContext = RequestContext.get(); Set<AtlasVertex> deletionCandidateVertices = new HashSet<>(); for (AtlasVertex instanceVertex : instanceVertices) { String guid = GraphHelper.getIdFromVertex(instanceVertex); Id.EntityState state = GraphHelper.getState(instanceVertex); if (requestContext.getDeletedEntityIds().contains(guid) || state == Id.EntityState.DELETED) { 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); // Record all deletion candidate GUIDs in RequestContext // 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); } }
/** * Deletes the entity vertex - deletes the traits and all the references * * @param instanceVertex * @throws AtlasException */ public void deleteEntity(Vertex instanceVertex) throws AtlasException { RequestContext requestContext = RequestContext.get(); String guid = GraphHelper.getIdFromVertex(instanceVertex); Id.EntityState state = GraphHelper.getState(instanceVertex); if (requestContext.getDeletedEntityIds().contains(guid) || state == Id.EntityState.DELETED) { LOG.debug("Skipping deleting {} as its already deleted", guid); return; } String typeName = GraphHelper.getTypeName(instanceVertex); requestContext.recordEntityDelete(guid, typeName); deleteAllTraits(instanceVertex); deleteTypeVertex(instanceVertex, false); }
@Override @GraphTransaction public AtlasClient.EntityResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException { LOG.debug("updating entity {}", entity); try { TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler); instanceToGraphMapper.mapTypedInstanceToGraph( TypedInstanceToGraphMapper.Operation.UPDATE_PARTIAL, entity); RequestContext requestContext = RequestContext.get(); return new AtlasClient.EntityResult( requestContext.getCreatedEntityIds(), requestContext.getUpdatedEntityIds(), requestContext.getDeletedEntityIds()); } catch (AtlasException e) { throw new RepositoryException(e); } }