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
|
|
|
|
}
|
|
|
|
|
2017-07-25 23:23:22 +00:00
|
|
|
// convertApplyErrors parses the results of a raftApply and returns the index at
|
2017-08-07 21:13:05 +00:00
|
|
|
// 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.
|
2017-07-25 23:23:22 +00:00
|
|
|
// 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,
|
|
|
|
}
|
2017-07-25 23:23:22 +00:00
|
|
|
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) {
|
2017-07-25 23:23:22 +00:00
|
|
|
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) {
|
2017-07-25 23:23:22 +00:00
|
|
|
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) {
|
2017-07-25 23:23:22 +00:00
|
|
|
fsmErrIntf, index, raftErr := d.apply(structs.DeploymentAllocHealthRequestType, req)
|
|
|
|
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
|
2017-06-28 22:35:52 +00:00
|
|
|
}
|
2018-04-06 22:53:14 +00:00
|
|
|
|
2018-04-10 22:02:52 +00:00
|
|
|
func (d *deploymentWatcherRaftShim) UpdateAllocDesiredTransition(req *structs.AllocUpdateDesiredTransitionRequest) (uint64, error) {
|
2018-04-06 22:53:14 +00:00
|
|
|
fsmErrIntf, index, raftErr := d.apply(structs.AllocUpdateDesiredTransitionRequestType, req)
|
|
|
|
return d.convertApplyErrors(fsmErrIntf, index, raftErr)
|
|
|
|
}
|