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

Class AnnotationRpc

src/tsd/AnnotationRpc.java:40–479  ·  view source on GitHub ↗

Handles create, update, replace and delete calls for individual annotation objects. Annotations are stored in the data table alongside data points. Queries will return annotations along with the data if requested. This RPC is only used for modifying the individual entries. @since 2.0

Source from the content-addressed store, hash-verified

38 * @since 2.0
39 */
40final class AnnotationRpc implements HttpRpc {
41 private static final Logger LOG = LoggerFactory.getLogger(AnnotationRpc.class);
42
43 /**
44 * Performs CRUD methods on individual annotation objects.
45 * @param tsdb The TSD to which we belong
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());

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…