Search in sources :

Example 6 with SakuliForwarderCheckedException

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;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) IOException(java.io.IOException) SakuliForwarderCheckedException(org.sakuli.exceptions.SakuliForwarderCheckedException)

Example 7 with SakuliForwarderCheckedException

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));
    }
}
Also used : IOException(java.io.IOException) SakuliForwarderCheckedException(org.sakuli.exceptions.SakuliForwarderCheckedException)

Example 8 with SakuliForwarderCheckedException

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));
    }
}
Also used : IOException(java.io.IOException) SakuliForwarderCheckedException(org.sakuli.exceptions.SakuliForwarderCheckedException)

Aggregations

SakuliForwarderCheckedException (org.sakuli.exceptions.SakuliForwarderCheckedException)8 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)3 ArrayList (java.util.ArrayList)2 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)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 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)1 SakuliForwarderRuntimeException (org.sakuli.exceptions.SakuliForwarderRuntimeException)1 Test (org.testng.annotations.Test)1 BASE64Encoder (sun.misc.BASE64Encoder)1