示例#1
0
文件: job.go 项目: Jitendrakry/fleet
func (r *EtcdRegistry) hydrateJob(j *job.Job) (err error) {
	j.TargetState, err = r.jobTargetState(j.Name)
	if err != nil {
		return
	}

	j.TargetMachineID, err = r.jobTargetMachine(j.Name)
	if err != nil {
		return
	}

	j.UnitState = r.getUnitState(j.Name)
	j.State = r.determineJobState(j.Name)

	return
}
示例#2
0
文件: job.go 项目: JuanCarlosM/fleet
func (r *EtcdRegistry) hydrateJob(j *job.Job) error {
	tgt, err := r.jobTargetState(j.Name)
	if err != nil {
		return err
	}

	j.TargetState = tgt

	j.TargetMachineID, err = r.jobTargetMachine(j.Name)
	if err != nil {
		return err
	}

	j.UnitState = r.getUnitState(j.Name)
	j.State = r.determineJobState(j.Name)

	return nil
}
示例#3
0
func newClusterState(units []job.Unit, sUnits []job.ScheduledUnit, machines []machine.MachineState) *clusterState {
	sUnitMap := make(map[string]*job.ScheduledUnit)
	for _, sUnit := range sUnits {
		sUnit := sUnit
		sUnitMap[sUnit.Name] = &sUnit
	}

	jMap := make(map[string]*job.Job)
	guMap := make(map[string]*job.Unit)
	for _, u := range units {
		if u.IsGlobal() {
			u := u
			guMap[u.Name] = &u
		} else {
			j := job.Job{
				Name:        u.Name,
				Unit:        u.Unit,
				TargetState: u.TargetState,
			}

			if sUnit, ok := sUnitMap[u.Name]; ok {
				j.TargetMachineID = sUnit.TargetMachineID
				j.State = sUnit.State
			}

			jMap[j.Name] = &j
		}
	}

	mMap := make(map[string]*machine.MachineState, len(machines))
	for _, ms := range machines {
		ms := ms
		mMap[ms.ID] = &ms
	}

	return &clusterState{
		jobs:     jMap,
		gUnits:   guMap,
		machines: mMap,
	}
}
示例#4
0
文件: job.go 项目: BillTheBest/fleet
func (r *EtcdRegistry) parseJobDir(j *job.Job, dir *etcd.Node) (err error) {
	var heartbeat string
	for _, node := range dir.Nodes {
		switch node.Key {
		case r.jobTargetStatePath(j.Name):
			j.TargetState, err = job.ParseJobState(node.Value)
			if err != nil {
				return
			}
		case r.jobTargetAgentPath(j.Name):
			j.TargetMachineID = node.Value
		case r.jobHeartbeatPath(j.Name):
			heartbeat = node.Value
		}
	}

	j.UnitState = r.getUnitState(j.Name)

	js := determineJobState(j, heartbeat)
	j.State = &js

	return
}