|
20 | 20 | */ |
21 | 21 | package eu.openanalytics.containerproxy.backend.docker; |
22 | 22 |
|
| 23 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 24 | +import com.fasterxml.jackson.databind.ObjectMapper; |
23 | 25 | import eu.openanalytics.containerproxy.ContainerFailedToStartException; |
24 | 26 | import eu.openanalytics.containerproxy.event.NewProxyEvent; |
25 | 27 | import eu.openanalytics.containerproxy.model.runtime.Container; |
|
48 | 50 | import org.mandas.docker.client.messages.ContainerConfig; |
49 | 51 | import org.mandas.docker.client.messages.ContainerCreation; |
50 | 52 | import org.mandas.docker.client.messages.ContainerInfo; |
| 53 | +import org.mandas.docker.client.messages.ContainerState; |
51 | 54 | import org.mandas.docker.client.messages.HostConfig; |
52 | 55 | import org.mandas.docker.client.messages.PortBinding; |
53 | 56 | import org.mandas.docker.client.messages.RegistryAuth; |
@@ -307,7 +310,24 @@ public List<ExistingContainerInfo> scanExistingContainers() throws Exception { |
307 | 310 |
|
308 | 311 | @Override |
309 | 312 | public boolean isProxyHealthy(Proxy proxy) { |
310 | | - return true; // TODO |
| 313 | + for (Container container : proxy.getContainers()) { |
| 314 | + try { |
| 315 | + ContainerInfo info = dockerClient.inspectContainer(container.getId()); |
| 316 | + ContainerState state = info.state(); |
| 317 | + if (!state.running() || !state.status().equals("running")) { |
| 318 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 319 | + slog.warn(proxy, "Docker container failed: container not running, state reported by docker: " + objectMapper.writeValueAsString(state)); |
| 320 | + return false; |
| 321 | + } |
| 322 | + return true; |
| 323 | + } catch (ContainerNotFoundException e) { |
| 324 | + slog.warn(proxy, "Docker container failed: container does not exist"); |
| 325 | + return false; |
| 326 | + } catch (DockerException | InterruptedException | JsonProcessingException e) { |
| 327 | + throw new RuntimeException(e); |
| 328 | + } |
| 329 | + } |
| 330 | + return true; |
311 | 331 | } |
312 | 332 |
|
313 | 333 | @Override |
|
0 commit comments