github.com/aminovpavel/nomad@v0.11.8/nomad/volumewatcher_shim.go (about) 1 package nomad 2 3 import ( 4 "github.com/hashicorp/nomad/nomad/structs" 5 ) 6 7 // volumeWatcherRaftShim is the shim that provides the state watching 8 // methods. These should be set by the server and passed to the volume 9 // watcher. 10 type volumeWatcherRaftShim 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 (shim *volumeWatcherRaftShim) 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 (shim *volumeWatcherRaftShim) UpsertVolumeClaims(req *structs.CSIVolumeClaimBatchRequest) (uint64, error) { 29 fsmErrIntf, index, raftErr := shim.apply(structs.CSIVolumeClaimBatchRequestType, req) 30 return shim.convertApplyErrors(fsmErrIntf, index, raftErr) 31 }