Search in sources :

Example 86 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class DiscoveryREST method searchUsingBasic.

/**
 * Retrieve data for the specified fulltext query
 *
 * @param query          Fulltext 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 FullText lookup with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid fulltext or query parameters
 */
@GET
@Path("/basic")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingBasic(@QueryParam("query") String query, @QueryParam("typeName") String typeName, @QueryParam("classification") String classification, @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws AtlasBaseException {
    Servlets.validateQueryParamLength("typeName", typeName);
    Servlets.validateQueryParamLength("classification", classification);
    if (StringUtils.isNotEmpty(query) && query.length() > maxFullTextQueryLength) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_QUERY_LENGTH, Constants.MAX_FULLTEXT_QUERY_STR_LENGTH);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingBasic(" + query + "," + typeName + "," + classification + "," + limit + "," + offset + ")");
        }
        SearchParameters searchParameters = new SearchParameters();
        searchParameters.setTypeName(typeName);
        searchParameters.setClassification(classification);
        searchParameters.setQuery(query);
        searchParameters.setExcludeDeletedEntities(excludeDeletedEntities);
        searchParameters.setLimit(limit);
        searchParameters.setOffset(offset);
        return atlasDiscoveryService.searchWithParameters(searchParameters);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) 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 87 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class DiscoveryREST method searchUsingAttribute.

/**
 * Retrieve data for the specified attribute search query
 *
 * @param attrName        Attribute name
 * @param attrValuePrefix Attibute value to search on
 * @param typeName        limit the result to only entities of specified type 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 FullText lookup with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid wildcard or query parameters
 */
@GET
@Path("/attribute")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingAttribute(@QueryParam("attrName") String attrName, @QueryParam("attrValuePrefix") String attrValuePrefix, @QueryParam("typeName") String typeName, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws AtlasBaseException {
    Servlets.validateQueryParamLength("attrName", attrName);
    Servlets.validateQueryParamLength("attrValuePrefix", attrValuePrefix);
    Servlets.validateQueryParamLength("typeName", typeName);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingAttribute(" + attrName + "," + attrValuePrefix + "," + typeName + "," + limit + "," + offset + ")");
        }
        if (StringUtils.isEmpty(attrName) && StringUtils.isEmpty(attrValuePrefix)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, String.format("attrName : %s, attrValue: %s for attribute search.", attrName, attrValuePrefix));
        }
        return atlasDiscoveryService.searchUsingBasicQuery(null, typeName, null, attrName, attrValuePrefix, true, 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 88 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class EmbeddedServer method start.

public void start() throws AtlasBaseException {
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.EMBEDDED_SERVER_START, e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) IOException(java.io.IOException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 89 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class TypesResource method getTypesByFilter.

/**
 * Return the list of type names in the type system which match the specified filter.
 *
 * @return list of type names
 * @param typeCategory returns types whose relationshipCategory is the given typeCategory
 * @param supertype returns types which contain the given supertype
 * @param notsupertype returns types which do not contain the given supertype
 *
 * Its possible to specify combination of these filters in one request and the conditions are combined with AND
 * For example, typeCategory = TRAIT && supertype contains 'X' && supertype !contains 'Y'
 * If there is no filter, all the types are returned
 */
@GET
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTypesByFilter(@Context HttpServletRequest request, @QueryParam("type") String typeCategory, @QueryParam("supertype") String supertype, @QueryParam("notsupertype") String notsupertype) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.getTypesByFilter({}, {}, {})", typeCategory, supertype, notsupertype);
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")");
    }
    Map<String, Object> response = new HashMap<>();
    try {
        List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
        response.put(AtlasClient.RESULTS, result);
        response.put(AtlasClient.COUNT, result.size());
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.warn("TypesREST exception: {} {}", e.getClass().getSimpleName(), e.getMessage());
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get types list", e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get types list", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.getTypesByFilter({}, {}, {})", typeCategory, supertype, notsupertype);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 90 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class TypesResource method update.

/**
 * Update of existing types - if the given type doesn't exist, creates new type
 * Allowed updates are:
 * 1. Add optional attribute
 * 2. Change required to optional attribute
 * 3. Add super types - super types shouldn't contain any required attributes
 * @param request
 * @return
 */
@PUT
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response update(@Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.update()");
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
    }
    try {
        final String typeDefinition = Servlets.getRequestPayload(request);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Updating type with definition {} ", typeDefinition);
        }
        AtlasTypesDef updateTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
        AtlasTypesDef updatedTypesDef = typeDefStore.createUpdateTypesDef(updateTypesDef);
        List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
        List<Map<String, Object>> typesResponse = new ArrayList<>(typeNames.size());
        for (String typeName : typeNames) {
            typesResponse.add(Collections.singletonMap(AtlasClient.NAME, typeName));
        }
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.TYPES, typesResponse);
        return Response.ok().entity(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to persist types", e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.update()");
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HashMap(java.util.HashMap) Map(java.util.Map) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 ArrayList (java.util.ArrayList)60 Test (org.testng.annotations.Test)60 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24