use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class StartContainersCommandHandler method executeInJob.
@Override
void executeInJob(final IDockerContainer container, final IDockerConnection connection) {
try {
final RunConsole console = getRunConsole(connection, container);
if (console != null) {
// if we are auto-logging, show the console
console.showConsole();
// Start the container
((DockerConnection) connection).startContainer(container.id(), console.getOutputStream());
} else {
((DockerConnection) connection).startContainer(container.id(), null);
}
((DockerConnection) connection).getContainers(true);
} catch (DockerException | InterruptedException e) {
final String errorMessage = DVMessages.getFormattedString(CONTAINER_START_ERROR_MSG, container.id());
openError(errorMessage, e);
}
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class RunConsole method attachToTerminal.
public static void attachToTerminal(final IDockerConnection connection, final String containerId, final DockerConsoleOutputStream out) {
Thread t = new Thread(() -> {
try {
DockerConnection conn = (DockerConnection) connection;
IDockerContainerState state = conn.getContainerInfo(containerId).state();
do {
if (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
Thread.sleep(300);
}
state = conn.getContainerInfo(containerId).state();
} while (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate())));
// Pause as there appears to be some timing issue with regards
// to the Container saying it is running, but an exception
// thrown when we try and attach.
Thread.sleep(300);
state = conn.getContainerInfo(containerId).state();
if (state.running()) {
conn.attachCommand(containerId, null, out);
} else {
// notify any console listener that there is no more output
// going to follow
out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
}
} catch (Exception e) {
Activator.log(e);
// notify any console listener that there is no more output
// going to follow
out.notifyConsoleListeners(new byte[] { 0 }, 0, 0);
}
});
t.start();
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class RunConsole method attachToConsole.
/**
* The console will be attached to the underlying container.
*
* @param connection
* The connection associated with this console.
*/
public void attachToConsole(final IDockerConnection connection) {
final InputStream in = getInputStream();
Thread t = new Thread(() -> {
try {
DockerConnection conn = (DockerConnection) connection;
if (conn.getContainerInfo(containerId).config().openStdin()) {
IDockerContainerState state = conn.getContainerInfo(containerId).state();
do {
if (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate()))) {
Thread.sleep(300);
}
state = conn.getContainerInfo(containerId).state();
} while (!state.running() && (state.finishDate() == null || state.finishDate().before(state.startDate())));
Thread.sleep(300);
state = conn.getContainerInfo(containerId).state();
if (state.running()) {
conn.attachCommand(containerId, in, null);
}
}
} catch (Exception e) {
Activator.log(e);
}
});
t.start();
attached = true;
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class BuildDockerImageJob method run.
@Override
protected IStatus run(final IProgressMonitor progressMonitor) {
try {
this.progressMonitor = progressMonitor;
final IPath pathToDockerfile = path.addTrailingSeparator().append(// $NON-NLS-1$
"Dockerfile");
if (verifyPathToDockerfile(pathToDockerfile)) {
final int numberOfBuildOperations = countLines(// $NON-NLS-1$
pathToDockerfile.toOSString());
if (numberOfBuildOperations == 0) {
Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, JobMessages.getString(SKIP_EMPTY_DOCKERFILE)));
} else {
this.console.clearConsole();
this.console.activate();
this.progressMonitor.beginTask(JobMessages.getString(BUILD_IMAGE_JOB_TITLE), numberOfBuildOperations + 1);
if (repoName == null) {
// Give the Image a default name so it can be tagged
// later.
// Otherwise, the Image will be treated as an
// intermediate
// Image
// by the view filters and Tag Image action will be
// disabled.
// Use the current time in milliseconds to make it
// unique.
final String name = // $NON-NLS-1$
"dockerfile:" + Long.toHexString(System.currentTimeMillis());
((DockerConnection) connection).buildImage(this.path, name, this, this.buildOptions);
} else {
((DockerConnection) connection).buildImage(this.path, this.repoName, this, this.buildOptions);
}
connection.getImages(true);
}
}
} catch (DockerException | InterruptedException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), JobMessages.getString(BUILD_IMAGE_ERROR_MESSAGE), e.getMessage()));
} finally {
// make sure the progress monitor is 'done' even if the build failed
// or
// timed out.
this.progressMonitor.done();
}
return Status.OK_STATUS;
}
use of org.eclipse.linuxtools.internal.docker.core.DockerConnection in project linuxtools by eclipse.
the class ContainerVMInstall method getName.
@Override
public String getName() {
if (name == null) {
DockerConnection conn = getConnection();
ImageQuery q = new ImageQuery(conn, image.id());
name = q.getDefaultJVMName();
q.destroy();
}
return name;
}
Aggregations