forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume_fetch_source.go
94 lines (80 loc) · 2.2 KB
/
volume_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
88
89
90
91
92
93
94
package resource
import (
"os"
"time"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc/worker"
)
type volumeFetchSource struct {
logger lager.Logger
volume worker.Volume
container worker.Container
cache Cache
versionedSource VersionedSource
worker worker.Worker
resourceOptions ResourceOptions
containerCreator FetchContainerCreator
}
func NewVolumeFetchSource(
logger lager.Logger,
volume worker.Volume,
worker worker.Worker,
resourceOptions ResourceOptions,
containerCreator FetchContainerCreator,
) FetchSource {
return &volumeFetchSource{
logger: logger,
volume: volume,
worker: worker,
cache: volumeCache{volume},
resourceOptions: resourceOptions,
versionedSource: NewGetVersionedSource(volume, resourceOptions.Version(), nil),
containerCreator: containerCreator,
}
}
func (s *volumeFetchSource) IsInitialized() (bool, error) {
return s.cache.IsInitialized()
}
func (s *volumeFetchSource) VersionedSource() VersionedSource {
return s.versionedSource
}
func (s *volumeFetchSource) LockName() (string, error) {
return s.resourceOptions.LockName(s.worker.Name())
}
func (s *volumeFetchSource) Initialize(signals <-chan os.Signal, ready chan<- struct{}) error {
var err error
s.container, err = s.containerCreator.CreateWithVolume(string(s.resourceOptions.ResourceType()), s.volume, s.worker)
if err != nil {
s.logger.Error("failed-to-create-container", err)
return err
}
s.versionedSource, err = NewResource(s.container).Get(
s.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 *volumeFetchSource) Release(finalTTL *time.Duration) {
s.volume.Release(finalTTL)
if s.container != nil {
s.container.Release(finalTTL)
}
}