Search in sources :

Example 11 with RequestContext

use of org.apache.atlas.RequestContext 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 12 with RequestContext

use of org.apache.atlas.RequestContext in project incubator-atlas by apache.

the class AuditFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    final String requestTimeISO9601 = DateTimeHelper.formatDateUTC(new Date());
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final String requestId = UUID.randomUUID().toString();
    final Thread currentThread = Thread.currentThread();
    final String oldName = currentThread.getName();
    String user = getUserFromRequest(httpRequest);
    try {
        currentThread.setName(formatName(oldName, requestId));
        RequestContext requestContext = RequestContext.createContext();
        requestContext.setUser(user);
        recordAudit(httpRequest, requestTimeISO9601, user);
        filterChain.doFilter(request, response);
    } finally {
        // put the request id into the response so users can trace logs for this request
        ((HttpServletResponse) response).setHeader(AtlasClient.REQUEST_ID, requestId);
        currentThread.setName(oldName);
        recordMetrics();
        RequestContext.clear();
        RequestContextV1.clear();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestContext(org.apache.atlas.RequestContext) Date(java.util.Date)

Aggregations

RequestContext (org.apache.atlas.RequestContext)12 AtlasException (org.apache.atlas.AtlasException)4 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)4 RepositoryException (org.apache.atlas.repository.RepositoryException)4 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)2 GuidMapping (org.apache.atlas.model.instance.GuidMapping)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 FilterChain (javax.servlet.FilterChain)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1 EntityResult (org.apache.atlas.model.legacy.EntityResult)1