use of org.sakuli.exceptions.SakuliForwarderException in project sakuli by ConSol.
the class GearmanResultServiceImpl method saveAllResults.
@Override
public void saveAllResults() {
logger.info("======= SEND RESULTS TO GEARMAN SERVER ======");
GearmanClient gearmanClient = getGearmanClient();
GearmanJobServerConnection connection = getGearmanConnection(properties.getServerHost(), properties.getServerPort());
List<NagiosCheckResult> results = new ArrayList<>();
results.add(nagiosCheckResultBuilder.build());
if (properties.isCacheEnabled()) {
results.addAll(cacheService.getCachedResults());
if (results.size() > 1) {
logger.info(String.format("Processing %s cached results first", results.size() - 1));
}
}
try {
if (!gearmanClient.addJobServer(connection)) {
exceptionHandler.handleException(new SakuliForwarderException(String.format("Failed to connect to Gearman server '%s:%s'", properties.getServerHost(), properties.getServerPort())), true);
} else {
//sending in reverse original happened order
Collections.reverse(results);
results = results.stream().filter(checkResult -> !sendResult(gearmanClient, checkResult)).collect(Collectors.toList());
Collections.reverse(results);
}
} catch (Exception e) {
exceptionHandler.handleException(new SakuliForwarderException(e, String.format("Could not transfer Sakuli results to the Gearman server '%s:%s'", properties.getServerHost(), properties.getServerPort())), true);
}
//save all not send results
if (properties.isCacheEnabled()) {
cacheService.cacheResults(results);
}
gearmanClient.shutdown();
logger.info("======= FINISHED: SEND RESULTS TO GEARMAN SERVER ======");
}
Aggregations