You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

288 rivejä
10 KiB

  1. // Copyright 2018 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package dataproc
  16. import (
  17. "math"
  18. "time"
  19. "cloud.google.com/go/internal/version"
  20. gax "github.com/googleapis/gax-go"
  21. "golang.org/x/net/context"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. dataprocpb "google.golang.org/genproto/googleapis/cloud/dataproc/v1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // JobControllerCallOptions contains the retry settings for each method of JobControllerClient.
  31. type JobControllerCallOptions struct {
  32. SubmitJob []gax.CallOption
  33. GetJob []gax.CallOption
  34. ListJobs []gax.CallOption
  35. UpdateJob []gax.CallOption
  36. CancelJob []gax.CallOption
  37. DeleteJob []gax.CallOption
  38. }
  39. func defaultJobControllerClientOptions() []option.ClientOption {
  40. return []option.ClientOption{
  41. option.WithEndpoint("dataproc.googleapis.com:443"),
  42. option.WithScopes(DefaultAuthScopes()...),
  43. }
  44. }
  45. func defaultJobControllerCallOptions() *JobControllerCallOptions {
  46. retry := map[[2]string][]gax.CallOption{
  47. {"default", "idempotent"}: {
  48. gax.WithRetry(func() gax.Retryer {
  49. return gax.OnCodes([]codes.Code{
  50. codes.DeadlineExceeded,
  51. codes.Unavailable,
  52. }, gax.Backoff{
  53. Initial: 100 * time.Millisecond,
  54. Max: 60000 * time.Millisecond,
  55. Multiplier: 1.3,
  56. })
  57. }),
  58. },
  59. }
  60. return &JobControllerCallOptions{
  61. SubmitJob: retry[[2]string{"default", "non_idempotent"}],
  62. GetJob: retry[[2]string{"default", "idempotent"}],
  63. ListJobs: retry[[2]string{"default", "idempotent"}],
  64. UpdateJob: retry[[2]string{"default", "non_idempotent"}],
  65. CancelJob: retry[[2]string{"default", "non_idempotent"}],
  66. DeleteJob: retry[[2]string{"default", "idempotent"}],
  67. }
  68. }
  69. // JobControllerClient is a client for interacting with Google Cloud Dataproc API.
  70. //
  71. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  72. type JobControllerClient struct {
  73. // The connection to the service.
  74. conn *grpc.ClientConn
  75. // The gRPC API client.
  76. jobControllerClient dataprocpb.JobControllerClient
  77. // The call options for this service.
  78. CallOptions *JobControllerCallOptions
  79. // The x-goog-* metadata to be sent with each request.
  80. xGoogMetadata metadata.MD
  81. }
  82. // NewJobControllerClient creates a new job controller client.
  83. //
  84. // The JobController provides methods to manage jobs.
  85. func NewJobControllerClient(ctx context.Context, opts ...option.ClientOption) (*JobControllerClient, error) {
  86. conn, err := transport.DialGRPC(ctx, append(defaultJobControllerClientOptions(), opts...)...)
  87. if err != nil {
  88. return nil, err
  89. }
  90. c := &JobControllerClient{
  91. conn: conn,
  92. CallOptions: defaultJobControllerCallOptions(),
  93. jobControllerClient: dataprocpb.NewJobControllerClient(conn),
  94. }
  95. c.setGoogleClientInfo()
  96. return c, nil
  97. }
  98. // Connection returns the client's connection to the API service.
  99. func (c *JobControllerClient) Connection() *grpc.ClientConn {
  100. return c.conn
  101. }
  102. // Close closes the connection to the API service. The user should invoke this when
  103. // the client is no longer required.
  104. func (c *JobControllerClient) Close() error {
  105. return c.conn.Close()
  106. }
  107. // setGoogleClientInfo sets the name and version of the application in
  108. // the `x-goog-api-client` header passed on each request. Intended for
  109. // use by Google-written clients.
  110. func (c *JobControllerClient) setGoogleClientInfo(keyval ...string) {
  111. kv := append([]string{"gl-go", version.Go()}, keyval...)
  112. kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
  113. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  114. }
  115. // SubmitJob submits a job to a cluster.
  116. func (c *JobControllerClient) SubmitJob(ctx context.Context, req *dataprocpb.SubmitJobRequest, opts ...gax.CallOption) (*dataprocpb.Job, error) {
  117. ctx = insertMetadata(ctx, c.xGoogMetadata)
  118. opts = append(c.CallOptions.SubmitJob[0:len(c.CallOptions.SubmitJob):len(c.CallOptions.SubmitJob)], opts...)
  119. var resp *dataprocpb.Job
  120. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  121. var err error
  122. resp, err = c.jobControllerClient.SubmitJob(ctx, req, settings.GRPC...)
  123. return err
  124. }, opts...)
  125. if err != nil {
  126. return nil, err
  127. }
  128. return resp, nil
  129. }
  130. // GetJob gets the resource representation for a job in a project.
  131. func (c *JobControllerClient) GetJob(ctx context.Context, req *dataprocpb.GetJobRequest, opts ...gax.CallOption) (*dataprocpb.Job, error) {
  132. ctx = insertMetadata(ctx, c.xGoogMetadata)
  133. opts = append(c.CallOptions.GetJob[0:len(c.CallOptions.GetJob):len(c.CallOptions.GetJob)], opts...)
  134. var resp *dataprocpb.Job
  135. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  136. var err error
  137. resp, err = c.jobControllerClient.GetJob(ctx, req, settings.GRPC...)
  138. return err
  139. }, opts...)
  140. if err != nil {
  141. return nil, err
  142. }
  143. return resp, nil
  144. }
  145. // ListJobs lists regions/{region}/jobs in a project.
  146. func (c *JobControllerClient) ListJobs(ctx context.Context, req *dataprocpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
  147. ctx = insertMetadata(ctx, c.xGoogMetadata)
  148. opts = append(c.CallOptions.ListJobs[0:len(c.CallOptions.ListJobs):len(c.CallOptions.ListJobs)], opts...)
  149. it := &JobIterator{}
  150. it.InternalFetch = func(pageSize int, pageToken string) ([]*dataprocpb.Job, string, error) {
  151. var resp *dataprocpb.ListJobsResponse
  152. req.PageToken = pageToken
  153. if pageSize > math.MaxInt32 {
  154. req.PageSize = math.MaxInt32
  155. } else {
  156. req.PageSize = int32(pageSize)
  157. }
  158. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  159. var err error
  160. resp, err = c.jobControllerClient.ListJobs(ctx, req, settings.GRPC...)
  161. return err
  162. }, opts...)
  163. if err != nil {
  164. return nil, "", err
  165. }
  166. return resp.Jobs, resp.NextPageToken, nil
  167. }
  168. fetch := func(pageSize int, pageToken string) (string, error) {
  169. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  170. if err != nil {
  171. return "", err
  172. }
  173. it.items = append(it.items, items...)
  174. return nextPageToken, nil
  175. }
  176. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  177. return it
  178. }
  179. // UpdateJob updates a job in a project.
  180. func (c *JobControllerClient) UpdateJob(ctx context.Context, req *dataprocpb.UpdateJobRequest, opts ...gax.CallOption) (*dataprocpb.Job, error) {
  181. ctx = insertMetadata(ctx, c.xGoogMetadata)
  182. opts = append(c.CallOptions.UpdateJob[0:len(c.CallOptions.UpdateJob):len(c.CallOptions.UpdateJob)], opts...)
  183. var resp *dataprocpb.Job
  184. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  185. var err error
  186. resp, err = c.jobControllerClient.UpdateJob(ctx, req, settings.GRPC...)
  187. return err
  188. }, opts...)
  189. if err != nil {
  190. return nil, err
  191. }
  192. return resp, nil
  193. }
  194. // CancelJob starts a job cancellation request. To access the job resource
  195. // after cancellation, call
  196. // regions/{region}/jobs.list (at /dataproc/docs/reference/rest/v1/projects.regions.jobs/list) or
  197. // regions/{region}/jobs.get (at /dataproc/docs/reference/rest/v1/projects.regions.jobs/get).
  198. func (c *JobControllerClient) CancelJob(ctx context.Context, req *dataprocpb.CancelJobRequest, opts ...gax.CallOption) (*dataprocpb.Job, error) {
  199. ctx = insertMetadata(ctx, c.xGoogMetadata)
  200. opts = append(c.CallOptions.CancelJob[0:len(c.CallOptions.CancelJob):len(c.CallOptions.CancelJob)], opts...)
  201. var resp *dataprocpb.Job
  202. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  203. var err error
  204. resp, err = c.jobControllerClient.CancelJob(ctx, req, settings.GRPC...)
  205. return err
  206. }, opts...)
  207. if err != nil {
  208. return nil, err
  209. }
  210. return resp, nil
  211. }
  212. // DeleteJob deletes the job from the project. If the job is active, the delete fails,
  213. // and the response returns FAILED_PRECONDITION.
  214. func (c *JobControllerClient) DeleteJob(ctx context.Context, req *dataprocpb.DeleteJobRequest, opts ...gax.CallOption) error {
  215. ctx = insertMetadata(ctx, c.xGoogMetadata)
  216. opts = append(c.CallOptions.DeleteJob[0:len(c.CallOptions.DeleteJob):len(c.CallOptions.DeleteJob)], opts...)
  217. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  218. var err error
  219. _, err = c.jobControllerClient.DeleteJob(ctx, req, settings.GRPC...)
  220. return err
  221. }, opts...)
  222. return err
  223. }
  224. // JobIterator manages a stream of *dataprocpb.Job.
  225. type JobIterator struct {
  226. items []*dataprocpb.Job
  227. pageInfo *iterator.PageInfo
  228. nextFunc func() error
  229. // InternalFetch is for use by the Google Cloud Libraries only.
  230. // It is not part of the stable interface of this package.
  231. //
  232. // InternalFetch returns results from a single call to the underlying RPC.
  233. // The number of results is no greater than pageSize.
  234. // If there are no more results, nextPageToken is empty and err is nil.
  235. InternalFetch func(pageSize int, pageToken string) (results []*dataprocpb.Job, nextPageToken string, err error)
  236. }
  237. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  238. func (it *JobIterator) PageInfo() *iterator.PageInfo {
  239. return it.pageInfo
  240. }
  241. // Next returns the next result. Its second return value is iterator.Done if there are no more
  242. // results. Once Next returns Done, all subsequent calls will return Done.
  243. func (it *JobIterator) Next() (*dataprocpb.Job, error) {
  244. var item *dataprocpb.Job
  245. if err := it.nextFunc(); err != nil {
  246. return item, err
  247. }
  248. item = it.items[0]
  249. it.items = it.items[1:]
  250. return item, nil
  251. }
  252. func (it *JobIterator) bufLen() int {
  253. return len(it.items)
  254. }
  255. func (it *JobIterator) takeBuf() interface{} {
  256. b := it.items
  257. it.items = nil
  258. return b
  259. }