-
Notifications
You must be signed in to change notification settings - Fork 115
/
get_state.go
107 lines (88 loc) · 2.68 KB
/
get_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
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
package action
import (
"errors"
boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
boshjobsuper "github.com/cloudfoundry/bosh-agent/jobsupervisor"
boshvitals "github.com/cloudfoundry/bosh-agent/platform/vitals"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type GetStateAction struct {
settingsService boshsettings.Service
specService boshas.V1Service
jobSupervisor boshjobsuper.JobSupervisor
vitalsService boshvitals.Service
}
func NewGetState(
settingsService boshsettings.Service,
specService boshas.V1Service,
jobSupervisor boshjobsuper.JobSupervisor,
vitalsService boshvitals.Service,
) (action GetStateAction) {
action.settingsService = settingsService
action.specService = specService
action.jobSupervisor = jobSupervisor
action.vitalsService = vitalsService
return
}
func (a GetStateAction) IsAsynchronous(_ ProtocolVersion) bool {
return false
}
func (a GetStateAction) IsPersistent() bool {
return false
}
func (a GetStateAction) IsLoggable() bool {
return true
}
type GetStateV1ApplySpec struct {
boshas.V1ApplySpec
AgentID string `json:"agent_id"`
JobState string `json:"job_state"`
Vitals *boshvitals.Vitals `json:"vitals,omitempty"`
Processes []boshjobsuper.Process `json:"processes,omitempty"`
VM boshsettings.VM `json:"vm"`
}
func (a GetStateAction) Run(filters ...string) (GetStateV1ApplySpec, error) {
spec, err := a.specService.Get()
if err != nil {
return GetStateV1ApplySpec{}, bosherr.WrapError(err, "Getting current spec")
}
var vitals boshvitals.Vitals
var vitalsReference *boshvitals.Vitals
if len(filters) > 0 && filters[0] == "full" {
vitals, err = a.vitalsService.Get()
if err != nil {
return GetStateV1ApplySpec{}, bosherr.WrapError(err, "Building full vitals")
}
vitalsReference = &vitals
}
processes, err := a.jobSupervisor.Processes()
if err != nil {
return GetStateV1ApplySpec{}, bosherr.WrapError(err, "Getting processes status")
}
settings := a.settingsService.GetSettings()
value := GetStateV1ApplySpec{
spec,
settings.AgentID,
a.jobSupervisor.Status(),
vitalsReference,
processes,
settings.VM,
}
if value.NetworkSpecs == nil {
value.NetworkSpecs = map[string]boshas.NetworkSpec{}
}
if value.ResourcePoolSpecs == nil {
value.ResourcePoolSpecs = map[string]interface{}{}
}
if value.PackageSpecs == nil {
value.PackageSpecs = map[string]boshas.PackageSpec{}
}
return value, nil
}
func (a GetStateAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a GetStateAction) Cancel() error {
return errors.New("not supported")
}