Exemplo n.º 1
0
 public ByDateRecyclingStrategy(int daysBeforeDeletion, IMatchlist imageWhitelist, IMatchlist stateBlacklist, IDictionary <string, DateTime> imageLastTouchDate, ImageDeletionOrderType deletionOrder) : base(imageWhitelist, stateBlacklist)
 {
     if (daysBeforeDeletion < 0)
     {
         throw new ArgumentOutOfRangeException("daysBeforeDeletion");
     }
     this.DaysBeforeDeletion  = daysBeforeDeletion;
     this.ImageDeletionOrder  = deletionOrder;
     this._imageLastTouchDate = imageLastTouchDate;
 }
Exemplo n.º 2
0
        public ByDiskSpaceRecyclingStrategy(double sizeLimitInGigabyte, IMatchlist imageWhitelist, IMatchlist stateBlacklist, IDictionary <string, DateTime> imageLastTouchDate, ImageDeletionOrderType deletionOrder) : base(imageWhitelist, stateBlacklist)
        {
            if (sizeLimitInGigabyte < 0)
            {
                throw new ArgumentOutOfRangeException("sizeLimitInGigabyte");
            }

            this.SizeLimitInGigabyte = sizeLimitInGigabyte;
            this.ImageDeletionOrder  = deletionOrder;
            this._imageLastTouchDate = imageLastTouchDate;
        }
Exemplo n.º 3
0
 public DockerGarbageCollector(IDockerClient dockerClient,
                               DockerImageDependencyTreeBuilder dependencyGraphBuilder,
                               DockerRepositoryDescriptor repoDescriptor,
                               RecyclingStrategy recyclingStrategy,
                               IMatchlist containerStateBlacklist,
                               int executionIntervalInMinutes,
                               ILogger logger)
 {
     this._dockerClient            = dockerClient;
     this._dependencyGraphBuilder  = dependencyGraphBuilder;
     this._repoDescriptor          = repoDescriptor;
     this._containerStateBlacklist = containerStateBlacklist;
     this._logger = logger;
     this._executionIntervalInMinutes = executionIntervalInMinutes;
     this._recyclingStrategy          = recyclingStrategy;
 }
Exemplo n.º 4
0
        public int GetContainerCount(IMatchlist states)
        {
            var count = 0;

            foreach (var container in Containers)
            {
                // created      A container that has been created (e.g. with docker create) but not started
                // restarting   A container that is in the process of being restarted
                // running      A currently running container
                // paused       A container whose processes have been paused
                // exited       A container that ran and completed ("stopped" in other contexts, although a created container is technically also "stopped")
                // dead         A container that the daemon tried and failed to stop (usually due to a busy device or resource used by the container)
                // removing

                if (states.Match(container.State.Status))
                {
                    count++;
                }
            }
            return(count);
        }
 public void PrintDependencyGraph(IList <DockerImageNode> baseImageNodes, IList <DockerImageNode> highlights, IMatchlist containerStateBlacklist, int indent = 2, string highlightMarker = "<---")
 {
     Console.WriteLine("Image dependency graph:");
     foreach (var node in baseImageNodes)
     {
         _printDependencyGraph(node, highlights, containerStateBlacklist);
     }
 }
        private void _printDependencyGraph(DockerImageNode node, IList <DockerImageNode> highlights, IMatchlist containerStateBlacklist, int indentOffset = 0, int indent = 2, string highlightMarker = "<---")
        {
            Console.Write(_indent(indentOffset) + $"Image: {DockerImageNode.GetImageShortId(node.InspectResponse.ID)} ({node.InspectResponse.RepoTags.FirstOrDefault() ?? "<none>"}) {(int)((DateTime.UtcNow - node.InspectResponse.Created).TotalDays)} days {node.DiskSize/(1024*1024)} MB ");

            if (node.Containers.Count > 0)
            {
                Console.Write($"({node.GetContainerCount() - node.GetContainerCount(containerStateBlacklist)}/{node.Containers.Count}) ");
            }

            if (highlights.Any(i => string.Equals(i.InspectResponse.ID, node.InspectResponse.ID, StringComparison.InvariantCultureIgnoreCase)))
            {
                Console.Write($"{highlightMarker} {highlights.IndexOf(node) + 1}");
            }

            Console.WriteLine();

            foreach (var child in node.Children)
            {
                _printDependencyGraph(child, highlights, containerStateBlacklist, indentOffset + indent);
            }
        }
 public TestStrategy(IMatchlist imageWhitelist, IMatchlist stateBlacklist) : base(imageWhitelist, stateBlacklist)
 {
 }
Exemplo n.º 8
0
 public RecyclingStrategy(IMatchlist imageWhitelist, IMatchlist stateBlacklist)
 {
     this._imageWhitelist = imageWhitelist;
     this._stateBlacklist = stateBlacklist;
 }