Processes a last data point query @param tsdb The TSDB to which we belong @param query The HTTP query to parse/respond
(final TSDB tsdb, final HttpQuery query)
| 344 | * @param query The HTTP query to parse/respond |
| 345 | */ |
| 346 | private void handleLastDataPointQuery(final TSDB tsdb, final HttpQuery query) { |
| 347 | |
| 348 | final LastPointQuery data_query; |
| 349 | if (query.method() == HttpMethod.POST) { |
| 350 | switch (query.apiVersion()) { |
| 351 | case 0: |
| 352 | case 1: |
| 353 | data_query = query.serializer().parseLastPointQueryV1(); |
| 354 | break; |
| 355 | default: |
| 356 | throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, |
| 357 | "Requested API version not implemented", "Version " + |
| 358 | query.apiVersion() + " is not implemented"); |
| 359 | } |
| 360 | } else { |
| 361 | data_query = this.parseLastPointQuery(tsdb, query); |
| 362 | } |
| 363 | |
| 364 | if (data_query.sub_queries == null || data_query.sub_queries.isEmpty()) { |
| 365 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 366 | "Missing sub queries"); |
| 367 | } |
| 368 | |
| 369 | // a list of deferreds to wait on |
| 370 | final ArrayList<Deferred<Object>> calls = new ArrayList<Deferred<Object>>(); |
| 371 | // final results for serialization |
| 372 | final List<IncomingDataPoint> results = new ArrayList<IncomingDataPoint>(); |
| 373 | |
| 374 | /** |
| 375 | * Used to catch exceptions |
| 376 | */ |
| 377 | final class ErrBack implements Callback<Object, Exception> { |
| 378 | public Object call(final Exception e) throws Exception { |
| 379 | Throwable ex = e; |
| 380 | while (ex.getClass().equals(DeferredGroupException.class)) { |
| 381 | if (ex.getCause() == null) { |
| 382 | LOG.warn("Unable to get to the root cause of the DGE"); |
| 383 | break; |
| 384 | } |
| 385 | ex = ex.getCause(); |
| 386 | } |
| 387 | if (ex instanceof RuntimeException) { |
| 388 | throw new BadRequestException(ex); |
| 389 | } else { |
| 390 | throw e; |
| 391 | } |
| 392 | } |
| 393 | @Override |
| 394 | public String toString() { |
| 395 | return "Error back"; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | final class FetchCB implements Callback<Deferred<Object>, ArrayList<IncomingDataPoint>> { |
| 400 | @Override |
| 401 | public Deferred<Object> call(final ArrayList<IncomingDataPoint> dps) throws Exception { |
| 402 | synchronized(results) { |
| 403 | for (final IncomingDataPoint dp : dps) { |
no test coverage detected