// GetJob get predefined job for a qor job instance
350972
func (job *QorJob) GetJob() *Job {
	if job.Job != nil {
		return job.Job
	}
	return nil
}
365356
func (c *Cron) AddJob(spec string, cmd Job) error {
	schedule, err := Parse(spec)
	if err != nil {
		return err
	}
	c.Schedule(schedule, cmd)
	return nil
}
259723
func awaitJob(ctx context.Context, client api.Server, jobID job.ID) (job.Result, error) {
	var result job.Result
	err := backoff(100*time.Millisecond, 2, 50, 1*time.Minute, func() (bool, error) {
		j, err := client.JobStatus(ctx, jobID)
		if err != nil {
			return false, err
		}
		switch j.StatusString {
		case job.StatusFailed:
			return false, j
		case job.StatusSucceeded:
			if j.Err != "" {
				// How did we succeed but still get an error!?
				return false, j
			}
			result = j.Result
			return true, nil
		}
		return false, nil
	})
	return result, err
}
792061
func (j *Jenkins) GetAllJobs() ([]*Job, error) {
	exec := Executor{Raw: new(ExecutorResponse), Jenkins: j}
	_, err := j.Requester.GetJSON("/", exec.Raw, nil)

	if err != nil {
		return nil, err
	}

	jobs := make([]*Job, len(exec.Raw.Jobs))
	for i, job := range exec.Raw.Jobs {
		ji, err := j.GetJob(job.Name)
		if err != nil {
			return nil, err
		}
		jobs[i] = ji
	}
	return jobs, nil
}
130565
func (p *ReadOnlySchedulerClient) GetJobSummary(ctx context.Context, role string) (r *Response, err error) {
  var _args54 ReadOnlySchedulerGetJobSummaryArgs
  _args54.Role = role
  var _result55 ReadOnlySchedulerGetJobSummaryResult
  if err = p.Client_().Call(ctx, "getJobSummary", &_args54, &_result55); err != nil {
    return
  }
  return _result55.GetSuccess(), nil
}
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
}
1132757
func (j *JobGetter) ApiJob(jpath string) (*api.Job, error) {
	var jobfile io.Reader
	switch jpath {
	case "-":
		if j.testStdin != nil {
			jobfile = j.testStdin
		} else {
			jobfile = os.Stdin
		}
	default:
		if len(jpath) == 0 {
			return nil, fmt.Errorf("Error jobfile path has to be specified.")
		}

		job, err := ioutil.TempFile("", "jobfile")
		if err != nil {
			return nil, err
		}
		defer os.Remove(job.Name())

		if err := job.Close(); err != nil {
			return nil, err
		}

		// Get the pwd
		pwd, err := os.Getwd()
		if err != nil {
			return nil, err
		}

		client := &gg.Client{
			Src: jpath,
			Pwd: pwd,
			Dst: job.Name(),
		}

		if err := client.Get(); err != nil {
			return nil, fmt.Errorf("Error getting jobfile from %q: %v", jpath, err)
		} else {
			file, err := os.Open(job.Name())
			defer file.Close()
			if err != nil {
				return nil, fmt.Errorf("Error opening file %q: %v", jpath, err)
			}
			jobfile = file
		}
	}

	// Parse the JobFile
	jobStruct, err := jobspec.Parse(jobfile)
	if err != nil {
		return nil, fmt.Errorf("Error parsing job file from %s: %v", jpath, err)
	}

	return jobStruct, nil
}
132736
func (d *Domain) GetJobInfo() (*DomainJobInfo, error) {
	var cinfo C.virDomainJobInfo

	var err C.virError
	ret := C.virDomainGetJobInfoWrapper(d.ptr, &cinfo, &err)
	if ret == -1 {
		return nil, makeError(&err)
	}

	return &DomainJobInfo{
		Type:             DomainJobType(cinfo._type),
		TimeElapsedSet:   true,
		TimeElapsed:      uint64(cinfo.timeElapsed),
		TimeRemainingSet: true,
		TimeRemaining:    uint64(cinfo.timeRemaining),
		DataTotalSet:     true,
		DataTotal:        uint64(cinfo.dataTotal),
		DataProcessedSet: true,
		DataProcessed:    uint64(cinfo.dataProcessed),
		DataRemainingSet: true,
		DataRemaining:    uint64(cinfo.dataRemaining),
		MemTotalSet:      true,
		MemTotal:         uint64(cinfo.memTotal),
		MemProcessedSet:  true,
		MemProcessed:     uint64(cinfo.memProcessed),
		MemRemainingSet:  true,
		MemRemaining:     uint64(cinfo.memRemaining),
		DiskTotalSet:     true,
		DiskTotal:        uint64(cinfo.fileTotal),
		DiskProcessedSet: true,
		DiskProcessed:    uint64(cinfo.fileProcessed),
		DiskRemainingSet: true,
		DiskRemaining:    uint64(cinfo.fileRemaining),
	}, nil
}
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
}
836071
func (s *SchedulerServer) getJob(ctx context.Context, ref *scheduler.JobRef) (*engine.Job, error) {
	jobID := ref.GetProject() + "/" + ref.GetJob()
	switch job, err := s.Engine.GetVisibleJob(ctx, jobID); {
	case err == nil:
		return job, nil
	case err == engine.ErrNoSuchJob:
		return nil, status.Errorf(codes.NotFound, "no such job or no READ permission")
	default:
		return nil, status.Errorf(codes.Internal, "internal error when fetching job: %s", err)
	}
}
590179
func (api *API) LogpushJob(zoneID string, jobID int) (LogpushJob, error) {
	uri := "/zones/" + zoneID + "/logpush/jobs/" + strconv.Itoa(jobID)
	res, err := api.makeRequest("GET", uri, nil)
	if err != nil {
		return LogpushJob{}, errors.Wrap(err, errMakeRequestError)
	}
	var r LogpushJobDetailsResponse
	err = json.Unmarshal(res, &r)
	if err != nil {
		return LogpushJob{}, errors.Wrap(err, errUnmarshalError)
	}
	return r.Result, nil
}
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
}
920011
func (s *SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) (*scheduler.JobsReply, error) {
	if in.GetCursor() != "" {
		// Paging in GetJobs isn't implemented until we have enough jobs to care.
		// Until then, not empty cursor implies no more jobs to return.
		return &scheduler.JobsReply{Jobs: []*scheduler.Job{}, NextCursor: ""}, nil
	}
	var ejobs []*engine.Job
	var err error
	if in.GetProject() == "" {
		ejobs, err = s.Engine.GetVisibleJobs(ctx)
	} else {
		ejobs, err = s.Engine.GetVisibleProjectJobs(ctx, in.GetProject())
	}
	if err != nil {
		return nil, status.Errorf(codes.Internal, "internal error: %s", err)
	}

	jobs := make([]*scheduler.Job, len(ejobs))
	for i, ej := range ejobs {
		traits, err := presentation.GetJobTraits(ctx, s.Catalog, ej)
		if err != nil {
			return nil, status.Errorf(codes.Internal, "failed to get traits: %s", err)
		}
		jobs[i] = &scheduler.Job{
			JobRef: &scheduler.JobRef{
				Project: ej.ProjectID,
				Job:     ej.JobName(),
			},
			Schedule: ej.Schedule,
			State: &scheduler.JobState{
				UiStatus: string(presentation.GetPublicStateKind(ej, traits)),
			},
			Paused: ej.Paused,
		}
	}
	return &scheduler.JobsReply{Jobs: jobs, NextCursor: ""}, nil
}
546429
func (s *StoreToJobLister) GetPodJobs(pod *api.Pod) (jobs []extensions.Job, err error) {
	var selector labels.Selector
	var job extensions.Job

	if len(pod.Labels) == 0 {
		err = fmt.Errorf("no jobs found for pod %v because it has no labels", pod.Name)
		return
	}

	for _, m := range s.Store.List() {
		job = *m.(*extensions.Job)
		if job.Namespace != pod.Namespace {
			continue
		}

		selector, _ = unversioned.LabelSelectorAsSelector(job.Spec.Selector)
		if !selector.Matches(labels.Set(pod.Labels)) {
			continue
		}
		jobs = append(jobs, job)
	}
	if len(jobs) == 0 {
		err = fmt.Errorf("could not find jobs for pod %s in namespace %s with labels: %v", pod.Name, pod.Namespace, pod.Labels)
	}
	return
}
997474
func (t *Template) GetAllAWSBatchJobQueueResources() map[string]*resources.AWSBatchJobQueue {
	results := map[string]*resources.AWSBatchJobQueue{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSBatchJobQueue:
			results[name] = resource
		}
	}
	return results
}
92484
func (e *engineImpl) getProjectJobs(c context.Context, projectID string) (map[string]*Job, error) {
	q := ds.NewQuery("Job").
		Eq("Enabled", true).
		Eq("ProjectID", projectID)
	entities := []*Job{}
	if err := ds.GetAll(c, q, &entities); err != nil {
		return nil, transient.Tag.Apply(err)
	}
	out := make(map[string]*Job, len(entities))
	for _, job := range entities {
		if job.Enabled && job.ProjectID == projectID {
			out[job.JobID] = job
		}
	}
	return out, nil
}
420045
func (impl *adminImpl) GetJobState(c context.Context, id *api.JobID) (*api.JobState, error) {
	job, err := impl.ctl.GetJob(c, mapper.JobID(id.JobId))
	if err != nil {
		return nil, toStatus(err)
	}
	cfg := &api.JobConfig{}
	if err := proto.Unmarshal(job.Config.Params, cfg); err != nil {
		return nil, toStatus(errors.Annotate(err, "failed to unmarshal JobConfig").Err())
	}
	info, err := job.FetchInfo(c)
	if err != nil {
		return nil, toStatus(err)
	}
	return &api.JobState{Config: cfg, Info: info}, nil
}