use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class ContainerCommandProcess method waitFor.
@Override
public synchronized int waitFor() throws InterruptedException {
if (done) {
return 0;
}
try {
if (!threadDone) {
while (!threadStarted) {
Thread.sleep(200);
}
}
IDockerContainerExit exit = connection.waitForContainer(containerId);
done = true;
// give logging thread at most 5 seconds to finish
int i = 0;
while (!threadDone && i++ < 10) {
Thread.sleep(500);
}
if (!threadDone) {
// we are stuck
try {
Activator.logWarningMessage(LaunchMessages.getFormattedString(// $NON-NLS-1$
"ContainerLoggingNotResponding.msg", containerId.substring(0, 8)));
this.stdout.close();
this.stderr.close();
} catch (IOException e) {
// do nothing
}
}
if (!containerRemoved) {
connection.stopLoggingThread(containerId);
}
if (!containerRemoved && !keepContainer) {
exitValue = exitValue();
containerRemoved = true;
connection.removeContainer(containerId);
}
if (!((DockerConnection) connection).isLocal()) {
CopyVolumesFromImageJob job = new CopyVolumesFromImageJob(connection, imageName, remoteVolumes);
job.schedule();
job.join();
}
return exit.statusCode();
} catch (DockerException e) {
return -1;
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerComposeUpShortcut method launch.
@Override
protected void launch(IResource resource, String mode) {
// the predicate to apply on the launch configuration to find the
// matching candidates
final Predicate<ILaunchConfiguration> predicate = config -> {
try {
final String sourcePath = config.getAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR, // $NON-NLS-1$
"");
final boolean workspaceRelative = config.getAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, false);
final IPath dockerfilePath = getPath(sourcePath, workspaceRelative);
return dockerfilePath.equals(resource.getLocation().removeLastSegments(1));
} catch (CoreException e) {
Activator.log(e);
return false;
}
};
final ILaunchConfiguration config = findLaunchConfiguration(IDockerComposeLaunchConfigurationConstants.CONFIG_TYPE_ID, resource, predicate);
if (config != null) {
DebugUITools.launch(config, mode);
} else {
Activator.log(new DockerException(LaunchMessages.getString(// $NON-NLS-1$
"DockerComposeUpShortcut.launchconfig.error")));
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class RunImageLaunchConfigurationTabGroup method createTabs.
@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
runSelectionModel = null;
runVolumesModel = null;
runNetworkModel = null;
if (DockerConnectionManager.getInstance().hasConnections()) {
runSelectionModel = new ImageRunSelectionModel(CommandUtils.getCurrentConnection(null));
runNetworkModel = new ImageRunNetworkModel(CommandUtils.getCurrentConnection(null));
try {
runVolumesModel = new ImageRunResourceVolumesVariablesModel(CommandUtils.getCurrentConnection(null));
} catch (DockerException e) {
// do nothing
}
}
setTabs(new AbstractLaunchConfigurationTab[] { new RunImageMainTab(runSelectionModel, runVolumesModel, runNetworkModel), new RunImageVolumesTab(runVolumesModel), new RunImagePortsTab(runSelectionModel), new RunImageLinksTab(runSelectionModel), new RunImageNetworkTab(runNetworkModel), new RunImageEnvironmentTab(runVolumesModel), new RunImageLabelsTab(runVolumesModel), new RunImageResourcesTab(runVolumesModel), new org.eclipse.debug.ui.CommonTab() });
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerContainersView method setLabelFilterIds.
private void setLabelFilterIds() {
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
boolean filterLabels = preferences.getBoolean(FILTER_WITH_LABELS_PREFERENCE, Boolean.FALSE);
if (filterLabels) {
String filterLabelString = preferences.get(CONTAINER_FILTER_LABELS, // $NON-NLS-1$
"");
if (filterLabelString.isEmpty()) {
containersWithLabelsViewerFilter.setIds(null);
} else {
// $NON-NLS-1$
String[] labels = filterLabelString.split("\u00a0");
LinkedHashMap<String, String> labelMap = new LinkedHashMap<>();
for (String label : labels) {
if (label.length() > 1) {
// $NON-NLS-1$
String[] tokens = label.split("=");
String key = tokens[0];
// $NON-NLS-1$
String value = "";
if (tokens.length > 1)
value = tokens[1];
labelMap.put(key, value);
}
}
Set<String> filterIds = new HashSet<>();
try {
filterIds = ((DockerConnection) connection).getContainerIdsWithLabels(labelMap);
} catch (DockerException e) {
Activator.log(e);
}
containersWithLabelsViewerFilter.setIds(filterIds);
}
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerExplorerContentProvider method openRetry.
/**
* Call the {@link IDockerConnection#open(boolean)} in a background job to
* continually retry opening the connection and avoid blocking the UI.
*
* @param connection
* the connection to open/ping
*/
private void openRetry(final IDockerConnection connection) {
final Job openRetryJob = new LoadingJob(// $NON-NLS-1$
DVMessages.getFormattedString(// $NON-NLS-1$
"PingJob2.msg", connection.getName(), connection.getUri()), connection) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
setMonitor(monitor);
long totalSleep = 0;
// 3 second default
long sleepTime = 3000;
for (; ; ) {
try {
// check if Connection is removed or cancelled
if (monitor.isCanceled() || DockerConnectionManager.getInstance().getConnectionByUri(connection.getUri()) == null) {
synchronized (openRetryJobs) {
openRetryJobs.remove(connection);
}
return Status.CANCEL_STATUS;
}
connection.open(true);
connection.ping();
synchronized (openRetryJobs) {
openRetryJobs.remove(connection);
}
return Status.OK_STATUS;
} catch (DockerException e) {
// ignore
}
try {
Thread.sleep(sleepTime);
totalSleep += sleepTime;
// we never use.
if (totalSleep > 300000) {
// prevent a future overflow
totalSleep = 0;
sleepTime = Platform.getPreferencesService().getLong(// $NON-NLS-1$
"org.eclipse.linuxtools.docker.ui", // $NON-NLS-1$
"containerRefreshTime", // $NON-NLS-1$
15000, null);
}
} catch (InterruptedException e) {
synchronized (openRetryJobs) {
openRetryJobs.remove(connection);
}
return Status.CANCEL_STATUS;
}
}
}
};
synchronized (openRetryJobs) {
openRetryJobs.put(connection, openRetryJob);
}
openRetryJob.setSystem(true);
openRetryJob.schedule();
}
Aggregations