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