use of io.fabric8.maven.docker.util.GavLabel in project docker-maven-plugin by fabric8io.
the class CopyMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws IOException, MojoExecutionException {
DockerAccess dockerAccess = hub.getDockerAccess();
RunService runService = hub.getRunService();
ArchiveService archiveService = hub.getArchiveService();
QueryService queryService = hub.getQueryService();
GavLabel gavLabel = getGavLabel();
if (createContainers) {
RegistryService registryService = hub.getRegistryService();
log.debug("Copy mojo is invoked standalone, copying from new temporary containers");
copyFromTemporaryContainers(dockerAccess, runService, registryService, archiveService, queryService, gavLabel);
} else if (invokedTogetherWithDockerStart()) {
log.debug("Copy mojo is invoked together with start mojo, copying from containers created by start mojo");
copyFromStartedContainers(dockerAccess, runService, archiveService, gavLabel);
} else {
log.debug("Copy mojo is invoked standalone, copying from existing containers");
copyFromExistingContainers(dockerAccess, archiveService, queryService);
}
}
use of io.fabric8.maven.docker.util.GavLabel in project docker-maven-plugin by fabric8io.
the class StopMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, IOException, ExecException {
QueryService queryService = hub.getQueryService();
RunService runService = hub.getRunService();
GavLabel gavLabel = getGavLabel();
if (!keepRunning) {
if (invokedTogetherWithDockerStart()) {
runService.stopStartedContainers(keepContainer, removeVolumes, autoCreateCustomNetworks, gavLabel);
} else {
stopContainers(queryService, runService, gavLabel);
}
}
// Switch off all logging
LogDispatcher dispatcher = getLogDispatcher(hub);
dispatcher.untrackAllContainerLogs();
}
use of io.fabric8.maven.docker.util.GavLabel in project docker-maven-plugin by fabric8io.
the class BaseMojoTest method givenMavenProject.
protected void givenMavenProject(AbstractDockerMojo mojo) {
projectGroupId = "mock.group";
projectArtifactId = "mock-artifact";
projectVersion = "1.0.0-MOCK";
try {
projectBaseDirectory = temporaryFolder.newFolder("mock-base").getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException(e);
}
projectBuildDirectory = new File(projectBaseDirectory, "mock-target").getAbsolutePath();
projectGavLabel = new GavLabel(projectGroupId, projectArtifactId, projectVersion);
new Expectations() {
{
mavenProject.getProperties();
result = new Properties();
minTimes = 0;
mavenProject.getBuild();
result = mavenBuild;
minTimes = 0;
mavenProject.getGroupId();
result = projectGroupId;
minTimes = 0;
mavenProject.getArtifactId();
result = projectArtifactId;
minTimes = 0;
mavenProject.getVersion();
result = projectVersion;
minTimes = 0;
mavenProject.getBasedir();
result = projectBaseDirectory;
minTimes = 0;
mavenBuild.getDirectory();
result = projectBuildDirectory;
minTimes = 0;
}
};
Deencapsulation.setField(mojo, "images", Collections.emptyList());
Deencapsulation.setField(mojo, "resolvedImages", Collections.emptyList());
Deencapsulation.setField(mojo, "project", mavenProject);
Deencapsulation.setField(mojo, "log", this.ansiLogger);
mojo.setPluginContext(new HashMap());
mojo.getPluginContext().put(CONTEXT_KEY_LOG_DISPATCHER, logDispatcher);
}
use of io.fabric8.maven.docker.util.GavLabel in project docker-maven-plugin by fabric8io.
the class RunServiceTest method failAfterRetryingIfInsufficientPortBindingInformation.
@Test(expected = PortBindingException.class)
public void failAfterRetryingIfInsufficientPortBindingInformation(@Mocked Container container, @Mocked ImageConfiguration imageConfiguration, @Mocked PortMapping portMapping) throws DockerAccessException {
new Expectations() {
{
docker.createContainer(withAny(new ContainerCreateConfig("img")), anyString);
result = "containerId";
portMapping.needsPropertiesUpdate();
result = true;
queryService.getMandatoryContainer("containerId");
result = container;
times = 20;
container.isRunning();
result = true;
container.getPortBindings();
result = new PortBindingException("5432/tcp", new Gson().fromJson("{\"5432/tcp\": []}", JsonObject.class));
}
};
runService.createAndStartContainer(imageConfiguration, portMapping, new GavLabel("Im:A:Test"), properties, getBaseDirectory(), "blah", new Date());
}
use of io.fabric8.maven.docker.util.GavLabel in project docker-maven-plugin by fabric8io.
the class RunServiceTest method retryIfInsufficientPortBindingInformation.
@Test
public void retryIfInsufficientPortBindingInformation(@Mocked Container container, @Mocked ImageConfiguration imageConfiguration, @Mocked PortMapping portMapping) throws DockerAccessException {
new Expectations() {
{
docker.createContainer(withAny(new ContainerCreateConfig("img")), anyString);
result = "containerId";
portMapping.needsPropertiesUpdate();
result = true;
queryService.getMandatoryContainer("containerId");
result = container;
times = 2;
container.isRunning();
result = true;
container.getPortBindings();
result = new PortBindingException("5432/tcp", new Gson().fromJson("{\"5432/tcp\": []}", JsonObject.class));
returns(ImmutableMap.of("5432/tcp", new Container.PortBinding(56741, "0.0.0.0")), ImmutableMap.of("5432/tcp", new Container.PortBinding(56741, "0.0.0.0")));
}
};
String containerId = runService.createAndStartContainer(imageConfiguration, portMapping, new GavLabel("Im:A:Test"), properties, getBaseDirectory(), "blah", new Date());
new Verifications() {
{
assertEquals("containerId", containerId);
}
};
}
Aggregations