// CreateJob submits a new job to be executed. This call is not
// idempotent, so calling it twice will create two jobs.
16287
func (s *JobClient) Create(ctx context.Context, input *CreateJobInput) (*CreateJobOutput, error) {
	fullPath := path.Join("/", s.client.AccountName, "jobs")

	reqInput := client.RequestInput{
		Method: http.MethodPost,
		Path:   fullPath,
		Body:   input,
	}
	respBody, respHeaders, err := s.client.ExecuteRequestStorage(ctx, reqInput)
	if respBody != nil {
		defer respBody.Close()
	}
	if err != nil {
		return nil, errors.Wrap(err, "unable to create job")
	}

	jobURI := respHeaders.Get("Location")
	parts := strings.Split(jobURI, "/")
	jobID := parts[len(parts)-1]

	response := &CreateJobOutput{
		JobID: jobID,
	}

	return response, nil
}
965147
func (c *jobsV1) Create(job *extensions.Job) (result *extensions.Job, err error) {
	result = &extensions.Job{}
	err = c.r.Post().Namespace(c.ns).Resource("jobs").Body(job).Do().Into(result)
	return
}
254319
func NewMockJobRenderer(ctrl *gomock.Controller) *MockJobRenderer {
	mock := &MockJobRenderer{ctrl: ctrl}
	mock.recorder = &MockJobRendererMockRecorder{mock}
	return mock
}
934942
func (client Client) CreateJob(jobName, jobConfigXML string) error {
	req, err := http.NewRequest("POST", fmt.Sprintf("%s/createItem?name=%s", client.baseURL.String(), jobName), bytes.NewBuffer([]byte(jobConfigXML)))
	if err != nil {
		return err
	}
	req.Header.Set("Content-type", "application/xml")
	req.SetBasicAuth(client.userName, client.password)

	responseCode, data, err := consumeResponse(req)
	if err != nil {
		return err
	}
	if responseCode != http.StatusOK {
		return fmt.Errorf("Error creating Jenkins job.  Status code: %d, response=%s\n", responseCode, string(data))
	}
	return nil
}
821599
func (s *REST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
	req, ok := obj.(*appsapi.DeploymentRequest)
	if !ok {
		return nil, errors.NewInternalError(fmt.Errorf("wrong object passed for requesting a new rollout: %#v", obj))
	}
	var ret runtime.Object
	err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
		configObj, err := s.store.Get(ctx, req.Name, &metav1.GetOptions{})
		if err != nil {
			return err
		}
		config := configObj.(*appsapi.DeploymentConfig)
		old := config

		if errs := validation.ValidateRequestForDeploymentConfig(req, config); len(errs) > 0 {
			return errors.NewInvalid(apps.Kind("DeploymentRequest"), req.Name, errs)
		}

		// We need to process the deployment config before we can determine if it is possible to trigger
		// a deployment.
		if req.Latest {
			if err := processTriggers(config, s.is, req.Force, req.ExcludeTriggers); err != nil {
				return err
			}
		}

		canTrigger, causes, err := canTrigger(config, s.rn, req.Force)
		if err != nil {
			return err
		}
		// If we cannot trigger then there is nothing to do here.
		if !canTrigger {
			ret = &metav1.Status{
				Message: fmt.Sprintf("deployment config %q cannot be instantiated", config.Name),
				Code:    int32(204),
			}
			return nil
		}
		klog.V(4).Infof("New deployment for %q caused by %#v", config.Name, causes)

		config.Status.Details = new(appsapi.DeploymentDetails)
		config.Status.Details.Causes = causes
		switch causes[0].Type {
		case appsapi.DeploymentTriggerOnConfigChange:
			config.Status.Details.Message = "config change"
		case appsapi.DeploymentTriggerOnImageChange:
			config.Status.Details.Message = "image change"
		case appsapi.DeploymentTriggerManual:
			config.Status.Details.Message = "manual change"
		}
		config.Status.LatestVersion++

		userInfo, _ := apirequest.UserFrom(ctx)
		attrs := admission.NewAttributesRecord(config, old, apps.Kind("DeploymentConfig").WithVersion(""), config.Namespace, config.Name, apps.Resource("DeploymentConfig").WithVersion(""), "", admission.Update, false, userInfo)
		if err := s.admit.(admission.MutationInterface).Admit(attrs); err != nil {
			return err
		}
		if err := s.admit.(admission.ValidationInterface).Validate(attrs); err != nil {
			return err
		}

		ret, _, err = s.store.Update(
			ctx,
			config.Name,
			rest.DefaultUpdatedObjectInfo(config),
			rest.AdmissionToValidateObjectFunc(s.admit, attrs),
			rest.AdmissionToValidateObjectUpdateFunc(s.admit, attrs),
			false,
			&metav1.UpdateOptions{},
		)
		return err
	})

	return ret, err
}
1241003
func newJobs(c *ExtensionsClient, namespace string) *jobs {
	return &jobs{
		client: c,
		ns:     namespace,
	}
}
564989
func (d *Deployment) Create(id string) error {
	return attempts.Run(func() error {
		if err := d.set(&discoverd.ServiceMeta{}, NewDeploymentMeta(id)); err == nil {
			return nil
		}
		if err := d.update(); err != nil {
			return err
		}
		return d.set(d.meta, NewDeploymentMeta(id))
	})
}
9955
func (client Client) DeleteJob(jobName string) error {
	retry := retry.New(3, retry.DefaultBackoffFunc)
	work := func() error {
		req, err := http.NewRequest("POST", fmt.Sprintf("%s/job/%s/doDelete", client.baseURL.String(), jobName), bytes.NewBuffer([]byte("")))
		if err != nil {
			return err
		}
		req.Header.Set("Content-type", "application/xml")
		req.SetBasicAuth(client.userName, client.password)

		responseCode, data, err := consumeResponse(req)
		if err != nil {
			return err
		}
		if responseCode != http.StatusFound {
			return fmt.Errorf("Error deleting Jenkins job.  Status code: %d, response=%s\n", responseCode, string(data))
		}
		return nil
	}
	return retry.Try(work)
}
252696
func NewCleanupJob(pv *apiv1.PersistentVolume, volMode apiv1.PersistentVolumeMode, imageName string, nodeName string, namespace string, mountPath string,
	config common.MountConfig) (*batch_v1.Job, error) {
	priv := true
	// Container definition
	jobContainer := apiv1.Container{
		Name:  JobContainerName,
		Image: imageName,
		SecurityContext: &apiv1.SecurityContext{
			Privileged: &priv,
		},
	}
	if volMode == apiv1.PersistentVolumeBlock {
		jobContainer.Command = config.BlockCleanerCommand
		jobContainer.Env = []apiv1.EnvVar{{Name: common.LocalPVEnv, Value: mountPath}}
	} else if volMode == apiv1.PersistentVolumeFilesystem {
		// We only have one way to clean filesystem, so no need to customize
		// filesystem cleaner command.
		jobContainer.Command = []string{"/scripts/fsclean.sh"}
		jobContainer.Env = []apiv1.EnvVar{{Name: common.LocalFilesystemEnv, Value: mountPath}}
	} else {
		return nil, fmt.Errorf("unknown PersistentVolume mode: %v", volMode)
	}
	mountName := common.GenerateMountName(&config)
	volumes := []apiv1.Volume{
		{
			Name: mountName,
			VolumeSource: apiv1.VolumeSource{
				HostPath: &apiv1.HostPathVolumeSource{
					Path: config.HostDir,
				},
			},
		},
	}
	jobContainer.VolumeMounts = []apiv1.VolumeMount{{
		Name:      mountName,
		MountPath: config.MountDir},
	}

	// Make job query-able by some useful labels for admins.
	labels := map[string]string{
		common.NodeNameLabel: nodeName,
		PVLabel:              pv.Name,
		PVUuidLabel:          string(pv.UID),
	}

	// Annotate job with useful information that cannot be set as labels due to label name restrictions.
	annotations := map[string]string{
		DeviceAnnotation:    mountPath,
		StartTimeAnnotation: time.Now().Format(time.RFC3339Nano),
	}

	podTemplate := apiv1.Pod{}
	podTemplate.Spec = apiv1.PodSpec{
		Containers:   []apiv1.Container{jobContainer},
		Volumes:      volumes,
		NodeSelector: map[string]string{common.NodeNameLabel: nodeName},
	}
	podTemplate.ObjectMeta = meta_v1.ObjectMeta{
		Name:        generateCleaningJobName(pv.Name),
		Namespace:   namespace,
		Labels:      labels,
		Annotations: annotations,
	}
	job := &batch_v1.Job{}
	job.ObjectMeta = podTemplate.ObjectMeta
	job.Spec.Template.Spec = podTemplate.Spec
	job.Spec.Template.Spec.RestartPolicy = apiv1.RestartPolicyOnFailure

	return job, nil
}
260826
func (j *Jenkins) BuildJob(name string, options ...interface{}) (int64, error) {
	job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name}
	var params map[string]string
	if len(options) > 0 {
		params, _ = options[0].(map[string]string)
	}
	return job.InvokeSimple(params)
}
640598
func (j *Jenkins) CreateJob(config string, options ...interface{}) (*Job, error) {
	qr := make(map[string]string)
	if len(options) > 0 {
		qr["name"] = options[0].(string)
	} else {
		return nil, errors.New("Error Creating Job, job name is missing")
	}
	jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + qr["name"]}
	job, err := jobObj.Create(config, qr)
	if err != nil {
		return nil, err
	}
	return job, nil
}
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
}
286653
func NewCmdCreateJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	o := NewCreateJobOptions(ioStreams)
	cmd := &cobra.Command{
		Use:     "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]",
		Short:   jobLong,
		Long:    jobLong,
		Example: jobExample,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(o.Complete(f, cmd, args))
			cmdutil.CheckErr(o.Validate())
			cmdutil.CheckErr(o.Run())
		},
	}

	o.PrintFlags.AddFlags(cmd)

	cmdutil.AddApplyAnnotationFlags(cmd)
	cmdutil.AddValidateFlags(cmd)
	cmdutil.AddDryRunFlag(cmd)
	cmd.Flags().StringVar(&o.Image, "image", o.Image, "Image name to run.")
	cmd.Flags().StringVar(&o.From, "from", o.From, "The name of the resource to create a Job from (only cronjob is supported).")

	return cmd
}
247033
func (s *CancelSimulationJobInput) SetJob(v string) *CancelSimulationJobInput {
	s.Job = &v
	return s
}
390143
func (j *Jenkins) CopyJob(copyFrom string, newName string) (*Job, error) {
	job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + copyFrom}
	_, err := job.Poll()
	if err != nil {
		return nil, err
	}
	return job.Copy(newName)
}
741016
func NewCreateJobOptions(ioStreams genericclioptions.IOStreams) *CreateJobOptions {
	return &CreateJobOptions{
		PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
		IOStreams:  ioStreams,
	}
}
991016
func (u *FakeAPIUtil) DeleteJob(jobName string, namespace string) error {
	u.DeletedJobs[namespace+"/"+jobName] = jobName
	return nil
}