open-nomad/nomad/deployment_watcher_shims.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
2.2 KiB
Go
Raw Normal View History

2017-06-28 22:35:52 +00:00
package nomad
2017-06-29 05:00:18 +00:00
import (
"github.com/hashicorp/nomad/nomad/structs"
)
2017-06-28 22:35:52 +00:00
// deploymentWatcherRaftShim is the shim that provides the state watching
// methods. These should be set by the server and passed to the deployment
// watcher.
type deploymentWatcherRaftShim struct {
// apply is used to apply a message to Raft
apply raftApplyFn
}
// convertApplyErrors parses the results of a raftApply and returns the index at
// which it was applied and any error that occurred. Raft Apply returns two
// separate errors, Raft library errors and user returned errors from the FSM.
// This helper, joins the errors by inspecting the applyResponse for an error.
func (d *deploymentWatcherRaftShim) convertApplyErrors(applyResp interface{}, index uint64, err error) (uint64, error) {
if applyResp != nil {
if fsmErr, ok := applyResp.(error); ok && fsmErr != nil {
return index, fsmErr
}
}
return index, err
}
2017-06-28 22:35:52 +00:00
func (d *deploymentWatcherRaftShim) UpsertJob(job *structs.Job) (uint64, error) {
2017-06-30 02:08:25 +00:00
job.SetSubmitTime()
2017-06-28 22:35:52 +00:00
update := &structs.JobRegisterRequest{
Job: job,
}
fsmErrIntf, index, raftErr := d.apply(structs.JobRegisterRequestType, update)
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
2017-06-28 22:35:52 +00:00
}
2017-07-03 19:05:01 +00:00
func (d *deploymentWatcherRaftShim) UpdateDeploymentStatus(u *structs.DeploymentStatusUpdateRequest) (uint64, error) {
fsmErrIntf, index, raftErr := d.apply(structs.DeploymentStatusUpdateRequestType, u)
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
2017-06-28 22:35:52 +00:00
}
2017-07-03 19:05:01 +00:00
func (d *deploymentWatcherRaftShim) UpdateDeploymentPromotion(req *structs.ApplyDeploymentPromoteRequest) (uint64, error) {
fsmErrIntf, index, raftErr := d.apply(structs.DeploymentPromoteRequestType, req)
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
2017-06-28 22:35:52 +00:00
}
2017-07-03 19:05:01 +00:00
func (d *deploymentWatcherRaftShim) UpdateDeploymentAllocHealth(req *structs.ApplyDeploymentAllocHealthRequest) (uint64, error) {
fsmErrIntf, index, raftErr := d.apply(structs.DeploymentAllocHealthRequestType, req)
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
2017-06-28 22:35:52 +00:00
}
2018-04-10 22:02:52 +00:00
func (d *deploymentWatcherRaftShim) UpdateAllocDesiredTransition(req *structs.AllocUpdateDesiredTransitionRequest) (uint64, error) {
fsmErrIntf, index, raftErr := d.apply(structs.AllocUpdateDesiredTransitionRequestType, req)
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
}