Search in sources :

Example 1 with AbstractRegistry

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

the class PushImageCommandHandler method performPushImage.

private void performPushImage(final ImagePush wizard, final IDockerConnection connection) {
    if (connection == null) {
        Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PUSHING_IMAGE, wizard.getSelectedImageTag()), DVMessages.getFormattedString(NO_CONNECTION)));
        return;
    }
    final Job pushImageJob = new Job(DVMessages.getFormattedString(PUSH_IMAGE_JOB_TITLE, wizard.getSelectedImageTag())) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            final IDockerImage image = wizard.getImage();
            final String defaultImageNameTag = wizard.getDefaultImageName();
            final String selectedImageNameTag = wizard.getSelectedImageTag();
            // TODO: remove cast once AbstractRegistry methods are
            // part of the IRegistry interface
            final AbstractRegistry registry = (AbstractRegistry) wizard.getRegistry();
            final boolean forceTagging = wizard.isForceTagging();
            final boolean keepTaggedImage = wizard.isKeepTaggedImage();
            monitor.beginTask(DVMessages.getString(PUSH_IMAGE_JOB_TASK), IProgressMonitor.UNKNOWN);
            // push the image and let the progress
            // handler refresh the images when done
            final String tmpRegistryTag = getNameToTag(selectedImageNameTag, registry);
            boolean tagCreated = false;
            try {
                // selected)
                if (!image.repoTags().contains(tmpRegistryTag) || forceTagging) {
                    // TODO: remove cast to DockerConnection once the
                    // 'tagImage' is added in the public API
                    ((DockerConnection) connection).tagImage(defaultImageNameTag, tmpRegistryTag, forceTagging);
                    tagCreated = true;
                }
                // push image
                if (!registry.isAuthProvided()) {
                    connection.pushImage(tmpRegistryTag, new DefaultImagePushProgressHandler(connection, tmpRegistryTag));
                } else {
                    final IRegistryAccount registryAccount = (IRegistryAccount) registry;
                    connection.pushImage(tmpRegistryTag, registryAccount, new DefaultImagePushProgressHandler(connection, tmpRegistryTag));
                }
            } catch (final DockerException e) {
                Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PUSHING_IMAGE, defaultImageNameTag), e.getMessage()));
                Activator.logErrorMessage(DVMessages.getFormattedString(ERROR_PUSHING_IMAGE, defaultImageNameTag), e);
            // for now
            } catch (InterruptedException e) {
            // do nothing
            } finally {
                if (tagCreated && !keepTaggedImage) {
                    try {
                        connection.removeTag(tmpRegistryTag);
                        connection.getImages(true);
                    } catch (Exception e) {
                    // do nothing
                    }
                }
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    pushImageJob.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) AbstractRegistry(org.eclipse.linuxtools.docker.core.AbstractRegistry) DefaultImagePushProgressHandler(org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) Job(org.eclipse.core.runtime.jobs.Job) DockerException(org.eclipse.linuxtools.docker.core.DockerException)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 AbstractRegistry (org.eclipse.linuxtools.docker.core.AbstractRegistry)1 DockerException (org.eclipse.linuxtools.docker.core.DockerException)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)1 IRegistryAccount (org.eclipse.linuxtools.docker.core.IRegistryAccount)1 DefaultImagePushProgressHandler (org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler)1 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)1