// GetJobSpec get job spec
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
}
1155742
func (s *Products) GetVMCredentialsByJob(jobName string) (vmCredentials VMCredentials, err error) {
	var job Jobs
	if job, err = s.GetJob(jobName); err == nil {

		if s.isLegacyFormat(job) {
			vmCredentials = s.extractLegacyCredentials(job)
		} else {
			vmCredentials = s.extractCredentials(job)
		}
	}
	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
}
1136740
func (e *engineImpl) GetDebugJobState(c context.Context, jobID string) (*DebugJobState, error) {
	job, err := e.getJob(c, jobID)
	switch {
	case err != nil:
		return nil, errors.Annotate(err, "failed to fetch Job entity").Err()
	case job == nil:
		return nil, ErrNoSuchJob
	}

	state := &DebugJobState{Job: job}

	// Fill in FinishedInvocations.
	state.FinishedInvocations, err = unmarshalFinishedInvs(job.FinishedInvocationsRaw)
	if err != nil {
		return nil, errors.Annotate(err, "failed to unmarshal FinishedInvocationsRaw").Err()
	}

	// Fill in RecentlyFinishedSet.
	finishedSet := recentlyFinishedSet(c, jobID)
	listing, err := finishedSet.List(c)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch recentlyFinishedSet").Err()
	}
	state.RecentlyFinishedSet = make([]int64, len(listing.Items))
	for i, itm := range listing.Items {
		state.RecentlyFinishedSet[i] = finishedSet.ItemToInvID(&itm)
	}

	// Fill in PendingTriggersSet.
	triggersSet := pendingTriggersSet(c, jobID)
	_, state.PendingTriggersSet, err = triggersSet.Triggers(c)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch pendingTriggersSet").Err()
	}

	// Ask the corresponding task.Manager to fill in DebugManagerState. Pass it
	// a phony controller configured just enough to be useful for fetching the
	// state, but not anything else.
	ctl, err := controllerForInvocation(c, e, &Invocation{
		ID:    -1,
		JobID: jobID,
		Task:  job.Task,
	})
	if err == nil {
		state.ManagerState, err = ctl.manager.GetDebugState(c, ctl)
	}
	if state.ManagerState == nil {
		state.ManagerState = &internal.DebugManagerState{}
	}
	if err != nil {
		state.ManagerState.Error = err.Error()
	}
	if ctl != nil {
		state.ManagerState.DebugLog = ctl.debugLog
	}

	return state, nil
}
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
}
948504
func ValidateSpec(spec SysSpec, runtime string) (error, error) {
	// OS-level validators.
	var osValidators = []Validator{
		&OSValidator{Reporter: DefaultReporter},
		&KernelValidator{Reporter: DefaultReporter},
		&CgroupsValidator{Reporter: DefaultReporter},
		&packageValidator{reporter: DefaultReporter},
	}
	// Docker-specific validators.
	var dockerValidators = []Validator{
		&DockerValidator{Reporter: DefaultReporter},
	}

	validators := osValidators
	switch runtime {
	case "docker":
		validators = append(validators, dockerValidators...)
	}
	return Validate(spec, validators)
}
900871
func validateJob(job *structs.Job) (invalid, warnings error) {
	validationErrors := new(multierror.Error)
	if err := job.Validate(); err != nil {
		multierror.Append(validationErrors, err)
	}

	// Get any warnings
	warnings = job.Warnings()

	// TODO: Validate the driver configurations. These had to be removed in 0.9
	//       to support driver plugins, but see issue: #XXXX for more info.

	if job.Type == structs.JobTypeCore {
		multierror.Append(validationErrors, fmt.Errorf("job type cannot be core"))
	}

	if len(job.Payload) != 0 {
		multierror.Append(validationErrors, fmt.Errorf("job can't be submitted with a payload, only dispatched"))
	}

	return validationErrors.ErrorOrNil(), warnings
}
1071593
func getJobFromTemplate(sj *batchv1beta1.CronJob, scheduledTime time.Time) (*batchv1.Job, error) {
	labels := copyLabels(&sj.Spec.JobTemplate)
	annotations := copyAnnotations(&sj.Spec.JobTemplate)
	// We want job names for a given nominal start time to have a deterministic name to avoid the same job being created twice
	name := fmt.Sprintf("%s-%d", sj.Name, getTimeHash(scheduledTime))

	job := &batchv1.Job{
		ObjectMeta: metav1.ObjectMeta{
			Labels:          labels,
			Annotations:     annotations,
			Name:            name,
			OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(sj, controllerKind)},
		},
	}
	if err := legacyscheme.Scheme.Convert(&sj.Spec.JobTemplate.Spec, &job.Spec, nil); err != nil {
		return nil, fmt.Errorf("unable to convert job template: %v", err)
	}
	return job, nil
}
451690
func (jenkins *Jenkins) GetJob(name string) (job Job, err error) {
	err = jenkins.get(fmt.Sprintf("/job/%s", name), nil, &job)
	return
}
556438
func (s *InstallationSettings) FindJobByProductAndJobName(productName, jobName string) (job Jobs, err error) {
	var product Products
	if product, err = s.FindByProductID(productName); err == nil {
		job, err = product.GetJob(jobName)
	}
	return
}
585279
func (worker *Worker) GetJob(jobID string) (QorJobInterface, error) {
	qorJob := worker.JobResource.NewStruct().(QorJobInterface)

	context := worker.Admin.NewContext(nil, nil)
	context.ResourceID = jobID
	context.Resource = worker.JobResource

	if err := worker.JobResource.FindOneHandler(qorJob, nil, context.Context); err == nil {
		for _, job := range worker.Jobs {
			if job.Name == qorJob.GetJobName() {
				qorJob.SetJob(job)
				return qorJob, nil
			}
		}
		return nil, fmt.Errorf("failed to load job: %v, unregistered job type: %v", jobID, qorJob.GetJobName())
	}
	return nil, fmt.Errorf("failed to find job: %v", jobID)
}
1274163
func GetChaincodeDeploymentSpec(code []byte, pr *platforms.Registry) (*peer.ChaincodeDeploymentSpec, error) {
	cds := &peer.ChaincodeDeploymentSpec{}
	err := proto.Unmarshal(code, cds)
	if err != nil {
		return nil, errors.Wrap(err, "error unmarshaling ChaincodeDeploymentSpec")
	}

	// FAB-2122: Validate the CDS according to platform specific requirements
	return cds, pr.ValidateDeploymentSpec(cds.CCType(), cds.Bytes())
}
585310
func (p *ReadOnlySchedulerClient) GetJobUpdateDiff(ctx context.Context, request *JobUpdateRequest) (r *Response, err error) {
  var _args74 ReadOnlySchedulerGetJobUpdateDiffArgs
  _args74.Request = request
  var _result75 ReadOnlySchedulerGetJobUpdateDiffResult
  if err = p.Client_().Call(ctx, "getJobUpdateDiff", &_args74, &_result75); err != nil {
    return
  }
  return _result75.GetSuccess(), nil
}
1363319
func Convert_v1beta1_CronJobSpec_To_batch_CronJobSpec(in *v1beta1.CronJobSpec, out *batch.CronJobSpec, s conversion.Scope) error {
	return autoConvert_v1beta1_CronJobSpec_To_batch_CronJobSpec(in, out, s)
}
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
}
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
}
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
}