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;
}
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();
}
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();
}
}
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);
}
});
}
Aggregations