DEFAULT_STATS.add(BasicRollupsOutputSerializer.MetricStat.NUM_POINTS);
}
public static RollupsQueryParams parseParams(Map<String, List<String>> params) throws InvalidRequestException {
if (params == null || params.isEmpty()) {
throw new InvalidRequestException("No query parameters present.");
}
List<String> points = params.get("points");
List<String> res = params.get("resolution");
List<String> from = params.get("from");
List<String> to = params.get("to");
List<String> select = params.get("select");
if (points == null && res == null) {
throw new InvalidRequestException("Either 'points' or 'resolution' is required.");
}
if (points != null && points.size() != 1) {
throw new InvalidRequestException("Invalid parameter: points=" + points);
} else if (res != null && res.size() != 1) {
throw new InvalidRequestException("Invalid parameter: resolution=" + res);
} else if (from == null || from.size() != 1) {
throw new InvalidRequestException("Invalid parameter: from=" + from);
} else if (to == null || to.size() != 1) {
throw new InvalidRequestException("Invalid parameter: to="+ to);
}
long fromTime = Long.parseLong(from.get(0));
long toTime = Long.parseLong(to.get(0));
if (toTime <= fromTime) {
throw new InvalidRequestException("paramter 'to' must be greater than 'from'");
}
Set<BasicRollupsOutputSerializer.MetricStat> stats = getStatsToFilter(select);
if (points != null) {
try {
return new RollupsQueryParams(fromTime, toTime, Integer.parseInt(points.get(0)), stats);
} catch (NumberFormatException ex) {
throw new InvalidRequestException("'points' param must be a valid integer");
}
} else {
return new RollupsQueryParams(fromTime, toTime, Resolution.fromString(res.get(0)), stats);
}
}