github.com/emate/nomad@v0.8.2-wo-binpacking/nomad/deployment_watcher_shims.go (about) 1 package nomad 2 3 import ( 4 "github.com/hashicorp/nomad/nomad/structs" 5 ) 6 7 // deploymentWatcherRaftShim is the shim that provides the state watching 8 // methods. These should be set by the server and passed to the deployment 9 // watcher. 10 type deploymentWatcherRaftShim struct { 11 // apply is used to apply a message to Raft 12 apply raftApplyFn 13 } 14 15 // convertApplyErrors parses the results of a raftApply and returns the index at 16 // which it was applied and any error that occurred. Raft Apply returns two 17 // separate errors, Raft library errors and user returned errors from the FSM. 18 // This helper, joins the errors by inspecting the applyResponse for an error. 19 func (d *deploymentWatcherRaftShim) convertApplyErrors(applyResp interface{}, index uint64, err error) (uint64, error) { 20 if applyResp != nil { 21 if fsmErr, ok := applyResp.(error); ok && fsmErr != nil { 22 return index, fsmErr 23 } 24 } 25 return index, err 26 } 27 28 func (d *deploymentWatcherRaftShim) UpsertEvals(evals []*structs.Evaluation) (uint64, error) { 29 update := &structs.EvalUpdateRequest{ 30 Evals: evals, 31 } 32 fsmErrIntf, index, raftErr := d.apply(structs.EvalUpdateRequestType, update) 33 return d.convertApplyErrors(fsmErrIntf, index, raftErr) 34 } 35 36 func (d *deploymentWatcherRaftShim) UpsertJob(job *structs.Job) (uint64, error) { 37 job.SetSubmitTime() 38 update := &structs.JobRegisterRequest{ 39 Job: job, 40 } 41 fsmErrIntf, index, raftErr := d.apply(structs.JobRegisterRequestType, update) 42 return d.convertApplyErrors(fsmErrIntf, index, raftErr) 43 } 44 45 func (d *deploymentWatcherRaftShim) UpdateDeploymentStatus(u *structs.DeploymentStatusUpdateRequest) (uint64, error) { 46 fsmErrIntf, index, raftErr := d.apply(structs.DeploymentStatusUpdateRequestType, u) 47 return d.convertApplyErrors(fsmErrIntf, index, raftErr) 48 } 49 50 func (d *deploymentWatcherRaftShim) UpdateDeploymentPromotion(req *structs.ApplyDeploymentPromoteRequest) (uint64, error) { 51 fsmErrIntf, index, raftErr := d.apply(structs.DeploymentPromoteRequestType, req) 52 return d.convertApplyErrors(fsmErrIntf, index, raftErr) 53 } 54 55 func (d *deploymentWatcherRaftShim) UpdateDeploymentAllocHealth(req *structs.ApplyDeploymentAllocHealthRequest) (uint64, error) { 56 fsmErrIntf, index, raftErr := d.apply(structs.DeploymentAllocHealthRequestType, req) 57 return d.convertApplyErrors(fsmErrIntf, index, raftErr) 58 }