Fix weird NotModifiedException bug (3.2.3)

This commit is contained in:
Tobias Eidelpes 2021-05-18 23:01:06 +02:00
parent ffbd44826b
commit ae25560fb5
2 changed files with 16 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package dst.ass3.elastic.impl;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.exception.NotModifiedException;
import com.github.dockerjava.core.DockerClientBuilder;
import dst.ass3.elastic.ContainerException;
import dst.ass3.elastic.ContainerInfo;
@ -26,15 +27,21 @@ public class ContainerService implements IContainerService {
@Override
public void stopContainer(String containerId) throws ContainerException {
containers.forEach(containerInfo -> {
if (containerInfo.getContainerId().equals(containerId)) {
containers.remove(containerInfo);
dockerClient.stopContainerCmd(containerId).exec();
dockerClient.removeContainerCmd(containerId).exec();
return;
boolean found = false;
for (ContainerInfo info : containers) {
if (info.getContainerId().equals(containerId)) {
containers.remove(info);
found = true;
break;
}
});
throw new ContainerNotFoundException("Container with id " + containerId + " not found");
}
if (!found)
throw new ContainerNotFoundException("Container with id " + containerId + " not found");
try {
dockerClient.stopContainerCmd(containerId).exec();
} catch (NotModifiedException ignored) {
}
}
@Override

View File

@ -10,8 +10,7 @@ public class ElasticityFactory implements IElasticityFactory {
@Override
public IContainerService createContainerService() {
// TODO
return null;
return new ContainerService();
}
@Override