Search in sources :

Example 1 with WaitConfiguration

use of io.fabric8.maven.docker.config.WaitConfiguration in project docker-maven-plugin by fabric8io.

the class ContainerTrackerTest method getImageConfiguration.

private ImageConfiguration getImageConfiguration(String name, String alias, int shutdown, int kill, String preStop, boolean breakOnError) {
    WaitConfiguration waitConfig = null;
    if (shutdown != 0 && kill != 0) {
        WaitConfiguration.Builder builder = new WaitConfiguration.Builder().shutdown(shutdown).kill(kill);
        if (preStop != null) {
            builder.preStop(preStop);
            builder.breakOnError(breakOnError);
        }
        waitConfig = builder.build();
    }
    return new ImageConfiguration.Builder().name(name).alias(alias).runConfig(new RunImageConfiguration.Builder().wait(waitConfig).build()).build();
}
Also used : WaitConfiguration(io.fabric8.maven.docker.config.WaitConfiguration)

Example 2 with WaitConfiguration

use of io.fabric8.maven.docker.config.WaitConfiguration in project docker-maven-plugin by fabric8io.

the class WaitService method prepareWaitCheckers.

private List<WaitChecker> prepareWaitCheckers(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws MojoExecutionException {
    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 MojoExecutionException("Unable to access container.", e);
        }
    }
    if (wait.getHealthy() == Boolean.TRUE) {
        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) Container(io.fabric8.maven.docker.model.Container) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException)

Example 3 with WaitConfiguration

use of io.fabric8.maven.docker.config.WaitConfiguration in project docker-maven-plugin by fabric8io.

the class StartMojo method startImage.

private void startImage(final ImageConfiguration image, final ServiceHub hub, final ExecutorCompletionService<StartedContainer> startingContainers, final PortMapping.PropertyWriteHelper portMappingPropertyWriteHelper) {
    final RunService runService = hub.getRunService();
    final Properties projProperties = project.getProperties();
    final RunImageConfiguration runConfig = image.getRunConfiguration();
    final PortMapping portMapping = runService.createPortMapping(runConfig, projProperties);
    final LogDispatcher dispatcher = getLogDispatcher(hub);
    startingContainers.submit(new Callable<StartedContainer>() {

        @Override
        public StartedContainer call() throws Exception {
            final String containerId = runService.createAndStartContainer(image, portMapping, getPomLabel(), projProperties, project.getBasedir());
            // Update port-mapping writer
            portMappingPropertyWriteHelper.add(portMapping, runConfig.getPortPropertyFile());
            if (showLogs(image)) {
                dispatcher.trackContainerLog(containerId, serviceHubFactory.getLogOutputSpecFactory().createSpec(containerId, image));
            }
            // Wait if requested
            hub.getWaitService().wait(image, projProperties, containerId);
            WaitConfiguration waitConfig = runConfig.getWaitConfiguration();
            if (waitConfig != null && waitConfig.getExec() != null && waitConfig.getExec().getPostStart() != null) {
                try {
                    runService.execInContainer(containerId, waitConfig.getExec().getPostStart(), image);
                } catch (ExecException exp) {
                    if (waitConfig.getExec().isBreakOnError()) {
                        throw exp;
                    } else {
                        log.warn("Cannot run postStart: %s", exp.getMessage());
                    }
                }
            }
            return new StartedContainer(image, containerId);
        }
    });
}
Also used : LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) ExecException(io.fabric8.maven.docker.access.ExecException) PortMapping(io.fabric8.maven.docker.access.PortMapping) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) ExecException(io.fabric8.maven.docker.access.ExecException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)2 WaitConfiguration (io.fabric8.maven.docker.config.WaitConfiguration)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ExecException (io.fabric8.maven.docker.access.ExecException)1 PortMapping (io.fabric8.maven.docker.access.PortMapping)1 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)1 Container (io.fabric8.maven.docker.model.Container)1 IOException (java.io.IOException)1