Search in sources :

Example 21 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class AtlasClient method updateEntities.

protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException {
    LOG.debug("Updating entities: {}", entities);
    JSONObject response = callAPIWithBody(API.UPDATE_ENTITY, entities.toString());
    EntityResult results = extractEntityResult(response);
    LOG.debug("Update entities returned results: {}", results);
    return results;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) EntityResult(org.apache.atlas.model.legacy.EntityResult)

Example 22 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class AtlasClient method deleteEntities.

/**
     * Delete the specified entities from the repository
     *
     * @param guids guids of entities to delete
     * @return List of entity ids updated/deleted
     * @throws AtlasServiceException
     */
public EntityResult deleteEntities(final String... guids) throws AtlasServiceException {
    LOG.debug("Deleting entities: {}", guids);
    JSONObject jsonResponse = callAPIWithRetries(API.DELETE_ENTITIES, null, new ResourceCreator() {

        @Override
        public WebResource createResource() {
            API api = API.DELETE_ENTITIES;
            WebResource resource = getResource(api);
            for (String guid : guids) {
                resource = resource.queryParam(GUID.toLowerCase(), guid);
            }
            return resource;
        }
    });
    EntityResult results = extractEntityResult(jsonResponse);
    LOG.debug("Delete entities returned results: {}", results);
    return results;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) EntityResult(org.apache.atlas.model.legacy.EntityResult)

Example 23 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method deleteEntities.

@Override
@GraphTransaction
public EntityResult deleteEntities(List<String> guids) throws RepositoryException {
    if (guids == null || guids.size() == 0) {
        throw new IllegalArgumentException("guids must be non-null and non-empty");
    }
    // Retrieve vertices for requested guids.
    Map<String, AtlasVertex> vertices = graphHelper.getVerticesForGUIDs(guids);
    Collection<AtlasVertex> deletionCandidates = vertices.values();
    if (LOG.isDebugEnabled()) {
        for (String guid : guids) {
            if (!vertices.containsKey(guid)) {
                // Entity does not exist - treat as non-error, since the caller
                // wanted to delete the entity and it's already gone.
                LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
            }
        }
    }
    if (deletionCandidates.isEmpty()) {
        LOG.info("No deletion candidate entities were found for guids %s", guids);
        return new EntityResult(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
    }
    try {
        deleteHandler.deleteEntities(deletionCandidates);
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
    RequestContext requestContext = RequestContext.get();
    return createEntityResultFromContext(requestContext);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 24 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method createEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("adding entities={}", entities);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
        List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        EntityResult entityResult = new EntityResult(createdGuids, null, null);
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(entityResult);
        result.setGuidMapping(mapping);
        return result;
    } catch (EntityExistsException e) {
        throw e;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 25 with EntityResult

use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.

the class DefaultMetadataService method deleteGuids.

private EntityResult deleteGuids(List<String> deleteCandidateGuids) throws AtlasException {
    EntityResult entityResult = repository.deleteEntities(deleteCandidateGuids);
    onEntitiesAddedUpdated(entityResult);
    return entityResult;
}
Also used : EntityResult(org.apache.atlas.model.legacy.EntityResult)

Aggregations

EntityResult (org.apache.atlas.model.legacy.EntityResult)33 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)12 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 List (java.util.List)11 Referenceable (org.apache.atlas.typesystem.Referenceable)11 ImmutableList (com.google.common.collect.ImmutableList)10 Id (org.apache.atlas.typesystem.persistence.Id)6 HashMap (java.util.HashMap)5 WebResource (com.sun.jersey.api.client.WebResource)4 GuidMapping (org.apache.atlas.model.instance.GuidMapping)4 Map (java.util.Map)3 AtlasException (org.apache.atlas.AtlasException)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)2 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2