Search in sources :

Example 6 with GavLabel

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);
    }
}
Also used : DockerAccess(io.fabric8.maven.docker.access.DockerAccess) RunService(io.fabric8.maven.docker.service.RunService) GavLabel(io.fabric8.maven.docker.util.GavLabel) ArchiveService(io.fabric8.maven.docker.service.ArchiveService) QueryService(io.fabric8.maven.docker.service.QueryService) RegistryService(io.fabric8.maven.docker.service.RegistryService)

Example 7 with GavLabel

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();
}
Also used : RunService(io.fabric8.maven.docker.service.RunService) GavLabel(io.fabric8.maven.docker.util.GavLabel) QueryService(io.fabric8.maven.docker.service.QueryService) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 8 with GavLabel

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);
}
Also used : GavLabel(io.fabric8.maven.docker.util.GavLabel) Expectations(mockit.Expectations) HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Example 9 with GavLabel

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());
}
Also used : Expectations(mockit.Expectations) GavLabel(io.fabric8.maven.docker.util.GavLabel) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) Gson(com.google.gson.Gson) PortBindingException(io.fabric8.maven.docker.model.PortBindingException) Date(java.util.Date) Test(org.junit.Test)

Example 10 with GavLabel

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);
        }
    };
}
Also used : Expectations(mockit.Expectations) GavLabel(io.fabric8.maven.docker.util.GavLabel) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) Gson(com.google.gson.Gson) PortBindingException(io.fabric8.maven.docker.model.PortBindingException) Verifications(mockit.Verifications) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GavLabel (io.fabric8.maven.docker.util.GavLabel)7 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 Expectations (mockit.Expectations)5 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)4 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)4 RunService (io.fabric8.maven.docker.service.RunService)4 Test (org.junit.Test)4 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)3 Container (io.fabric8.maven.docker.model.Container)3 Network (io.fabric8.maven.docker.model.Network)3 PortBindingException (io.fabric8.maven.docker.model.PortBindingException)3 QueryService (io.fabric8.maven.docker.service.QueryService)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Properties (java.util.Properties)3 Gson (com.google.gson.Gson)2 PortMapping (io.fabric8.maven.docker.access.PortMapping)2 CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)2 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)2 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)2