use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.
the class DockerConnection method removeContainer.
@Override
public void removeContainer(final String id) throws DockerException, InterruptedException {
try {
// kill container
client.removeContainer(id);
// update container list
listContainers();
} 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.DockerContainerNotFoundException in project linuxtools by eclipse.
the class DockerConnection method createContainer.
@Override
public String createContainer(final IDockerContainerConfig c, IDockerHostConfig hc, final String containerName) throws DockerException, InterruptedException {
try {
HostConfig.Builder hbuilder = HostConfig.builder().containerIdFile(hc.containerIDFile()).publishAllPorts(hc.publishAllPorts()).privileged(hc.privileged()).networkMode(hc.networkMode()).readonlyRootfs(((DockerHostConfig) hc).readonlyRootfs());
if (((DockerHostConfig) hc).tmpfs() != null) {
hbuilder.tmpfs(ImmutableMap.copyOf(((DockerHostConfig) hc).tmpfs()));
}
if (((DockerHostConfig) hc).capAdd() != null) {
hbuilder.capAdd(((DockerHostConfig) hc).capAdd());
}
if (((DockerHostConfig) hc).capDrop() != null) {
hbuilder.capDrop(((DockerHostConfig) hc).capDrop());
}
if (hc.binds() != null)
hbuilder.binds(hc.binds());
if (hc.dns() != null)
hbuilder.dns(hc.dns());
if (hc.dnsSearch() != null)
hbuilder.dnsSearch(hc.dnsSearch());
if (hc.links() != null)
hbuilder.links(hc.links());
if (hc.lxcConf() != null) {
List<IDockerConfParameter> lxcconf = hc.lxcConf();
ArrayList<LxcConfParameter> lxcreal = new ArrayList<>();
for (IDockerConfParameter param : lxcconf) {
// TODO: Fix This
}
hbuilder.lxcConf(lxcreal);
}
if (hc.portBindings() != null) {
Map<String, List<IDockerPortBinding>> bindings = hc.portBindings();
HashMap<String, List<PortBinding>> realBindings = new HashMap<>();
for (Entry<String, List<IDockerPortBinding>> entry : bindings.entrySet()) {
String key = entry.getKey();
List<IDockerPortBinding> bindingList = entry.getValue();
ArrayList<PortBinding> newList = new ArrayList<>();
for (IDockerPortBinding binding : bindingList) {
newList.add(PortBinding.of(binding.hostIp(), binding.hostPort()));
}
realBindings.put(key, newList);
}
hbuilder.portBindings(realBindings);
}
if (hc.volumesFrom() != null) {
hbuilder.volumesFrom(hc.volumesFrom());
}
if (hc.securityOpt() != null) {
hbuilder.securityOpt(hc.securityOpt());
}
// interface
if (((DockerHostConfig) hc).memory() != null) {
hbuilder.memory(((DockerHostConfig) hc).memory());
}
// interface
if (((DockerHostConfig) hc).cpuShares() != null && ((DockerHostConfig) hc).cpuShares().longValue() > 0) {
hbuilder.cpuShares(((DockerHostConfig) hc).cpuShares());
}
ContainerConfig.Builder builder = ContainerConfig.builder().hostname(c.hostname()).domainname(c.domainname()).user(c.user()).attachStdin(c.attachStdin()).attachStdout(c.attachStdout()).attachStderr(c.attachStderr()).tty(c.tty()).openStdin(c.openStdin()).stdinOnce(c.stdinOnce()).cmd(c.cmd()).image(c.image()).hostConfig(hbuilder.build()).workingDir(c.workingDir()).labels(c.labels()).networkDisabled(c.networkDisabled());
// don't set those fields in the builder.
if (c.portSpecs() != null) {
builder = builder.portSpecs(c.portSpecs());
}
if (c.exposedPorts() != null) {
builder = builder.exposedPorts(c.exposedPorts());
}
if (c.env() != null) {
builder = builder.env(c.env());
}
if (c.volumes() != null) {
builder = builder.volumes(c.volumes());
}
if (c.entrypoint() != null) {
builder = builder.entrypoint(c.entrypoint());
}
if (c.onBuild() != null) {
builder = builder.onBuild(c.onBuild());
}
// create container with default random name if an empty/null
// containerName argument was passed
final ContainerCreation creation = client.createContainer(builder.build(), (containerName != null && !containerName.isEmpty()) ? containerName : null);
final String id = creation.id();
// force a refresh of the current containers to include the new one
listContainers();
return id;
} 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);
}
}
use of org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException in project linuxtools by eclipse.
the class DockerConnection method pauseContainer.
@Override
public void pauseContainer(final String id) throws DockerException, InterruptedException {
try {
// pause container
client.pauseContainer(id);
// update container list
listContainers();
} 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.DockerContainerNotFoundException 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.DockerContainerNotFoundException in project linuxtools by eclipse.
the class DockerConnection method killContainer.
@Override
public void killContainer(final String id) throws DockerException, InterruptedException {
try {
// kill container
client.killContainer(id);
synchronized (loggingThreads) {
if (loggingThreads.containsKey(id)) {
loggingThreads.get(id).kill();
loggingThreads.remove(id);
}
}
// update container list
listContainers();
} catch (ContainerNotFoundException e) {
throw new DockerContainerNotFoundException(e);
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
// Permit kill to fail silently even on non-running containers
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
Aggregations