From 2a0081e174e870420f4243e6b7cc00d40327458d Mon Sep 17 00:00:00 2001 From: Aleksandr Andrienko Date: Tue, 1 Nov 2016 17:53:08 +0200 Subject: [PATCH] CHE-2927: Add logs for active containers checked by DockerContainerCleaner. (#2950) Signed-off-by: Aleksandr Andrienko --- .../machine/cleaner/DockerContainerCleaner.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/cleaner/DockerContainerCleaner.java b/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/cleaner/DockerContainerCleaner.java index 06677a25b55..7b696bbb6e3 100644 --- a/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/cleaner/DockerContainerCleaner.java +++ b/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/cleaner/DockerContainerCleaner.java @@ -23,6 +23,8 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -31,7 +33,7 @@ import static org.eclipse.che.plugin.docker.machine.DockerContainerNameGenerator.ContainerNameInfo; /** - * Job for periodically clean up inactive docker containers + * Job for periodically clean up inactive docker containers and log list active containers. * * @author Alexander Andrienko */ @@ -59,19 +61,22 @@ public DockerContainerCleaner(CheEnvironmentEngine environmentEngine, unit = TimeUnit.MINUTES) @Override public void run() { + List activeContainers = new ArrayList<>(); try { for (ContainerListEntry container : dockerConnector.listContainers()) { - Optional optional = nameGenerator.parse(container.getNames()[0]); + String containerName = container.getNames()[0]; + Optional optional = nameGenerator.parse(containerName); if (optional.isPresent()) { try { // container is orphaned if not found exception is thrown environmentEngine.getMachine(optional.get().getWorkspaceId(), optional.get().getMachineId()); - + activeContainers.add(containerName); } catch (NotFoundException e) { cleanUp(container); } catch (Exception e) { - LOG.error("Failed to clean up inactive container. " + e.getLocalizedMessage(), e); + LOG.error(format("Failed to check activity for container with name '%s'. Cause: %s", + containerName, e.getLocalizedMessage()), e); } } } @@ -80,6 +85,7 @@ public void run() { } catch (Exception e) { LOG.error("Failed to clean up inactive containers", e); } + LOG.info("List containers registered in the api: " + activeContainers); } private void cleanUp(ContainerListEntry container) {