@Test public void deserialize() throws Exception { TypedInput input = new TypedByteArray(MIME_TYPE, JSON.getBytes()); List<InfluxDbResult> result = (List<InfluxDbResult>) influxDbResponseConverter.fromBody(input, List.class); assertThat(result, is(results)); }
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()))) { String json = reader.readLine(); log.debug("Converting response from influxDb: {}", json); Map result = getResultObject(json); List<Map> seriesList = (List<Map>) result.get("series"); if (CollectionUtils.isEmpty(seriesList)) { log.warn("Received no data from Influxdb."); return null; } Map series = seriesList.get(0); List<String> seriesColumns = (List<String>) series.get("columns"); List<List> seriesValues = (List<List>) series.get("values"); List<InfluxDbResult> influxDbResultsList = new ArrayList<InfluxDbResult>(seriesValues.size()); for (int i = 1; i < seriesColumns.size(); i++) { String id = seriesColumns.get(i); long firstTimeMillis = extractTimeInMillis(seriesValues, 0); long stepMillis = calculateStep(seriesValues, firstTimeMillis); List<Double> values = new ArrayList<>(seriesValues.size()); for (List<Object> valueRow : seriesValues) { if (valueRow.get(i) != null) { values.add(Double.valueOf((Integer) valueRow.get(i))); } } influxDbResultsList.add(new InfluxDbResult(id, firstTimeMillis, stepMillis, null, values)); } log.debug("Converted response: {} ", influxDbResultsList); return influxDbResultsList; } catch (IOException e) { e.printStackTrace(); } return null; }
InfluxDbResponseConverter implements Converter { @Override public Object fromBody(TypedInput body, Type type) throws ConversionException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()))) { String json = reader.readLine(); log.debug("Converting response from influxDb: {}", json); Map result = getResultObject(json); List<Map> seriesList = (List<Map>) result.get("series"); if (CollectionUtils.isEmpty(seriesList)) { log.warn("Received no data from Influxdb."); return null; } Map series = seriesList.get(0); List<String> seriesColumns = (List<String>) series.get("columns"); List<List> seriesValues = (List<List>) series.get("values"); List<InfluxDbResult> influxDbResultsList = new ArrayList<InfluxDbResult>(seriesValues.size()); for (int i = 1; i < seriesColumns.size(); i++) { String id = seriesColumns.get(i); long firstTimeMillis = extractTimeInMillis(seriesValues, 0); long stepMillis = calculateStep(seriesValues, firstTimeMillis); List<Double> values = new ArrayList<>(seriesValues.size()); for (List<Object> valueRow : seriesValues) { if (valueRow.get(i) != null) { values.add(Double.valueOf((Integer) valueRow.get(i))); } } influxDbResultsList.add(new InfluxDbResult(id, firstTimeMillis, stepMillis, null, values)); } log.debug("Converted response: {} ", influxDbResultsList); return influxDbResultsList; } catch (IOException e) { e.printStackTrace(); } return null; } }
InfluxDbResponseConverter implements Converter { @Override public Object fromBody(TypedInput body, Type type) throws ConversionException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()))) { String json = reader.readLine(); log.debug("Converting response from influxDb: {}", json); Map result = getResultObject(json); List<Map> seriesList = (List<Map>) result.get("series"); if (CollectionUtils.isEmpty(seriesList)) { log.warn("Received no data from Influxdb."); return null; } Map series = seriesList.get(0); List<String> seriesColumns = (List<String>) series.get("columns"); List<List> seriesValues = (List<List>) series.get("values"); List<InfluxDbResult> influxDbResultsList = new ArrayList<InfluxDbResult>(seriesValues.size()); for (int i = 1; i < seriesColumns.size(); i++) { String id = seriesColumns.get(i); long firstTimeMillis = extractTimeInMillis(seriesValues, 0); long stepMillis = calculateStep(seriesValues, firstTimeMillis); List<Double> values = new ArrayList<>(seriesValues.size()); for (List<Object> valueRow : seriesValues) { if (valueRow.get(i) != null) { values.add(Double.valueOf((Integer) valueRow.get(i))); } } influxDbResultsList.add(new InfluxDbResult(id, firstTimeMillis, stepMillis, null, values)); } log.debug("Converted response: {} ", influxDbResultsList); return influxDbResultsList; } catch (IOException e) { e.printStackTrace(); } return null; } @Autowired  InfluxDbResponseConverter(ObjectMapper kayentaObjectMapper); }
InfluxDbResponseConverter implements Converter { @Override public Object fromBody(TypedInput body, Type type) throws ConversionException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()))) { String json = reader.readLine(); log.debug("Converting response from influxDb: {}", json); Map result = getResultObject(json); List<Map> seriesList = (List<Map>) result.get("series"); if (CollectionUtils.isEmpty(seriesList)) { log.warn("Received no data from Influxdb."); return null; } Map series = seriesList.get(0); List<String> seriesColumns = (List<String>) series.get("columns"); List<List> seriesValues = (List<List>) series.get("values"); List<InfluxDbResult> influxDbResultsList = new ArrayList<InfluxDbResult>(seriesValues.size()); for (int i = 1; i < seriesColumns.size(); i++) { String id = seriesColumns.get(i); long firstTimeMillis = extractTimeInMillis(seriesValues, 0); long stepMillis = calculateStep(seriesValues, firstTimeMillis); List<Double> values = new ArrayList<>(seriesValues.size()); for (List<Object> valueRow : seriesValues) { if (valueRow.get(i) != null) { values.add(Double.valueOf((Integer) valueRow.get(i))); } } influxDbResultsList.add(new InfluxDbResult(id, firstTimeMillis, stepMillis, null, values)); } log.debug("Converted response: {} ", influxDbResultsList); return influxDbResultsList; } catch (IOException e) { e.printStackTrace(); } return null; } @Autowired  InfluxDbResponseConverter(ObjectMapper kayentaObjectMapper); @Override Object fromBody(TypedInput body, Type type); @Override TypedOutput toBody(Object object); }
InfluxDbResponseConverter implements Converter { @Override public Object fromBody(TypedInput body, Type type) throws ConversionException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()))) { String json = reader.readLine(); log.debug("Converting response from influxDb: {}", json); Map result = getResultObject(json); List<Map> seriesList = (List<Map>) result.get("series"); if (CollectionUtils.isEmpty(seriesList)) { log.warn("Received no data from Influxdb."); return null; } Map series = seriesList.get(0); List<String> seriesColumns = (List<String>) series.get("columns"); List<List> seriesValues = (List<List>) series.get("values"); List<InfluxDbResult> influxDbResultsList = new ArrayList<InfluxDbResult>(seriesValues.size()); for (int i = 1; i < seriesColumns.size(); i++) { String id = seriesColumns.get(i); long firstTimeMillis = extractTimeInMillis(seriesValues, 0); long stepMillis = calculateStep(seriesValues, firstTimeMillis); List<Double> values = new ArrayList<>(seriesValues.size()); for (List<Object> valueRow : seriesValues) { if (valueRow.get(i) != null) { values.add(Double.valueOf((Integer) valueRow.get(i))); } } influxDbResultsList.add(new InfluxDbResult(id, firstTimeMillis, stepMillis, null, values)); } log.debug("Converted response: {} ", influxDbResultsList); return influxDbResultsList; } catch (IOException e) { e.printStackTrace(); } return null; } @Autowired  InfluxDbResponseConverter(ObjectMapper kayentaObjectMapper); @Override Object fromBody(TypedInput body, Type type); @Override TypedOutput toBody(Object object);  }