forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_fetch_source.go
87 lines (73 loc) · 1.95 KB
/
container_fetch_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package resource
import (
"os"
"time"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc/worker"
)
type containerFetchSource struct {
logger lager.Logger
container worker.Container
versionedSource VersionedSource
cache Cache
resourceOptions ResourceOptions
}
func NewContainerFetchSource(
logger lager.Logger,
container worker.Container,
resourceOptions ResourceOptions,
) FetchSource {
mounts := container.VolumeMounts()
var cache Cache
cache = noopCache{}
for _, mount := range mounts {
if mount.MountPath == ResourcesDir("get") {
cache = volumeCache{mount.Volume}
}
}
return &containerFetchSource{
logger: logger,
container: container,
cache: cache,
resourceOptions: resourceOptions,
versionedSource: NewGetVersionedSource(cache.Volume(), resourceOptions.Version(), nil),
}
}
func (s *containerFetchSource) IsInitialized() (bool, error) {
return s.cache.IsInitialized()
}
func (s *containerFetchSource) VersionedSource() VersionedSource {
return s.versionedSource
}
func (s *containerFetchSource) LockName() (string, error) {
return s.resourceOptions.LockName(s.container.WorkerName())
}
func (s *containerFetchSource) Initialize(signals <-chan os.Signal, ready chan<- struct{}) error {
var err error
s.versionedSource, err = NewResource(s.container).Get(
s.cache.Volume(),
s.resourceOptions.IOConfig(),
s.resourceOptions.Source(),
s.resourceOptions.Params(),
s.resourceOptions.Version(),
signals,
ready,
)
if err == ErrAborted {
s.logger.Error("get-run-resource-aborted", err, lager.Data{"container": s.container.Handle()})
return ErrInterrupted
}
if err != nil {
s.logger.Error("failed-to-fetch-resource", err)
return err
}
err = s.cache.Initialize()
if err != nil {
s.logger.Error("failed-to-initialize-cache", err)
return err
}
return nil
}
func (s *containerFetchSource) Release(finalTTL *time.Duration) {
s.container.Release(finalTTL)
}