This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cppforlife/bosh-provisioner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
concrete_jobs_repository.go
86 lines (68 loc) · 1.81 KB
/
concrete_jobs_repository.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
package jobsrepo
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
bpindex "github.com/cppforlife/bosh-provisioner/index"
bprel "github.com/cppforlife/bosh-provisioner/release"
)
type CJRepository struct {
index bpindex.Index
logger boshlog.Logger
}
type jobToJobKey struct {
JobName string
JobVersion string
// Fingerprint of a job captures its dependenices; however,
// that does not capture package changes in an associated release.
JobFingerprint string
}
func NewConcreteJobsRepository(
index bpindex.Index,
logger boshlog.Logger,
) CJRepository {
return CJRepository{
index: index,
logger: logger,
}
}
func (r CJRepository) Find(job bprel.Job) (JobRecord, bool, error) {
var record JobRecord
err := r.index.Find(r.key(job), &record)
if err != nil {
if err == bpindex.ErrNotFound {
return record, false, nil
}
return record, false, bosherr.WrapError(err, "Finding job record")
}
return record, true, nil
}
func (r CJRepository) FindByReleaseJob(rec ReleaseJobRecord) (JobRecord, bool, error) {
var record JobRecord
key := jobToJobKey{
JobName: rec.JobName,
JobVersion: rec.JobVersion,
JobFingerprint: rec.JobFingerprint,
}
err := r.index.Find(key, &record)
if err != nil {
if err == bpindex.ErrNotFound {
return record, false, nil
}
return record, false, bosherr.WrapError(err, "Finding job record")
}
return record, true, nil
}
func (r CJRepository) Save(job bprel.Job, record JobRecord) error {
err := r.index.Save(r.key(job), record)
if err != nil {
return bosherr.WrapError(err, "Saving job record")
}
return nil
}
func (r CJRepository) key(job bprel.Job) jobToJobKey {
return jobToJobKey{
JobName: job.Name,
JobVersion: job.Version,
JobFingerprint: job.Fingerprint,
}
}