Search in sources :

Example 1 with WaitChecker

use of io.fabric8.maven.docker.wait.WaitChecker 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)

Example 2 with WaitChecker

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

the class WaitService method getUrlWaitChecker.

// =================================================================================================================
private WaitChecker getUrlWaitChecker(String imageConfigDesc, Properties projectProperties, WaitConfiguration wait) {
    String waitUrl = StrSubstitutor.replace(wait.getUrl(), projectProperties);
    WaitConfiguration.HttpConfiguration httpConfig = wait.getHttp();
    HttpPingChecker checker;
    if (httpConfig != null) {
        checker = new HttpPingChecker(waitUrl, httpConfig.getMethod(), httpConfig.getStatus(), httpConfig.isAllowAllHosts());
        log.info("%s: Waiting on url %s with method %s for status %s.", imageConfigDesc, waitUrl, httpConfig.getMethod(), httpConfig.getStatus());
    } else {
        checker = new HttpPingChecker(waitUrl);
        log.info("%s: Waiting on url %s.", imageConfigDesc, waitUrl);
    }
    return checker;
}
Also used : HttpPingChecker(io.fabric8.maven.docker.wait.HttpPingChecker) WaitConfiguration(io.fabric8.maven.docker.config.WaitConfiguration)

Example 3 with WaitChecker

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

the class WaitService method prepareWaitCheckers.

private List<WaitChecker> prepareWaitCheckers(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws IOException {
    WaitConfiguration wait = getWaitConfiguration(imageConfig);
    if (wait == null) {
        return Collections.emptyList();
    }
    List<WaitChecker> checkers = new ArrayList<>();
    if (wait.getUrl() != null) {
        checkers.add(getUrlWaitChecker(imageConfig.getDescription(), projectProperties, wait));
    }
    if (wait.getLog() != null) {
        log.debug("LogWaitChecker: Waiting on %s", wait.getLog());
        checkers.add(new LogWaitChecker(wait.getLog(), dockerAccess, containerId, log));
    }
    if (wait.getTcp() != null) {
        try {
            Container container = queryService.getMandatoryContainer(containerId);
            checkers.add(getTcpWaitChecker(container, imageConfig.getDescription(), projectProperties, wait.getTcp()));
        } catch (DockerAccessException e) {
            throw new IOException("Unable to access container " + containerId, e);
        }
    }
    if (Boolean.TRUE.equals(wait.getHealthy())) {
        checkers.add(new HealthCheckChecker(dockerAccess, containerId, imageConfig.getDescription(), log));
    }
    if (wait.getExit() != null) {
        checkers.add(new ExitCodeChecker(wait.getExit(), queryService, containerId));
    }
    return checkers;
}
Also used : WaitConfiguration(io.fabric8.maven.docker.config.WaitConfiguration) HealthCheckChecker(io.fabric8.maven.docker.wait.HealthCheckChecker) Container(io.fabric8.maven.docker.model.Container) LogWaitChecker(io.fabric8.maven.docker.wait.LogWaitChecker) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) ArrayList(java.util.ArrayList) ExitCodeChecker(io.fabric8.maven.docker.wait.ExitCodeChecker) IOException(java.io.IOException) LogWaitChecker(io.fabric8.maven.docker.wait.LogWaitChecker) WaitChecker(io.fabric8.maven.docker.wait.WaitChecker)

Aggregations

WaitConfiguration (io.fabric8.maven.docker.config.WaitConfiguration)2 LogWaitChecker (io.fabric8.maven.docker.wait.LogWaitChecker)2 WaitChecker (io.fabric8.maven.docker.wait.WaitChecker)2 IOException (java.io.IOException)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 Container (io.fabric8.maven.docker.model.Container)1 ExitCodeChecker (io.fabric8.maven.docker.wait.ExitCodeChecker)1 HealthCheckChecker (io.fabric8.maven.docker.wait.HealthCheckChecker)1 HttpPingChecker (io.fabric8.maven.docker.wait.HttpPingChecker)1 PreconditionFailedException (io.fabric8.maven.docker.wait.PreconditionFailedException)1 WaitTimeoutException (io.fabric8.maven.docker.wait.WaitTimeoutException)1 ArrayList (java.util.ArrayList)1