Search in sources :

Example 1 with LogDispatcher

use of io.fabric8.maven.docker.log.LogDispatcher in project docker-maven-plugin by fabric8io.

the class AbstractDockerMojo method getLogDispatcher.

protected LogDispatcher getLogDispatcher(ServiceHub hub) {
    LogDispatcher dispatcher = (LogDispatcher) getPluginContext().get(CONTEXT_KEY_LOG_DISPATCHER);
    if (dispatcher == null) {
        dispatcher = new LogDispatcher(hub.getDockerAccess());
        getPluginContext().put(CONTEXT_KEY_LOG_DISPATCHER, dispatcher);
    }
    return dispatcher;
}
Also used : LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 2 with LogDispatcher

use of io.fabric8.maven.docker.log.LogDispatcher in project docker-maven-plugin by fabric8io.

the class StopMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException, ExecException {
    QueryService queryService = hub.getQueryService();
    RunService runService = hub.getRunService();
    PomLabel pomLabel = getPomLabel();
    if (!keepRunning) {
        if (invokedTogetherWithDockerStart()) {
            runService.stopStartedContainers(keepContainer, removeVolumes, autoCreateCustomNetworks, pomLabel);
        } else {
            stopContainers(queryService, runService, pomLabel);
        }
    }
    // Switch off all logging
    LogDispatcher dispatcher = getLogDispatcher(hub);
    dispatcher.untrackAllContainerLogs();
}
Also used : RunService(io.fabric8.maven.docker.service.RunService) QueryService(io.fabric8.maven.docker.service.QueryService) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) PomLabel(io.fabric8.maven.docker.util.PomLabel)

Example 3 with LogDispatcher

use of io.fabric8.maven.docker.log.LogDispatcher in project docker-maven-plugin by fabric8io.

the class LogsMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException {
    QueryService queryService = hub.getQueryService();
    LogDispatcher logDispatcher = getLogDispatcher(hub);
    for (ImageConfiguration image : getResolvedImages()) {
        String imageName = image.getName();
        if (logAll) {
            for (Container container : queryService.getContainersForImage(imageName)) {
                doLogging(logDispatcher, image, container.getId());
            }
        } else {
            Container container = queryService.getLatestContainerForImage(imageName);
            if (container != null) {
                doLogging(logDispatcher, image, container.getId());
            }
        }
    }
    if (follow) {
        // Block forever ....
        waitForEver();
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) QueryService(io.fabric8.maven.docker.service.QueryService) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 4 with LogDispatcher

use of io.fabric8.maven.docker.log.LogDispatcher 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

LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)4 QueryService (io.fabric8.maven.docker.service.QueryService)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ExecException (io.fabric8.maven.docker.access.ExecException)1 PortMapping (io.fabric8.maven.docker.access.PortMapping)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 Container (io.fabric8.maven.docker.model.Container)1 RunService (io.fabric8.maven.docker.service.RunService)1 PomLabel (io.fabric8.maven.docker.util.PomLabel)1 IOException (java.io.IOException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1