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);
}
}
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();
}
Aggregations