Handles bulk deletions of a range of annotations (local or global) using query string or body data @param tsdb The TSD to which we belong @param query The query to parse and respond to
(final TSDB tsdb, HttpQuery query)
| 248 | * @param query The query to parse and respond to |
| 249 | */ |
| 250 | void executeBulkDelete(final TSDB tsdb, HttpQuery query) { |
| 251 | try { |
| 252 | final AnnotationBulkDelete delete_request; |
| 253 | if (query.hasContent()) { |
| 254 | delete_request = query.serializer().parseAnnotationBulkDeleteV1(); |
| 255 | } else { |
| 256 | delete_request = parseBulkDeleteQS(query); |
| 257 | } |
| 258 | |
| 259 | // validate the start time on the string. Users could request a timestamp of |
| 260 | // 0 to delete all annotations, BUT we don't want them doing that accidentally |
| 261 | if (delete_request.start_time == null || delete_request.start_time.isEmpty()) { |
| 262 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 263 | "Missing the start time value"); |
| 264 | } |
| 265 | if (!delete_request.global && |
| 266 | (delete_request.tsuids == null || delete_request.tsuids.isEmpty())) { |
| 267 | throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, |
| 268 | "Missing the TSUIDs or global annotations flag"); |
| 269 | } |
| 270 | |
| 271 | final int pre_allocate = delete_request.tsuids != null ? |
| 272 | delete_request.tsuids.size() + 1 : 1; |
| 273 | List<Deferred<Integer>> deletes = new ArrayList<Deferred<Integer>>(pre_allocate); |
| 274 | if (delete_request.global) { |
| 275 | deletes.add(Annotation.deleteRange(tsdb, null, |
| 276 | delete_request.getStartTime(), delete_request.getEndTime())); |
| 277 | } |
| 278 | if (delete_request.tsuids != null) { |
| 279 | for (String tsuid : delete_request.tsuids) { |
| 280 | deletes.add(Annotation.deleteRange(tsdb, UniqueId.stringToUid(tsuid), |
| 281 | delete_request.getStartTime(), delete_request.getEndTime())); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | Deferred.group(deletes).joinUninterruptibly(); |
| 286 | delete_request.total_deleted = 0; // just in case the caller set it |
| 287 | for (Deferred<Integer> count : deletes) { |
| 288 | delete_request.total_deleted += count.joinUninterruptibly(); |
| 289 | } |
| 290 | query.sendReply(query.serializer() |
| 291 | .formatAnnotationBulkDeleteV1(delete_request)); |
| 292 | } catch (BadRequestException e) { |
| 293 | throw e; |
| 294 | } catch (IllegalArgumentException e) { |
| 295 | throw new BadRequestException(e); |
| 296 | } catch (RuntimeException e) { |
| 297 | throw new BadRequestException(e); |
| 298 | } catch (Exception e) { |
| 299 | throw new RuntimeException("Shouldn't be here", e); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Parses a query string for annotation information. Note that {@code custom} |
no test coverage detected