Beispiel #1
0
 public RollupTask parseRollupTask(String json) throws BeanValidationException, QueryException {
   JsonParser parser = new JsonParser();
   JsonObject taskObject = parser.parse(json).getAsJsonObject();
   RollupTask task = parseRollupTask(taskObject, "");
   task.addJson(taskObject.toString().replaceAll("\\n", ""));
   return task;
 }
Beispiel #2
0
  public List<RollupTask> parseRollupTasks(String json)
      throws BeanValidationException, QueryException {
    List<RollupTask> tasks = new ArrayList<RollupTask>();
    JsonParser parser = new JsonParser();
    JsonArray rollupTasks = parser.parse(json).getAsJsonArray();
    for (int i = 0; i < rollupTasks.size(); i++) {
      JsonObject taskObject = rollupTasks.get(i).getAsJsonObject();
      RollupTask task = parseRollupTask(taskObject, "tasks[" + i + "]");
      task.addJson(taskObject.toString().replaceAll("\\n", ""));
      tasks.add(task);
    }

    return tasks;
  }
Beispiel #3
0
  public RollupTask parseRollupTask(JsonObject rollupTask, String context)
      throws BeanValidationException, QueryException {
    RollupTask task = m_gson.fromJson(rollupTask.getAsJsonObject(), RollupTask.class);

    validateObject(task);

    JsonArray rollups = rollupTask.getAsJsonObject().getAsJsonArray("rollups");
    if (rollups != null) {
      for (int j = 0; j < rollups.size(); j++) {
        JsonObject rollupObject = rollups.get(j).getAsJsonObject();
        Rollup rollup = m_gson.fromJson(rollupObject, Rollup.class);

        context = context + "rollup[" + j + "]";
        validateObject(rollup, context);

        JsonObject queryObject = rollupObject.getAsJsonObject("query");
        List<QueryMetric> queries = parseQueryMetric(queryObject, context);

        for (int k = 0; k < queries.size(); k++) {
          QueryMetric query = queries.get(k);
          context += ".query[" + k + "]";
          validateHasRangeAggregator(query, context);

          // Add aggregators needed for rollups
          SaveAsAggregator saveAsAggregator =
              (SaveAsAggregator) m_aggregatorFactory.createAggregator("save_as");
          saveAsAggregator.setMetricName(rollup.getSaveAs());

          TrimAggregator trimAggregator =
              (TrimAggregator) m_aggregatorFactory.createAggregator("trim");
          trimAggregator.setTrim(TrimAggregator.Trim.LAST);

          query.addAggregator(saveAsAggregator);
          query.addAggregator(trimAggregator);
        }

        rollup.addQueries(queries);
        task.addRollup(rollup);
      }
    }

    return task;
  }