forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cascading_blobstore.go
70 lines (57 loc) · 1.86 KB
/
cascading_blobstore.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
package blobstore
import (
utilblobstore "github.com/cloudfoundry/bosh-utils/blobstore"
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
const logTag = "cascadingBlobstore"
type cascadingBlobstore struct {
innerBlobstore utilblobstore.DigestBlobstore
blobManagers []BlobManagerInterface
logger boshlog.Logger
}
func NewCascadingBlobstore(
innerBlobstore utilblobstore.DigestBlobstore,
blobManagers []BlobManagerInterface,
logger boshlog.Logger,
) utilblobstore.DigestBlobstore {
return cascadingBlobstore{
innerBlobstore: innerBlobstore,
blobManagers: blobManagers,
logger: logger,
}
}
func (b cascadingBlobstore) Get(blobID string, digest boshcrypto.Digest) (string, error) {
for _, blobManager := range b.blobManagers {
if blobManager.BlobExists(blobID) {
blobPath, err := blobManager.GetPath(blobID, digest)
if err != nil {
return "", err
}
b.logger.Debug(logTag, "Found blob with BlobManager. BlobID: %s", blobID)
return blobPath, nil
}
}
return b.innerBlobstore.Get(blobID, digest)
}
func (b cascadingBlobstore) CleanUp(fileName string) error {
return b.innerBlobstore.CleanUp(fileName)
}
func (b cascadingBlobstore) Create(fileName string) (string, boshcrypto.MultipleDigest, error) {
return b.innerBlobstore.Create(fileName)
}
func (b cascadingBlobstore) Validate() error {
return b.innerBlobstore.Validate()
}
func (b cascadingBlobstore) Delete(blobID string) error {
for _, blobManager := range b.blobManagers {
if blobManager.BlobExists(blobID) {
return blobManager.Delete(blobID)
}
}
// We do not delete from the inner blobstore as external blobstores do not
// currently support deletion. Also, the bosh-agent should not be responsible
// for deleting blobs from the external blobstore which is managed by the
// BOSH Director.
return nil
}