Search in sources :

Example 66 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project atlas by apache.

the class MetadataDiscoveryResource method searchUsingQueryDSL.

/**
 * Search using query DSL format.
 *
 * @param dslQuery search query in DSL format.
 * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
 * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
 * Limit and offset in API are used in conjunction with limit and offset in DSL query
 * Final limit = min(API limit, max(query limit - API offset, 0))
 * Final offset = API offset + query offset
 *
 * @return JSON representing the type and results.
 */
@GET
@Path("search/dsl")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingQueryDSL(" + dslQuery + ", " + limit + ", " + offset + ")");
        }
        dslQuery = ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null");
        QueryParams queryParams = validateQueryParams(limit, offset);
        AtlasSearchResult result = atlasDiscoveryService.searchUsingDslQuery(dslQuery, queryParams.limit(), queryParams.offset());
        DSLSearchResult dslResult = new DSLSearchResult();
        dslResult.setQueryType(QUERY_TYPE_DSL);
        dslResult.setRequestId(Servlets.getRequestId());
        dslResult.setDataType(result.getType());
        dslResult.setQuery(result.getQueryText());
        dslResult.setCount(0);
        if (CollectionUtils.isNotEmpty(result.getEntities())) {
            for (AtlasEntityHeader entityHeader : result.getEntities()) {
                Referenceable entity = getEntity(entityHeader.getGuid());
                dslResult.addResult(entity);
            }
            if (dslResult.getResults() != null) {
                dslResult.setCount(dslResult.getResults().size());
            }
        } else if (result.getAttributes() != null && CollectionUtils.isNotEmpty(result.getAttributes().getName())) {
            List<String> attrNames = result.getAttributes().getName();
            for (List<Object> attrValues : result.getAttributes().getValues()) {
                if (attrValues == null) {
                    continue;
                }
                Referenceable entity = new Referenceable();
                for (int i = 0; i < attrNames.size(); i++) {
                    String attrName = attrNames.get(i);
                    Object attrValue = attrValues.size() > i ? attrValues.get(i) : null;
                    entity.set(attrName, attrValue);
                }
                dslResult.addResult(entity);
            }
            if (dslResult.getResults() != null) {
                dslResult.setCount(dslResult.getResults().size());
            }
        }
        String response = AtlasJson.toV1SearchJson(dslResult);
        return Response.ok(response).build();
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset);
        }
    }
}
Also used : DSLSearchResult(org.apache.atlas.v1.model.discovery.DSLSearchResult) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) QueryParams(org.apache.atlas.query.QueryParams) List(java.util.List) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project atlas by apache.

the class DiscoveryREST method getSavedSearch.

/**
 * @param searchName Name of the saved search
 * @param userName User for whom the search is retrieved
 * @return
 * @throws AtlasBaseException
 */
@GET
@Path("saved/{name}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasUserSavedSearch getSavedSearch(@PathParam("name") String searchName, @QueryParam("user") String userName) throws AtlasBaseException {
    Servlets.validateQueryParamLength("name", searchName);
    Servlets.validateQueryParamLength("user", userName);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.getSavedSearch(userName=" + userName + ", name=" + searchName + ")");
        }
        return atlasDiscoveryService.getSavedSearchByName(Servlets.getUserName(httpServletRequest), userName, searchName);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 68 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project atlas by apache.

the class DiscoveryREST method searchRelatedEntities.

/**
 * Relationship search to search for related entities satisfying the search parameters
 *
 * @param guid            Attribute name
 * @param relation        relationName
 * @param sortByAttribute sort the result using this attribute name, default value is 'name'
 * @param sortOrder       sorting order
 * @param limit           limit the result set to only include the specified number of entries
 * @param offset          start offset of the result set (useful for pagination)
 * @return Atlas search result
 * @throws AtlasBaseException
 * @HTTP 200 On successful search
 * @HTTP 400 guid is not a valid entity type or attributeName is not a valid relationship attribute
 */
@GET
@Path("relationship")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchRelatedEntities(@QueryParam("guid") String guid, @QueryParam("relation") String relation, @QueryParam("sortBy") String sortByAttribute, @QueryParam("sortOrder") SortOrder sortOrder, @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    Servlets.validateQueryParamLength("relation", relation);
    Servlets.validateQueryParamLength("sortBy", sortByAttribute);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.relatedEntitiesSearchUsingGremlin(" + guid + ", " + relation + ", " + sortByAttribute + ", " + sortOrder + ", " + excludeDeletedEntities + ", " + ", " + limit + ", " + offset + ")");
        }
        return atlasDiscoveryService.searchRelatedEntities(guid, relation, sortByAttribute, sortOrder, excludeDeletedEntities, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 69 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project atlas by apache.

the class DiscoveryREST method searchUsingDSL.

/**
 * Retrieve data for the specified DSL
 *
 * @param query          DSL query
 * @param typeName       limit the result to only entities of specified type or its sub-types
 * @param classification limit the result to only entities tagged with the given classification or or its sub-types
 * @param limit          limit the result set to only include the specified number of entries
 * @param offset         start offset of the result set (useful for pagination)
 * @return Search results
 * @throws AtlasBaseException
 * @HTTP 200 On successful DSL execution with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid DSL or query parameters
 */
@GET
@Path("/dsl")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingDSL(@QueryParam("query") String query, @QueryParam("typeName") String typeName, @QueryParam("classification") String classification, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws AtlasBaseException {
    Servlets.validateQueryParamLength("typeName", typeName);
    Servlets.validateQueryParamLength("classification", classification);
    if (StringUtils.isNotEmpty(query) && query.length() > maxDslQueryLength) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_QUERY_LENGTH, Constants.MAX_DSL_QUERY_STR_LENGTH);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingDSL(" + query + "," + typeName + "," + classification + "," + limit + "," + offset + ")");
        }
        String queryStr = atlasDiscoveryService.getDslQueryUsingTypeNameClassification(query, typeName, classification);
        return atlasDiscoveryService.searchUsingDslQuery(queryStr, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 70 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project atlas by apache.

the class DiscoveryREST method deleteSavedSearch.

/**
 * @param guid Name of the saved search
 */
@DELETE
@Path("saved/{guid}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteSavedSearch(@PathParam("guid") String guid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.deleteSavedSearch(guid=" + guid + ")");
        }
        atlasDiscoveryService.deleteSavedSearch(Servlets.getUserName(httpServletRequest), guid);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)108 Produces (javax.ws.rs.Produces)76 Path (javax.ws.rs.Path)67 Consumes (javax.ws.rs.Consumes)45 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)45 GET (javax.ws.rs.GET)43 HashMap (java.util.HashMap)27 JSONObject (org.codehaus.jettison.json.JSONObject)24 WebApplicationException (javax.ws.rs.WebApplicationException)22 ArrayList (java.util.ArrayList)14 DELETE (javax.ws.rs.DELETE)11 POST (javax.ws.rs.POST)11 PUT (javax.ws.rs.PUT)11 AtlasException (org.apache.atlas.AtlasException)10 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)10 JSONArray (org.codehaus.jettison.json.JSONArray)9 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)8 DiscoveryException (org.apache.atlas.discovery.DiscoveryException)7 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)7 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)7