use of org.sakuli.exceptions.SakuliForwarderException in project sakuli by ConSol.
the class DatabaseResultServiceImpl method saveAllResults.
@Override
public void saveAllResults() {
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 (Throwable e) {
exceptionHandler.handleException(new SakuliForwarderException(e, String.format("error by saving the results to the database [%s]", testSuite.toString())), true);
}
}
use of org.sakuli.exceptions.SakuliForwarderException in project sakuli by ConSol.
the class Icinga2ResultServiceImpl method saveAllResults.
@Override
public void saveAllResults() {
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 {
exceptionHandler.handleException(new SakuliForwarderException(String.format("Unexpected result of REST-POST to Incinga monitoring server (%s): %s", icinga2RestCient.getTargetCheckResult().getUri(), result.getFirstElementAsString())));
}
}
use of org.sakuli.exceptions.SakuliForwarderException in project sakuli by ConSol.
the class AbstractTemplateOutputBuilder method createOutput.
/**
* Converts the current test suite to a string based on the template for the concrete converter.
*
* @return
*/
public String createOutput() throws SakuliForwarderException {
try {
JtwigModel model = createModel();
EnvironmentConfiguration configuration = EnvironmentConfigurationBuilder.configuration().extensions().add(new SpacelessExtension(new SpacelessConfiguration(new LeadingWhitespaceRemover()))).and().functions().add(new IsBlankFunction()).add(new GetOutputStateFunction()).add(new GetOutputDurationFunction()).add(new ExtractScreenshotFunction(screenshotDivConverter)).add(new AbbreviateFunction()).and().build();
JtwigTemplate template = JtwigTemplate.fileTemplate(getTemplatePath().toFile(), configuration);
logger.debug(String.format("Render model into JTwig template. Model: '%s'", model));
return template.render(model);
} catch (Throwable thr) {
throw new SakuliForwarderException(thr, "Exception during rendering of Twig template occurred!");
}
}
use of org.sakuli.exceptions.SakuliForwarderException in project sakuli by ConSol.
the class ScreenshotDivConverter method extractScreenshotAsBase64.
protected String extractScreenshotAsBase64(Throwable exception) {
if (exception instanceof SakuliExceptionWithScreenshot) {
Path screenshotPath = ((SakuliExceptionWithScreenshot) exception).getScreenshot();
if (screenshotPath != null) {
try {
byte[] binaryScreenshot = Files.readAllBytes(screenshotPath);
String base64String = new BASE64Encoder().encode(binaryScreenshot);
for (String newLine : Arrays.asList("\n", "\r")) {
base64String = StringUtils.remove(base64String, newLine);
}
return base64String;
} catch (IOException e) {
exceptionHandler.handleException(new SakuliForwarderException(e, String.format("error during the BASE64 encoding of the screenshot '%s'", screenshotPath.toString())));
}
}
}
return null;
}
use of org.sakuli.exceptions.SakuliForwarderException 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 ======");
});
}
Aggregations