use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class RestartContainersCommandHandler method executeInJob.
@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
try {
final RunConsole console = getRunConsole(connection, container);
long waitTime = Platform.getPreferencesService().getLong(// $NON-NLS-1$
"org.eclipse.linuxtools.docker.ui", PreferenceConstants.RESTART_WAIT_TIME, DEFAULT_WAIT_TIME, null);
if (console != null) {
// if we are auto-logging, show the console
console.showConsole();
// Start the container
((DockerConnection) connection).restartContainer(container.id(), (int) waitTime, console.getOutputStream());
} else {
((DockerConnection) connection).restartContainer(container.id(), (int) waitTime, null);
}
connection.getContainers(true);
} catch (DockerException | InterruptedException e) {
final String errorMessage = DVMessages.getFormattedString(CONTAINER_RESTART_ERROR_MSG, container.id());
openError(errorMessage, e);
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class ShowInSystemExplorerCommandHandler method execute.
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final List<DockerContainerVolume> volumes = CommandUtils.getSelectedVolumes(activePart);
if (volumes == null || volumes.isEmpty()) {
return null;
}
final DockerContainerVolume selectedVolume = volumes.get(0);
final File hostFile = new File(selectedVolume.getHostPath());
final String launchCmd = getShowInSystemExplorerCommand(hostFile);
if (launchCmd == null) {
return null;
}
final Job job = new Job(CommandMessages.getString("command.showIn.systemExplorer")) {
// $NON-NLS-1$
@Override
protected IStatus run(final IProgressMonitor monitor) {
try {
final Process p = getLaunchProcess(launchCmd, hostFile);
final int retCode = p.waitFor();
if (retCode != 0 && !Util.isWindows()) {
Activator.log(new DockerException(CommandMessages.getFormattedString(// $NON-NLS-1$
"command.showIn.systemExplorer.failure.command.execute", launchCmd, Integer.toString(retCode))));
}
} catch (IOException | InterruptedException e) {
Activator.logErrorMessage(CommandMessages.getFormattedString(// $NON-NLS-1$
"command.showIn.systemExplorer.failure", launchCmd), e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return null;
}
use of org.eclipse.linuxtools.docker.core.DockerException in project jbosstools-openshift by jbosstools.
the class PushImageToRegistryJob method doRun.
@Override
protected IStatus doRun(final IProgressMonitor monitor) {
monitor.beginTask("Pushing image to registry", 1);
final String tmpImageName = getPushToRegistryImageName();
try {
// first, we need to tag the image with the OpenShift target
// project
this.dockerConnection.tagImage(imageName, tmpImageName);
// then we can push that image with the new name
this.dockerConnection.pushImage(tmpImageName, registryAccount, getPushProgressHandler(tmpImageName));
// FIXME: needs more fined tuned error handling once Neon.0 is no longer supported:
// catch (DockerException | InterruptedException e) {
// see https://issues.jboss.org/browse/JBIDE-22764
} catch (Exception e) {
return new Status(IStatus.ERROR, OpenShiftCoreActivator.PLUGIN_ID, "Failed to push the selected Docker image into OpenShift registry", e);
} finally {
// we need to untag the image, even if the push operation failed
try {
this.dockerConnection.removeTag(tmpImageName);
} catch (DockerException | InterruptedException e) {
return new Status(IStatus.WARNING, OpenShiftCoreActivator.PLUGIN_ID, "Pushed the selected Docker image into OpenShift registry but failed to untag it afterwards", e);
}
monitor.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method startContainer.
@Override
public void startContainer(final String id, final OutputStream stream) throws DockerException, InterruptedException {
final IDockerContainerInfo containerInfo = getContainerInfo(id);
if (containerInfo == null) {
throw new DockerException(DockerMessages.getFormattedString("DockerContainerNotFound.error", // $NON-NLS-1$
id));
}
try {
// start container
client.startContainer(id);
// Log the started container if a stream is provided
if (stream != null && containerInfo != null && containerInfo.config() != null && !containerInfo.config().tty()) {
// display logs for container
synchronized (loggingThreads) {
LogThread t = loggingThreads.get(id);
if (t == null || !t.isAlive()) {
t = new LogThread(id, getClientCopy(), true);
loggingThreads.put(id, t);
t.setOutputStream(stream);
t.start();
}
}
}
// list of containers needs to be refreshed once the container started, to reflect it new state.
listContainers();
} catch (ContainerNotFoundException e) {
// clearly stated so report there was a problem starting the command
throw new DockerException(DockerMessages.getFormattedString("DockerStartContainer.error", // $NON-NLS-1$
getCmdString(containerInfo)));
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
throw new DockerException(e.message());
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method killContainer.
@Override
public void killContainer(final String id) throws DockerException, InterruptedException {
try {
// kill container
client.killContainer(id);
synchronized (loggingThreads) {
if (loggingThreads.containsKey(id)) {
loggingThreads.get(id).kill();
loggingThreads.remove(id);
}
}
// update container list
listContainers();
} catch (ContainerNotFoundException e) {
throw new DockerContainerNotFoundException(e);
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
// Permit kill to fail silently even on non-running containers
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
Aggregations