protected List<AtlasResults> processInput(BufferedReader reader) { List<String[]> tokenizedLines = reader .lines() .filter(line -> !StringUtils.isEmpty(line)) .map(line -> line.split(": ", 2)) .collect(Collectors.toList()); tokenizedLines .stream() .map(tokenizedLine -> tokenizedLine[0]) .filter(openingToken -> !openingToken.equals("data")) .forEach(nonDataOpeningToken -> log.info("Received opening token other than 'data' from Atlas: {}", nonDataOpeningToken)); List<AtlasResults> atlasResultsList = tokenizedLines .stream() .map(this::convertTokenizedLineToAtlasResults) .filter(Objects::nonNull) .collect(Collectors.toList()); if (!atlasResultsList.get(atlasResultsList.size() - 1).getType().equals("close")) { log.error("Received data from Atlas that did not terminate with a 'close'."); throw new RetryableQueryException("Atlas response did not end in a 'close', we cannot guarantee all data was received."); } return atlasResultsList; }
protected AtlasResults convertTokenizedLineToAtlasResults(String[] tokenizedLine) { try { AtlasResults atlasResults = kayentaObjectMapper.readValue(tokenizedLine[1], AtlasResults.class); String atlasResultsType = atlasResults.getType(); if (StringUtils.isEmpty(atlasResultsType) || !EXPECTED_RESULTS_TYPE_LIST.contains(atlasResultsType)) { if (atlasResultsType.equals("error")) { if (atlasResults.getMessage().contains("IllegalStateException")) { throw new FatalQueryException("Atlas query failed: " + atlasResults.getMessage()); } else { throw new RetryableQueryException("Atlas query failed: " + atlasResults.getMessage()); } } log.info("Received results of type other than 'timeseries' or 'close' from Atlas: {}", atlasResults); return null; } return atlasResults; } catch (IOException e) { log.error("Cannot process Atlas results", e); return null; } }
protected List<AtlasResults> processInput(BufferedReader reader) { List<String[]> tokenizedLines = reader .lines() .filter(line -> !StringUtils.isEmpty(line)) .map(line -> line.split(": ", 2)) .collect(Collectors.toList()); tokenizedLines .stream() .map(tokenizedLine -> tokenizedLine[0]) .filter(openingToken -> !openingToken.equals("data")) .forEach(nonDataOpeningToken -> log.info("Received opening token other than 'data' from Atlas: {}", nonDataOpeningToken)); List<AtlasResults> atlasResultsList = tokenizedLines .stream() .map(this::convertTokenizedLineToAtlasResults) .filter(Objects::nonNull) .collect(Collectors.toList()); if (!atlasResultsList.get(atlasResultsList.size() - 1).getType().equals("close")) { log.error("Received data from Atlas that did not terminate with a 'close'."); throw new RetryableQueryException("Atlas response did not end in a 'close', we cannot guarantee all data was received."); } return atlasResultsList; }
protected AtlasResults convertTokenizedLineToAtlasResults(String[] tokenizedLine) { try { AtlasResults atlasResults = kayentaObjectMapper.readValue(tokenizedLine[1], AtlasResults.class); String atlasResultsType = atlasResults.getType(); if (StringUtils.isEmpty(atlasResultsType) || !EXPECTED_RESULTS_TYPE_LIST.contains(atlasResultsType)) { if (atlasResultsType.equals("error")) { if (atlasResults.getMessage().contains("IllegalStateException")) { throw new FatalQueryException("Atlas query failed: " + atlasResults.getMessage()); } else { throw new RetryableQueryException("Atlas query failed: " + atlasResults.getMessage()); } } log.info("Received results of type other than 'timeseries' or 'close' from Atlas: {}", atlasResults); return null; } return atlasResults; } catch (IOException e) { log.error("Cannot process Atlas results", e); return null; } }