use of org.gearman.common.GearmanJobServerConnection in project sakuli by ConSol.
the class GearmanResultServiceImpl method tearDown.
@Override
public void tearDown(Optional<AbstractTestDataEntity> dataEntity, boolean asyncCall) {
dataEntity.ifPresent(data -> {
logger.info("======= SEND RESULTS TO GEARMAN SERVER ======");
GearmanClient gearmanClient = getGearmanClient();
GearmanJobServerConnection connection = getGearmanConnection(properties.getServerHost(), properties.getServerPort());
List<NagiosCheckResult> results = new ArrayList<>();
try {
results.add(nagiosCheckResultBuilder.build(data));
if (properties.isCacheEnabled()) {
results.addAll(cacheService.getCachedResults());
if (results.size() > 1) {
logger.info(String.format("Processing %s cached results first", results.size() - 1));
}
}
if (!gearmanClient.addJobServer(connection)) {
throw new SakuliForwarderCheckedException(String.format("Failed to connect to Gearman server '%s:%s'", properties.getServerHost(), properties.getServerPort()));
} else {
// sending in reverse original happened order
Collections.reverse(results);
results = results.stream().filter(checkResult -> !sendResult(gearmanClient, checkResult, asyncCall, data)).collect(Collectors.toList());
Collections.reverse(results);
}
} catch (Exception e) {
handleTeardownException((e instanceof SakuliForwarderException) ? e : new SakuliForwarderRuntimeException(String.format("Could not transfer Sakuli results to the Gearman server '%s:%s'", properties.getServerHost(), properties.getServerPort()), e), asyncCall, data);
}
// save all not send results
if (properties.isCacheEnabled()) {
try {
cacheService.cacheResults(results);
} catch (SakuliForwarderCheckedException e) {
handleTeardownException(e, asyncCall, data);
}
}
gearmanClient.shutdown();
logger.info("======= FINISHED: SEND RESULTS TO GEARMAN SERVER ======");
});
}
use of org.gearman.common.GearmanJobServerConnection 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