Source:
public RestCallManifest runQueries(RestClient restClient, Map<String, String> entries, String tempDir, DiagConfig diagConfig) { List<String> textExtensions = diagConfig.getTextFileExtensions(); int attempts = diagConfig.getCallRetries(); int pause = diagConfig.getPauseRetries(); List<String> requireRetry = diagConfig.getRequireRetry(); RestCallManifest restCallManifest = new RestCallManifest(); Map<String, String> workEntries = new LinkedHashMap<>(); workEntries.putAll(entries); for (int i = 1; i <= attempts; i++) { if (workEntries.size() == 0) { break; } if (i > 1 && i <= attempts) { try { logger.info("Some calls failed: retrying in seconds.", pause / 1000); Thread.sleep(pause); } catch (Exception e) { logger.error("Failed pause on error.", e); } } restCallManifest.setRuns(i); Set<String> keys = workEntries.keySet(); Set<String> removalEntries = new HashSet<>(); for (String queryName : keys) { String query = workEntries.get(queryName); String filename = buildFileName(queryName, tempDir, textExtensions); logger.info("Running query:{} - {}", queryName, query); RestResult restResult = runQuery(filename, query, restClient); if (restResult.getStatus() == 200) { removalEntries.add(queryName); restCallManifest.setCallHistory(queryName, i, true); logger.info("Results written to: {}", filename); } else { restCallManifest.setCallHistory(queryName, i, false); if (!requireRetry.contains(queryName) || !isRetryable(restResult.getStatus())) { removalEntries.add(queryName); restResult.toFile(filename); logger.info("Call failed. Bypassing."); } else { if (i == attempts) { restResult.toFile(filename); } else { logger.info("Call failed: flagged for retry."); } } } } for(String entry: removalEntries){ workEntries.remove(entry); } } return restCallManifest; }

Target:
public RestCallManifest runQueries(RestClient restClient, Map<String, String> entries, String tempDir, DiagConfig diagConfig) { List<String> textExtensions = diagConfig.getTextFileExtensions(); int attempts = diagConfig.getCallRetries(); int pause = diagConfig.getPauseRetries(); List<String> requireRetry = diagConfig.getRequireRetry(); RestCallManifest restCallManifest = new RestCallManifest(); Map<String, String> workEntries = new LinkedHashMap<>(); workEntries.putAll(entries); for (int i = 1; i <= attempts; i++) { if (workEntries.size() == 0) { break; } if (i > 1) { try { logger.info("Some calls failed: retrying in seconds.", pause / 1000); Thread.sleep(pause); } catch (Exception e) { logger.error("Failed pause on error.", e); } } restCallManifest.setRuns(i); Set<String> keys = workEntries.keySet(); Set<String> removalEntries = new HashSet<>(); for (String queryName : keys) { String query = workEntries.get(queryName); String filename = buildFileName(queryName, tempDir, textExtensions); logger.info("Running query:{} - {}", queryName, query); RestResult restResult = runQuery(filename, query, restClient); if (restResult.getStatus() == 200) { removalEntries.add(queryName); restCallManifest.setCallHistory(queryName, i, true); logger.info("Results written to: {}", filename); } else { restCallManifest.setCallHistory(queryName, i, false); if (!requireRetry.contains(queryName) || !isRetryable(restResult.getStatus())) { removalEntries.add(queryName); restResult.toFile(filename); logger.info("Call failed. Bypassing."); } else { if (i == attempts) { restResult.toFile(filename); } else { logger.info("Call failed: flagged for retry."); } } } } for(String entry: removalEntries){ workEntries.remove(entry); } } return restCallManifest; }