Search in sources :

Example 1 with SearchType

use of net.opentsdb.search.SearchQuery.SearchType in project opentsdb by OpenTSDB.

the class SearchRpc method execute.

/**
 * Handles the /api/search/<type> endpoint
 * @param tsdb The TSDB to which we belong
 * @param query The HTTP query to work with
 */
@Override
public void execute(TSDB tsdb, HttpQuery query) {
    final HttpMethod method = query.getAPIMethod();
    if (method != HttpMethod.GET && method != HttpMethod.POST) {
        throw new BadRequestException("Unsupported method: " + method.getName());
    }
    // the uri will be /api/vX/search/<type> or /api/search/<type>
    final String[] uri = query.explodeAPIPath();
    final String endpoint = uri.length > 1 ? uri[1] : "";
    final SearchType type;
    final SearchQuery search_query;
    try {
        type = SearchQuery.parseSearchType(endpoint);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid search query type supplied", e);
    }
    if (query.hasContent()) {
        search_query = query.serializer().parseSearchQueryV1();
    } else {
        search_query = parseQueryString(query, type);
    }
    search_query.setType(type);
    if (type == SearchType.LOOKUP) {
        processLookup(tsdb, query, search_query);
        return;
    }
    try {
        final SearchQuery results = tsdb.executeSearch(search_query).joinUninterruptibly();
        query.sendReply(query.serializer().formatSearchResultsV1(results));
    } catch (IllegalStateException e) {
        throw new BadRequestException("Searching is not enabled", e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SearchQuery(net.opentsdb.search.SearchQuery) SearchType(net.opentsdb.search.SearchQuery.SearchType) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) DeferredGroupException(com.stumbleupon.async.DeferredGroupException)

Aggregations

DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 SearchQuery (net.opentsdb.search.SearchQuery)1 SearchType (net.opentsdb.search.SearchQuery.SearchType)1 HttpMethod (org.jboss.netty.handler.codec.http.HttpMethod)1