Search in sources :

Example 6 with IDockerConnection

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

the class RunDockerImageLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) {
    try {
        ILaunchConfiguration config = launch.getLaunchConfiguration();
        final IDockerContainerConfig containerConfig = getDockerContainerConfig(config);
        final IDockerHostConfig hostConfig = getDockerHostConfig(config);
        final IDockerConnection connection = getDockerConnection(config);
        if (connection == null)
            return;
        final IDockerImage image = getDockerImage(config, connection);
        RunImageCommandHandler.runImage(image, containerConfig, hostConfig, config.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONTAINER_NAME, (String) null), config.getAttribute(IRunDockerImageLaunchConfigurationConstants.AUTO_REMOVE, false));
    } catch (CoreException e) {
        Activator.log(e);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) CoreException(org.eclipse.core.runtime.CoreException) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 7 with IDockerConnection

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

the class RunDockerImageLaunchConfigurationDelegate method getDockerConnection.

private IDockerConnection getDockerConnection(ILaunchConfiguration config) throws CoreException {
    String configName = config.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONNECTION_NAME, // $NON-NLS-1$
    "");
    IDockerConnection connection = DockerConnectionManager.getInstance().findConnection(configName);
    if (connection == null) {
        connection = chooseConnection(DockerConnectionManager.getInstance().getConnections());
    }
    return connection;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 8 with IDockerConnection

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

the class RunImageMainTab method isValid.

@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
    try {
        if (model == null)
            return false;
        String connectionName = launchConfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONNECTION_NAME, // $NON-NLS-1$
        "");
        if (connectionName.isEmpty()) {
            return false;
        } else {
            // Verify Connection is active
            IDockerConnection connection = DockerConnectionManager.getInstance().findConnection(connectionName);
            if (connection == null || !connection.isOpen()) {
                setErrorMessage(WizardMessages.getFormattedString(// $NON-NLS-1$
                "ErrorInactiveConnection.msg", connectionName));
                return false;
            }
        }
        final IStatus imageSelectionValidationStatus = new ImageSelectionValidator().validate(model.getSelectedImageName());
        if (!imageSelectionValidationStatus.isOK()) {
            setErrorMessage(imageSelectionValidationStatus.getMessage());
            return false;
        }
        final IStatus imageNameValidationStatus = new ImageNameValidator().validate(model.getSelectedImageName());
        if (!imageNameValidationStatus.isOK()) {
            setErrorMessage(imageNameValidationStatus.getMessage());
            return false;
        }
        final IStatus containerNameValidationStatus = new ContainerNameValidator().validate(model.getContainerName());
        if (!containerNameValidationStatus.isOK()) {
            setErrorMessage(containerNameValidationStatus.getMessage());
            return false;
        }
    } catch (CoreException e) {
        Activator.log(e);
    }
    setErrorMessage(null);
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ImageNameValidator(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageNameValidator) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 9 with IDockerConnection

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

the class ImageSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    Label connLbl = new Label(composite, SWT.NONE);
    connLbl.setText(Messages.ImageSelectionDialog_connection_label);
    ComboViewer connCmb = new ComboViewer(composite, SWT.READ_ONLY);
    connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    connCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
                try {
                    ((DockerConnection) conn).open(false);
                } catch (DockerException e) {
                }
            }
            return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
        }
    });
    // $NON-NLS-1$
    connCmb.setInput("place_holder");
    Label imageLbl = new Label(composite, SWT.NONE);
    imageLbl.setText(Messages.ImageSelectionDialog_image_label);
    ComboViewer imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
    imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    imageCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            IDockerConnection conn = (IDockerConnection) inputElement;
            return conn.getImages().stream().filter(// $NON-NLS-1$
            i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
        }
    });
    imageCmb.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            IDockerImage img = (IDockerImage) element;
            return img.repoTags().get(0);
        }
    });
    imageCmb.setInput(null);
    connCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
            connection = conn;
            imageCmb.setInput(conn);
        }
    });
    imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerImage img = (IDockerImage) sel.getFirstElement();
            image = img;
            getOkButton().setEnabled(true);
        }
    });
    return composite;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Shell(org.eclipse.swt.widgets.Shell) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) DockerException(org.eclipse.linuxtools.docker.core.DockerException) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 10 with IDockerConnection

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

the class DefaultDockerConnectionStorageManager method loadConnections.

@Override
public List<IDockerConnection> loadConnections() {
    final List<IDockerConnection> connections = new ArrayList<>();
    final IPath stateLocation = Activator.getDefault().getStateLocation();
    final File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME).toFile();
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        if (connectionFile.exists()) {
            Document d = db.parse(connectionFile);
            Element e = d.getDocumentElement();
            // Get the stored configuration data
            // $NON-NLS-1$
            NodeList connectionNodes = e.getElementsByTagName("connection");
            for (int x = 0; x < connectionNodes.getLength(); ++x) {
                Node n = connectionNodes.item(x);
                NamedNodeMap attrs = n.getAttributes();
                // $NON-NLS-1$
                Node nameNode = attrs.getNamedItem("name");
                // $NON-NLS-1$
                Node uriNode = attrs.getNamedItem("uri");
                // $NON-NLS-1$
                Node usernameNode = attrs.getNamedItem("username");
                // $NON-NLS-1$
                Node certNode = attrs.getNamedItem("cert");
                if (uriNode != null) {
                    String uri = uriNode.getNodeValue();
                    String name = nameNode.getNodeValue();
                    if (usernameNode != null) {
                        String username = usernameNode.getNodeValue();
                        String key = DockerConnection.getPreferencesKey(uri, username);
                        ISecurePreferences root = SecurePreferencesFactory.getDefault();
                        ISecurePreferences node = root.node(key);
                        @SuppressWarnings("unused") String password;
                        try {
                            // $NON-NLS-1$
                            password = node.get("password", null);
                        } catch (StorageException e1) {
                            e1.printStackTrace();
                        }
                    }
                    final DockerConnection.Builder builder = new DockerConnection.Builder().name(name);
                    if (uri.startsWith("unix:")) {
                        // $NON-NLS-1$
                        final DockerConnection connection = builder.unixSocketConnection(new UnixSocketConnectionSettings(uri));
                        connections.add(connection);
                    } else {
                        final String pathToCertificates = certNode != null ? certNode.getNodeValue() : null;
                        final DockerConnection connection = builder.tcpConnection(new TCPConnectionSettings(uri, pathToCertificates));
                        connections.add(connection);
                    }
                }
            }
        }
    } catch (ParserConfigurationException | SAXException | IOException e) {
        Activator.log(e);
    }
    return connections;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NamedNodeMap(org.w3c.dom.NamedNodeMap) IPath(org.eclipse.core.runtime.IPath) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) StorageException(org.eclipse.equinox.security.storage.StorageException)

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