github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/mrs/v1/job/requests.go (about) 1 package job 2 3 import ( 4 "log" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 10 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 11 } 12 13 type CreateOpts struct { 14 JobType int `json:"job_type" required:"true"` 15 JobName string `json:"job_name" required:"true"` 16 ClusterID string `json:"cluster_id" required:"true"` 17 JarPath string `json:"jar_path" required:"true"` 18 Arguments string `json:"arguments,omitempty"` 19 Input string `json:"input,omitempty"` 20 Output string `json:"output,omitempty"` 21 JobLog string `json:"job_log,omitempty"` 22 HiveScriptPath string `json:"hive_script_path,omitempty"` 23 IsProtected bool `json:"is_protected,omitempty"` 24 IsPublic bool `json:"is_public,omitempty"` 25 } 26 27 type CreateOptsBuilder interface { 28 ToJobCreateMap() (map[string]interface{}, error) 29 } 30 31 func (opts CreateOpts) ToJobCreateMap() (map[string]interface{}, error) { 32 return golangsdk.BuildRequestBody(opts, "") 33 } 34 35 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 36 b, err := opts.ToJobCreateMap() 37 if err != nil { 38 r.Err = err 39 return 40 } 41 log.Printf("[DEBUG] create url:%q, body=%#v", createURL(c), b) 42 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, 43 MoreHeaders: RequestOpts.MoreHeaders} 44 _, r.Err = c.Post(createURL(c), b, &r.Body, reqOpt) 45 return 46 } 47 48 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 49 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}, 50 MoreHeaders: RequestOpts.MoreHeaders} 51 _, r.Err = c.Get(getURL(c, id), &r.Body, reqOpt) 52 return 53 } 54 55 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 56 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}, 57 MoreHeaders: RequestOpts.MoreHeaders} 58 _, r.Err = c.Delete(deleteURL(c, id), reqOpt) 59 return 60 }