Search in sources :

Example 1 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection 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 IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection 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 IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection 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 IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class BuildDockerImageLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    final String sourcePathLocation = configuration.getAttribute(SOURCE_PATH_LOCATION, (String) null);
    final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(SOURCE_PATH_WORKSPACE_RELATIVE_LOCATION, false);
    final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
    final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
    final String repoName = configuration.getAttribute(REPO_NAME, (String) null);
    final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
    final Map<String, Object> buildOptions = new HashMap<>();
    buildOptions.put(QUIET_BUILD, configuration.getAttribute(QUIET_BUILD, false));
    buildOptions.put(NO_CACHE, configuration.getAttribute(NO_CACHE, false));
    buildOptions.put(RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(RM_INTERMEDIATE_CONTAINERS, true));
    buildOptions.put(FORCE_RM_INTERMEDIATE_CONTAINERS, configuration.getAttribute(FORCE_RM_INTERMEDIATE_CONTAINERS, false));
    if (connection != null && sourcePath != null) {
        final Job buildImageJob = new BuildDockerImageJob(connection, sourcePath, repoName, buildOptions);
        buildImageJob.schedule();
    } else {
        final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
        "run");
        // prompt the user with the launch configuration editor
        Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) Job(org.eclipse.core.runtime.jobs.Job) BuildDockerImageJob(org.eclipse.linuxtools.internal.docker.ui.jobs.BuildDockerImageJob)

Example 5 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class DockerComposeUpLaunchConfigurationDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
    final String sourcePathLocation = configuration.getAttribute(WORKING_DIR, (String) null);
    final boolean sourcePathWorkspaceRelativeLocation = configuration.getAttribute(WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, false);
    final IPath sourcePath = BuildDockerImageUtils.getPath(sourcePathLocation, sourcePathWorkspaceRelativeLocation);
    final String connectionName = configuration.getAttribute(DOCKER_CONNECTION, (String) null);
    final IDockerConnection connection = DockerConnectionManager.getInstance().getConnectionByName(connectionName);
    if (connection != null && sourcePath != null) {
        final Job dockerComposeUpJob = new DockerComposeUpJob(connection, sourcePath.toOSString(), configuration);
        dockerComposeUpJob.schedule();
    } else {
        final ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(configuration, // $NON-NLS-1$
        "run");
        // prompt the user with the launch configuration editor
        Display.getDefault().syncExec(() -> DebugUITools.openLaunchConfigurationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), configuration, launchGroup.getIdentifier(), null));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) DockerComposeUpJob(org.eclipse.linuxtools.internal.docker.ui.jobs.DockerComposeUpJob) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ILaunchGroup(org.eclipse.debug.ui.ILaunchGroup) Job(org.eclipse.core.runtime.jobs.Job) DockerComposeUpJob(org.eclipse.linuxtools.internal.docker.ui.jobs.DockerComposeUpJob)

Aggregations

IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)90 DockerException (org.eclipse.linuxtools.docker.core.DockerException)24 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)20 Job (org.eclipse.core.runtime.jobs.Job)17 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)16 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)15 Test (org.junit.Test)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)9 File (java.io.File)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)8 IPath (org.eclipse.core.runtime.IPath)7 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 List (java.util.List)5 IDockerConnectionStorageManager (org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager)5 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)5 DockerClient (com.spotify.docker.client.DockerClient)4 HashMap (java.util.HashMap)4