use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DisplayContainerLogCommandHandler method execute.
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final IDockerConnection connection = CommandUtils.getCurrentConnection(activePart);
final List<IDockerContainer> selectedContainers = CommandUtils.getSelectedContainers(activePart);
if (selectedContainers.size() != 1 || connection == null) {
return null;
}
final IDockerContainer container = selectedContainers.get(0);
final String id = container.id();
final String name = container.name();
if (connection.getContainerInfo(id).config().tty()) {
RunConsole.attachToTerminal(connection, id, null);
return null;
}
try {
final RunConsole rc = RunConsole.findConsole(id);
if (rc != null) {
if (!rc.isAttached()) {
rc.attachToConsole(connection);
}
Display.getDefault().syncExec(() -> rc.setTitle(DVMessages.getFormattedString(CONTAINER_LOG_TITLE, name)));
OutputStream stream = rc.getOutputStream();
// Only bother to ask for a log if
// one isn't currently active
EnumDockerLoggingStatus status = ((DockerConnection) connection).loggingStatus(id);
if (status != EnumDockerLoggingStatus.LOGGING_ACTIVE && !((DockerConnection) connection).getContainerInfo(id).config().tty()) {
rc.clearConsole();
((DockerConnection) connection).logContainer(id, stream);
}
rc.showConsole();
}
} catch (DockerException | InterruptedException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_LOGGING_CONTAINER, id), e.getMessage()));
}
return null;
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class EnableConnectionCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof CommonNavigator) {
final CommonViewer viewer = ((CommonNavigator) activePart).getCommonViewer();
final ITreeSelection selection = (ITreeSelection) viewer.getSelection();
for (TreePath treePath : selection.getPaths()) {
final IDockerConnection conn = (IDockerConnection) treePath.getLastSegment();
if (!conn.isOpen()) {
final Job openConnectionJob = new Job(CommandMessages.getFormattedString(// $NON-NLS-1$
"command.enableconnection", conn.getUri())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
conn.open(true);
Display.getDefault().asyncExec(() -> viewer.refresh(conn));
} catch (DockerException e) {
Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
"command.enableconnection.failure"), e);
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
openConnectionJob.schedule();
}
}
}
return null;
}
use of org.eclipse.linuxtools.docker.core.DockerException 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();
}
use of org.eclipse.linuxtools.docker.core.DockerException 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();
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class RefreshCommandHandler method getRefreshJobs.
private List<Job> getRefreshJobs(final IWorkbenchPart activePart) {
final IDockerConnection connection = getCurrentConnection(activePart);
final ArrayList<Job> jobs = new ArrayList<>();
if (activePart instanceof DockerImagesView) {
jobs.add(getRefreshImagesJob(connection));
} else if (activePart instanceof DockerContainersView) {
jobs.add(getRefreshContainersJob(connection));
} else if (activePart instanceof DockerExplorerView) {
DockerExplorerView dockerExplorerView = (DockerExplorerView) activePart;
final ITreeSelection selection = dockerExplorerView.getCommonViewer().getStructuredSelection();
if (selection.getFirstElement() instanceof DockerContainersCategory) {
jobs.add(getRefreshContainersJob(connection));
} else if (selection.getFirstElement() instanceof DockerImagesCategory) {
jobs.add(getRefreshImagesJob(connection));
} else {
final IDockerConnection[] connections = DockerConnectionManager.getInstance().getConnections();
for (IDockerConnection selectedConnection : connections) {
if (!selectedConnection.isOpen()) {
try {
selectedConnection.open(true);
} catch (DockerException e) {
// do nothing
}
}
if (selectedConnection.isOpen()) {
jobs.add(getRefreshContainersJob(selectedConnection));
jobs.add(getRefreshImagesJob(selectedConnection));
}
}
}
}
return jobs;
}
Aggregations