forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
presented_job_state.go
41 lines (32 loc) · 1.06 KB
/
presented_job_state.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
package drain
import (
"encoding/json"
boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
// presentedJobState exposes only limited subset of apply spec to drain scripts.
// New fields should only be exposed once concrete use cases develop.
type presentedJobState struct {
applySpec *boshas.V1ApplySpec
}
type presentedJobStateEnvelope struct {
// PersistentDisk is exposed to determine if data needs to be migrated off
// when disk is completely removed or shrinks in size
PersistentDisk int `json:"persistent_disk"`
}
func newPresentedJobState(applySpec *boshas.V1ApplySpec) presentedJobState {
return presentedJobState{applySpec: applySpec}
}
func (js presentedJobState) MarshalToJSONString() (string, error) {
if js.applySpec == nil {
return "", nil
}
envelope := presentedJobStateEnvelope{
PersistentDisk: js.applySpec.PersistentDisk,
}
bytes, err := json.Marshal(envelope)
if err != nil {
return "", bosherr.WrapError(err, "Marshalling job state")
}
return string(bytes), nil
}