use of org.eclipse.che.plugin.docker.machine.DockerContainerNameGenerator.ContainerNameInfo in project che by eclipse.
the class DockerAbandonedResourcesCleaner method cleanContainers.
/**
* Cleans up CHE docker containers which don't tracked by API any more.
*/
@VisibleForTesting
void cleanContainers() {
List<String> activeContainers = new ArrayList<>();
try {
for (ContainerListEntry container : dockerConnector.listContainers()) {
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) {
cleanUpContainer(container);
} catch (Exception e) {
LOG.error(format("Failed to check activity for container with name '%s'. Cause: %s", containerName, e.getLocalizedMessage()), e);
}
}
}
} catch (IOException e) {
LOG.error("Failed to get list docker containers", e);
} catch (Exception e) {
LOG.error("Failed to clean up inactive containers", e);
}
LOG.info("List containers registered in the api: " + activeContainers);
}
Aggregations