コード例 #1
0
 private JSONObject convertThawInfoToJSON(BucketThawer bucketThawer) {
   return JsonUtils.writeKeyValueAsJson(
       JsonObjectNames.BUCKET_COLLECTION,
       bucketThawer.getThawedBuckets(),
       JsonObjectNames.FAILED_BUCKET_COLLECTION,
       bucketThawer.getFailedBuckets());
 }
コード例 #2
0
  /**
   * Thaws a range of buckets in either a specific index or all indexes on the archiving fs.
   *
   * @param index Any index that exists in both the archiving filesystem and splunk. Defaults to all
   *     indexes in the archiving fs.
   * @param from Start date of thawing interval (on the form yyyy-MM-dd). Defaults to 0001-01-01.
   * @param to End date of thawing interval (on the form yyyy-MM-dd). Defaults to 9999-12-31.
   * @return
   */
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  public String thawBuckets(
      @FormParam("index") String index, @FormParam("from") String from, @FormParam("to") String to)
      throws JSONException {

    logger.info(
        happened(
            "Received REST request to thaw buckets",
            "endpoint",
            ENDPOINT_BUCKET_THAW,
            "index",
            index,
            "from",
            from,
            "to",
            to));

    if (from == null) {
      logger.info("No from time provided - defaulting to 0001-01-01");
      from = "0001-01-01";
    }
    if (to == null) {
      logger.info("No to time provided - defaulting to 9999-12-31");
      to = "9999-12-31";
    }

    Date fromDate = StringDateConverter.convert(from);
    Date toDate = StringDateConverter.convert(to);
    if (fromDate == null || toDate == null) {
      logger.error(happened("Invalid time interval provided."));
      throw new IllegalArgumentException(
          "From and to date must be provided on the form yyyy-DD-mm");
    }

    logMetricsAtEndpoint(ENDPOINT_BUCKET_THAW);
    // thaw
    BucketThawer bucketThawer = BucketThawerFactory.createDefaultThawer();
    bucketThawer.thawBuckets(index, fromDate, toDate);

    JSONObject json = convertThawInfoToJSON(bucketThawer);
    List<JSONObject> jsons =
        RequestOnSearchPeers.createPost(ENDPOINT_BUCKET_THAW, index, from, to).execute().jsons;
    jsons.add(json);

    return JsonUtils.mergeJsonsWithKeys(
            jsons, JsonObjectNames.BUCKET_COLLECTION, JsonObjectNames.FAILED_BUCKET_COLLECTION)
        .toString();
  }