|
| 1 | +package cos |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/xml" |
| 6 | + "fmt" |
| 7 | + "net/http" |
| 8 | +) |
| 9 | + |
| 10 | +type BatchService service |
| 11 | + |
| 12 | +type BatchRequestHeaders struct { |
| 13 | + XCosAppid int `header:"x-cos-appid"` |
| 14 | + ContentLength string `header:"Content-Length,omitempty"` |
| 15 | + ContentType string `header:"Content-Type,omitempty"` |
| 16 | + Headers *http.Header `header:"-"` |
| 17 | +} |
| 18 | + |
| 19 | +// BatchProgressSummary |
| 20 | +type BatchProgressSummary struct { |
| 21 | + NumberOfTasksFailed int `xml:"NumberOfTasksFailed"` |
| 22 | + NumberOfTasksSucceeded int `xml:"NumberOfTasksSucceeded"` |
| 23 | + TotalNumberOfTasks int `xml:"TotalNumberOfTasks"` |
| 24 | +} |
| 25 | + |
| 26 | +// BatchJobReport |
| 27 | +type BatchJobReport struct { |
| 28 | + Bucket string `xml:"Bucket"` |
| 29 | + Enabled string `xml:"Enabled"` |
| 30 | + Format string `xml:"Format"` |
| 31 | + Prefix string `xml:"Prefix,omitempty"` |
| 32 | + ReportScope string `xml:"ReportScope"` |
| 33 | +} |
| 34 | + |
| 35 | +// BatchJobOperationCopy |
| 36 | +type BatchMetadata struct { |
| 37 | + Key string `xml:"Key"` |
| 38 | + Value string `xml:"Value"` |
| 39 | +} |
| 40 | +type BatchNewObjectMetadata struct { |
| 41 | + CacheControl string `xml:"CacheControl,omitempty"` |
| 42 | + ContentDisposition string `xml:"ContentDisposition,omitempty"` |
| 43 | + ContentEncoding string `xml:"ContentEncoding,omitempty"` |
| 44 | + ContentType string `xml:"ContentType,omitempty"` |
| 45 | + HttpExpiresDate string `xml:"HttpExpiresDate,omitempty"` |
| 46 | + SSEAlgorithm string `xml:"SSEAlgorithm,omitempty"` |
| 47 | + UserMetadata []BatchMetadata `xml:"UserMetadata>member,omitempty"` |
| 48 | +} |
| 49 | +type BatchGrantee struct { |
| 50 | + DisplayName string `xml:"DisplayName,omitempty"` |
| 51 | + Identifier string `xml:"Identifier"` |
| 52 | + TypeIdentifier string `xml:"TypeIdentifier"` |
| 53 | +} |
| 54 | +type BatchCOSGrant struct { |
| 55 | + Grantee *BatchGrantee `xml:"Grantee"` |
| 56 | + Permission string `xml:"Permission"` |
| 57 | +} |
| 58 | +type BatchAccessControlGrants struct { |
| 59 | + COSGrants *BatchCOSGrant `xml:"COSGrant,omitempty"` |
| 60 | +} |
| 61 | +type BatchJobOperationCopy struct { |
| 62 | + AccessControlGrants *BatchAccessControlGrants `xml:"AccessControlGrants,omitempty"` |
| 63 | + CannedAccessControlList string `xml:"CannedAccessControlList,omitempty"` |
| 64 | + MetadataDirective string `xml:"MetadataDirective,omitempty"` |
| 65 | + ModifiedSinceConstraint int64 `xml:"ModifiedSinceConstraint,omitempty"` |
| 66 | + UnModifiedSinceConstraint int64 `xml:"UnModifiedSinceConstraint,omitempty"` |
| 67 | + NewObjectMetadata *BatchNewObjectMetadata `xml:"NewObjectMetadata,omitempty"` |
| 68 | + StorageClass string `xml:"StorageClass,omitempty"` |
| 69 | + TargetResource string `xml:"TargetResource"` |
| 70 | +} |
| 71 | + |
| 72 | +// BatchJobOperation |
| 73 | +type BatchJobOperation struct { |
| 74 | + PutObjectCopy *BatchJobOperationCopy `xml:"COSPutObjectCopy,omitempty" header:"-"` |
| 75 | +} |
| 76 | + |
| 77 | +// BatchJobManifest |
| 78 | +type BatchJobManifestLocation struct { |
| 79 | + ETag string `xml:"ETag" header:"-"` |
| 80 | + ObjectArn string `xml:"ObjectArn" header:"-"` |
| 81 | + ObjectVersionId string `xml:"ObjectVersionId,omitempty" header:"-"` |
| 82 | +} |
| 83 | +type BatchJobManifestSpec struct { |
| 84 | + Fields []string `xml:"Fields>member,omitempty" header:"-"` |
| 85 | + Format string `xml:"Format" header:"-"` |
| 86 | +} |
| 87 | +type BatchJobManifest struct { |
| 88 | + Location *BatchJobManifestLocation `xml:"Location" header:"-"` |
| 89 | + Spec *BatchJobManifestSpec `xml:"Spec" header:"-"` |
| 90 | +} |
| 91 | + |
| 92 | +type BatchCreateJobOptions struct { |
| 93 | + XMLName xml.Name `xml:"CreateJobRequest" header:"-"` |
| 94 | + ClientRequestToken string `xml:"ClientRequestToken" header:"-"` |
| 95 | + ConfirmationRequired string `xml:"ConfirmationRequired,omitempty" header:"-"` |
| 96 | + Description string `xml:"Description,omitempty" header:"-"` |
| 97 | + Manifest *BatchJobManifest `xml:"Manifest" header:"-"` |
| 98 | + Operation *BatchJobOperation `xml:"Operation" header:"-"` |
| 99 | + Priority int `xml:"Priority" header:"-"` |
| 100 | + Report *BatchJobReport `xml:"Report" header:"-"` |
| 101 | + RoleArn string `xml:"RoleArn" header:"-"` |
| 102 | +} |
| 103 | + |
| 104 | +type BatchCreateJobResult struct { |
| 105 | + XMLName xml.Name `xml:"CreateJobResult"` |
| 106 | + JobId string `xml:"JobId"` |
| 107 | +} |
| 108 | + |
| 109 | +func processETag(opt *BatchCreateJobOptions) *BatchCreateJobOptions { |
| 110 | + if opt != nil && opt.Manifest != nil && opt.Manifest.Location != nil { |
| 111 | + opt.Manifest.Location.ETag = "<ETag>" + opt.Manifest.Location.ETag + "</ETag>" |
| 112 | + } |
| 113 | + return opt |
| 114 | +} |
| 115 | + |
| 116 | +func (s *BatchService) CreateJob(ctx context.Context, opt *BatchCreateJobOptions, headers *BatchRequestHeaders) (*BatchCreateJobResult, *Response, error) { |
| 117 | + var res BatchCreateJobResult |
| 118 | + sendOpt := sendOptions{ |
| 119 | + baseURL: s.client.BaseURL.BatchURL, |
| 120 | + uri: "/jobs", |
| 121 | + method: http.MethodPost, |
| 122 | + optHeader: headers, |
| 123 | + body: opt, |
| 124 | + result: &res, |
| 125 | + } |
| 126 | + |
| 127 | + resp, err := s.client.send(ctx, &sendOpt) |
| 128 | + return &res, resp, err |
| 129 | +} |
| 130 | + |
| 131 | +type BatchJobFailureReasons struct { |
| 132 | + FailureCode string `xml:"FailureCode"` |
| 133 | + FailureReason string `xml:"FailureReason"` |
| 134 | +} |
| 135 | + |
| 136 | +type BatchDescribeJob struct { |
| 137 | + ConfirmationRequired string `xml:"ConfirmationRequired,omitempty"` |
| 138 | + CreationTime string `xml:"CreationTime,omitempty"` |
| 139 | + Description string `xml:"Description,omitempty"` |
| 140 | + FailureReasons *BatchJobFailureReasons `xml:"FailureReasons>JobFailure,omitempty"` |
| 141 | + JobId string `xml:"JobId"` |
| 142 | + Manifest *BatchJobManifest `xml:"Manifest"` |
| 143 | + Operation *BatchJobOperation `xml:"Operation"` |
| 144 | + Priority int `xml:"Priority"` |
| 145 | + ProgressSummary *BatchProgressSummary `xml:"ProgressSummary"` |
| 146 | + Report *BatchJobReport `xml:"Report,omitempty"` |
| 147 | + RoleArn string `xml:"RoleArn,omitempty"` |
| 148 | + Status string `xml:"Status,omitempty"` |
| 149 | + StatusUpdateReason string `xml:"StatusUpdateReason,omitempty"` |
| 150 | + SuspendedCause string `xml:"SuspendedCause,omitempty"` |
| 151 | + SuspendedDate string `xml:"SuspendedDate,omitempty"` |
| 152 | + TerminationDate string `xml:"TerminationDate,omitempty"` |
| 153 | +} |
| 154 | +type BatchDescribeJobResult struct { |
| 155 | + XMLName xml.Name `xml:"DescribeJobResult"` |
| 156 | + Job *BatchDescribeJob `xml:"Job"` |
| 157 | +} |
| 158 | + |
| 159 | +func (s *BatchService) DescribeJob(ctx context.Context, id string, headers *BatchRequestHeaders) (*BatchDescribeJobResult, *Response, error) { |
| 160 | + var res BatchDescribeJobResult |
| 161 | + u := fmt.Sprintf("/jobs/%s", id) |
| 162 | + sendOpt := sendOptions{ |
| 163 | + baseURL: s.client.BaseURL.BatchURL, |
| 164 | + uri: u, |
| 165 | + method: http.MethodGet, |
| 166 | + optHeader: headers, |
| 167 | + result: &res, |
| 168 | + } |
| 169 | + resp, err := s.client.send(ctx, &sendOpt) |
| 170 | + return &res, resp, err |
| 171 | +} |
| 172 | + |
| 173 | +type BatchListJobsOptions struct { |
| 174 | + JobStatuses string `url:"jobStatuses,omitempty" header:"-"` |
| 175 | + MaxResults int `url:"maxResults,omitempty" header:"-"` |
| 176 | + NextToken string `url:"nextToken,omitempty" header:"-"` |
| 177 | +} |
| 178 | + |
| 179 | +type BatchListJobsMember struct { |
| 180 | + CreationTime string `xml:"CreationTime,omitempty"` |
| 181 | + Description string `xml:"Description,omitempty"` |
| 182 | + JobId string `xml:"JobId,omitempty"` |
| 183 | + Operation string `xml:"Operation,omitempty"` |
| 184 | + Priority int `xml:"Priority,omitempty"` |
| 185 | + ProgressSummary *BatchProgressSummary `xml:"ProgressSummary,omitempty"` |
| 186 | + Status string `xml:"Status,omitempty"` |
| 187 | + TerminationDate string `xml:"TerminationDate,omitempty"` |
| 188 | +} |
| 189 | +type BatchListJobs struct { |
| 190 | + Members []BatchListJobsMember `xml:"member,omitempty"` |
| 191 | +} |
| 192 | +type BatchListJobsResult struct { |
| 193 | + XMLName xml.Name `xml:"ListJobsResult"` |
| 194 | + Jobs *BatchListJobs `xml:"Jobs"` |
| 195 | + NextToken string `xml:"NextToken,omitempty"` |
| 196 | +} |
| 197 | + |
| 198 | +func (s *BatchService) ListJobs(ctx context.Context, opt *BatchListJobsOptions, headers *BatchRequestHeaders) (*BatchListJobsResult, *Response, error) { |
| 199 | + var res BatchListJobsResult |
| 200 | + sendOpt := sendOptions{ |
| 201 | + baseURL: s.client.BaseURL.BatchURL, |
| 202 | + uri: "/jobs", |
| 203 | + method: http.MethodGet, |
| 204 | + optQuery: opt, |
| 205 | + optHeader: headers, |
| 206 | + result: &res, |
| 207 | + } |
| 208 | + resp, err := s.client.send(ctx, &sendOpt) |
| 209 | + return &res, resp, err |
| 210 | +} |
| 211 | + |
| 212 | +type BatchUpdatePriorityOptions struct { |
| 213 | + JobId string `url:"-" header:"-" xml:"-"` |
| 214 | + Priority int `url:"priority" header:"-" xml:"-"` |
| 215 | +} |
| 216 | +type BatchUpdatePriorityResult struct { |
| 217 | + XMLName xml.Name `xml:"UpdateJobPriorityResult"` |
| 218 | + JobId string `xml:"JobId,omitempty"` |
| 219 | + Priority int `xml:"Priority,omitempty"` |
| 220 | +} |
| 221 | + |
| 222 | +func (s *BatchService) UpdateJobPriority(ctx context.Context, opt *BatchUpdatePriorityOptions, headers *BatchRequestHeaders) (*BatchUpdatePriorityResult, *Response, error) { |
| 223 | + u := fmt.Sprintf("/jobs/%s/priority", opt.JobId) |
| 224 | + var res BatchUpdatePriorityResult |
| 225 | + sendOpt := sendOptions{ |
| 226 | + baseURL: s.client.BaseURL.BatchURL, |
| 227 | + uri: u, |
| 228 | + method: http.MethodPost, |
| 229 | + optQuery: opt, |
| 230 | + optHeader: headers, |
| 231 | + result: &res, |
| 232 | + } |
| 233 | + resp, err := s.client.send(ctx, &sendOpt) |
| 234 | + return &res, resp, err |
| 235 | +} |
| 236 | + |
| 237 | +type BatchUpdateStatusOptions struct { |
| 238 | + JobId string `header:"-" url:"-" xml:"-"` |
| 239 | + RequestedJobStatus string `url:"requestedJobStatus" header:"-" xml:"-"` |
| 240 | + StatusUpdateReason string `url:"statusUpdateReason,omitempty" header:"-", xml:"-"` |
| 241 | +} |
| 242 | +type BatchUpdateStatusResult struct { |
| 243 | + XMLName xml.Name `xml:"UpdateJobStatusResult"` |
| 244 | + JobId string `xml:"JobId,omitempty"` |
| 245 | + Status string `xml:"Status,omitempty"` |
| 246 | + StatusUpdateReason string `xml:"StatusUpdateReason,omitempty"` |
| 247 | +} |
| 248 | + |
| 249 | +func (s *BatchService) UpdateJobStatus(ctx context.Context, opt *BatchUpdateStatusOptions, headers *BatchRequestHeaders) (*BatchUpdateStatusResult, *Response, error) { |
| 250 | + u := fmt.Sprintf("/jobs/%s/status", opt.JobId) |
| 251 | + var res BatchUpdateStatusResult |
| 252 | + sendOpt := sendOptions{ |
| 253 | + baseURL: s.client.BaseURL.BatchURL, |
| 254 | + uri: u, |
| 255 | + method: http.MethodPost, |
| 256 | + optQuery: opt, |
| 257 | + optHeader: headers, |
| 258 | + result: &res, |
| 259 | + } |
| 260 | + resp, err := s.client.send(ctx, &sendOpt) |
| 261 | + return &res, resp, err |
| 262 | +} |
0 commit comments