Update list statuses to use filters

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-07-11 09:28:43 -07:00
parent 4322664b88
commit 46deddf460
8 changed files with 135 additions and 99 deletions

View File

@@ -68,7 +68,7 @@ type IngestManager interface {
// ListStatuses returns the status of any active ingestions whose ref match the
// provided regular expression. If empty, all active ingestions will be
// returned.
ListStatuses(ctx context.Context, ref string) ([]Status, error)
ListStatuses(ctx context.Context, filters ...string) ([]Status, error)
// Abort completely cancels the ingest operation targeted by ref.
Abort(ctx context.Context, ref string) error

View File

@@ -7,11 +7,11 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
"time"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/filters"
"github.com/containerd/containerd/log"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
@@ -140,7 +140,7 @@ func (s *store) Status(ctx context.Context, ref string) (Status, error) {
return s.status(s.ingestRoot(ref))
}
func (s *store) ListStatuses(ctx context.Context, re string) ([]Status, error) {
func (s *store) ListStatuses(ctx context.Context, fs ...string) ([]Status, error) {
fp, err := os.Open(filepath.Join(s.root, "ingest"))
if err != nil {
return nil, err
@@ -153,7 +153,7 @@ func (s *store) ListStatuses(ctx context.Context, re string) ([]Status, error) {
return nil, err
}
rec, err := regexp.Compile(re)
filter, err := filters.ParseAll(fs...)
if err != nil {
return nil, err
}
@@ -178,11 +178,9 @@ func (s *store) ListStatuses(ctx context.Context, re string) ([]Status, error) {
continue
}
if !rec.MatchString(stat.Ref) {
continue
if filter.Match(adaptStatus(stat)) {
active = append(active, stat)
}
active = append(active, stat)
}
return active, nil
@@ -210,6 +208,20 @@ func (s *store) status(ingestPath string) (Status, error) {
}, nil
}
func adaptStatus(status Status) filters.Adaptor {
return filters.AdapterFunc(func(fieldpath []string) (string, bool) {
if len(fieldpath) == 0 {
return "", false
}
switch fieldpath[0] {
case "ref":
return status.Ref, true
}
return "", false
})
}
// total attempts to resolve the total expected size for the write.
func (s *store) total(ingestPath string) int64 {
totalS, err := readFileString(filepath.Join(ingestPath, "total"))