Search in sources :

Example 6 with DockerConnection

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

the class ContainerVMRunner method fileExists.

@Override
protected boolean fileExists(File file) {
    DockerConnection conn = ((ContainerVMInstall) fVMInstance).getConnection();
    ImageQuery q = new ImageQuery(conn, fVMInstance.getId());
    try {
        return q.isFile(file);
    } finally {
        q.destroy();
    }
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection)

Example 7 with DockerConnection

use of org.eclipse.linuxtools.internal.docker.core.DockerConnection 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 8 with DockerConnection

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

the class SearchDialogTest method mockResults.

private void mockResults() {
    final DockerClient client = MockDockerClientFactory.onSearch(IMAGE_NAME, MockImageSearchResultFactory.name(IMAGE_NAME).build(), MockImageSearchResultFactory.name("other/bar").build()).build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from(DEFAULT_CONNECTION_NAME, client).withDefaultTCPConnectionSettings();
    MockDockerConnectionManager.configureConnectionManager(dockerConnection);
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerClient(com.spotify.docker.client.DockerClient)

Example 9 with DockerConnection

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

the class EditDockerConnectionPage method onTestConnectionButtonSelection.

/**
 * Verifies that the given connection settings work by trying to connect to
 * the target Docker daemon
 *
 * @return
 */
private SelectionListener onTestConnectionButtonSelection() {
    return new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            try {
                getWizard().getContainer().run(true, false, monitor -> {
                    monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
                    "DockerConnectionPage.pingTask"), IProgressMonitor.UNKNOWN);
                    try {
                        final DockerConnection dockerConnection = getDockerConnection();
                        dockerConnection.open(false);
                        dockerConnection.close();
                        // ping succeeded
                        displaySuccessDialog();
                    } catch (DockerException e) {
                        // only log if there's an underlying cause.
                        if (e.getCause() != null) {
                            displayErrorDialog(e.getCause());
                        } else {
                            displayErrorDialog(e);
                        }
                    }
                });
            } catch (InvocationTargetException | InterruptedException o_O) {
                Activator.log(o_O);
            }
        }

        private void displaySuccessDialog() {
            displayDialog(WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.success"), WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.pingSuccess"), SWT.ICON_INFORMATION, new String[] { WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.ok") });
        }

        private void displayErrorDialog(final Throwable cause) {
            displayDialog(WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.failure"), WizardMessages.getFormattedString(// $NON-NLS-1$
            "DockerConnectionPage.pingFailure", cause.getMessage()), SWT.ICON_ERROR, new String[] { WizardMessages.getString(// $NON-NLS-1$
            "DockerConnectionPage.ok") });
        }

        private void displayDialog(final String dialogTitle, final String dialogMessage, final int icon, final String[] buttonLabels) {
            Display.getDefault().syncExec(() -> new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dialogTitle, null, dialogMessage, icon, buttonLabels, 0).open());
        }
    };
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with DockerConnection

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

the class DockerContainersViewSWTBotTest method shouldRemoveListenersWhenClosingView.

@Test
public void shouldRemoveListenersWhenClosingView() {
    // given
    final DockerClient client = MockDockerClientFactory.container(MockContainerFactory.name("angry_bar").status("Stopped").build()).build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    SWTUtils.getTreeItem(dockerExplorerBotView, "Test").select();
    // remove the DockerContainerRefreshManager
    dockerConnection.removeContainerListener(DockerContainerRefreshManager.getInstance());
    assertThat(dockerConnection.getContainerListeners()).hasSize(2);
    // close the Docker Containers View
    dockerContainersViewBot.close();
    // there should be one listener left: DockerExplorerView
    assertThat(dockerConnection.getContainerListeners()).hasSize(1);
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerClient(com.spotify.docker.client.DockerClient) Test(org.junit.Test)

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