MCPcopy
hub / github.com/OpenTSDB/opentsdb / execute

Method execute

src/tsd/AnnotationRpc.java:48–134  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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();

Callers

nothing calls this directly

Calls 15

executeBulkMethod · 0.95
parseQSMethod · 0.95
fetchSingleAnnotationMethod · 0.95
syncToStorageMethod · 0.95
deleteMethod · 0.95
getAPIMethodMethod · 0.80
serializerMethod · 0.80
sendReplyMethod · 0.80
getNameMethod · 0.65
explodeAPIPathMethod · 0.45
hasContentMethod · 0.45

Tested by

no test coverage detected