Search in sources :

Example 1 with PreconditionFailedException

use of io.fabric8.maven.docker.wait.PreconditionFailedException in project docker-maven-plugin by fabric8io.

the class WaitService method wait.

// ========================================================================================================
public void wait(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws IOException {
    List<WaitChecker> checkers = prepareWaitCheckers(imageConfig, projectProperties, containerId);
    int timeout = getTimeOut(imageConfig);
    if (checkers.isEmpty()) {
        if (timeout > 0) {
            log.info("%s: Pausing for %d ms", imageConfig.getDescription(), timeout);
            WaitUtil.sleep(timeout);
        }
        return;
    }
    String logLine = extractCheckerLog(checkers);
    ContainerRunningPrecondition precondition = new ContainerRunningPrecondition(dockerAccess, containerId);
    try {
        long waited = WaitUtil.wait(precondition, timeout, checkers);
        log.info("%s: Waited %s %d ms", imageConfig.getDescription(), logLine, waited);
    } catch (WaitTimeoutException exp) {
        String desc = String.format("%s: Timeout after %d ms while waiting %s", imageConfig.getDescription(), exp.getWaited(), logLine);
        log.error(desc);
        throw new IOException(desc);
    } catch (PreconditionFailedException exp) {
        String desc = String.format("%s: Container stopped with exit code %d unexpectedly after %d ms while waiting %s", imageConfig.getDescription(), precondition.getExitCode(), exp.getWaited(), logLine);
        log.error(desc);
        throw new IOException(desc);
    }
}
Also used : PreconditionFailedException(io.fabric8.maven.docker.wait.PreconditionFailedException) IOException(java.io.IOException) LogWaitChecker(io.fabric8.maven.docker.wait.LogWaitChecker) WaitChecker(io.fabric8.maven.docker.wait.WaitChecker) WaitTimeoutException(io.fabric8.maven.docker.wait.WaitTimeoutException)

Aggregations

LogWaitChecker (io.fabric8.maven.docker.wait.LogWaitChecker)1 PreconditionFailedException (io.fabric8.maven.docker.wait.PreconditionFailedException)1 WaitChecker (io.fabric8.maven.docker.wait.WaitChecker)1 WaitTimeoutException (io.fabric8.maven.docker.wait.WaitTimeoutException)1 IOException (java.io.IOException)1