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);
}
}
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 ======");
});
}
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);
}
}
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'");
}
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()));
}
}
Aggregations