MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / executeBulkUpdate

Method executeBulkUpdate

src/tsd/AnnotationRpc.java:163–242  ·  view source on GitHub ↗

Performs CRU methods on a list of annotation objects to reduce calls to the API. Only supports body content and adding or updating annotation objects. Deletions are separate. @param tsdb The TSD to which we belong @param method The request method @param query The query to parse and respond to

(final TSDB tsdb, final HttpMethod method, HttpQuery query)

Source from the content-addressed store, hash-verified

161 * @param query The query to parse and respond to
162 */
163 void executeBulkUpdate(final TSDB tsdb, final HttpMethod method, HttpQuery query) {
164 final List<Annotation> notes;
165 try {
166 notes = query.serializer().parseAnnotationsV1();
167 } catch (IllegalArgumentException e){
168 throw new BadRequestException(e);
169 } catch (JSONException e){
170 throw new BadRequestException(e);
171 }
172 final List<Deferred<Annotation>> callbacks =
173 new ArrayList<Deferred<Annotation>>(notes.size());
174
175 /**
176 * Storage callback used to determine if the storage call was successful
177 * or not. Also returns the updated object from storage.
178 */
179 class SyncCB implements Callback<Deferred<Annotation>, Boolean> {
180 final private Annotation note;
181
182 public SyncCB(final Annotation note) {
183 this.note = note;
184 }
185
186 @Override
187 public Deferred<Annotation> call(Boolean success) throws Exception {
188 if (!success) {
189 throw new BadRequestException(
190 HttpResponseStatus.INTERNAL_SERVER_ERROR,
191 "Failed to save an Annotation to storage",
192 "This may be caused by another process modifying storage data: "
193 + note);
194 }
195
196 return Annotation.getAnnotation(tsdb, note.getTSUID(),
197 note.getStartTime());
198 }
199 }
200
201 /**
202 * Simple callback that will index the updated annotation
203 */
204 class IndexCB implements Callback<Deferred<Annotation>, Annotation> {
205 @Override
206 public Deferred<Annotation> call(final Annotation note) throws Exception {
207 tsdb.indexAnnotation(note);
208 return Deferred.fromResult(note);
209 }
210 }
211
212 for (Annotation note : notes) {
213 try {
214 Deferred<Annotation> deferred =
215 note.syncToStorage(tsdb, method == HttpMethod.PUT)
216 .addCallbackDeferring(new SyncCB(note));
217 Deferred<Annotation> indexer =
218 deferred.addCallbackDeferring(new IndexCB());
219 callbacks.add(indexer);
220 } catch (IllegalStateException e) {

Callers 1

executeBulkMethod · 0.95

Calls 10

serializerMethod · 0.80
clearMethod · 0.80
sendReplyMethod · 0.80
sizeMethod · 0.65
getMessageMethod · 0.65
parseAnnotationsV1Method · 0.45
syncToStorageMethod · 0.45
addMethod · 0.45
groupMethod · 0.45
formatAnnotationsV1Method · 0.45

Tested by

no test coverage detected