github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/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) UpsertJob(job *structs.Job) (uint64, error) {
    29  	job.SetSubmitTime()
    30  	update := &structs.JobRegisterRequest{
    31  		Job: job,
    32  	}
    33  	fsmErrIntf, index, raftErr := d.apply(structs.JobRegisterRequestType, update)
    34  	return d.convertApplyErrors(fsmErrIntf, index, raftErr)
    35  }
    36  
    37  func (d *deploymentWatcherRaftShim) UpdateDeploymentStatus(u *structs.DeploymentStatusUpdateRequest) (uint64, error) {
    38  	fsmErrIntf, index, raftErr := d.apply(structs.DeploymentStatusUpdateRequestType, u)
    39  	return d.convertApplyErrors(fsmErrIntf, index, raftErr)
    40  }
    41  
    42  func (d *deploymentWatcherRaftShim) UpdateDeploymentPromotion(req *structs.ApplyDeploymentPromoteRequest) (uint64, error) {
    43  	fsmErrIntf, index, raftErr := d.apply(structs.DeploymentPromoteRequestType, req)
    44  	return d.convertApplyErrors(fsmErrIntf, index, raftErr)
    45  }
    46  
    47  func (d *deploymentWatcherRaftShim) UpdateDeploymentAllocHealth(req *structs.ApplyDeploymentAllocHealthRequest) (uint64, error) {
    48  	fsmErrIntf, index, raftErr := d.apply(structs.DeploymentAllocHealthRequestType, req)
    49  	return d.convertApplyErrors(fsmErrIntf, index, raftErr)
    50  }
    51  
    52  func (d *deploymentWatcherRaftShim) UpdateAllocDesiredTransition(req *structs.AllocUpdateDesiredTransitionRequest) (uint64, error) {
    53  	fsmErrIntf, index, raftErr := d.apply(structs.AllocUpdateDesiredTransitionRequestType, req)
    54  	return d.convertApplyErrors(fsmErrIntf, index, raftErr)
    55  }