Beispiel #1
0
func (cs *clusterState) agents() map[string]*agent.AgentState {
	agents := make(map[string]*agent.AgentState, len(cs.machines))
	for _, ms := range cs.machines {
		ms := ms
		agents[ms.ID] = agent.NewAgentState(ms)
	}

	for _, j := range cs.jobs {
		j := j
		if !j.Scheduled() || j.TargetState == job.JobStateInactive {
			continue
		}
		if as, ok := agents[j.TargetMachineID]; ok {
			u := &job.Unit{
				Name:        j.Name,
				Unit:        j.Unit,
				TargetState: j.TargetState,
			}
			as.Units[j.Name] = u
		}
	}

	for _, gu := range cs.gUnits {
		gu := gu
		for _, a := range agents {
			if machine.HasMetadata(a.MState, gu.RequiredTargetMetadata()) {
				a.Units[gu.Name] = gu
			}
		}
	}

	return agents
}
Beispiel #2
0
func (cs *clusterState) agents() map[string]*agent.AgentState {
	agents := make(map[string]*agent.AgentState, len(cs.machines))
	for _, ms := range cs.machines {
		ms := ms
		agents[ms.ID] = agent.NewAgentState(ms)
	}

	for _, j := range cs.jobs {
		j := j
		if !j.Scheduled() || j.TargetState == job.JobStateInactive {
			continue
		}
		if as, ok := agents[j.TargetMachineID]; ok {
			as.Jobs[j.Name] = j
		}
	}

	for _, gu := range cs.gUnits {
		j := &job.Job{
			Name:        gu.Name,
			Unit:        gu.Unit,
			TargetState: gu.TargetState,
		}
		for _, a := range agents {
			a.Jobs[gu.Name] = j
		}
	}

	return agents
}