Search in sources :

Example 1 with DefaultImagePullProgressHandler

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

the class ImageRunSelectionPage method pullSelectedImage.

private void pullSelectedImage() {
    try {
        getContainer().run(true, true, monitor -> {
            final IDockerConnection connection = model.getSelectedConnection();
            final String imageName = model.getSelectedImageName();
            monitor.beginTask(WizardMessages.getFormattedString("ImageRunSelectionPage.pullingTask", // $NON-NLS-1$
            imageName), 1);
            try {
                connection.pullImage(imageName, new DefaultImagePullProgressHandler(connection, imageName));
            } catch (final DockerException e) {
                Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PULLING_IMAGE, imageName), e.getMessage()));
            } finally {
                monitor.done();
                // refresh the widgets
                model.refreshImageNames();
                if (model.getImageNames().contains(imageName)) {
                    model.setSelectedImageName(imageName);
                    model.setSelectedImageNeedsPulling(false);
                    // Force revalidation by changing writeValue which
                    // is made to be a dependency of the ImageCombo
                    // MultiValidator.
                    Display.getDefault().syncExec(() -> {
                        writeValue.setValue(Long.toString(System.currentTimeMillis()));
                    });
                }
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        Activator.log(e);
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DefaultImagePullProgressHandler(org.eclipse.linuxtools.internal.docker.core.DefaultImagePullProgressHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with DefaultImagePullProgressHandler

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

the class PullImageCommandHandler method performPullImage.

private void performPullImage(final IDockerConnection connection, final String imageName, final AbstractRegistry registry) {
    final Job pullImageJob = new Job(DVMessages.getFormattedString(PULL_IMAGE_JOB_TITLE, imageName)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(PULL_IMAGE_JOB_TASK), IProgressMonitor.UNKNOWN);
            // handler refresh the images when done
            try {
                if (registry == null || registry.isDockerHubRegistry()) {
                    ((DockerConnection) connection).pullImage(imageName, new DefaultImagePullProgressHandler(connection, imageName));
                } else {
                    String fullImageName = registry.getServerHost() + '/' + imageName;
                    if (registry instanceof IRegistryAccount) {
                        IRegistryAccount account = (IRegistryAccount) registry;
                        ((DockerConnection) connection).pullImage(fullImageName, account, new DefaultImagePullProgressHandler(connection, fullImageName));
                    } else {
                        ((DockerConnection) connection).pullImage(fullImageName, new DefaultImagePullProgressHandler(connection, fullImageName));
                    }
                }
            } catch (final DockerException e) {
                Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PULLING_IMAGE, imageName), e.getMessage()));
            // for now
            } catch (InterruptedException | DockerCertificateException e) {
            // do nothing
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    pullImageJob.schedule();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) Job(org.eclipse.core.runtime.jobs.Job) DefaultImagePullProgressHandler(org.eclipse.linuxtools.internal.docker.core.DefaultImagePullProgressHandler)

Aggregations

DockerException (org.eclipse.linuxtools.docker.core.DockerException)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 DefaultImagePullProgressHandler (org.eclipse.linuxtools.internal.docker.core.DefaultImagePullProgressHandler)2 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IRegistryAccount (org.eclipse.linuxtools.docker.core.IRegistryAccount)1 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)1