use of org.eclipse.linuxtools.docker.core.DockerException 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.docker.core.DockerException in project linuxtools by eclipse.
the class UnpauseContainersCommandHandler 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
connection.unpauseContainer(container.id(), console.getOutputStream());
} else {
connection.unpauseContainer(container.id(), null);
}
} catch (DockerException | InterruptedException e) {
final String errorMessage = DVMessages.getFormattedString(CONTAINER_UNPAUSE_ERROR_MSG, container.id());
openError(errorMessage, e);
}
}
use of org.eclipse.linuxtools.docker.core.DockerException 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.docker.core.DockerException in project linuxtools by eclipse.
the class DockerComposeUpJob method run.
@Override
protected IStatus run(final IProgressMonitor monitor) {
final String dockerComposeInstallDir = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.DOCKER_COMPOSE_INSTALLATION_DIRECTORY);
final Thread commandThread = new Thread(() -> {
// open console view
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(dockerComposeConsole);
try {
// run the 'docker-compose up' command
final Process dockerComposeSystemProcess = DockerCompose.getInstance().up(this.connection, dockerComposeInstallDir, this.workingDir);
final ILaunch launch = new Launch(launchConfiguration, ILaunchManager.RUN_MODE, null);
final IProcess dockerComposeProcess = DebugPlugin.newProcess(launch, dockerComposeSystemProcess, // $NON-NLS-1$
"docker-compose up");
dockerComposeConsole.setDockerComposeProcess(// $NON-NLS-1$
dockerComposeProcess);
final int exitCode = dockerComposeSystemProcess.waitFor();
if (exitCode != 0) {
Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getDefault().getActiveShell(), JobMessages.getString(// $NON-NLS-1$
"DockerCompose.dialog.title"), JobMessages.getString(// $NON-NLS-1$
"DockerComposeUp.start.error")));
}
} catch (DockerCommandNotFoundException e) {
// just display the error to the user, there's no need to report
// an error in the log and in AERI for that.
Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), JobMessages.getString(// $NON-NLS-1$
"DockerCompose.dialog.title"), e.getMessage()));
} catch (DockerException | InterruptedException e) {
Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getCurrent().getActiveShell(), JobMessages.getString(// $NON-NLS-1$
"DockerCompose.dialog.title"), e.getMessage()));
Activator.log(e);
}
});
commandThread.start();
return Status.OK_STATUS;
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class NewDockerConnectionPage method onSearchButtonSelection.
private SelectionListener onSearchButtonSelection() {
return new SelectionAdapter() {
private String getVMDriverInstallDir() {
return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.VM_DRIVER_INSTALLATION_DIRECTORY);
}
private String getDockerMachineInstallDir() {
return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.DOCKER_MACHINE_INSTALLATION_DIRECTORY);
}
@Override
public void widgetSelected(SelectionEvent e) {
if (!checkDockerMachineInstallDirs()) {
return;
}
final String dockerMachineInstallDir = getDockerMachineInstallDir();
final String vmDriverInstallDir = getVMDriverInstallDir();
final Map<String, Boolean> allMachineStates = retrieveDockerMachineNames(dockerMachineInstallDir, vmDriverInstallDir);
final List<String> activeMachineNames = allMachineStates.entrySet().stream().filter((machineEntry) -> machineEntry.getValue().booleanValue()).map((machineEntry) -> machineEntry.getKey()).collect(Collectors.toList());
if (activeMachineNames.size() > 0) {
ListDialog connPrompt = new ListDialog(getShell());
connPrompt.setContentProvider(new ConnectionSelectionContentProvider());
connPrompt.setLabelProvider(new ConnectionSelectionLabelProvider());
connPrompt.setTitle(WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.title"));
connPrompt.setMessage(WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.message"));
connPrompt.setInput(activeMachineNames.toArray(new String[0]));
if (connPrompt.open() == 0 && connPrompt.getResult().length > 0) {
final String name = ((String) connPrompt.getResult()[0]);
model.setBindingMode(EnumDockerConnectionSettings.TCP_CONNECTION);
model.setConnectionName(name);
model.setUnixSocketPath(null);
try {
final String host = DockerMachine.getInstance().getHost(name, dockerMachineInstallDir, vmDriverInstallDir);
model.setTcpHost(host);
} catch (DockerException e1) {
Activator.log(e1);
}
try {
final String certPath = DockerMachine.getInstance().getCertPath(name, dockerMachineInstallDir, vmDriverInstallDir);
if (certPath != null) {
model.setTcpTLSVerify(true);
model.setTcpCertPath(certPath);
} else {
model.setTcpTLSVerify(false);
model.setTcpCertPath(null);
}
} catch (DockerException e1) {
Activator.log(e1);
}
}
} else {
if (allMachineStates.size() == 1) {
MessageDialog.openInformation(getShell(), WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.discovery.title"), WizardMessages.getFormattedString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.discovery.innactive.single", allMachineStates.entrySet().iterator().next().getKey()));
} else if (allMachineStates.size() > 1) {
final String allMachineNames = allMachineStates.entrySet().stream().map((machineEntry) -> machineEntry.getKey()).collect(Collectors.joining(", "));
MessageDialog.openInformation(getShell(), WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.discovery.title"), WizardMessages.getFormattedString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.discovery.innactive.multiple", allMachineNames));
} else {
MessageDialog.openInformation(getShell(), WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.discovery.title"), WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.searchDialog.discovery.empty"));
}
}
}
/**
* Verifies that the install dirs for Docker Machine and its driver
* are valid, otherwise offers to open the preference page to fix
* the settings.
*
* @return <code>true</code> if the settings are valid,
* <code>false</code> otherwise.
*/
private boolean checkDockerMachineInstallDirs() {
if (!validDockerMachineInstallDirs()) {
final boolean confirm = MessageDialog.openConfirm(getShell(), WizardMessages.getString(// $NON-NLS-1$
"DockerMachineSupport.title"), WizardMessages.getString(// $NON-NLS-1$
"DockerMachineSupport.message"));
if (confirm) {
PreferencesUtil.createPreferenceDialogOn(getShell(), DOCKER_MACHINE_PREFERENCE_PAGE_ID, new String[] { DOCKER_MACHINE_PREFERENCE_PAGE_ID }, null).open();
// after user input data, check again
if (!validDockerMachineInstallDirs()) {
MessageDialog.openError(getShell(), WizardMessages.getString(// $NON-NLS-1$
"DockerMachineSupport.title"), WizardMessages.getString(// $NON-NLS-1$
"DockerMachineSupport.message.invalid"));
return false;
}
} else {
return false;
}
}
return true;
}
/**
* @return <code>true</code> if the install dirs for Docker Machine
* and its drivers are valid, <code>false</code> otherwise.
*/
private boolean validDockerMachineInstallDirs() {
return DockerMachine.getInstance().checkPathToDockerMachine(getDockerMachineInstallDir()) && // $NON-NLS-1$
!getVMDriverInstallDir().equals("");
}
/**
* Retrieves the docker machine names along with a boolean flag to
* indicate if it is running or not.
*
* @param dockerMachineInstallDir
* @param vmDriverInstallDir
* @return
*/
private Map<String, Boolean> retrieveDockerMachineNames(final String dockerMachineInstallDir, final String vmDriverInstallDir) {
try {
final String[] dmNames = DockerMachine.getInstance().getNames(dockerMachineInstallDir);
return java.util.stream.Stream.of(dmNames).collect(Collectors.toMap(name -> name, name -> {
try {
return DockerMachine.getInstance().getHost(name, dockerMachineInstallDir, vmDriverInstallDir) != null;
} catch (DockerException e) {
Activator.log(e);
return false;
}
}));
} catch (DockerException e) {
Activator.log(e);
return Collections.emptyMap();
}
}
};
}
Aggregations