Implements the /api/query endpoint to fetch data from OpenTSDB. @param tsdb The TSDB to use for fetching data @param query The HTTP query for parsing and responding
(final TSDB tsdb, final HttpQuery query)
| 86 | * @param query The HTTP query for parsing and responding |
| 87 | */ |
| 88 | @Override |
| 89 | public void execute(final TSDB tsdb, final HttpQuery query) |
| 90 | throws IOException { |
| 91 | |
| 92 | // only accept GET/POST/DELETE |
| 93 | if (query.method() != HttpMethod.GET && query.method() != HttpMethod.POST && |
| 94 | query.method() != HttpMethod.DELETE) { |
| 95 | throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, |
| 96 | "Method not allowed", "The HTTP method [" + query.method().getName() + |
| 97 | "] is not permitted for this endpoint"); |
| 98 | } |
| 99 | if (query.method() == HttpMethod.DELETE && |
| 100 | !tsdb.getConfig().getBoolean("tsd.http.query.allow_delete")) { |
| 101 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 102 | "Bad request", |
| 103 | "Deleting data is not enabled (tsd.http.query.allow_delete=false)"); |
| 104 | } |
| 105 | |
| 106 | final String[] uri = query.explodeAPIPath(); |
| 107 | final String endpoint = uri.length > 1 ? uri[1] : ""; |
| 108 | |
| 109 | if (endpoint.toLowerCase().equals("last")) { |
| 110 | handleLastDataPointQuery(tsdb, query); |
| 111 | } else if (endpoint.toLowerCase().equals("gexp")){ |
| 112 | handleQuery(tsdb, query, true); |
| 113 | } else if (endpoint.toLowerCase().equals("exp")) { |
| 114 | handleExpressionQuery(tsdb, query); |
| 115 | return; |
| 116 | } else { |
| 117 | handleQuery(tsdb, query, false); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Processing for a data point query |