// getParentUIDFromJob extracts UID of job's parent and whether it was found
340121
func getParentUIDFromJob(j batchv1.Job) (types.UID, bool) {
	controllerRef := metav1.GetControllerOf(&j)

	if controllerRef == nil {
		return types.UID(""), false
	}

	if controllerRef.Kind != "CronJob" {
		klog.V(4).Infof("Job with non-CronJob parent, name %s namespace %s", j.Name, j.Namespace)
		return types.UID(""), false
	}

	return controllerRef.UID, true
}
224375
func (j *Job) GetJobVersions(args *structs.JobVersionsRequest,
	reply *structs.JobVersionsResponse) error {
	if done, err := j.srv.forward("Job.GetJobVersions", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"nomad", "job", "get_job_versions"}, time.Now())

	// Check for read-job permissions
	if aclObj, err := j.srv.ResolveToken(args.AuthToken); err != nil {
		return err
	} else if aclObj != nil && !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilityReadJob) {
		return structs.ErrPermissionDenied
	}

	// Setup the blocking query
	opts := blockingOptions{
		queryOpts: &args.QueryOptions,
		queryMeta: &reply.QueryMeta,
		run: func(ws memdb.WatchSet, state *state.StateStore) error {
			// Look for the job
			out, err := state.JobVersionsByID(ws, args.RequestNamespace(), args.JobID)
			if err != nil {
				return err
			}

			// Setup the output
			reply.Versions = out
			if len(out) != 0 {
				reply.Index = out[0].ModifyIndex

				// Compute the diffs
				if args.Diffs {
					for i := 0; i < len(out)-1; i++ {
						old, new := out[i+1], out[i]
						d, err := old.Diff(new, true)
						if err != nil {
							return fmt.Errorf("failed to create job diff: %v", err)
						}
						reply.Diffs = append(reply.Diffs, d)
					}
				}
			} else {
				// Use the last index that affected the nodes table
				index, err := state.Index("job_version")
				if err != nil {
					return err
				}
				reply.Index = index
			}

			// Set the query response
			j.srv.setQueryMeta(&reply.QueryMeta)
			return nil
		}}
	return j.srv.blockingRPC(&opts)
}
395642
func (s *InstallationSettings) FindVMCredentialsByProductAndJob(productName, jobName string) (vmCredentials VMCredentials, err error) {
	var product Products
	if product, err = s.FindByProductID(productName); err == nil {
		vmCredentials, err = product.GetVMCredentialsByJob(jobName)
		vmCredentials.SSLKey = s.Infrastructure.IaaSConfig.SSHPrivateKey
	}
	return
}
1291
func GenerateJobID(hostID, uuid string) string {
	if uuid == "" {
		uuid = random.UUID()
	}
	return hostID + "-" + uuid
}
294817
func (s *adminServer) GetDebugJobState(c context.Context, r *schedulerpb.JobRef) (resp *internal.DebugJobState, err error) {
	switch state, err := s.Engine.GetDebugJobState(c, r.Project+"/"+r.Job); {
	case err == engine.ErrNoSuchJob:
		return nil, status.Errorf(codes.NotFound, "no such job")
	case err != nil:
		return nil, err
	default:
		return &internal.DebugJobState{
			Enabled:    state.Job.Enabled,
			Paused:     state.Job.Paused,
			LastTriage: google.NewTimestamp(state.Job.LastTriage),
			CronState: &internal.DebugJobState_CronState{
				Enabled:       state.Job.Cron.Enabled,
				Generation:    state.Job.Cron.Generation,
				LastRewind:    google.NewTimestamp(state.Job.Cron.LastRewind),
				LastTickWhen:  google.NewTimestamp(state.Job.Cron.LastTick.When),
				LastTickNonce: state.Job.Cron.LastTick.TickNonce,
			},
			ManagerState:        state.ManagerState,
			ActiveInvocations:   state.Job.ActiveInvocations,
			FinishedInvocations: state.FinishedInvocations,
			RecentlyFinishedSet: state.RecentlyFinishedSet,
			PendingTriggersSet:  state.PendingTriggersSet,
		}, nil
	}
}
234975
func (cs *CloudStackClient) GetAsyncJobResult(jobid string, timeout int64) (json.RawMessage, error) {
	var timer time.Duration
	currentTime := time.Now().Unix()

	for {
		p := cs.Asyncjob.NewQueryAsyncJobResultParams(jobid)
		r, err := cs.Asyncjob.QueryAsyncJobResult(p)
		if err != nil {
			return nil, err
		}

		// Status 1 means the job is finished successfully
		if r.Jobstatus == 1 {
			return r.Jobresult, nil
		}

		// When the status is 2, the job has failed
		if r.Jobstatus == 2 {
			if r.Jobresulttype == "text" {
				return nil, fmt.Errorf(string(r.Jobresult))
			} else {
				return nil, fmt.Errorf("Undefined error: %s", string(r.Jobresult))
			}
		}

		if time.Now().Unix()-currentTime > timeout {
			return nil, AsyncTimeoutErr
		}

		// Add an (extremely simple) exponential backoff like feature to prevent
		// flooding the CloudStack API
		if timer < 15 {
			timer++
		}

		time.Sleep(timer * time.Second)
	}
}
910666
func (c *Host) DiscoverdDeregisterJob(id string) error {
	return c.c.Put(fmt.Sprintf("/host/jobs/%s/discoverd-deregister", id), nil, nil)
}
799345
func (e *engineImpl) getJob(c context.Context, jobID string) (*Job, error) {
	job := &Job{JobID: jobID}
	switch err := ds.Get(c, job); {
	case err == nil:
		return job, nil
	case err == ds.ErrNoSuchEntity:
		return nil, nil
	default:
		return nil, transient.Tag.Apply(err)
	}
}
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
}
150445
func (we *WorkflowExecutor) GetMainContainerID() (string, error) {
	if we.mainContainerID != "" {
		return we.mainContainerID, nil
	}
	ctrStatus, err := we.GetMainContainerStatus()
	if err != nil {
		return "", err
	}
	if ctrStatus == nil {
		return "", nil
	}
	we.mainContainerID = containerID(ctrStatus.ContainerID)
	return we.mainContainerID, nil
}
559747
func (m *Meta) GetDDLJobByIdx(index int64, jobListKeys ...JobListKeyType) (*model.Job, error) {
	listKey := m.jobListKey
	if len(jobListKeys) != 0 {
		listKey = jobListKeys[0]
	}

	startTime := time.Now()
	job, err := m.getDDLJob(listKey, index)
	metrics.MetaHistogram.WithLabelValues(metrics.GetDDLJobByIdx, metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
	return job, errors.Trace(err)
}
143733
func (p *ReadOnlySchedulerClient) GetJobs(ctx context.Context, ownerRole string) (r *Response, err error) {
  var _args64 ReadOnlySchedulerGetJobsArgs
  _args64.OwnerRole = ownerRole
  var _result65 ReadOnlySchedulerGetJobsResult
  if err = p.Client_().Call(ctx, "getJobs", &_args64, &_result65); err != nil {
    return
  }
  return _result65.GetSuccess(), nil
}
236224
func (d *ddl) getHistoryDDLJob(id int64) (*model.Job, error) {
	var job *model.Job

	err := kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
		t := meta.NewMeta(txn)
		var err1 error
		job, err1 = t.GetHistoryDDLJob(id)
		return errors.Trace(err1)
	})

	return job, errors.Trace(err)
}
115846
func getParentNameAndOrdinal(pod *v1.Pod) (string, int) {
	parent := ""
	ordinal := -1
	subMatches := statefulPodRegex.FindStringSubmatch(pod.Name)
	if len(subMatches) < 3 {
		return parent, ordinal
	}
	parent = subMatches[1]
	if i, err := strconv.ParseInt(subMatches[2], 10, 32); err == nil {
		ordinal = int(i)
	}
	return parent, ordinal
}
361005
func (client Client) GetJobs() (map[string]JobDescriptor, error) {
	retry := retry.New(3, retry.DefaultBackoffFunc)

	var data []byte
	work := func() error {
		req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/json/jobs", client.baseURL.String()), nil)
		if err != nil {
			return err
		}
		req.Header.Set("Accept", "application/json")
		req.SetBasicAuth(client.userName, client.password)

		var responseCode int
		responseCode, data, err = consumeResponse(req)
		if err != nil {
			return err
		}

		if responseCode != http.StatusOK {
			Log.Printf("%s", string(data))
			return fmt.Errorf("%s", string(data))
		}

		return nil
	}

	if err := retry.Try(work); err != nil {
		return nil, err
	}

	var t Jobs
	if err := json.Unmarshal(data, &t); err != nil {
		return nil, err
	}

	jobs := make(map[string]JobDescriptor)
	for _, v := range t.Jobs {
		jobs[v.Name] = v
	}
	return jobs, nil
}
556100
func (s *Products) GetIPsByJob(jobname string) (ips []string) {
	for vmName, ipList := range s.IPS {
		if strings.HasPrefix(vmName, jobname+"-") {
			ips = append(ips, ipList...)
		}
	}
	return
}
70215
func (client *Client) GetJob(jobURL JobURL) (Job, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{URL: string(jobURL)})
	if err != nil {
		return Job{}, nil, err
	}

	var job Job
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &job,
	}

	err = client.connection.Make(request, &response)
	return job, response.Warnings, err
}