Search in sources :

Example 1 with SakuliForwarderRuntimeException

use of org.sakuli.exceptions.SakuliForwarderRuntimeException in project sakuli by ConSol.

the class JsonResultServiceImpl method teardownTestSuite.

@Override
public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException {
    try {
        logger.info("======= WRITE TEST OUTPUT AS JSON FILE ======");
        String output = outputBuilder.createOutput();
        logger.debug(String.format("JSON Output:\n%s", output));
        writeToFile(createJsonFilePath(testSuite.getId()), output);
        logger.info("======= FINISHED: WRITE TEST OUTPUT AS JSON FILE ======");
    } catch (Exception e) {
        throw new SakuliForwarderRuntimeException("Couldn't create the JSON result file for: " + testSuite);
    }
}
Also used : SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) IOException(java.io.IOException) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) SakuliForwarderCheckedException(org.sakuli.exceptions.SakuliForwarderCheckedException)

Example 2 with SakuliForwarderRuntimeException

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

Example 3 with SakuliForwarderRuntimeException

use of org.sakuli.exceptions.SakuliForwarderRuntimeException in project sakuli by ConSol.

the class DatabaseResultServiceImpl method teardownTestSuite.

@Override
public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException {
    LOGGER.info("======= SAVE RESULTS TO DATABASE ======");
    try {
        daoTestSuite.saveTestSuiteResult();
        daoTestSuite.saveTestSuiteToSahiJobs();
        if (!CollectionUtils.isEmpty(testSuite.getTestCases())) {
            for (TestCase tc : testSuite.getTestCasesAsSortedSet()) {
                // write testcase and steps to DB
                daoTestCase.saveTestCaseResult(tc);
                LOGGER.info("... try to save all STEPS for test case '" + tc.getId() + "'!");
                SortedSet<TestCaseStep> steps = tc.getStepsAsSortedSet();
                if (!steps.isEmpty()) {
                    daoTestCaseStep.saveTestCaseSteps(steps, tc.getDbPrimaryKey());
                    LOGGER.info("all STEPS for '" + tc.getId() + "' saved!");
                } else {
                    LOGGER.info("no STEPS for '\" + tc.getId() +\"'found => no STEPS saved in DB!");
                }
            }
        }
        LOGGER.info("======= FINISHED: SAVE RESULTS TO DATABASE ======");
    } catch (Exception e) {
        throw new SakuliForwarderRuntimeException("error by saving the results to the database for: " + testSuite.toString(), e);
    }
}
Also used : SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) DaoTestCase(org.sakuli.services.forwarder.database.dao.DaoTestCase) TestCase(org.sakuli.datamodel.TestCase) DaoTestCaseStep(org.sakuli.services.forwarder.database.dao.DaoTestCaseStep) TestCaseStep(org.sakuli.datamodel.TestCaseStep) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException)

Example 4 with SakuliForwarderRuntimeException

use of org.sakuli.exceptions.SakuliForwarderRuntimeException in project sakuli by ConSol.

the class NagiosExceptionBuilderTest method testBuildUnexpectedErrorException.

@Test
public void testBuildUnexpectedErrorException() throws Exception {
    SakuliForwarderRuntimeException sakuliForwarderException = NagiosExceptionBuilder.buildUnexpectedErrorException(new Exception("TEST"), "localhost", 4370);
    assertEquals(sakuliForwarderException.getMessage(), "unexpected error by sending the results to the gearman forwarder 'localhost:'4370'");
}
Also used : SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) Test(org.testng.annotations.Test)

Example 5 with SakuliForwarderRuntimeException

use of org.sakuli.exceptions.SakuliForwarderRuntimeException in project sakuli by ConSol.

the class Icinga2ResultServiceImpl method teardownTestSuite.

@Override
public void teardownTestSuite(@NonNull TestSuite testSuite) throws RuntimeException {
    LOGGER.info("======= SEND RESULTS TO ICINGA SERVER ======");
    LOGGER.info("POST Sakuli results to '{}'", icinga2RestCient.getTargetCheckResult().getUri().toString());
    Entity<Icinga2Request> payload = Entity.json(icinga2CheckResultBuilder.build());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("ICINGA Payload: {}", convertToJSON(payload));
    }
    Response response = icinga2RestCient.getTargetCheckResult().request(MediaType.APPLICATION_JSON_TYPE).post(payload);
    Icinga2Result result = response.readEntity(Icinga2Result.class);
    if (result.isSuccess()) {
        LOGGER.info("ICINGA Response: {}", result.getFirstElementAsString());
        LOGGER.info("======= FINISHED: SEND RESULTS TO ICINGA SERVER ======");
    } else {
        throw new SakuliForwarderRuntimeException(String.format("Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString()));
    }
}
Also used : Response(javax.ws.rs.core.Response) SakuliForwarderRuntimeException(org.sakuli.exceptions.SakuliForwarderRuntimeException) Icinga2Result(org.sakuli.services.forwarder.icinga2.model.Icinga2Result) Icinga2Request(org.sakuli.services.forwarder.icinga2.model.Icinga2Request)

Aggregations

SakuliForwarderRuntimeException (org.sakuli.exceptions.SakuliForwarderRuntimeException)6 SakuliForwarderCheckedException (org.sakuli.exceptions.SakuliForwarderCheckedException)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 GearmanJobResult (org.gearman.client.GearmanJobResult)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 TestCase (org.sakuli.datamodel.TestCase)1 TestCaseStep (org.sakuli.datamodel.TestCaseStep)1 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)1 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)1 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)1 NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)1 Icinga2Request (org.sakuli.services.forwarder.icinga2.model.Icinga2Request)1 Icinga2Result (org.sakuli.services.forwarder.icinga2.model.Icinga2Result)1