Search in sources :

Example 46 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method startExecContainer.

@Override
public void startExecContainer(String containerId, LogOutputSpec outputSpec) throws DockerAccessException {
    try {
        String url = urlBuilder.startExecContainer(containerId);
        JsonObject request = new JsonObject();
        request.addProperty("Detach", false);
        request.addProperty("Tty", true);
        log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_POST_WITH_REQUEST, url, request);
        delegate.post(url, request.toString(), createExecResponseHandler(outputSpec), HTTP_OK);
    } catch (Exception e) {
        throw new DockerAccessException(e, "Unable to start container id [%s]", containerId);
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) FileNotFoundException(java.io.FileNotFoundException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException)

Example 47 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.

the class StartMojo method prepareStart.

// Prepare start like creating custom networks, auto pull images, map aliases and return the list of images
// to start in the correct order
private Queue<ImageConfiguration> prepareStart(ServiceHub hub, QueryService queryService, RunService runService, Set<String> imageAliases) throws DockerAccessException, MojoExecutionException {
    final Queue<ImageConfiguration> imagesWaitingToStart = new ArrayDeque<>();
    for (StartOrderResolver.Resolvable resolvable : runService.getImagesConfigsInOrder(queryService, getResolvedImages())) {
        final ImageConfiguration imageConfig = (ImageConfiguration) resolvable;
        // Still to check: How to work with linking, volumes, etc ....
        // String imageName = new ImageName(imageConfig.getName()).getFullNameWithTag(registry);
        RegistryService registryService = hub.getRegistryService();
        pullImage(registryService, imageConfig, pullRegistry);
        RunImageConfiguration runConfig = imageConfig.getRunConfiguration();
        NetworkConfig config = runConfig.getNetworkingConfig();
        List<String> bindMounts = extractBindMounts(runConfig.getVolumeConfiguration());
        List<VolumeConfiguration> volumes = getVolumes();
        if (!bindMounts.isEmpty() && volumes != null) {
            runService.createVolumesAsPerVolumeBinds(hub, bindMounts, volumes);
        }
        if (autoCreateCustomNetworks && config.isCustomNetwork()) {
            runService.createCustomNetworkIfNotExistant(config.getCustomNetwork());
        }
        imagesWaitingToStart.add(imageConfig);
        updateAliasesSet(imageAliases, imageConfig.getAlias());
    }
    return imagesWaitingToStart;
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) StartOrderResolver(io.fabric8.maven.docker.util.StartOrderResolver) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) RegistryService(io.fabric8.maven.docker.service.RegistryService) RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) ArrayDeque(java.util.ArrayDeque) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration)

Example 48 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.

the class CopyMojo method copyFromStartedContainers.

private void copyFromStartedContainers(DockerAccess dockerAccess, RunService runService, ArchiveService archiveService, GavLabel gavLabel) throws IOException, MojoExecutionException {
    List<ContainerDescriptor> containerDescriptors = runService.getContainers(gavLabel);
    for (ContainerDescriptor containerDescriptor : containerDescriptors) {
        ImageConfiguration imageConfiguration = containerDescriptor.getImageConfig();
        CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
        String imageName = imageConfiguration.getName();
        if (isEmpty(copyConfiguration)) {
            log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
            continue;
        }
        String containerId = containerDescriptor.getContainerId();
        log.debug("Found %s container of %s image started by start mojo", containerId, imageName);
        copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
    }
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration) ContainerDescriptor(io.fabric8.maven.docker.service.RunService.ContainerDescriptor)

Example 49 with Start

use of io.fabric8.arquillian.kubernetes.event.Start 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 50 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingSingleLineSucceeds.

@Test(expected = LogCallback.DoneException.class)
public void matchingSingleLineSucceeds() throws Exception {
    final String patternString = "The start has finished right now";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patternString);
    new Expectations() {

        {
            callback.matched();
            times = 1;
        }
    };
    logMatchCallback.log(1, new Timestamp(), patternString);
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)27 Test (org.junit.Test)25 File (java.io.File)18 HashMap (java.util.HashMap)16 Map (java.util.Map)10 Git (org.eclipse.jgit.api.Git)10 ArrayList (java.util.ArrayList)9 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)8 Bundle (org.osgi.framework.Bundle)8 PatchException (io.fabric8.patch.management.PatchException)7 URISyntaxException (java.net.URISyntaxException)7 BundleException (org.osgi.framework.BundleException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 CuratorFramework (org.apache.curator.framework.CuratorFramework)6 Container (io.fabric8.api.Container)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)5 FabricService (io.fabric8.api.FabricService)5 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)5 HashSet (java.util.HashSet)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5