use of com.spotify.docker.client.messages.Container in project linuxtools by eclipse.
the class DockerConnection method listContainers.
private List<IDockerContainer> listContainers() throws DockerException {
final Map<String, IDockerContainer> updatedContainersById = new HashMap<>();
List<IDockerContainer> sortedContainers;
synchronized (containerLock) {
try {
final List<Container> nativeContainers = new ArrayList<>();
synchronized (clientLock) {
// containers list left in the queue
if (client == null) {
// there's no client.
return Collections.emptyList();
}
nativeContainers.addAll(client.listContainers(DockerClient.ListContainersParam.allContainers()));
}
// in the future.
for (Container nativeContainer : nativeContainers) {
// them with a logging thread.
if (nativeContainer.status() != null && nativeContainer.status().startsWith(Messages.Exited_specifier)) {
synchronized (loggingThreads) {
if (loggingThreads.containsKey(nativeContainer.id())) {
loggingThreads.get(nativeContainer.id()).requestStop();
loggingThreads.remove(nativeContainer.id());
}
}
}
// skip containers that are being removed
if (nativeContainer.status() != null && nativeContainer.status().equals(Messages.Removal_In_Progress_specifier)) {
continue;
}
// re-use info from existing container with same id
if (this.containers != null && this.containersById.containsKey(nativeContainer.id())) {
final IDockerContainer container = this.containersById.get(nativeContainer.id());
updatedContainersById.put(nativeContainer.id(), new DockerContainer(this, nativeContainer, container.info()));
} else {
updatedContainersById.put(nativeContainer.id(), new DockerContainer(this, nativeContainer));
}
}
} catch (DockerTimeoutException e) {
if (isOpen()) {
Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.Docker_Connection_Timeout, e));
close();
}
} catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
if (isOpen() && e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause() instanceof ProcessingException) {
close();
} else {
throw new DockerException(e.getMessage());
}
} finally {
this.containersById = updatedContainersById;
sortedContainers = sort(updatedContainersById.values(), (container, otherContainer) -> container.name().compareTo(otherContainer.name()));
this.containers = sortedContainers;
}
}
// perform notification outside of containerLock so we don't have a View
// causing a deadlock
// TODO: we should probably notify the listeners only if the containers
// list changed.
notifyContainerListeners(sortedContainers);
return sortedContainers;
}
Aggregations