Search in sources :

Example 6 with DockerException

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

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

the class DockerConnection method attachCommand.

public void attachCommand(final String id, final InputStream in, @SuppressWarnings("unused") final DockerConsoleOutputStream out) throws DockerException {
    final byte[] prevCmd = new byte[1024];
    try {
        final LogStream pty_stream = client.attachContainer(id, AttachParameter.STDIN, AttachParameter.STDOUT, AttachParameter.STDERR, AttachParameter.STREAM, AttachParameter.LOGS);
        final IDockerContainerInfo info = getContainerInfo(id);
        final boolean isTtyEnabled = info.config().tty();
        final boolean isOpenStdin = info.config().openStdin();
        if (isTtyEnabled) {
            openTerminal(pty_stream, info.name(), out);
        }
        // Data from the given input stream
        // Written to container's STDIN
        Thread t_in = new Thread(() -> {
            byte[] buff = new byte[1024];
            int n;
            try {
                WritableByteChannel pty_out = HttpHijackWorkaround.getOutputStream(pty_stream, getUri());
                while ((n = in.read(buff)) != -1 && getContainerInfo(id).state().running()) {
                    synchronized (prevCmd) {
                        pty_out.write(ByteBuffer.wrap(buff, 0, n));
                        for (int i = 0; i < prevCmd.length; i++) {
                            prevCmd[i] = buff[i];
                        }
                    }
                    buff = new byte[1024];
                }
            } catch (Exception e) {
            }
        });
        if (!isTtyEnabled && isOpenStdin) {
            t_in.start();
        }
    } catch (Exception e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) WritableByteChannel(java.nio.channels.WritableByteChannel) LogStream(com.spotify.docker.client.LogStream) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) DockerPingConnectionException(org.eclipse.linuxtools.docker.core.DockerPingConnectionException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ProcessingException(javax.ws.rs.ProcessingException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StorageException(org.eclipse.equinox.security.storage.StorageException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerOpenConnectionException(org.eclipse.linuxtools.docker.core.DockerOpenConnectionException)

Example 8 with DockerException

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

the class DockerConnection method pushImage.

@Override
public void pushImage(final String name, final IRegistryAccount info, final IDockerProgressHandler handler) throws DockerException, InterruptedException {
    try {
        final DockerClient client = dockerClientFactory.getClient(this.connectionSettings, info);
        final DockerProgressHandler d = new DockerProgressHandler(handler);
        client.push(name, d);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException | DockerCertificateException e) {
        DockerException f = new DockerException(e);
        throw f;
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerProgressHandler(org.eclipse.linuxtools.docker.core.IDockerProgressHandler) DockerClient(com.spotify.docker.client.DockerClient) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException)

Example 9 with DockerException

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

the class DockerConnection method createNetwork.

@Override
public IDockerNetworkCreation createNetwork(IDockerNetworkConfig cfg) throws DockerException, InterruptedException {
    try {
        Ipam.Builder ipamBuilder = Ipam.builder().driver(cfg.ipam().driver());
        List<IDockerIpamConfig> ipamCfgs = cfg.ipam().config();
        for (IDockerIpamConfig ipamCfg : ipamCfgs) {
            ipamBuilder = ipamBuilder.config(ipamCfg.subnet(), ipamCfg.ipRange(), ipamCfg.gateway());
        }
        Ipam ipam = ipamBuilder.build();
        NetworkConfig.Builder networkConfigBuilder = NetworkConfig.builder().name(cfg.name()).driver(cfg.driver()).ipam(ipam);
        networkConfigBuilder.options(cfg.options());
        NetworkConfig networkConfig = networkConfigBuilder.build();
        com.spotify.docker.client.messages.NetworkCreation creation = client.createNetwork(networkConfig);
        return new DockerNetworkCreation(creation);
    } catch (com.spotify.docker.client.exceptions.DockerException e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) NetworkConfig(com.spotify.docker.client.messages.NetworkConfig) IDockerNetworkConfig(org.eclipse.linuxtools.docker.core.IDockerNetworkConfig) IDockerNetworkCreation(org.eclipse.linuxtools.docker.core.IDockerNetworkCreation) Ipam(com.spotify.docker.client.messages.Ipam) IDockerIpamConfig(org.eclipse.linuxtools.docker.core.IDockerIpamConfig)

Example 10 with DockerException

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

the class DockerConnection method getInfo.

@Override
public IDockerConnectionInfo getInfo() throws DockerException {
    if (this.client == null) {
        return null;
    }
    try {
        final Info info = this.client.info();
        final Version version = this.client.version();
        return new DockerConnectionInfo(info, version);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
        throw new DockerException(Messages.Docker_General_Info_Failure, e);
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerVersion(org.eclipse.linuxtools.docker.core.IDockerVersion) Version(com.spotify.docker.client.messages.Version) Info(com.spotify.docker.client.messages.Info) IDockerConnectionInfo(org.eclipse.linuxtools.docker.core.IDockerConnectionInfo) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) ImageInfo(com.spotify.docker.client.messages.ImageInfo) IDockerConnectionInfo(org.eclipse.linuxtools.docker.core.IDockerConnectionInfo)

Aggregations

DockerException (org.eclipse.linuxtools.docker.core.DockerException)80 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)27 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)19 Job (org.eclipse.core.runtime.jobs.Job)17 IOException (java.io.IOException)16 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)16 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)16 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)15 ArrayList (java.util.ArrayList)14 DockerClient (com.spotify.docker.client.DockerClient)13 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)10 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)9 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)8 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)7 ProcessingException (javax.ws.rs.ProcessingException)7 IPath (org.eclipse.core.runtime.IPath)7 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)7 LogStream (com.spotify.docker.client.LogStream)6 File (java.io.File)6 HashMap (java.util.HashMap)6