use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method pullImage.
@Override
public void pullImage(final String imageId, final IRegistryAccount info, final IDockerProgressHandler handler) throws DockerException, InterruptedException, DockerCertificateException {
try {
final DockerClient client = dockerClientFactory.getClient(this.connectionSettings, info);
final DockerProgressHandler d = new DockerProgressHandler(handler);
client.pull(imageId, d);
listImages();
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
throw new DockerException(e.message());
} catch (com.spotify.docker.client.exceptions.DockerException e) {
DockerException f = new DockerException(e);
throw f;
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method containerChanges.
@Override
public List<IDockerContainerChange> containerChanges(final String id) throws DockerException, InterruptedException {
List<IDockerContainerChange> containerChanges = new ArrayList<>();
try {
DockerClient copy = getClientCopy();
List<ContainerChange> changes = copy.inspectContainerChanges(id);
for (ContainerChange change : changes) {
containerChanges.add(new DockerContainerChange(change.path(), change.kind()));
}
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
return containerChanges;
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method getContainerIdsWithLabels.
public Set<String> getContainerIdsWithLabels(Map<String, String> labels) throws DockerException {
Set<String> labelSet = new HashSet<>();
try {
final List<Container> nativeContainers = new ArrayList<>();
synchronized (clientLock) {
// containers list left in the queue
if (client == null) {
// there's no client.
return Collections.emptySet();
}
DockerClient clientCopy = getClientCopy();
DockerClient.ListContainersParam[] parms = new DockerClient.ListContainersParam[2];
parms[0] = DockerClient.ListContainersParam.allContainers();
// DockerClient doesn't support multiple labels with its
// ListContainersParam so we have
// to do a kludge and put in control chars ourselves and pretend
// we have a label with no value.
// $NON-NLS-1$
String separator = "";
StringBuffer labelString = new StringBuffer();
for (Entry<String, String> entry : labels.entrySet()) {
labelString.append(separator);
if (// $NON-NLS-1$
entry.getValue() == null || "".equals(entry.getValue()))
labelString.append(entry.getKey());
else {
labelString.append(// $NON-NLS-1$
entry.getKey() + "=" + entry.getValue());
}
// $NON-NLS-1$
separator = "\",\"";
}
parms[1] = DockerClient.ListContainersParam.withLabel(labelString.toString());
nativeContainers.addAll(clientCopy.listContainers(parms));
}
// Containers
for (Container nativeContainer : nativeContainers) {
labelSet.add(nativeContainer.id());
}
} 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());
}
}
return labelSet;
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method logContainer.
@Override
public void logContainer(final String id, final OutputStream stream) throws DockerException, InterruptedException {
try {
// or keep running
synchronized (loggingThreads) {
ContainerInfo info = client.inspectContainer(id);
LogThread t = loggingThreads.get(id);
if (t == null || !t.isAlive()) {
t = new LogThread(id, getClientCopy(), info.state().running());
loggingThreads.put(id, t);
t.setOutputStream(stream);
t.start();
} else {
// we aren't going to use the stream given...close it
try {
stream.close();
} catch (IOException e) {
// do nothing...we tried to close the stream
}
}
}
} catch (ContainerNotFoundException e) {
throw new DockerContainerNotFoundException(e);
} 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 attachLog.
@Override
public void attachLog(final String id, final OutputStream out, final OutputStream err) throws DockerException, InterruptedException, IOException {
DockerClient copyClient;
try {
copyClient = getClientCopy();
LogStream stream = copyClient.logs(id, LogsParam.follow(), LogsParam.stdout(), LogsParam.stderr());
stream.attach(out, err);
stream.close();
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
Aggregations