1// Copyright 2021 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 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package automl 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "cloud.google.com/go/longrunning" 27 lroauto "cloud.google.com/go/longrunning/autogen" 28 "github.com/golang/protobuf/proto" 29 gax "github.com/googleapis/gax-go/v2" 30 "google.golang.org/api/iterator" 31 "google.golang.org/api/option" 32 "google.golang.org/api/option/internaloption" 33 gtransport "google.golang.org/api/transport/grpc" 34 automlpb "google.golang.org/genproto/googleapis/cloud/automl/v1" 35 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 36 "google.golang.org/grpc" 37 "google.golang.org/grpc/codes" 38 "google.golang.org/grpc/metadata" 39) 40 41var newClientHook clientHook 42 43// CallOptions contains the retry settings for each method of Client. 44type CallOptions struct { 45 CreateDataset []gax.CallOption 46 GetDataset []gax.CallOption 47 ListDatasets []gax.CallOption 48 UpdateDataset []gax.CallOption 49 DeleteDataset []gax.CallOption 50 ImportData []gax.CallOption 51 ExportData []gax.CallOption 52 GetAnnotationSpec []gax.CallOption 53 CreateModel []gax.CallOption 54 GetModel []gax.CallOption 55 ListModels []gax.CallOption 56 DeleteModel []gax.CallOption 57 UpdateModel []gax.CallOption 58 DeployModel []gax.CallOption 59 UndeployModel []gax.CallOption 60 ExportModel []gax.CallOption 61 GetModelEvaluation []gax.CallOption 62 ListModelEvaluations []gax.CallOption 63} 64 65func defaultClientOptions() []option.ClientOption { 66 return []option.ClientOption{ 67 internaloption.WithDefaultEndpoint("automl.googleapis.com:443"), 68 internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), 69 internaloption.WithDefaultAudience("https://automl.googleapis.com/"), 70 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 71 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 72 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 73 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 74 } 75} 76 77func defaultCallOptions() *CallOptions { 78 return &CallOptions{ 79 CreateDataset: []gax.CallOption{}, 80 GetDataset: []gax.CallOption{ 81 gax.WithRetry(func() gax.Retryer { 82 return gax.OnCodes([]codes.Code{ 83 codes.DeadlineExceeded, 84 codes.Unavailable, 85 }, gax.Backoff{ 86 Initial: 100 * time.Millisecond, 87 Max: 60000 * time.Millisecond, 88 Multiplier: 1.30, 89 }) 90 }), 91 }, 92 ListDatasets: []gax.CallOption{ 93 gax.WithRetry(func() gax.Retryer { 94 return gax.OnCodes([]codes.Code{ 95 codes.DeadlineExceeded, 96 codes.Unavailable, 97 }, gax.Backoff{ 98 Initial: 100 * time.Millisecond, 99 Max: 60000 * time.Millisecond, 100 Multiplier: 1.30, 101 }) 102 }), 103 }, 104 UpdateDataset: []gax.CallOption{}, 105 DeleteDataset: []gax.CallOption{ 106 gax.WithRetry(func() gax.Retryer { 107 return gax.OnCodes([]codes.Code{ 108 codes.DeadlineExceeded, 109 codes.Unavailable, 110 }, gax.Backoff{ 111 Initial: 100 * time.Millisecond, 112 Max: 60000 * time.Millisecond, 113 Multiplier: 1.30, 114 }) 115 }), 116 }, 117 ImportData: []gax.CallOption{}, 118 ExportData: []gax.CallOption{}, 119 GetAnnotationSpec: []gax.CallOption{ 120 gax.WithRetry(func() gax.Retryer { 121 return gax.OnCodes([]codes.Code{ 122 codes.DeadlineExceeded, 123 codes.Unavailable, 124 }, gax.Backoff{ 125 Initial: 100 * time.Millisecond, 126 Max: 60000 * time.Millisecond, 127 Multiplier: 1.30, 128 }) 129 }), 130 }, 131 CreateModel: []gax.CallOption{}, 132 GetModel: []gax.CallOption{ 133 gax.WithRetry(func() gax.Retryer { 134 return gax.OnCodes([]codes.Code{ 135 codes.DeadlineExceeded, 136 codes.Unavailable, 137 }, gax.Backoff{ 138 Initial: 100 * time.Millisecond, 139 Max: 60000 * time.Millisecond, 140 Multiplier: 1.30, 141 }) 142 }), 143 }, 144 ListModels: []gax.CallOption{ 145 gax.WithRetry(func() gax.Retryer { 146 return gax.OnCodes([]codes.Code{ 147 codes.DeadlineExceeded, 148 codes.Unavailable, 149 }, gax.Backoff{ 150 Initial: 100 * time.Millisecond, 151 Max: 60000 * time.Millisecond, 152 Multiplier: 1.30, 153 }) 154 }), 155 }, 156 DeleteModel: []gax.CallOption{ 157 gax.WithRetry(func() gax.Retryer { 158 return gax.OnCodes([]codes.Code{ 159 codes.DeadlineExceeded, 160 codes.Unavailable, 161 }, gax.Backoff{ 162 Initial: 100 * time.Millisecond, 163 Max: 60000 * time.Millisecond, 164 Multiplier: 1.30, 165 }) 166 }), 167 }, 168 UpdateModel: []gax.CallOption{}, 169 DeployModel: []gax.CallOption{}, 170 UndeployModel: []gax.CallOption{}, 171 ExportModel: []gax.CallOption{}, 172 GetModelEvaluation: []gax.CallOption{ 173 gax.WithRetry(func() gax.Retryer { 174 return gax.OnCodes([]codes.Code{ 175 codes.DeadlineExceeded, 176 codes.Unavailable, 177 }, gax.Backoff{ 178 Initial: 100 * time.Millisecond, 179 Max: 60000 * time.Millisecond, 180 Multiplier: 1.30, 181 }) 182 }), 183 }, 184 ListModelEvaluations: []gax.CallOption{ 185 gax.WithRetry(func() gax.Retryer { 186 return gax.OnCodes([]codes.Code{ 187 codes.DeadlineExceeded, 188 codes.Unavailable, 189 }, gax.Backoff{ 190 Initial: 100 * time.Millisecond, 191 Max: 60000 * time.Millisecond, 192 Multiplier: 1.30, 193 }) 194 }), 195 }, 196 } 197} 198 199// Client is a client for interacting with Cloud AutoML API. 200// 201// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 202type Client struct { 203 // Connection pool of gRPC connections to the service. 204 connPool gtransport.ConnPool 205 206 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 207 disableDeadlines bool 208 209 // The gRPC API client. 210 client automlpb.AutoMlClient 211 212 // LROClient is used internally to handle longrunning operations. 213 // It is exposed so that its CallOptions can be modified if required. 214 // Users should not Close this client. 215 LROClient *lroauto.OperationsClient 216 217 // The call options for this service. 218 CallOptions *CallOptions 219 220 // The x-goog-* metadata to be sent with each request. 221 xGoogMetadata metadata.MD 222} 223 224// NewClient creates a new auto ml client. 225// 226// AutoML Server API. 227// 228// The resource names are assigned by the server. 229// The server never reuses names that it has created after the resources with 230// those names are deleted. 231// 232// An ID of a resource is the last element of the item’s resource name. For 233// projects/{project_id}/locations/{location_id}/datasets/{dataset_id}, then 234// the id for the item is {dataset_id}. 235// 236// Currently the only supported location_id is “us-central1”. 237// 238// On any input that is documented to expect a string parameter in 239// snake_case or kebab-case, either of those cases is accepted. 240func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { 241 clientOpts := defaultClientOptions() 242 243 if newClientHook != nil { 244 hookOpts, err := newClientHook(ctx, clientHookParams{}) 245 if err != nil { 246 return nil, err 247 } 248 clientOpts = append(clientOpts, hookOpts...) 249 } 250 251 disableDeadlines, err := checkDisableDeadlines() 252 if err != nil { 253 return nil, err 254 } 255 256 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 257 if err != nil { 258 return nil, err 259 } 260 c := &Client{ 261 connPool: connPool, 262 disableDeadlines: disableDeadlines, 263 CallOptions: defaultCallOptions(), 264 265 client: automlpb.NewAutoMlClient(connPool), 266 } 267 c.setGoogleClientInfo() 268 269 c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 270 if err != nil { 271 // This error "should not happen", since we are just reusing old connection pool 272 // and never actually need to dial. 273 // If this does happen, we could leak connp. However, we cannot close conn: 274 // If the user invoked the constructor with option.WithGRPCConn, 275 // we would close a connection that's still in use. 276 // TODO: investigate error conditions. 277 return nil, err 278 } 279 return c, nil 280} 281 282// Connection returns a connection to the API service. 283// 284// Deprecated. 285func (c *Client) Connection() *grpc.ClientConn { 286 return c.connPool.Conn() 287} 288 289// Close closes the connection to the API service. The user should invoke this when 290// the client is no longer required. 291func (c *Client) Close() error { 292 return c.connPool.Close() 293} 294 295// setGoogleClientInfo sets the name and version of the application in 296// the `x-goog-api-client` header passed on each request. Intended for 297// use by Google-written clients. 298func (c *Client) setGoogleClientInfo(keyval ...string) { 299 kv := append([]string{"gl-go", versionGo()}, keyval...) 300 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 301 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 302} 303 304// CreateDataset creates a dataset. 305func (c *Client) CreateDataset(ctx context.Context, req *automlpb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) { 306 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 307 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 308 defer cancel() 309 ctx = cctx 310 } 311 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 312 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 313 opts = append(c.CallOptions.CreateDataset[0:len(c.CallOptions.CreateDataset):len(c.CallOptions.CreateDataset)], opts...) 314 var resp *longrunningpb.Operation 315 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 316 var err error 317 resp, err = c.client.CreateDataset(ctx, req, settings.GRPC...) 318 return err 319 }, opts...) 320 if err != nil { 321 return nil, err 322 } 323 return &CreateDatasetOperation{ 324 lro: longrunning.InternalNewOperation(c.LROClient, resp), 325 }, nil 326} 327 328// GetDataset gets a dataset. 329func (c *Client) GetDataset(ctx context.Context, req *automlpb.GetDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { 330 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 331 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 332 defer cancel() 333 ctx = cctx 334 } 335 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 336 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 337 opts = append(c.CallOptions.GetDataset[0:len(c.CallOptions.GetDataset):len(c.CallOptions.GetDataset)], opts...) 338 var resp *automlpb.Dataset 339 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 340 var err error 341 resp, err = c.client.GetDataset(ctx, req, settings.GRPC...) 342 return err 343 }, opts...) 344 if err != nil { 345 return nil, err 346 } 347 return resp, nil 348} 349 350// ListDatasets lists datasets in a project. 351func (c *Client) ListDatasets(ctx context.Context, req *automlpb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator { 352 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 353 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 354 opts = append(c.CallOptions.ListDatasets[0:len(c.CallOptions.ListDatasets):len(c.CallOptions.ListDatasets)], opts...) 355 it := &DatasetIterator{} 356 req = proto.Clone(req).(*automlpb.ListDatasetsRequest) 357 it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Dataset, string, error) { 358 var resp *automlpb.ListDatasetsResponse 359 req.PageToken = pageToken 360 if pageSize > math.MaxInt32 { 361 req.PageSize = math.MaxInt32 362 } else { 363 req.PageSize = int32(pageSize) 364 } 365 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 366 var err error 367 resp, err = c.client.ListDatasets(ctx, req, settings.GRPC...) 368 return err 369 }, opts...) 370 if err != nil { 371 return nil, "", err 372 } 373 374 it.Response = resp 375 return resp.GetDatasets(), resp.GetNextPageToken(), nil 376 } 377 fetch := func(pageSize int, pageToken string) (string, error) { 378 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 379 if err != nil { 380 return "", err 381 } 382 it.items = append(it.items, items...) 383 return nextPageToken, nil 384 } 385 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 386 it.pageInfo.MaxSize = int(req.GetPageSize()) 387 it.pageInfo.Token = req.GetPageToken() 388 return it 389} 390 391// UpdateDataset updates a dataset. 392func (c *Client) UpdateDataset(ctx context.Context, req *automlpb.UpdateDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { 393 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 394 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 395 defer cancel() 396 ctx = cctx 397 } 398 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "dataset.name", url.QueryEscape(req.GetDataset().GetName()))) 399 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 400 opts = append(c.CallOptions.UpdateDataset[0:len(c.CallOptions.UpdateDataset):len(c.CallOptions.UpdateDataset)], opts...) 401 var resp *automlpb.Dataset 402 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 403 var err error 404 resp, err = c.client.UpdateDataset(ctx, req, settings.GRPC...) 405 return err 406 }, opts...) 407 if err != nil { 408 return nil, err 409 } 410 return resp, nil 411} 412 413// DeleteDataset deletes a dataset and all of its contents. 414// Returns empty response in the 415// response field when it completes, 416// and delete_details in the 417// metadata field. 418func (c *Client) DeleteDataset(ctx context.Context, req *automlpb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) { 419 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 420 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 421 defer cancel() 422 ctx = cctx 423 } 424 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 425 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 426 opts = append(c.CallOptions.DeleteDataset[0:len(c.CallOptions.DeleteDataset):len(c.CallOptions.DeleteDataset)], opts...) 427 var resp *longrunningpb.Operation 428 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 429 var err error 430 resp, err = c.client.DeleteDataset(ctx, req, settings.GRPC...) 431 return err 432 }, opts...) 433 if err != nil { 434 return nil, err 435 } 436 return &DeleteDatasetOperation{ 437 lro: longrunning.InternalNewOperation(c.LROClient, resp), 438 }, nil 439} 440 441// ImportData imports data into a dataset. 442// For Tables this method can only be called on an empty Dataset. 443// 444// For Tables: 445// 446// A 447// schema_inference_version 448// parameter must be explicitly set. 449// Returns an empty response in the 450// response field when it completes. 451func (c *Client) ImportData(ctx context.Context, req *automlpb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) { 452 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 453 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 454 defer cancel() 455 ctx = cctx 456 } 457 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 458 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 459 opts = append(c.CallOptions.ImportData[0:len(c.CallOptions.ImportData):len(c.CallOptions.ImportData)], opts...) 460 var resp *longrunningpb.Operation 461 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 462 var err error 463 resp, err = c.client.ImportData(ctx, req, settings.GRPC...) 464 return err 465 }, opts...) 466 if err != nil { 467 return nil, err 468 } 469 return &ImportDataOperation{ 470 lro: longrunning.InternalNewOperation(c.LROClient, resp), 471 }, nil 472} 473 474// ExportData exports dataset’s data to the provided output location. 475// Returns an empty response in the 476// response field when it completes. 477func (c *Client) ExportData(ctx context.Context, req *automlpb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) { 478 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 479 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 480 defer cancel() 481 ctx = cctx 482 } 483 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 484 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 485 opts = append(c.CallOptions.ExportData[0:len(c.CallOptions.ExportData):len(c.CallOptions.ExportData)], opts...) 486 var resp *longrunningpb.Operation 487 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 488 var err error 489 resp, err = c.client.ExportData(ctx, req, settings.GRPC...) 490 return err 491 }, opts...) 492 if err != nil { 493 return nil, err 494 } 495 return &ExportDataOperation{ 496 lro: longrunning.InternalNewOperation(c.LROClient, resp), 497 }, nil 498} 499 500// GetAnnotationSpec gets an annotation spec. 501func (c *Client) GetAnnotationSpec(ctx context.Context, req *automlpb.GetAnnotationSpecRequest, opts ...gax.CallOption) (*automlpb.AnnotationSpec, error) { 502 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 503 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 504 defer cancel() 505 ctx = cctx 506 } 507 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 508 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 509 opts = append(c.CallOptions.GetAnnotationSpec[0:len(c.CallOptions.GetAnnotationSpec):len(c.CallOptions.GetAnnotationSpec)], opts...) 510 var resp *automlpb.AnnotationSpec 511 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 512 var err error 513 resp, err = c.client.GetAnnotationSpec(ctx, req, settings.GRPC...) 514 return err 515 }, opts...) 516 if err != nil { 517 return nil, err 518 } 519 return resp, nil 520} 521 522// CreateModel creates a model. 523// Returns a Model in the response 524// field when it completes. 525// When you create a model, several model evaluations are created for it: 526// a global evaluation, and one evaluation for each annotation spec. 527func (c *Client) CreateModel(ctx context.Context, req *automlpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { 528 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 529 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 530 defer cancel() 531 ctx = cctx 532 } 533 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 534 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 535 opts = append(c.CallOptions.CreateModel[0:len(c.CallOptions.CreateModel):len(c.CallOptions.CreateModel)], opts...) 536 var resp *longrunningpb.Operation 537 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 538 var err error 539 resp, err = c.client.CreateModel(ctx, req, settings.GRPC...) 540 return err 541 }, opts...) 542 if err != nil { 543 return nil, err 544 } 545 return &CreateModelOperation{ 546 lro: longrunning.InternalNewOperation(c.LROClient, resp), 547 }, nil 548} 549 550// GetModel gets a model. 551func (c *Client) GetModel(ctx context.Context, req *automlpb.GetModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { 552 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 553 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 554 defer cancel() 555 ctx = cctx 556 } 557 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 558 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 559 opts = append(c.CallOptions.GetModel[0:len(c.CallOptions.GetModel):len(c.CallOptions.GetModel)], opts...) 560 var resp *automlpb.Model 561 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 562 var err error 563 resp, err = c.client.GetModel(ctx, req, settings.GRPC...) 564 return err 565 }, opts...) 566 if err != nil { 567 return nil, err 568 } 569 return resp, nil 570} 571 572// ListModels lists models. 573func (c *Client) ListModels(ctx context.Context, req *automlpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { 574 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 575 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 576 opts = append(c.CallOptions.ListModels[0:len(c.CallOptions.ListModels):len(c.CallOptions.ListModels)], opts...) 577 it := &ModelIterator{} 578 req = proto.Clone(req).(*automlpb.ListModelsRequest) 579 it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Model, string, error) { 580 var resp *automlpb.ListModelsResponse 581 req.PageToken = pageToken 582 if pageSize > math.MaxInt32 { 583 req.PageSize = math.MaxInt32 584 } else { 585 req.PageSize = int32(pageSize) 586 } 587 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 588 var err error 589 resp, err = c.client.ListModels(ctx, req, settings.GRPC...) 590 return err 591 }, opts...) 592 if err != nil { 593 return nil, "", err 594 } 595 596 it.Response = resp 597 return resp.GetModel(), resp.GetNextPageToken(), nil 598 } 599 fetch := func(pageSize int, pageToken string) (string, error) { 600 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 601 if err != nil { 602 return "", err 603 } 604 it.items = append(it.items, items...) 605 return nextPageToken, nil 606 } 607 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 608 it.pageInfo.MaxSize = int(req.GetPageSize()) 609 it.pageInfo.Token = req.GetPageToken() 610 return it 611} 612 613// DeleteModel deletes a model. 614// Returns google.protobuf.Empty in the 615// response field when it completes, 616// and delete_details in the 617// metadata field. 618func (c *Client) DeleteModel(ctx context.Context, req *automlpb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) { 619 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 620 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 621 defer cancel() 622 ctx = cctx 623 } 624 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 625 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 626 opts = append(c.CallOptions.DeleteModel[0:len(c.CallOptions.DeleteModel):len(c.CallOptions.DeleteModel)], opts...) 627 var resp *longrunningpb.Operation 628 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 629 var err error 630 resp, err = c.client.DeleteModel(ctx, req, settings.GRPC...) 631 return err 632 }, opts...) 633 if err != nil { 634 return nil, err 635 } 636 return &DeleteModelOperation{ 637 lro: longrunning.InternalNewOperation(c.LROClient, resp), 638 }, nil 639} 640 641// UpdateModel updates a model. 642func (c *Client) UpdateModel(ctx context.Context, req *automlpb.UpdateModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { 643 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 644 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 645 defer cancel() 646 ctx = cctx 647 } 648 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "model.name", url.QueryEscape(req.GetModel().GetName()))) 649 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 650 opts = append(c.CallOptions.UpdateModel[0:len(c.CallOptions.UpdateModel):len(c.CallOptions.UpdateModel)], opts...) 651 var resp *automlpb.Model 652 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 653 var err error 654 resp, err = c.client.UpdateModel(ctx, req, settings.GRPC...) 655 return err 656 }, opts...) 657 if err != nil { 658 return nil, err 659 } 660 return resp, nil 661} 662 663// DeployModel deploys a model. If a model is already deployed, deploying it with the 664// same parameters has no effect. Deploying with different parametrs 665// (as e.g. changing 666// 667// node_number) 668// will reset the deployment state without pausing the model’s availability. 669// 670// Only applicable for Text Classification, Image Object Detection , Tables, and Image Segmentation; all other domains manage 671// deployment automatically. 672// 673// Returns an empty response in the 674// response field when it completes. 675func (c *Client) DeployModel(ctx context.Context, req *automlpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { 676 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 677 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 678 defer cancel() 679 ctx = cctx 680 } 681 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 682 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 683 opts = append(c.CallOptions.DeployModel[0:len(c.CallOptions.DeployModel):len(c.CallOptions.DeployModel)], opts...) 684 var resp *longrunningpb.Operation 685 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 686 var err error 687 resp, err = c.client.DeployModel(ctx, req, settings.GRPC...) 688 return err 689 }, opts...) 690 if err != nil { 691 return nil, err 692 } 693 return &DeployModelOperation{ 694 lro: longrunning.InternalNewOperation(c.LROClient, resp), 695 }, nil 696} 697 698// UndeployModel undeploys a model. If the model is not deployed this method has no effect. 699// 700// Only applicable for Text Classification, Image Object Detection and Tables; 701// all other domains manage deployment automatically. 702// 703// Returns an empty response in the 704// response field when it completes. 705func (c *Client) UndeployModel(ctx context.Context, req *automlpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { 706 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 707 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 708 defer cancel() 709 ctx = cctx 710 } 711 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 712 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 713 opts = append(c.CallOptions.UndeployModel[0:len(c.CallOptions.UndeployModel):len(c.CallOptions.UndeployModel)], opts...) 714 var resp *longrunningpb.Operation 715 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 716 var err error 717 resp, err = c.client.UndeployModel(ctx, req, settings.GRPC...) 718 return err 719 }, opts...) 720 if err != nil { 721 return nil, err 722 } 723 return &UndeployModelOperation{ 724 lro: longrunning.InternalNewOperation(c.LROClient, resp), 725 }, nil 726} 727 728// ExportModel exports a trained, “export-able”, model to a user specified Google Cloud 729// Storage location. A model is considered export-able if and only if it has 730// an export format defined for it in 731// ModelExportOutputConfig. 732// 733// Returns an empty response in the 734// response field when it completes. 735func (c *Client) ExportModel(ctx context.Context, req *automlpb.ExportModelRequest, opts ...gax.CallOption) (*ExportModelOperation, error) { 736 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 737 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 738 defer cancel() 739 ctx = cctx 740 } 741 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 742 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 743 opts = append(c.CallOptions.ExportModel[0:len(c.CallOptions.ExportModel):len(c.CallOptions.ExportModel)], opts...) 744 var resp *longrunningpb.Operation 745 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 746 var err error 747 resp, err = c.client.ExportModel(ctx, req, settings.GRPC...) 748 return err 749 }, opts...) 750 if err != nil { 751 return nil, err 752 } 753 return &ExportModelOperation{ 754 lro: longrunning.InternalNewOperation(c.LROClient, resp), 755 }, nil 756} 757 758// GetModelEvaluation gets a model evaluation. 759func (c *Client) GetModelEvaluation(ctx context.Context, req *automlpb.GetModelEvaluationRequest, opts ...gax.CallOption) (*automlpb.ModelEvaluation, error) { 760 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 761 cctx, cancel := context.WithTimeout(ctx, 5000*time.Millisecond) 762 defer cancel() 763 ctx = cctx 764 } 765 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 766 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 767 opts = append(c.CallOptions.GetModelEvaluation[0:len(c.CallOptions.GetModelEvaluation):len(c.CallOptions.GetModelEvaluation)], opts...) 768 var resp *automlpb.ModelEvaluation 769 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 770 var err error 771 resp, err = c.client.GetModelEvaluation(ctx, req, settings.GRPC...) 772 return err 773 }, opts...) 774 if err != nil { 775 return nil, err 776 } 777 return resp, nil 778} 779 780// ListModelEvaluations lists model evaluations. 781func (c *Client) ListModelEvaluations(ctx context.Context, req *automlpb.ListModelEvaluationsRequest, opts ...gax.CallOption) *ModelEvaluationIterator { 782 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 783 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 784 opts = append(c.CallOptions.ListModelEvaluations[0:len(c.CallOptions.ListModelEvaluations):len(c.CallOptions.ListModelEvaluations)], opts...) 785 it := &ModelEvaluationIterator{} 786 req = proto.Clone(req).(*automlpb.ListModelEvaluationsRequest) 787 it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.ModelEvaluation, string, error) { 788 var resp *automlpb.ListModelEvaluationsResponse 789 req.PageToken = pageToken 790 if pageSize > math.MaxInt32 { 791 req.PageSize = math.MaxInt32 792 } else { 793 req.PageSize = int32(pageSize) 794 } 795 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 796 var err error 797 resp, err = c.client.ListModelEvaluations(ctx, req, settings.GRPC...) 798 return err 799 }, opts...) 800 if err != nil { 801 return nil, "", err 802 } 803 804 it.Response = resp 805 return resp.GetModelEvaluation(), resp.GetNextPageToken(), nil 806 } 807 fetch := func(pageSize int, pageToken string) (string, error) { 808 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 809 if err != nil { 810 return "", err 811 } 812 it.items = append(it.items, items...) 813 return nextPageToken, nil 814 } 815 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 816 it.pageInfo.MaxSize = int(req.GetPageSize()) 817 it.pageInfo.Token = req.GetPageToken() 818 return it 819} 820 821// CreateDatasetOperation manages a long-running operation from CreateDataset. 822type CreateDatasetOperation struct { 823 lro *longrunning.Operation 824} 825 826// CreateDatasetOperation returns a new CreateDatasetOperation from a given name. 827// The name must be that of a previously created CreateDatasetOperation, possibly from a different process. 828func (c *Client) CreateDatasetOperation(name string) *CreateDatasetOperation { 829 return &CreateDatasetOperation{ 830 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 831 } 832} 833 834// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 835// 836// See documentation of Poll for error-handling information. 837func (op *CreateDatasetOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*automlpb.Dataset, error) { 838 var resp automlpb.Dataset 839 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 840 return nil, err 841 } 842 return &resp, nil 843} 844 845// Poll fetches the latest state of the long-running operation. 846// 847// Poll also fetches the latest metadata, which can be retrieved by Metadata. 848// 849// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 850// the operation has completed with failure, the error is returned and op.Done will return true. 851// If Poll succeeds and the operation has completed successfully, 852// op.Done will return true, and the response of the operation is returned. 853// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 854func (op *CreateDatasetOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*automlpb.Dataset, error) { 855 var resp automlpb.Dataset 856 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 857 return nil, err 858 } 859 if !op.Done() { 860 return nil, nil 861 } 862 return &resp, nil 863} 864 865// Metadata returns metadata associated with the long-running operation. 866// Metadata itself does not contact the server, but Poll does. 867// To get the latest metadata, call this method after a successful call to Poll. 868// If the metadata is not available, the returned metadata and error are both nil. 869func (op *CreateDatasetOperation) Metadata() (*automlpb.OperationMetadata, error) { 870 var meta automlpb.OperationMetadata 871 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 872 return nil, nil 873 } else if err != nil { 874 return nil, err 875 } 876 return &meta, nil 877} 878 879// Done reports whether the long-running operation has completed. 880func (op *CreateDatasetOperation) Done() bool { 881 return op.lro.Done() 882} 883 884// Name returns the name of the long-running operation. 885// The name is assigned by the server and is unique within the service from which the operation is created. 886func (op *CreateDatasetOperation) Name() string { 887 return op.lro.Name() 888} 889 890// CreateModelOperation manages a long-running operation from CreateModel. 891type CreateModelOperation struct { 892 lro *longrunning.Operation 893} 894 895// CreateModelOperation returns a new CreateModelOperation from a given name. 896// The name must be that of a previously created CreateModelOperation, possibly from a different process. 897func (c *Client) CreateModelOperation(name string) *CreateModelOperation { 898 return &CreateModelOperation{ 899 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 900 } 901} 902 903// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 904// 905// See documentation of Poll for error-handling information. 906func (op *CreateModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*automlpb.Model, error) { 907 var resp automlpb.Model 908 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 909 return nil, err 910 } 911 return &resp, nil 912} 913 914// Poll fetches the latest state of the long-running operation. 915// 916// Poll also fetches the latest metadata, which can be retrieved by Metadata. 917// 918// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 919// the operation has completed with failure, the error is returned and op.Done will return true. 920// If Poll succeeds and the operation has completed successfully, 921// op.Done will return true, and the response of the operation is returned. 922// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 923func (op *CreateModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*automlpb.Model, error) { 924 var resp automlpb.Model 925 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 926 return nil, err 927 } 928 if !op.Done() { 929 return nil, nil 930 } 931 return &resp, nil 932} 933 934// Metadata returns metadata associated with the long-running operation. 935// Metadata itself does not contact the server, but Poll does. 936// To get the latest metadata, call this method after a successful call to Poll. 937// If the metadata is not available, the returned metadata and error are both nil. 938func (op *CreateModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 939 var meta automlpb.OperationMetadata 940 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 941 return nil, nil 942 } else if err != nil { 943 return nil, err 944 } 945 return &meta, nil 946} 947 948// Done reports whether the long-running operation has completed. 949func (op *CreateModelOperation) Done() bool { 950 return op.lro.Done() 951} 952 953// Name returns the name of the long-running operation. 954// The name is assigned by the server and is unique within the service from which the operation is created. 955func (op *CreateModelOperation) Name() string { 956 return op.lro.Name() 957} 958 959// DeleteDatasetOperation manages a long-running operation from DeleteDataset. 960type DeleteDatasetOperation struct { 961 lro *longrunning.Operation 962} 963 964// DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name. 965// The name must be that of a previously created DeleteDatasetOperation, possibly from a different process. 966func (c *Client) DeleteDatasetOperation(name string) *DeleteDatasetOperation { 967 return &DeleteDatasetOperation{ 968 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 969 } 970} 971 972// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 973// 974// See documentation of Poll for error-handling information. 975func (op *DeleteDatasetOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 976 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 977} 978 979// Poll fetches the latest state of the long-running operation. 980// 981// Poll also fetches the latest metadata, which can be retrieved by Metadata. 982// 983// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 984// the operation has completed with failure, the error is returned and op.Done will return true. 985// If Poll succeeds and the operation has completed successfully, 986// op.Done will return true, and the response of the operation is returned. 987// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 988func (op *DeleteDatasetOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 989 return op.lro.Poll(ctx, nil, opts...) 990} 991 992// Metadata returns metadata associated with the long-running operation. 993// Metadata itself does not contact the server, but Poll does. 994// To get the latest metadata, call this method after a successful call to Poll. 995// If the metadata is not available, the returned metadata and error are both nil. 996func (op *DeleteDatasetOperation) Metadata() (*automlpb.OperationMetadata, error) { 997 var meta automlpb.OperationMetadata 998 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 999 return nil, nil 1000 } else if err != nil { 1001 return nil, err 1002 } 1003 return &meta, nil 1004} 1005 1006// Done reports whether the long-running operation has completed. 1007func (op *DeleteDatasetOperation) Done() bool { 1008 return op.lro.Done() 1009} 1010 1011// Name returns the name of the long-running operation. 1012// The name is assigned by the server and is unique within the service from which the operation is created. 1013func (op *DeleteDatasetOperation) Name() string { 1014 return op.lro.Name() 1015} 1016 1017// DeleteModelOperation manages a long-running operation from DeleteModel. 1018type DeleteModelOperation struct { 1019 lro *longrunning.Operation 1020} 1021 1022// DeleteModelOperation returns a new DeleteModelOperation from a given name. 1023// The name must be that of a previously created DeleteModelOperation, possibly from a different process. 1024func (c *Client) DeleteModelOperation(name string) *DeleteModelOperation { 1025 return &DeleteModelOperation{ 1026 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 1027 } 1028} 1029 1030// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1031// 1032// See documentation of Poll for error-handling information. 1033func (op *DeleteModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1034 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1035} 1036 1037// Poll fetches the latest state of the long-running operation. 1038// 1039// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1040// 1041// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1042// the operation has completed with failure, the error is returned and op.Done will return true. 1043// If Poll succeeds and the operation has completed successfully, 1044// op.Done will return true, and the response of the operation is returned. 1045// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1046func (op *DeleteModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1047 return op.lro.Poll(ctx, nil, opts...) 1048} 1049 1050// Metadata returns metadata associated with the long-running operation. 1051// Metadata itself does not contact the server, but Poll does. 1052// To get the latest metadata, call this method after a successful call to Poll. 1053// If the metadata is not available, the returned metadata and error are both nil. 1054func (op *DeleteModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1055 var meta automlpb.OperationMetadata 1056 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1057 return nil, nil 1058 } else if err != nil { 1059 return nil, err 1060 } 1061 return &meta, nil 1062} 1063 1064// Done reports whether the long-running operation has completed. 1065func (op *DeleteModelOperation) Done() bool { 1066 return op.lro.Done() 1067} 1068 1069// Name returns the name of the long-running operation. 1070// The name is assigned by the server and is unique within the service from which the operation is created. 1071func (op *DeleteModelOperation) Name() string { 1072 return op.lro.Name() 1073} 1074 1075// DeployModelOperation manages a long-running operation from DeployModel. 1076type DeployModelOperation struct { 1077 lro *longrunning.Operation 1078} 1079 1080// DeployModelOperation returns a new DeployModelOperation from a given name. 1081// The name must be that of a previously created DeployModelOperation, possibly from a different process. 1082func (c *Client) DeployModelOperation(name string) *DeployModelOperation { 1083 return &DeployModelOperation{ 1084 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 1085 } 1086} 1087 1088// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1089// 1090// See documentation of Poll for error-handling information. 1091func (op *DeployModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1092 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1093} 1094 1095// Poll fetches the latest state of the long-running operation. 1096// 1097// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1098// 1099// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1100// the operation has completed with failure, the error is returned and op.Done will return true. 1101// If Poll succeeds and the operation has completed successfully, 1102// op.Done will return true, and the response of the operation is returned. 1103// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1104func (op *DeployModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1105 return op.lro.Poll(ctx, nil, opts...) 1106} 1107 1108// Metadata returns metadata associated with the long-running operation. 1109// Metadata itself does not contact the server, but Poll does. 1110// To get the latest metadata, call this method after a successful call to Poll. 1111// If the metadata is not available, the returned metadata and error are both nil. 1112func (op *DeployModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1113 var meta automlpb.OperationMetadata 1114 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1115 return nil, nil 1116 } else if err != nil { 1117 return nil, err 1118 } 1119 return &meta, nil 1120} 1121 1122// Done reports whether the long-running operation has completed. 1123func (op *DeployModelOperation) Done() bool { 1124 return op.lro.Done() 1125} 1126 1127// Name returns the name of the long-running operation. 1128// The name is assigned by the server and is unique within the service from which the operation is created. 1129func (op *DeployModelOperation) Name() string { 1130 return op.lro.Name() 1131} 1132 1133// ExportDataOperation manages a long-running operation from ExportData. 1134type ExportDataOperation struct { 1135 lro *longrunning.Operation 1136} 1137 1138// ExportDataOperation returns a new ExportDataOperation from a given name. 1139// The name must be that of a previously created ExportDataOperation, possibly from a different process. 1140func (c *Client) ExportDataOperation(name string) *ExportDataOperation { 1141 return &ExportDataOperation{ 1142 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 1143 } 1144} 1145 1146// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1147// 1148// See documentation of Poll for error-handling information. 1149func (op *ExportDataOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1150 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1151} 1152 1153// Poll fetches the latest state of the long-running operation. 1154// 1155// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1156// 1157// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1158// the operation has completed with failure, the error is returned and op.Done will return true. 1159// If Poll succeeds and the operation has completed successfully, 1160// op.Done will return true, and the response of the operation is returned. 1161// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1162func (op *ExportDataOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1163 return op.lro.Poll(ctx, nil, opts...) 1164} 1165 1166// Metadata returns metadata associated with the long-running operation. 1167// Metadata itself does not contact the server, but Poll does. 1168// To get the latest metadata, call this method after a successful call to Poll. 1169// If the metadata is not available, the returned metadata and error are both nil. 1170func (op *ExportDataOperation) Metadata() (*automlpb.OperationMetadata, error) { 1171 var meta automlpb.OperationMetadata 1172 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1173 return nil, nil 1174 } else if err != nil { 1175 return nil, err 1176 } 1177 return &meta, nil 1178} 1179 1180// Done reports whether the long-running operation has completed. 1181func (op *ExportDataOperation) Done() bool { 1182 return op.lro.Done() 1183} 1184 1185// Name returns the name of the long-running operation. 1186// The name is assigned by the server and is unique within the service from which the operation is created. 1187func (op *ExportDataOperation) Name() string { 1188 return op.lro.Name() 1189} 1190 1191// ExportModelOperation manages a long-running operation from ExportModel. 1192type ExportModelOperation struct { 1193 lro *longrunning.Operation 1194} 1195 1196// ExportModelOperation returns a new ExportModelOperation from a given name. 1197// The name must be that of a previously created ExportModelOperation, possibly from a different process. 1198func (c *Client) ExportModelOperation(name string) *ExportModelOperation { 1199 return &ExportModelOperation{ 1200 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 1201 } 1202} 1203 1204// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1205// 1206// See documentation of Poll for error-handling information. 1207func (op *ExportModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1208 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1209} 1210 1211// Poll fetches the latest state of the long-running operation. 1212// 1213// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1214// 1215// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1216// the operation has completed with failure, the error is returned and op.Done will return true. 1217// If Poll succeeds and the operation has completed successfully, 1218// op.Done will return true, and the response of the operation is returned. 1219// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1220func (op *ExportModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1221 return op.lro.Poll(ctx, nil, opts...) 1222} 1223 1224// Metadata returns metadata associated with the long-running operation. 1225// Metadata itself does not contact the server, but Poll does. 1226// To get the latest metadata, call this method after a successful call to Poll. 1227// If the metadata is not available, the returned metadata and error are both nil. 1228func (op *ExportModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1229 var meta automlpb.OperationMetadata 1230 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1231 return nil, nil 1232 } else if err != nil { 1233 return nil, err 1234 } 1235 return &meta, nil 1236} 1237 1238// Done reports whether the long-running operation has completed. 1239func (op *ExportModelOperation) Done() bool { 1240 return op.lro.Done() 1241} 1242 1243// Name returns the name of the long-running operation. 1244// The name is assigned by the server and is unique within the service from which the operation is created. 1245func (op *ExportModelOperation) Name() string { 1246 return op.lro.Name() 1247} 1248 1249// ImportDataOperation manages a long-running operation from ImportData. 1250type ImportDataOperation struct { 1251 lro *longrunning.Operation 1252} 1253 1254// ImportDataOperation returns a new ImportDataOperation from a given name. 1255// The name must be that of a previously created ImportDataOperation, possibly from a different process. 1256func (c *Client) ImportDataOperation(name string) *ImportDataOperation { 1257 return &ImportDataOperation{ 1258 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 1259 } 1260} 1261 1262// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1263// 1264// See documentation of Poll for error-handling information. 1265func (op *ImportDataOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1266 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1267} 1268 1269// Poll fetches the latest state of the long-running operation. 1270// 1271// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1272// 1273// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1274// the operation has completed with failure, the error is returned and op.Done will return true. 1275// If Poll succeeds and the operation has completed successfully, 1276// op.Done will return true, and the response of the operation is returned. 1277// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1278func (op *ImportDataOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1279 return op.lro.Poll(ctx, nil, opts...) 1280} 1281 1282// Metadata returns metadata associated with the long-running operation. 1283// Metadata itself does not contact the server, but Poll does. 1284// To get the latest metadata, call this method after a successful call to Poll. 1285// If the metadata is not available, the returned metadata and error are both nil. 1286func (op *ImportDataOperation) Metadata() (*automlpb.OperationMetadata, error) { 1287 var meta automlpb.OperationMetadata 1288 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1289 return nil, nil 1290 } else if err != nil { 1291 return nil, err 1292 } 1293 return &meta, nil 1294} 1295 1296// Done reports whether the long-running operation has completed. 1297func (op *ImportDataOperation) Done() bool { 1298 return op.lro.Done() 1299} 1300 1301// Name returns the name of the long-running operation. 1302// The name is assigned by the server and is unique within the service from which the operation is created. 1303func (op *ImportDataOperation) Name() string { 1304 return op.lro.Name() 1305} 1306 1307// UndeployModelOperation manages a long-running operation from UndeployModel. 1308type UndeployModelOperation struct { 1309 lro *longrunning.Operation 1310} 1311 1312// UndeployModelOperation returns a new UndeployModelOperation from a given name. 1313// The name must be that of a previously created UndeployModelOperation, possibly from a different process. 1314func (c *Client) UndeployModelOperation(name string) *UndeployModelOperation { 1315 return &UndeployModelOperation{ 1316 lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), 1317 } 1318} 1319 1320// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 1321// 1322// See documentation of Poll for error-handling information. 1323func (op *UndeployModelOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 1324 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 1325} 1326 1327// Poll fetches the latest state of the long-running operation. 1328// 1329// Poll also fetches the latest metadata, which can be retrieved by Metadata. 1330// 1331// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 1332// the operation has completed with failure, the error is returned and op.Done will return true. 1333// If Poll succeeds and the operation has completed successfully, 1334// op.Done will return true, and the response of the operation is returned. 1335// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 1336func (op *UndeployModelOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 1337 return op.lro.Poll(ctx, nil, opts...) 1338} 1339 1340// Metadata returns metadata associated with the long-running operation. 1341// Metadata itself does not contact the server, but Poll does. 1342// To get the latest metadata, call this method after a successful call to Poll. 1343// If the metadata is not available, the returned metadata and error are both nil. 1344func (op *UndeployModelOperation) Metadata() (*automlpb.OperationMetadata, error) { 1345 var meta automlpb.OperationMetadata 1346 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 1347 return nil, nil 1348 } else if err != nil { 1349 return nil, err 1350 } 1351 return &meta, nil 1352} 1353 1354// Done reports whether the long-running operation has completed. 1355func (op *UndeployModelOperation) Done() bool { 1356 return op.lro.Done() 1357} 1358 1359// Name returns the name of the long-running operation. 1360// The name is assigned by the server and is unique within the service from which the operation is created. 1361func (op *UndeployModelOperation) Name() string { 1362 return op.lro.Name() 1363} 1364 1365// DatasetIterator manages a stream of *automlpb.Dataset. 1366type DatasetIterator struct { 1367 items []*automlpb.Dataset 1368 pageInfo *iterator.PageInfo 1369 nextFunc func() error 1370 1371 // Response is the raw response for the current page. 1372 // It must be cast to the RPC response type. 1373 // Calling Next() or InternalFetch() updates this value. 1374 Response interface{} 1375 1376 // InternalFetch is for use by the Google Cloud Libraries only. 1377 // It is not part of the stable interface of this package. 1378 // 1379 // InternalFetch returns results from a single call to the underlying RPC. 1380 // The number of results is no greater than pageSize. 1381 // If there are no more results, nextPageToken is empty and err is nil. 1382 InternalFetch func(pageSize int, pageToken string) (results []*automlpb.Dataset, nextPageToken string, err error) 1383} 1384 1385// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1386func (it *DatasetIterator) PageInfo() *iterator.PageInfo { 1387 return it.pageInfo 1388} 1389 1390// Next returns the next result. Its second return value is iterator.Done if there are no more 1391// results. Once Next returns Done, all subsequent calls will return Done. 1392func (it *DatasetIterator) Next() (*automlpb.Dataset, error) { 1393 var item *automlpb.Dataset 1394 if err := it.nextFunc(); err != nil { 1395 return item, err 1396 } 1397 item = it.items[0] 1398 it.items = it.items[1:] 1399 return item, nil 1400} 1401 1402func (it *DatasetIterator) bufLen() int { 1403 return len(it.items) 1404} 1405 1406func (it *DatasetIterator) takeBuf() interface{} { 1407 b := it.items 1408 it.items = nil 1409 return b 1410} 1411 1412// ModelEvaluationIterator manages a stream of *automlpb.ModelEvaluation. 1413type ModelEvaluationIterator struct { 1414 items []*automlpb.ModelEvaluation 1415 pageInfo *iterator.PageInfo 1416 nextFunc func() error 1417 1418 // Response is the raw response for the current page. 1419 // It must be cast to the RPC response type. 1420 // Calling Next() or InternalFetch() updates this value. 1421 Response interface{} 1422 1423 // InternalFetch is for use by the Google Cloud Libraries only. 1424 // It is not part of the stable interface of this package. 1425 // 1426 // InternalFetch returns results from a single call to the underlying RPC. 1427 // The number of results is no greater than pageSize. 1428 // If there are no more results, nextPageToken is empty and err is nil. 1429 InternalFetch func(pageSize int, pageToken string) (results []*automlpb.ModelEvaluation, nextPageToken string, err error) 1430} 1431 1432// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1433func (it *ModelEvaluationIterator) PageInfo() *iterator.PageInfo { 1434 return it.pageInfo 1435} 1436 1437// Next returns the next result. Its second return value is iterator.Done if there are no more 1438// results. Once Next returns Done, all subsequent calls will return Done. 1439func (it *ModelEvaluationIterator) Next() (*automlpb.ModelEvaluation, error) { 1440 var item *automlpb.ModelEvaluation 1441 if err := it.nextFunc(); err != nil { 1442 return item, err 1443 } 1444 item = it.items[0] 1445 it.items = it.items[1:] 1446 return item, nil 1447} 1448 1449func (it *ModelEvaluationIterator) bufLen() int { 1450 return len(it.items) 1451} 1452 1453func (it *ModelEvaluationIterator) takeBuf() interface{} { 1454 b := it.items 1455 it.items = nil 1456 return b 1457} 1458 1459// ModelIterator manages a stream of *automlpb.Model. 1460type ModelIterator struct { 1461 items []*automlpb.Model 1462 pageInfo *iterator.PageInfo 1463 nextFunc func() error 1464 1465 // Response is the raw response for the current page. 1466 // It must be cast to the RPC response type. 1467 // Calling Next() or InternalFetch() updates this value. 1468 Response interface{} 1469 1470 // InternalFetch is for use by the Google Cloud Libraries only. 1471 // It is not part of the stable interface of this package. 1472 // 1473 // InternalFetch returns results from a single call to the underlying RPC. 1474 // The number of results is no greater than pageSize. 1475 // If there are no more results, nextPageToken is empty and err is nil. 1476 InternalFetch func(pageSize int, pageToken string) (results []*automlpb.Model, nextPageToken string, err error) 1477} 1478 1479// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 1480func (it *ModelIterator) PageInfo() *iterator.PageInfo { 1481 return it.pageInfo 1482} 1483 1484// Next returns the next result. Its second return value is iterator.Done if there are no more 1485// results. Once Next returns Done, all subsequent calls will return Done. 1486func (it *ModelIterator) Next() (*automlpb.Model, error) { 1487 var item *automlpb.Model 1488 if err := it.nextFunc(); err != nil { 1489 return item, err 1490 } 1491 item = it.items[0] 1492 it.items = it.items[1:] 1493 return item, nil 1494} 1495 1496func (it *ModelIterator) bufLen() int { 1497 return len(it.items) 1498} 1499 1500func (it *ModelIterator) takeBuf() interface{} { 1501 b := it.items 1502 it.items = nil 1503 return b 1504} 1505