Search in sources :

Example 61 with IDockerConnection

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

the class NewDockerConnectionSWTBotTest method configureUnixSocketConnection.

private IDockerConnection configureUnixSocketConnection(final String connectionName, final String pathToSocket) {
    final DockerClient client = MockDockerClientFactory.build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from(connectionName, client).withUnixSocketConnectionSettings(pathToSocket);
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    return dockerConnection;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerClient(com.spotify.docker.client.DockerClient)

Example 62 with IDockerConnection

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

the class DefaultDockerConnectionStorageManager method saveConnections.

@Override
public void saveConnections(List<IDockerConnection> connections) {
    final IPath stateLocation = Activator.getDefault().getStateLocation();
    final File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME).toFile();
    try {
        if (!connectionFile.exists()) {
            connectionFile.createNewFile();
        }
        try (final PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(connectionFile)))) {
            // $NON-NLS-1$
            p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            // $NON-NLS-1$
            p.println("<connections>");
            for (IDockerConnection d : connections) {
                String name = d.getName();
                if (name.equals(Messages.Unnamed)) {
                    name = "";
                }
                p.print(// $NON-NLS-1$
                "<connection name=\"" + name + "\" uri=\"" + // $NON-NLS-1$
                d.getUri());
                if (d.getUsername() != null) {
                    // $NON-NLS-1$
                    p.print("\" username=\"" + d.getUsername());
                }
                if (d.getTcpCertPath() != null) {
                    // $NON-NLS-1$
                    p.print("\" cert=\"" + d.getTcpCertPath());
                }
                // $NON-NLS-1$
                p.println("\"/>");
            }
            // $NON-NLS-1$
            p.println("</connections>");
        }
    } catch (Exception e) {
        Activator.log(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) FileWriter(java.io.FileWriter) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) File(java.io.File) StorageException(org.eclipse.equinox.security.storage.StorageException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 63 with IDockerConnection

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

the class RunDockerImageLaunchConfigurationDelegate method chooseConnection.

/**
 * Show a selection dialog that allows the user to choose one of the
 * connections to use to build the Image.
 *
 * @param connections
 *            Array of connections.
 * @return The chosen connection, or <code>null</code> if the user cancelled
 *         the dialog.
 */
protected IDockerConnection chooseConnection(final IDockerConnection[] connections) {
    IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getActiveWorkbenchShell(), new ConnectionSelectionLabelProvider() {
    });
    dialog.setElements(connections);
    dialog.setTitle(LaunchMessages.getString(LaunchShortcut_Connection_Selection));
    dialog.setMessage(LaunchMessages.getString(LaunchShortcut_Choose_Connection));
    dialog.setMultipleSelection(false);
    int result = dialog.open();
    labelProvider.dispose();
    if (result == IStatus.OK) {
        return (IDockerConnection) dialog.getFirstResult();
    }
    return null;
}
Also used : ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 64 with IDockerConnection

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

the class ConnectionSettingsPropertySection method setInput.

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    super.setInput(part, selection);
    Assert.isTrue(selection instanceof ITreeSelection);
    Object input = ((ITreeSelection) selection).getFirstElement();
    Assert.isTrue(input instanceof IDockerConnection);
    IDockerConnection connection = (IDockerConnection) input;
    if (getTreeViewer() != null) {
        getTreeViewer().setInput(connection);
        getTreeViewer().expandAll();
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 65 with IDockerConnection

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

the class DockerExplorerContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement) {
    if (parentElement instanceof IDockerConnection) {
        // check the connection availability before returning the
        // 'containers' and 'images' child nodes.
        final IDockerConnection connection = (IDockerConnection) parentElement;
        if (connection.isOpen()) {
            return new Object[] { new DockerImagesCategory(connection), new DockerContainersCategory(connection) };
        } else if (connection.getState() == EnumDockerConnectionState.UNKNOWN) {
            open(connection);
            return new Object[] { new LoadingStub(connection) };
        } else if (connection.getState() == EnumDockerConnectionState.CLOSED) {
            synchronized (openRetryJobs) {
                Job job = openRetryJobs.get(connection);
                if (job == null) {
                    openRetry(connection);
                }
            }
            return new Object[] { new LoadingStub(connection) };
        }
        return new Object[0];
    } else if (parentElement instanceof DockerContainersCategory) {
        final DockerContainersCategory containersCategory = (DockerContainersCategory) parentElement;
        final IDockerConnection connection = containersCategory.getConnection();
        if (connection.isContainersLoaded()) {
            return connection.getContainers().toArray();
        }
        loadContainers(containersCategory);
        return new Object[] { new LoadingStub(containersCategory) };
    } else if (parentElement instanceof DockerImagesCategory) {
        final DockerImagesCategory imagesCategory = (DockerImagesCategory) parentElement;
        final IDockerConnection connection = imagesCategory.getConnection();
        if (connection.isImagesLoaded()) {
            // here we duplicate the images to show one org/repo with all
            // its tags per node in the tree
            final List<IDockerImage> allImages = connection.getImages();
            final List<IDockerImage> explorerImages = splitImageTagsByRepo(allImages);
            return explorerImages.toArray();
        }
        loadImages(imagesCategory);
        return new Object[] { new LoadingStub(imagesCategory) };
    } else if (parentElement instanceof IDockerContainer) {
        final DockerContainer container = (DockerContainer) parentElement;
        if (container.isInfoLoaded()) {
            final IDockerContainerInfo info = container.info();
            final IDockerNetworkSettings networkSettings = (info != null) ? info.networkSettings() : null;
            final IDockerHostConfig hostConfig = (info != null) ? info.hostConfig() : null;
            return new Object[] { new DockerContainerPortMappingsCategory(container, (networkSettings != null) ? networkSettings.ports() : Collections.<String, List<IDockerPortBinding>>emptyMap()), new DockerContainerVolumesCategory(container, (hostConfig != null) ? hostConfig.binds() : Collections.<String>emptyList()), new DockerContainerLinksCategory(container, (hostConfig != null) ? hostConfig.links() : Collections.<String>emptyList()) };
        }
        loadContainerInfo(container);
        return new Object[] { new LoadingStub(container) };
    } else if (parentElement instanceof DockerContainerLinksCategory) {
        final DockerContainerLinksCategory linksCategory = (DockerContainerLinksCategory) parentElement;
        return linksCategory.getLinks().toArray();
    } else if (parentElement instanceof DockerContainerPortMappingsCategory) {
        final DockerContainerPortMappingsCategory portMappingsCategory = (DockerContainerPortMappingsCategory) parentElement;
        return portMappingsCategory.getPortMappings().toArray();
    } else if (parentElement instanceof DockerContainerVolumesCategory) {
        final DockerContainerVolumesCategory volumesCategory = (DockerContainerVolumesCategory) parentElement;
        return volumesCategory.getVolumes().toArray();
    }
    return EMPTY;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) DockerContainer(org.eclipse.linuxtools.internal.docker.core.DockerContainer) IDockerNetworkSettings(org.eclipse.linuxtools.docker.core.IDockerNetworkSettings) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) Job(org.eclipse.core.runtime.jobs.Job)

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