forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.go
120 lines (100 loc) · 2.11 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
package db
import (
"fmt"
"sort"
"strings"
"time"
"github.com/concourse/atc"
)
type Volume struct {
Handle string
WorkerName string
TeamID int
ContainerTTL *time.Duration
TTL time.Duration
SizeInBytes int64
Identifier VolumeIdentifier
}
// pls gib algebraic data types
type VolumeIdentifier struct {
ResourceCache *ResourceCacheIdentifier
COW *COWIdentifier
Output *OutputIdentifier
Import *ImportIdentifier
Replication *ReplicationIdentifier
}
func (i VolumeIdentifier) Type() string {
switch {
case i.ResourceCache != nil:
return "cache"
case i.COW != nil:
return "copy"
case i.Output != nil:
return "output"
case i.Import != nil:
return "import"
case i.Replication != nil:
return "replication"
default:
return ""
}
}
func (i VolumeIdentifier) String() string {
switch {
case i.ResourceCache != nil:
return i.ResourceCache.String()
case i.COW != nil:
return i.COW.String()
case i.Output != nil:
return i.Output.String()
case i.Import != nil:
return i.Import.String()
case i.Replication != nil:
return i.Replication.String()
default:
return ""
}
}
type ResourceCacheIdentifier struct {
ResourceVersion atc.Version
ResourceHash string
}
func (i ResourceCacheIdentifier) String() string {
pairs := []string{}
for k, v := range i.ResourceVersion {
pairs = append(pairs, fmt.Sprintf("%s:%s", k, v))
}
sort.Sort(sort.StringSlice(pairs))
return strings.Join(pairs, ",")
}
type COWIdentifier struct {
ParentVolumeHandle string
}
func (i COWIdentifier) String() string {
return i.ParentVolumeHandle
}
type OutputIdentifier struct {
Name string
}
func (i OutputIdentifier) String() string {
return i.Name
}
type ReplicationIdentifier struct {
ReplicatedVolumeHandle string
}
func (i ReplicationIdentifier) String() string {
return i.ReplicatedVolumeHandle
}
type ImportIdentifier struct {
WorkerName string
Path string
Version *string
}
func (i ImportIdentifier) String() string {
return fmt.Sprintf("%s@%s", i.Path, *i.Version)
}
type SavedVolume struct {
Volume
ID int
ExpiresIn time.Duration
}