use of org.sakuli.exceptions.SakuliForwarderCheckedException in project sakuli by ConSol.
the class GearmanCacheService method getCachedResults.
/**
* Reads cached results from Gearman cache file.
*
* @return
*/
public List<NagiosCheckResult> getCachedResults() throws SakuliForwarderCheckedException {
List<NagiosCheckResult> results = new ArrayList<>();
Path cacheFile = testSuiteProperties.getTestSuiteFolder().resolve(CACHE_FILE);
if (Files.exists(cacheFile)) {
try {
List<String> lines = FileUtils.readLines(cacheFile.toFile(), Charset.forName(CHARSET_NAME));
StringBuilder resultBuilder = new StringBuilder();
String queueName = "";
String uuid = "";
for (String line : lines) {
if (line.trim().equals(CACHE_SEPARATOR)) {
results.add(new NagiosCheckResult(queueName, uuid, resultBuilder.toString()));
} else if (line.startsWith(CACHE_SEPARATOR)) {
resultBuilder = new StringBuilder();
queueName = line.substring(CACHE_SEPARATOR.length() + 1, line.indexOf(":"));
uuid = line.substring(line.indexOf(":") + 1).trim();
} else if (StringUtils.isNotEmpty(line)) {
resultBuilder.append(line).append(LINE_SEPARATOR);
}
}
} catch (IOException e) {
throw new SakuliForwarderCheckedException(e, String.format("Failed to read Gearman cache file '%s'", cacheFile));
}
}
return results;
}
use of org.sakuli.exceptions.SakuliForwarderCheckedException in project sakuli by ConSol.
the class CheckMKResultServiceImpl method writeToFile.
private void writeToFile(Path file, String output) throws SakuliForwarderCheckedException {
try {
LOGGER.info(String.format("Write file to '%s'", file));
Files.write(file, output.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
throw new SakuliForwarderCheckedException(e, String.format("Unexpected error by writing the output for check_mk to the following file '%s'", file));
}
}
use of org.sakuli.exceptions.SakuliForwarderCheckedException in project sakuli by ConSol.
the class JsonResultServiceImpl method writeToFile.
private void writeToFile(Path file, String output) throws SakuliForwarderCheckedException {
try {
logger.info(String.format("Write file to '%s'", file));
Files.write(file, output.getBytes(), StandardOpenOption.CREATE);
} catch (IOException e) {
throw new SakuliForwarderCheckedException(e, String.format("Unexpected error by writing the json output to the following file '%s'", file));
}
}
Aggregations