Search in sources :

Example 1 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class StartContainersCommandHandler method executeInJob.

@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
    try {
        final RunConsole console = getRunConsole(connection, container);
        if (console != null) {
            // if we are auto-logging, show the console
            console.showConsole();
            // Start the container
            ((DockerConnection) connection).startContainer(container.id(), console.getOutputStream());
        } else {
            ((DockerConnection) connection).startContainer(container.id(), null);
        }
        ((DockerConnection) connection).getContainers(true);
    } catch (DockerException | InterruptedException e) {
        final String errorMessage = DVMessages.getFormattedString(CONTAINER_START_ERROR_MSG, container.id());
        openError(errorMessage, e);
    }
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) CommandUtils.getRunConsole(org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils.getRunConsole) RunConsole(org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)

Example 2 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class RunConsole method attachToTerminal.

public static void attachToTerminal(final IDockerConnection connection, final String containerId, final DockerConsoleOutputStream out) {
    Thread t = new Thread(() -> {
        try {
            DockerConnection conn = (DockerConnection) connection;
            IDockerContainerState state = conn.getContainerInfo(containerId).state();
            do {
                if (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
                    Thread.sleep(300);
                }
                state = conn.getContainerInfo(containerId).state();
            } while (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate())));
            // Pause as there appears to be some timing issue with regards
            // to the Container saying it is running, but an exception
            // thrown when we try and attach.
            Thread.sleep(300);
            state = conn.getContainerInfo(containerId).state();
            if (state.running()) {
                conn.attachCommand(containerId, null, out);
            } else {
                // notify any console listener that there is no more output
                // going to follow
                out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
            }
        } catch (Exception e) {
            Activator.log(e);
            // notify any console listener that there is no more output
            // going to follow
            out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
        }
    });
    t.start();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) IDockerContainerState(org.eclipse.linuxtools.docker.core.IDockerContainerState) IOException(java.io.IOException)

Example 3 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class RunConsole method attachToConsole.

/**
 * The console will be attached to the underlying container.
 *
 * @param connection
 *            The connection associated with this console.
 */
public void attachToConsole(final IDockerConnection connection) {
    final InputStream in = getInputStream();
    Thread t = new Thread(() -> {
        try {
            DockerConnection conn = (DockerConnection) connection;
            if (conn.getContainerInfo(containerId).config().openStdin()) {
                IDockerContainerState state = conn.getContainerInfo(containerId).state();
                do {
                    if (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
                        Thread.sleep(300);
                    }
                    state = conn.getContainerInfo(containerId).state();
                } while (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate())));
                Thread.sleep(300);
                state = conn.getContainerInfo(containerId).state();
                if (state.running()) {
                    conn.attachCommand(containerId, in, null);
                }
            }
        } catch (Exception e) {
            Activator.log(e);
        }
    });
    t.start();
    attached = true;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) InputStream(java.io.InputStream) IDockerContainerState(org.eclipse.linuxtools.docker.core.IDockerContainerState) IOException(java.io.IOException)

Example 4 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class BuildDockerImageJob method run.

@Override
protected IStatus run(final IProgressMonitor progressMonitor) {
    try {
        this.progressMonitor = progressMonitor;
        final IPath pathToDockerfile = path.addTrailingSeparator().append(// $NON-NLS-1$
        "Dockerfile");
        if (verifyPathToDockerfile(pathToDockerfile)) {
            final int numberOfBuildOperations = countLines(// $NON-NLS-1$
            pathToDockerfile.toOSString());
            if (numberOfBuildOperations == 0) {
                Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, JobMessages.getString(SKIP_EMPTY_DOCKERFILE)));
            } else {
                this.console.clearConsole();
                this.console.activate();
                this.progressMonitor.beginTask(JobMessages.getString(BUILD_IMAGE_JOB_TITLE), numberOfBuildOperations + 1);
                if (repoName == null) {
                    // Give the Image a default name so it can be tagged
                    // later.
                    // Otherwise, the Image will be treated as an
                    // intermediate
                    // Image
                    // by the view filters and Tag Image action will be
                    // disabled.
                    // Use the current time in milliseconds to make it
                    // unique.
                    final String name = // $NON-NLS-1$
                    "dockerfile:" + Long.toHexString(System.currentTimeMillis());
                    ((DockerConnection) connection).buildImage(this.path, name, this, this.buildOptions);
                } else {
                    ((DockerConnection) connection).buildImage(this.path, this.repoName, this, this.buildOptions);
                }
                connection.getImages(true);
            }
        }
    } catch (DockerException | InterruptedException e) {
        Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), JobMessages.getString(BUILD_IMAGE_ERROR_MESSAGE), e.getMessage()));
    } finally {
        // make sure the progress monitor is 'done' even if the build failed
        // or
        // timed out.
        this.progressMonitor.done();
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IPath(org.eclipse.core.runtime.IPath)

Example 5 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.

the class ContainerVMInstall method getName.

@Override
public String getName() {
    if (name == null) {
        DockerConnection conn = getConnection();
        ImageQuery q = new ImageQuery(conn, image.id());
        name = q.getDefaultJVMName();
        q.destroy();
    }
    return name;
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection)

Aggregations

DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)108 DockerClient (com.spotify.docker.client.DockerClient)75 Test (org.junit.Test)71 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)31 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)21 DockerException (org.eclipse.linuxtools.docker.core.DockerException)18 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)15 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)9 RunWithProject (org.eclipse.linuxtools.internal.docker.ui.testutils.RunWithProject)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Job (org.eclipse.core.runtime.jobs.Job)8 Path (java.nio.file.Path)6 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)6 ProgressHandler (com.spotify.docker.client.ProgressHandler)5 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)5 PropertySheet (org.eclipse.ui.views.properties.PropertySheet)5 TabbedPropertySheetPage (org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)5 Before (org.junit.Before)5 File (java.io.File)4 IOException (java.io.IOException)4