@Test public void testExtractGrafanaAggregation() { }
public static Function extractGrafanaAggregation(JsonObject jsonElement) { if (!jsonElement.has("aggregator")) { return null; } JsonObject obj = jsonElement.get("aggregator").getAsJsonObject(); if (!obj.has("name") || !obj.has("args")) { return null; } String name = obj.get("name").getAsString(); if (name.equalsIgnoreCase("none")) { return null; } int multipleFactor = 1; if (obj.has("unit")) { multipleFactor = toSeconds(obj.get("unit").getAsString()); } Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(name); if (lookupFunction != null) { try { Function instance = (Function) lookupFunction.newInstance(); JsonArray ary = obj.get("args").getAsJsonArray(); Object[] args = new Object[ary.size()]; for (JsonElement element : ary) { JsonObject arg = element.getAsJsonObject(); if (!arg.has("index") || !arg.has("value")) { return null; } int index = arg.get("index").getAsInt(); switch (arg.get("type").getAsString().toLowerCase()) { case "string": args[index] = arg.get("value").getAsString(); break; case "int": args[index] = arg.get("value").getAsInt() * multipleFactor; break; case "long": args[index] = arg.get("value").getAsLong() * multipleFactor; break; case "double": args[index] = arg.get("value").getAsDouble(); break; } } instance.init(args); return instance; } catch (Exception e) { logger.log(Level.FINE, "Failed to extract aggregate function:" + jsonElement, e); } } return null; }
GrafanaUtils { public static Function extractGrafanaAggregation(JsonObject jsonElement) { if (!jsonElement.has("aggregator")) { return null; } JsonObject obj = jsonElement.get("aggregator").getAsJsonObject(); if (!obj.has("name") || !obj.has("args")) { return null; } String name = obj.get("name").getAsString(); if (name.equalsIgnoreCase("none")) { return null; } int multipleFactor = 1; if (obj.has("unit")) { multipleFactor = toSeconds(obj.get("unit").getAsString()); } Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(name); if (lookupFunction != null) { try { Function instance = (Function) lookupFunction.newInstance(); JsonArray ary = obj.get("args").getAsJsonArray(); Object[] args = new Object[ary.size()]; for (JsonElement element : ary) { JsonObject arg = element.getAsJsonObject(); if (!arg.has("index") || !arg.has("value")) { return null; } int index = arg.get("index").getAsInt(); switch (arg.get("type").getAsString().toLowerCase()) { case "string": args[index] = arg.get("value").getAsString(); break; case "int": args[index] = arg.get("value").getAsInt() * multipleFactor; break; case "long": args[index] = arg.get("value").getAsLong() * multipleFactor; break; case "double": args[index] = arg.get("value").getAsDouble(); break; } } instance.init(args); return instance; } catch (Exception e) { logger.log(Level.FINE, "Failed to extract aggregate function:" + jsonElement, e); } } return null; } }
GrafanaUtils { public static Function extractGrafanaAggregation(JsonObject jsonElement) { if (!jsonElement.has("aggregator")) { return null; } JsonObject obj = jsonElement.get("aggregator").getAsJsonObject(); if (!obj.has("name") || !obj.has("args")) { return null; } String name = obj.get("name").getAsString(); if (name.equalsIgnoreCase("none")) { return null; } int multipleFactor = 1; if (obj.has("unit")) { multipleFactor = toSeconds(obj.get("unit").getAsString()); } Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(name); if (lookupFunction != null) { try { Function instance = (Function) lookupFunction.newInstance(); JsonArray ary = obj.get("args").getAsJsonArray(); Object[] args = new Object[ary.size()]; for (JsonElement element : ary) { JsonObject arg = element.getAsJsonObject(); if (!arg.has("index") || !arg.has("value")) { return null; } int index = arg.get("index").getAsInt(); switch (arg.get("type").getAsString().toLowerCase()) { case "string": args[index] = arg.get("value").getAsString(); break; case "int": args[index] = arg.get("value").getAsInt() * multipleFactor; break; case "long": args[index] = arg.get("value").getAsLong() * multipleFactor; break; case "double": args[index] = arg.get("value").getAsDouble(); break; } } instance.init(args); return instance; } catch (Exception e) { logger.log(Level.FINE, "Failed to extract aggregate function:" + jsonElement, e); } } return null; } private  GrafanaUtils(); }
GrafanaUtils { public static Function extractGrafanaAggregation(JsonObject jsonElement) { if (!jsonElement.has("aggregator")) { return null; } JsonObject obj = jsonElement.get("aggregator").getAsJsonObject(); if (!obj.has("name") || !obj.has("args")) { return null; } String name = obj.get("name").getAsString(); if (name.equalsIgnoreCase("none")) { return null; } int multipleFactor = 1; if (obj.has("unit")) { multipleFactor = toSeconds(obj.get("unit").getAsString()); } Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(name); if (lookupFunction != null) { try { Function instance = (Function) lookupFunction.newInstance(); JsonArray ary = obj.get("args").getAsJsonArray(); Object[] args = new Object[ary.size()]; for (JsonElement element : ary) { JsonObject arg = element.getAsJsonObject(); if (!arg.has("index") || !arg.has("value")) { return null; } int index = arg.get("index").getAsInt(); switch (arg.get("type").getAsString().toLowerCase()) { case "string": args[index] = arg.get("value").getAsString(); break; case "int": args[index] = arg.get("value").getAsInt() * multipleFactor; break; case "long": args[index] = arg.get("value").getAsLong() * multipleFactor; break; case "double": args[index] = arg.get("value").getAsDouble(); break; } } instance.init(args); return instance; } catch (Exception e) { logger.log(Level.FINE, "Failed to extract aggregate function:" + jsonElement, e); } } return null; } private  GrafanaUtils(); static void queryAndGetData(StorageEngine engine, String dbName, long startTs, long endTs,
			List<GrafanaOutput> output, TargetSeries targetSeriesEntry); static Iterator<GrafanaOutputv2> queryAndGetDatav2(StorageEngine engine, String dbName, long startTs,
			long endTs, TargetSeries targetSeriesEntry); static void extractTargetsFromJson(JsonObject json, List<TargetSeries> targetSeries); static Function extractGrafanaAggregation(JsonObject jsonElement); static FunctionIteratorFactory extractGrafanaFunction(JsonObject jsonElement); static TagFilter extractGrafanaFilter(JsonObject element); static int toSeconds(String unit); }
GrafanaUtils { public static Function extractGrafanaAggregation(JsonObject jsonElement) { if (!jsonElement.has("aggregator")) { return null; } JsonObject obj = jsonElement.get("aggregator").getAsJsonObject(); if (!obj.has("name") || !obj.has("args")) { return null; } String name = obj.get("name").getAsString(); if (name.equalsIgnoreCase("none")) { return null; } int multipleFactor = 1; if (obj.has("unit")) { multipleFactor = toSeconds(obj.get("unit").getAsString()); } Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(name); if (lookupFunction != null) { try { Function instance = (Function) lookupFunction.newInstance(); JsonArray ary = obj.get("args").getAsJsonArray(); Object[] args = new Object[ary.size()]; for (JsonElement element : ary) { JsonObject arg = element.getAsJsonObject(); if (!arg.has("index") || !arg.has("value")) { return null; } int index = arg.get("index").getAsInt(); switch (arg.get("type").getAsString().toLowerCase()) { case "string": args[index] = arg.get("value").getAsString(); break; case "int": args[index] = arg.get("value").getAsInt() * multipleFactor; break; case "long": args[index] = arg.get("value").getAsLong() * multipleFactor; break; case "double": args[index] = arg.get("value").getAsDouble(); break; } } instance.init(args); return instance; } catch (Exception e) { logger.log(Level.FINE, "Failed to extract aggregate function:" + jsonElement, e); } } return null; } private  GrafanaUtils(); static void queryAndGetData(StorageEngine engine, String dbName, long startTs, long endTs,
			List<GrafanaOutput> output, TargetSeries targetSeriesEntry); static Iterator<GrafanaOutputv2> queryAndGetDatav2(StorageEngine engine, String dbName, long startTs,
			long endTs, TargetSeries targetSeriesEntry); static void extractTargetsFromJson(JsonObject json, List<TargetSeries> targetSeries); static Function extractGrafanaAggregation(JsonObject jsonElement); static FunctionIteratorFactory extractGrafanaFunction(JsonObject jsonElement); static TagFilter extractGrafanaFilter(JsonObject element); static int toSeconds(String unit);  }