Skip to content

Commit

Permalink
CHE-2927: Add logs for active containers checked by DockerContainerCl…
Browse files Browse the repository at this point in the history
…eaner. (#2950)

Signed-off-by: Aleksandr Andrienko <aandrienko@codenvy.com>
  • Loading branch information
AndrienkoAleksandr authored Nov 1, 2016
1 parent 60472f2 commit 2a0081e
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*/
Expand Down Expand Up @@ -59,19 +61,22 @@ public DockerContainerCleaner(CheEnvironmentEngine environmentEngine,
unit = TimeUnit.MINUTES)
@Override
public void run() {
List<String> activeContainers = new ArrayList<>();
try {
for (ContainerListEntry container : dockerConnector.listContainers()) {
Optional<ContainerNameInfo> optional = nameGenerator.parse(container.getNames()[0]);
String containerName = container.getNames()[0];
Optional<ContainerNameInfo> 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);
}
}
}
Expand All @@ -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) {
Expand Down

0 comments on commit 2a0081e

Please sign in to comment.