Performs CRUD methods on individual annotation objects. @param tsdb The TSD to which we belong @param query The query to parse and respond to
(final TSDB tsdb, HttpQuery query)
| 46 | * @param query The query to parse and respond to |
| 47 | */ |
| 48 | public void execute(final TSDB tsdb, HttpQuery query) throws IOException { |
| 49 | final HttpMethod method = query.getAPIMethod(); |
| 50 | |
| 51 | final String[] uri = query.explodeAPIPath(); |
| 52 | final String endpoint = uri.length > 1 ? uri[1] : ""; |
| 53 | if (endpoint != null && endpoint.toLowerCase().endsWith("bulk")) { |
| 54 | executeBulk(tsdb, method, query); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | final Annotation note; |
| 59 | if (query.hasContent()) { |
| 60 | note = query.serializer().parseAnnotationV1(); |
| 61 | } else { |
| 62 | note = parseQS(query); |
| 63 | } |
| 64 | |
| 65 | // GET |
| 66 | if (method == HttpMethod.GET) { |
| 67 | try { |
| 68 | if ("annotations".toLowerCase().equals(uri[0])) { |
| 69 | fetchMultipleAnnotations(tsdb, note, query); |
| 70 | } else { |
| 71 | fetchSingleAnnotation(tsdb, note, query); |
| 72 | } |
| 73 | } catch (BadRequestException e) { |
| 74 | throw e; |
| 75 | } catch (Exception e) { |
| 76 | throw new RuntimeException(e); |
| 77 | } |
| 78 | // POST |
| 79 | } else if (method == HttpMethod.POST || method == HttpMethod.PUT) { |
| 80 | |
| 81 | /** |
| 82 | * Storage callback used to determine if the storage call was successful |
| 83 | * or not. Also returns the updated object from storage. |
| 84 | */ |
| 85 | class SyncCB implements Callback<Deferred<Annotation>, Boolean> { |
| 86 | |
| 87 | @Override |
| 88 | public Deferred<Annotation> call(Boolean success) throws Exception { |
| 89 | if (!success) { |
| 90 | throw new BadRequestException( |
| 91 | HttpResponseStatus.INTERNAL_SERVER_ERROR, |
| 92 | "Failed to save the Annotation to storage", |
| 93 | "This may be caused by another process modifying storage data"); |
| 94 | } |
| 95 | |
| 96 | return Annotation.getAnnotation(tsdb, note.getTSUID(), |
| 97 | note.getStartTime()); |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | |
| 102 | try { |
| 103 | final Deferred<Annotation> process_meta = note.syncToStorage(tsdb, |
| 104 | method == HttpMethod.PUT).addCallbackDeferring(new SyncCB()); |
| 105 | final Annotation updated_meta = process_meta.joinUninterruptibly(); |
nothing calls this directly
no test coverage detected