github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/mrs/v2/jobs/requests.go (about) 1 package jobs 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 var requestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 9 MoreHeaders: map[string]string{"Content-Type": "application/json"}, 10 } 11 12 // CreateOpts is a structure representing information of the job creation. 13 type CreateOpts struct { 14 // Type of a job, and the valid values are as follows: 15 // MapReduce 16 // SparkSubmit 17 // HiveScript 18 // HiveSql 19 // DistCp, importing and exporting data 20 // SparkScript 21 // SparkSql 22 // Flink 23 // NOTE: 24 // Spark, Hive, and Flink jobs can be added to only clusters that include Spark, Hive, and Flink components. 25 JobType string `json:"job_type" required:"true"` 26 // Job name. It contains 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. 27 // NOTE: 28 // Identical job names are allowed but not recommended. 29 JobName string `json:"job_name" required:"true"` 30 // Key parameter for program execution. 31 // The parameter is specified by the function of the user's program. 32 // MRS is only responsible for loading the parameter. 33 // The parameter contains a maximum of 4,096 characters, excluding special characters such as ;|&>'<$, 34 // and can be left blank. 35 // NOTE: 36 // If you enter a parameter with sensitive information (such as the login password), the parameter may be exposed 37 // in the job details display and log printing. Exercise caution when performing this operation. 38 // For MRS 1.9.2 or later, a file path on OBS can start with obs://. To use this format to submit HiveScript or 39 // HiveSQL jobs, choose Components > Hive > Service Configuration on the cluster details page, set Type to All, 40 // and search for core.site.customized.configs. Add the endpoint configuration item (fs.obs.endpoint) of OBS and 41 // enter the endpoint corresponding to OBS in Value. Obtain the value from Regions and Endpoints. 42 // For MRS 3.0.2 or later, a file path on OBS can start with obs://. To use this format to submit HiveScript or 43 // HiveSQL jobs, choose Components > Hive > Service Configuration on Manager. Switch Basic to All, and search for 44 // core.site.customized.configs. Add the endpoint configuration item (fs.obs.endpoint) of OBS and enter the 45 // endpoint corresponding to OBS in Value. Obtain the value from Regions and Endpoints. 46 Arguments []string `json:"arguments,omitempty"` 47 // Program system parameter. 48 // The parameter contains a maximum of 2,048 characters, excluding special characters such as ><|'`&!\, and can be 49 // left blank. 50 Properties map[string]string `json:"properties,omitempty"` 51 } 52 53 // CreateOptsBuilder is an interface which to support request body build of the job creation. 54 type CreateOptsBuilder interface { 55 ToJobCreateMap() (map[string]interface{}, error) 56 } 57 58 // ToJobCreateMap is a method which to build a request body by the CreateOpts. 59 func (opts CreateOpts) ToJobCreateMap() (map[string]interface{}, error) { 60 return golangsdk.BuildRequestBody(opts, "") 61 } 62 63 // Create is a method to create a new mapreduce job. 64 func Create(client *golangsdk.ServiceClient, clusterId string, opts CreateOptsBuilder) (r CreateResult) { 65 reqBody, err := opts.ToJobCreateMap() 66 if err != nil { 67 r.Err = err 68 return 69 } 70 _, r.Err = client.Post(rootURL(client, clusterId), reqBody, &r.Body, nil) 71 return 72 } 73 74 // Get is a method to get an existing mapreduce job by cluster ID and job ID. 75 func Get(client *golangsdk.ServiceClient, clsuterId, jobId string) (r GetResult) { 76 _, r.Err = client.Get(resourceURL(client, clsuterId, jobId), &r.Body, &golangsdk.RequestOpts{ 77 MoreHeaders: requestOpts.MoreHeaders, 78 OkCodes: []int{200, 202}, 79 }) 80 return 81 } 82 83 // ListOpts is a structure representing information of the job updation. 84 type ListOpts struct { 85 // Job name. It contains 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. 86 JobName string `q:"job_name"` 87 // Type of a job, and the valid values are as follows: 88 // MapReduce 89 // SparkSubmit 90 // HiveScript 91 // HiveSql 92 // DistCp, importing and exporting data 93 // SparkScript 94 // SparkSql 95 // Flink 96 JobType string `q:"job_type"` 97 // Execution status of a job. 98 // FAILED: indicates that the job fails to be executed. 99 // KILLED: indicates that the job is terminated. 100 // New: indicates that the job is created. 101 // NEW_SAVING: indicates that the job has been created and is being saved. 102 // SUBMITTED: indicates that the job is submitted. 103 // ACCEPTED: indicates that the job is accepted. 104 // RUNNING: indicates that the job is running. 105 // FINISHED: indicates that the job is completed. 106 JobState string `q:"job_state"` 107 // Execution result of a job. 108 // FAILED: indicates that the job fails to be executed. 109 // KILLED: indicates that the job is manually terminated during execution. 110 // UNDEFINED: indicates that the job is being executed. 111 // SUCCEEDED: indicates that the job has been successfully executed. 112 JobResult string `q:"job_result"` 113 // Number of records displayed on each page in the returned result. The default value is 10. 114 Limit int `q:"limit"` 115 // Offset. 116 // The default offset from which the job list starts to be queried is 1. 117 Offset int `q:"offset"` 118 // Ranking mode of returned results. The default value is desc. 119 // asc: indicates that the returned results are ranked in ascending order. 120 // desc: indicates that the returned results are ranked in descending order. 121 SortBy string `q:"sort_by"` 122 // UTC timestamp after which a job is submitted, in milliseconds. For example, 1562032041362. 123 SubmittedTimeBegin int `q:"submitted_time_begin"` 124 // UTC timestamp before which a job is submitted, in milliseconds. For example, 1562032041362. 125 SubmittedTimeEnd int `q:"submitted_time_end"` 126 } 127 128 // ListOptsBuilder is an interface which to support request query build of the job list operation. 129 type ListOptsBuilder interface { 130 ToListQuery() (string, error) 131 } 132 133 // ToListQuery is a method which to build a request query by the ListOpts. 134 func (opts ListOpts) ToListQuery() (string, error) { 135 q, err := golangsdk.BuildQueryString(opts) 136 if err != nil { 137 return "", err 138 } 139 return q.String(), err 140 } 141 142 // List is a method to obtain an array of one or more mapreduce jobs according to the query parameters. 143 func List(client *golangsdk.ServiceClient, clusterId string, opts ListOptsBuilder) pagination.Pager { 144 url := rootURL(client, clusterId) 145 if opts != nil { 146 query, err := opts.ToListQuery() 147 if err != nil { 148 return pagination.Pager{Err: err} 149 } 150 url += query 151 } 152 153 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 154 return JobPage{pagination.SinglePageBase(r)} 155 }) 156 } 157 158 // DeleteOpts is a structure representing information of the job delete operation. 159 type DeleteOpts struct { 160 JobIds []string `json:"job_id_list,omitempty"` 161 } 162 163 // DeleteOptsBuilder is an interface which to support request body build of the job delete operation. 164 type DeleteOptsBuilder interface { 165 ToJobDeleteMap() (map[string]interface{}, error) 166 } 167 168 // ToJobDeleteMap is a method which to build a request body by the DeleteOpts. 169 func (opts DeleteOpts) ToJobDeleteMap() (map[string]interface{}, error) { 170 return golangsdk.BuildRequestBody(opts, "") 171 } 172 173 // Delete is a method to delete an existing mapreduce job. 174 func Delete(client *golangsdk.ServiceClient, clusterId string, opts DeleteOptsBuilder) (r DeleteResult) { 175 reqBody, err := opts.ToJobDeleteMap() 176 if err != nil { 177 r.Err = err 178 return 179 } 180 _, r.Err = client.Post(deleteURL(client, clusterId), reqBody, nil, nil) 181 return 182 }