Search in sources :

Example 6 with SakuliForwarderException

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 ======");
}
Also used : GearmanJobServerConnection(org.gearman.common.GearmanJobServerConnection) ArrayList(java.util.ArrayList) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException)

Aggregations

SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)6 ArrayList (java.util.ArrayList)2 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)2 NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Response (javax.ws.rs.core.Response)1 JtwigModel (org.jtwig.JtwigModel)1 JtwigTemplate (org.jtwig.JtwigTemplate)1 EnvironmentConfiguration (org.jtwig.environment.EnvironmentConfiguration)1 SpacelessExtension (org.jtwig.spaceless.SpacelessExtension)1 SpacelessConfiguration (org.jtwig.spaceless.configuration.SpacelessConfiguration)1 TestCase (org.sakuli.datamodel.TestCase)1 TestCaseStep (org.sakuli.datamodel.TestCaseStep)1 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)1 SakuliForwarderCheckedException (org.sakuli.exceptions.SakuliForwarderCheckedException)1 SakuliForwarderRuntimeException (org.sakuli.exceptions.SakuliForwarderRuntimeException)1 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)1 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)1 Icinga2Request (org.sakuli.services.forwarder.icinga2.model.Icinga2Request)1