forked from vmware-archive/atc
/
volume.go
132 lines (102 loc) · 3.04 KB
/
volume.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package worker
import (
"io"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc/db"
"github.com/concourse/baggageclaim"
)
//go:generate counterfeiter . Volume
type Volume interface {
Handle() string
Path() string
SetProperty(key string, value string) error
Properties() (baggageclaim.VolumeProperties, error)
SetPrivileged(bool) error
StreamIn(path string, tarStream io.Reader) error
StreamOut(path string) (io.ReadCloser, error)
COWStrategy() baggageclaim.COWStrategy
InitializeResourceCache(db.UsedResourceCache) error
InitializeTaskCache(lager.Logger, int, string, string, bool) error
CreateChildForContainer(db.CreatingContainer, string) (db.CreatingVolume, error)
Destroy() error
}
type VolumeMount struct {
Volume Volume
MountPath string
}
type volume struct {
bcVolume baggageclaim.Volume
dbVolume db.CreatedVolume
volumeClient VolumeClient
}
func NewVolume(
bcVolume baggageclaim.Volume,
dbVolume db.CreatedVolume,
volumeClient VolumeClient,
) Volume {
return &volume{
bcVolume: bcVolume,
dbVolume: dbVolume,
volumeClient: volumeClient,
}
}
func (v *volume) Handle() string { return v.bcVolume.Handle() }
func (v *volume) Path() string { return v.bcVolume.Path() }
func (v *volume) SetProperty(key string, value string) error {
return v.bcVolume.SetProperty(key, value)
}
func (v *volume) SetPrivileged(privileged bool) error {
return v.bcVolume.SetPrivileged(privileged)
}
func (v *volume) StreamIn(path string, tarStream io.Reader) error {
return v.bcVolume.StreamIn(path, tarStream)
}
func (v *volume) StreamOut(path string) (io.ReadCloser, error) {
return v.bcVolume.StreamOut(path)
}
func (v *volume) Properties() (baggageclaim.VolumeProperties, error) {
return v.bcVolume.Properties()
}
func (v *volume) Destroy() error {
return v.bcVolume.Destroy()
}
func (v *volume) COWStrategy() baggageclaim.COWStrategy {
return baggageclaim.COWStrategy{
Parent: v.bcVolume,
}
}
func (v *volume) InitializeResourceCache(urc db.UsedResourceCache) error {
return v.dbVolume.InitializeResourceCache(urc)
}
func (v *volume) InitializeTaskCache(
logger lager.Logger,
jobID int,
stepName string,
path string,
privileged bool,
) error {
if v.dbVolume.ParentHandle() == "" {
return v.dbVolume.InitializeTaskCache(jobID, stepName, path)
}
logger.Debug("creating-an-import-volume", lager.Data{"path": v.bcVolume.Path()})
// always create, if there are any existing task cache volumes they will be gced
// after initialization of the current one
importVolume, err := v.volumeClient.CreateVolumeForTaskCache(
logger,
VolumeSpec{
Strategy: baggageclaim.ImportStrategy{Path: v.bcVolume.Path()},
Privileged: privileged,
},
v.dbVolume.TeamID(),
jobID,
stepName,
path,
)
if err != nil {
return err
}
return importVolume.InitializeTaskCache(logger, jobID, stepName, path, privileged)
}
func (v *volume) CreateChildForContainer(creatingContainer db.CreatingContainer, mountPath string) (db.CreatingVolume, error) {
return v.dbVolume.CreateChildForContainer(creatingContainer, mountPath)
}