本文整理汇总了Golang中github.com/coreos/fleet/job.Job.Replaces方法的典型用法代码示例。如果您正苦于以下问题:Golang Job.Replaces方法的具体用法?Golang Job.Replaces怎么用?Golang Job.Replaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/fleet/job.Job
的用法示例。
在下文中一共展示了Job.Replaces方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetReplacedUnit
func (as *AgentState) GetReplacedUnit(j *job.Job) (string, error) {
cExists, replaced := as.hasReplace(j.Name, j.Replaces())
if !cExists {
return "", fmt.Errorf("cannot find units to be replaced for Unit(%s)", j.Name)
}
return replaced, nil
}
示例2: AbleToRun
// AbleToRun determines if an Agent can run the provided Job based on
// the Agent's current state. A boolean indicating whether this is the
// case or not is returned. The following criteria is used:
// - Agent must meet the Job's machine target requirement (if any)
// - Agent must have all of the Job's required metadata (if any)
// - Agent must have all required Peers of the Job scheduled locally (if any)
// - Job must not conflict with any other Units scheduled to the agent
// - Job must specially handle replaced units to be rescheduled
func (as *AgentState) AbleToRun(j *job.Job) (jobAction job.JobAction, errstr string) {
if tgt, ok := j.RequiredTarget(); ok && !as.MState.MatchID(tgt) {
return job.JobActionUnschedule, fmt.Sprintf("agent ID %q does not match required %q", as.MState.ID, tgt)
}
metadata := j.RequiredTargetMetadata()
if len(metadata) != 0 {
if !machine.HasMetadata(as.MState, metadata) {
return job.JobActionUnschedule, "local Machine metadata insufficient"
}
}
peers := j.Peers()
if len(peers) != 0 {
for _, peer := range peers {
if !as.unitScheduled(peer) {
return job.JobActionUnschedule, fmt.Sprintf("required peer Unit(%s) is not scheduled locally", peer)
}
}
}
if cExists, cJobName := as.HasConflict(j.Name, j.Conflicts()); cExists {
return job.JobActionUnschedule, fmt.Sprintf("found conflict with locally-scheduled Unit(%s)", cJobName)
}
// Handle Replace option specially for rescheduling the unit
if cExists, cJobName := as.hasReplace(j.Name, j.Replaces()); cExists {
return job.JobActionReschedule, fmt.Sprintf("found replace with locally-scheduled Unit(%s)", cJobName)
}
return job.JobActionSchedule, ""
}