// groupJobsByParent groups jobs into a map keyed by the job parent UID (e.g. scheduledJob).
// It has no receiver, to facilitate testing.
558388
func groupJobsByParent(js []batchv1.Job) map[types.UID][]batchv1.Job {
	jobsBySj := make(map[types.UID][]batchv1.Job)
	for _, job := range js {
		parentUID, found := getParentUIDFromJob(job)
		if !found {
			klog.V(4).Infof("Unable to get parent uid from job %s in namespace %s", job.Name, job.Namespace)
			continue
		}
		jobsBySj[parentUID] = append(jobsBySj[parentUID], job)
	}
	return jobsBySj
}
20361
func (jenkins *Jenkins) GetJobs() ([]Job, error) {
	var payload = struct {
		Jobs []Job `json:"jobs"`
	}{}
	err := jenkins.get("", nil, &payload)
	return payload.Jobs, err
}
308686
func materializeTaskGroups(job *structs.Job) map[string]*structs.TaskGroup {
	out := make(map[string]*structs.TaskGroup)
	if job.Stopped() {
		return out
	}

	for _, tg := range job.TaskGroups {
		for i := 0; i < tg.Count; i++ {
			name := fmt.Sprintf("%s.%s[%d]", job.Name, tg.Name, i)
			out[name] = tg
		}
	}
	return out
}
653023
func (impl *adminImpl) LaunchJob(c context.Context, cfg *api.JobConfig) (*api.JobID, error) {
	def, ok := mappers[cfg.Kind] // see mappers.go
	if !ok {
		return nil, status.Errorf(codes.InvalidArgument, "unknown mapper kind")
	}

	cfgBlob, err := proto.Marshal(cfg)
	if err != nil {
		return nil, status.Errorf(codes.Internal, "failed to marshal JobConfig - %s", err)
	}

	launchCfg := def.Config
	launchCfg.Mapper = def.mapperID()
	launchCfg.Params = cfgBlob

	jid, err := impl.ctl.LaunchJob(c, &launchCfg)
	if err != nil {
		return nil, toStatus(err)
	}

	return &api.JobID{JobId: int64(jid)}, nil
}
358743
func (s *StateStore) JobsByNamespace(ws memdb.WatchSet, namespace string) (memdb.ResultIterator, error) {
	txn := s.db.Txn(false)
	return s.jobsByNamespaceImpl(ws, namespace, txn)
}
904874
func (s *StateStore) EvalsByJob(ws memdb.WatchSet, namespace, jobID string) ([]*structs.Evaluation, error) {
	txn := s.db.Txn(false)

	// COMPAT 0.7: Upgrade old objects that do not have namespaces
	if namespace == "" {
		namespace = structs.DefaultNamespace
	}

	// Get an iterator over the node allocations
	iter, err := txn.Get("evals", "job_prefix", namespace, jobID)
	if err != nil {
		return nil, err
	}

	ws.Add(iter.WatchCh())

	var out []*structs.Evaluation
	for {
		raw := iter.Next()
		if raw == nil {
			break
		}

		e := raw.(*structs.Evaluation)

		// Filter non-exact matches
		if e.JobID != jobID {
			continue
		}

		out = append(out, e)
	}
	return out, nil
}
618331
func (s *Scheduler) maybeStartBlockedJobs(host *Host) {
	for _, job := range s.jobs {
		if job.State == JobStateBlocked && job.TagsMatchHost(host) {
			job.State = JobStatePending
			go s.StartJob(job)
		}
	}
}
584813
func (s *StateStore) JobByID(ws memdb.WatchSet, namespace, id string) (*structs.Job, error) {
	txn := s.db.Txn(false)
	return s.JobByIDTxn(ws, namespace, id, txn)
}
682857
func filterJobsByName(resp *healthd.ApiResponseJobs, name string) {
	filteredSlice := []*healthd.Job{}

	for _, job := range resp.Jobs {
		if strings.Contains(job.Name, name) {
			filteredSlice = append(filteredSlice, job)
		}
	}

	resp.Jobs = filteredSlice
}
682322
func (js *JobSummary) Copy() *JobSummary {
	newJobSummary := new(JobSummary)
	*newJobSummary = *js
	newTGSummary := make(map[string]TaskGroupSummary, len(js.Summary))
	for k, v := range js.Summary {
		newTGSummary[k] = v
	}
	newJobSummary.Summary = newTGSummary
	newJobSummary.Children = newJobSummary.Children.Copy()
	return newJobSummary
}
252528
func (c *Host) ListJobs() (map[string]host.ActiveJob, error) {
	var jobs map[string]host.ActiveJob
	err := c.c.Get("/host/jobs", &jobs)
	return jobs, err
}
71452
func (s *Scheduler) getRunnableJobs() (running_jobs [MAXJOBNUM]*Job, n int) {
	runnableJobs := [MAXJOBNUM]*Job{}
	n = 0
	sort.Sort(s)
	for i := 0; i < s.size; i++ {
		if s.jobs[i].shouldRun() {

			runnableJobs[n] = s.jobs[i]
			//fmt.Println(runnableJobs)
			n++
		} else {
			break
		}
	}
	return runnableJobs, n
}
535294
func (w *drainingJobWatcher) drainingJobs() map[structs.NamespacedID]struct{} {
	w.l.RLock()
	defer w.l.RUnlock()

	l := len(w.jobs)
	if l == 0 {
		return nil
	}

	draining := make(map[structs.NamespacedID]struct{}, l)
	for k := range w.jobs {
		draining[k] = struct{}{}
	}

	return draining
}
326471
func (k8s *Kubernetes) GetJobSpec(qorJob worker.QorJobInterface) (*v1.Job, error) {
	var (
		k8sJob     = &v1.Job{}
		currentPod = k8s.GetCurrentPod()
		namespace  = currentPod.GetNamespace()
	)

	if k8s.Config.Namespace != "" {
		namespace = k8s.Config.Namespace
	}

	if k8s.Config.JobTemplateMaker != nil {
		if err := yaml.Unmarshal([]byte(k8s.Config.JobTemplateMaker(qorJob)), k8sJob); err != nil {
			return nil, err
		}
		if k8sJob.ObjectMeta.Namespace != "" {
			namespace = k8sJob.ObjectMeta.Namespace
		}
	} else {
		if marshaledContainers, err := json.Marshal(currentPod.Spec.Containers); err == nil {
			json.Unmarshal(marshaledContainers, k8sJob.Spec.Template.Spec.Containers)
		}

		if marshaledVolumes, err := json.Marshal(currentPod.Spec.Volumes); err == nil {
			json.Unmarshal(marshaledVolumes, k8sJob.Spec.Template.Spec.Volumes)
		}
	}

	if k8sJob.TypeMeta.Kind == "" {
		k8sJob.TypeMeta.Kind = "Job"
	}

	if k8sJob.TypeMeta.APIVersion == "" {
		k8sJob.TypeMeta.APIVersion = "batch/v1"
	}

	if k8sJob.ObjectMeta.Namespace == "" {
		k8sJob.ObjectMeta.Namespace = namespace
	}

	return k8sJob, nil
}
414494
func listScheduledJobsAction(client *gocd.Client, c *cli.Context) (r interface{}, resp *gocd.APIResponse, err error) {
	return client.Jobs.ListScheduled(context.Background())
}
327905
func (j *Jenkins) GetAllJobNames() ([]InnerJob, error) {
	exec := Executor{Raw: new(ExecutorResponse), Jenkins: j}
	_, err := j.Requester.GetJSON("/", exec.Raw, nil)

	if err != nil {
		return nil, err
	}

	return exec.Raw.Jobs, nil
}
430534
func WithJobIDResponse(parent context.Context, jobID *string) context.Context {
	return context.WithValue(contextOrBackground(parent), keyJobIDResponse, jobID)
}