| 1 |
// Copyright 2025 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 |
|
| 17 |
package automl |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
automlpb "cloud.google.com/go/automl/apiv1/automlpb" |
| 30 |
"cloud.google.com/go/longrunning" |
| 31 |
lroauto "cloud.google.com/go/longrunning/autogen" |
| 32 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 33 |
gax "github.com/googleapis/gax-go/v2" |
| 34 |
"google.golang.org/api/iterator" |
| 35 |
"google.golang.org/api/option" |
| 36 |
"google.golang.org/api/option/internaloption" |
| 37 |
gtransport "google.golang.org/api/transport/grpc" |
| 38 |
httptransport "google.golang.org/api/transport/http" |
| 39 |
"google.golang.org/grpc" |
| 40 |
"google.golang.org/grpc/codes" |
| 41 |
"google.golang.org/protobuf/encoding/protojson" |
| 42 |
"google.golang.org/protobuf/proto" |
| 43 |
) |
| 44 |
|
| 45 |
var newClientHook clientHook |
| 46 |
|
| 47 |
// CallOptions contains the retry settings for each method of Client. |
| 48 |
type CallOptions struct { |
| 49 |
CreateDataset []gax.CallOption |
| 50 |
GetDataset []gax.CallOption |
| 51 |
ListDatasets []gax.CallOption |
| 52 |
UpdateDataset []gax.CallOption |
| 53 |
DeleteDataset []gax.CallOption |
| 54 |
ImportData []gax.CallOption |
| 55 |
ExportData []gax.CallOption |
| 56 |
GetAnnotationSpec []gax.CallOption |
| 57 |
CreateModel []gax.CallOption |
| 58 |
GetModel []gax.CallOption |
| 59 |
ListModels []gax.CallOption |
| 60 |
DeleteModel []gax.CallOption |
| 61 |
UpdateModel []gax.CallOption |
| 62 |
DeployModel []gax.CallOption |
| 63 |
UndeployModel []gax.CallOption |
| 64 |
ExportModel []gax.CallOption |
| 65 |
GetModelEvaluation []gax.CallOption |
| 66 |
ListModelEvaluations []gax.CallOption |
| 67 |
} |
| 68 |
|
| 69 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 70 |
return []option.ClientOption{ |
| 71 |
internaloption.WithDefaultEndpoint("automl.googleapis.com:443"), |
| 72 |
internaloption.WithDefaultEndpointTemplate("automl.UNIVERSE_DOMAIN:443"), |
| 73 |
internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), |
| 74 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 75 |
internaloption.WithDefaultAudience("https://automl.googleapis.com/"), |
| 76 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 77 |
internaloption.EnableJwtWithScope(), |
| 78 |
internaloption.EnableNewAuthLibrary(), |
| 79 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 80 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
func defaultCallOptions() *CallOptions { |
| 85 |
return &CallOptions{ |
| 86 |
CreateDataset: []gax.CallOption{ |
| 87 |
gax.WithTimeout(5000 * time.Millisecond), |
| 88 |
}, |
| 89 |
GetDataset: []gax.CallOption{ |
| 90 |
gax.WithTimeout(5000 * time.Millisecond), |
| 91 |
gax.WithRetry(func() gax.Retryer { |
| 92 |
return gax.OnCodes([]codes.Code{ |
| 93 |
codes.DeadlineExceeded, |
| 94 |
codes.Unavailable, |
| 95 |
}, gax.Backoff{ |
| 96 |
Initial: 100 * time.Millisecond, |
| 97 |
Max: 60000 * time.Millisecond, |
| 98 |
Multiplier: 1.30, |
| 99 |
}) |
| 100 |
}), |
| 101 |
}, |
| 102 |
ListDatasets: []gax.CallOption{ |
| 103 |
gax.WithTimeout(5000 * time.Millisecond), |
| 104 |
gax.WithRetry(func() gax.Retryer { |
| 105 |
return gax.OnCodes([]codes.Code{ |
| 106 |
codes.DeadlineExceeded, |
| 107 |
codes.Unavailable, |
| 108 |
}, gax.Backoff{ |
| 109 |
Initial: 100 * time.Millisecond, |
| 110 |
Max: 60000 * time.Millisecond, |
| 111 |
Multiplier: 1.30, |
| 112 |
}) |
| 113 |
}), |
| 114 |
}, |
| 115 |
UpdateDataset: []gax.CallOption{ |
| 116 |
gax.WithTimeout(5000 * time.Millisecond), |
| 117 |
}, |
| 118 |
DeleteDataset: []gax.CallOption{ |
| 119 |
gax.WithTimeout(5000 * time.Millisecond), |
| 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 |
ImportData: []gax.CallOption{ |
| 132 |
gax.WithTimeout(5000 * time.Millisecond), |
| 133 |
}, |
| 134 |
ExportData: []gax.CallOption{ |
| 135 |
gax.WithTimeout(5000 * time.Millisecond), |
| 136 |
}, |
| 137 |
GetAnnotationSpec: []gax.CallOption{ |
| 138 |
gax.WithTimeout(5000 * time.Millisecond), |
| 139 |
gax.WithRetry(func() gax.Retryer { |
| 140 |
return gax.OnCodes([]codes.Code{ |
| 141 |
codes.DeadlineExceeded, |
| 142 |
codes.Unavailable, |
| 143 |
}, gax.Backoff{ |
| 144 |
Initial: 100 * time.Millisecond, |
| 145 |
Max: 60000 * time.Millisecond, |
| 146 |
Multiplier: 1.30, |
| 147 |
}) |
| 148 |
}), |
| 149 |
}, |
| 150 |
CreateModel: []gax.CallOption{ |
| 151 |
gax.WithTimeout(5000 * time.Millisecond), |
| 152 |
}, |
| 153 |
GetModel: []gax.CallOption{ |
| 154 |
gax.WithTimeout(5000 * time.Millisecond), |
| 155 |
gax.WithRetry(func() gax.Retryer { |
| 156 |
return gax.OnCodes([]codes.Code{ |
| 157 |
codes.DeadlineExceeded, |
| 158 |
codes.Unavailable, |
| 159 |
}, gax.Backoff{ |
| 160 |
Initial: 100 * time.Millisecond, |
| 161 |
Max: 60000 * time.Millisecond, |
| 162 |
Multiplier: 1.30, |
| 163 |
}) |
| 164 |
}), |
| 165 |
}, |
| 166 |
ListModels: []gax.CallOption{ |
| 167 |
gax.WithTimeout(5000 * time.Millisecond), |
| 168 |
gax.WithRetry(func() gax.Retryer { |
| 169 |
return gax.OnCodes([]codes.Code{ |
| 170 |
codes.DeadlineExceeded, |
| 171 |
codes.Unavailable, |
| 172 |
}, gax.Backoff{ |
| 173 |
Initial: 100 * time.Millisecond, |
| 174 |
Max: 60000 * time.Millisecond, |
| 175 |
Multiplier: 1.30, |
| 176 |
}) |
| 177 |
}), |
| 178 |
}, |
| 179 |
DeleteModel: []gax.CallOption{ |
| 180 |
gax.WithTimeout(5000 * time.Millisecond), |
| 181 |
gax.WithRetry(func() gax.Retryer { |
| 182 |
return gax.OnCodes([]codes.Code{ |
| 183 |
codes.DeadlineExceeded, |
| 184 |
codes.Unavailable, |
| 185 |
}, gax.Backoff{ |
| 186 |
Initial: 100 * time.Millisecond, |
| 187 |
Max: 60000 * time.Millisecond, |
| 188 |
Multiplier: 1.30, |
| 189 |
}) |
| 190 |
}), |
| 191 |
}, |
| 192 |
UpdateModel: []gax.CallOption{ |
| 193 |
gax.WithTimeout(5000 * time.Millisecond), |
| 194 |
}, |
| 195 |
DeployModel: []gax.CallOption{ |
| 196 |
gax.WithTimeout(5000 * time.Millisecond), |
| 197 |
}, |
| 198 |
UndeployModel: []gax.CallOption{ |
| 199 |
gax.WithTimeout(5000 * time.Millisecond), |
| 200 |
}, |
| 201 |
ExportModel: []gax.CallOption{ |
| 202 |
gax.WithTimeout(5000 * time.Millisecond), |
| 203 |
}, |
| 204 |
GetModelEvaluation: []gax.CallOption{ |
| 205 |
gax.WithTimeout(5000 * time.Millisecond), |
| 206 |
gax.WithRetry(func() gax.Retryer { |
| 207 |
return gax.OnCodes([]codes.Code{ |
| 208 |
codes.DeadlineExceeded, |
| 209 |
codes.Unavailable, |
| 210 |
}, gax.Backoff{ |
| 211 |
Initial: 100 * time.Millisecond, |
| 212 |
Max: 60000 * time.Millisecond, |
| 213 |
Multiplier: 1.30, |
| 214 |
}) |
| 215 |
}), |
| 216 |
}, |
| 217 |
ListModelEvaluations: []gax.CallOption{ |
| 218 |
gax.WithTimeout(5000 * time.Millisecond), |
| 219 |
gax.WithRetry(func() gax.Retryer { |
| 220 |
return gax.OnCodes([]codes.Code{ |
| 221 |
codes.DeadlineExceeded, |
| 222 |
codes.Unavailable, |
| 223 |
}, gax.Backoff{ |
| 224 |
Initial: 100 * time.Millisecond, |
| 225 |
Max: 60000 * time.Millisecond, |
| 226 |
Multiplier: 1.30, |
| 227 |
}) |
| 228 |
}), |
| 229 |
}, |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
func defaultRESTCallOptions() *CallOptions { |
| 234 |
return &CallOptions{ |
| 235 |
CreateDataset: []gax.CallOption{ |
| 236 |
gax.WithTimeout(5000 * time.Millisecond), |
| 237 |
}, |
| 238 |
GetDataset: []gax.CallOption{ |
| 239 |
gax.WithTimeout(5000 * time.Millisecond), |
| 240 |
gax.WithRetry(func() gax.Retryer { |
| 241 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 242 |
Initial: 100 * time.Millisecond, |
| 243 |
Max: 60000 * time.Millisecond, |
| 244 |
Multiplier: 1.30, |
| 245 |
}, |
| 246 |
http.StatusGatewayTimeout, |
| 247 |
http.StatusServiceUnavailable) |
| 248 |
}), |
| 249 |
}, |
| 250 |
ListDatasets: []gax.CallOption{ |
| 251 |
gax.WithTimeout(5000 * time.Millisecond), |
| 252 |
gax.WithRetry(func() gax.Retryer { |
| 253 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 254 |
Initial: 100 * time.Millisecond, |
| 255 |
Max: 60000 * time.Millisecond, |
| 256 |
Multiplier: 1.30, |
| 257 |
}, |
| 258 |
http.StatusGatewayTimeout, |
| 259 |
http.StatusServiceUnavailable) |
| 260 |
}), |
| 261 |
}, |
| 262 |
UpdateDataset: []gax.CallOption{ |
| 263 |
gax.WithTimeout(5000 * time.Millisecond), |
| 264 |
}, |
| 265 |
DeleteDataset: []gax.CallOption{ |
| 266 |
gax.WithTimeout(5000 * time.Millisecond), |
| 267 |
gax.WithRetry(func() gax.Retryer { |
| 268 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 269 |
Initial: 100 * time.Millisecond, |
| 270 |
Max: 60000 * time.Millisecond, |
| 271 |
Multiplier: 1.30, |
| 272 |
}, |
| 273 |
http.StatusGatewayTimeout, |
| 274 |
http.StatusServiceUnavailable) |
| 275 |
}), |
| 276 |
}, |
| 277 |
ImportData: []gax.CallOption{ |
| 278 |
gax.WithTimeout(5000 * time.Millisecond), |
| 279 |
}, |
| 280 |
ExportData: []gax.CallOption{ |
| 281 |
gax.WithTimeout(5000 * time.Millisecond), |
| 282 |
}, |
| 283 |
GetAnnotationSpec: []gax.CallOption{ |
| 284 |
gax.WithTimeout(5000 * time.Millisecond), |
| 285 |
gax.WithRetry(func() gax.Retryer { |
| 286 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 287 |
Initial: 100 * time.Millisecond, |
| 288 |
Max: 60000 * time.Millisecond, |
| 289 |
Multiplier: 1.30, |
| 290 |
}, |
| 291 |
http.StatusGatewayTimeout, |
| 292 |
http.StatusServiceUnavailable) |
| 293 |
}), |
| 294 |
}, |
| 295 |
CreateModel: []gax.CallOption{ |
| 296 |
gax.WithTimeout(5000 * time.Millisecond), |
| 297 |
}, |
| 298 |
GetModel: []gax.CallOption{ |
| 299 |
gax.WithTimeout(5000 * time.Millisecond), |
| 300 |
gax.WithRetry(func() gax.Retryer { |
| 301 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 302 |
Initial: 100 * time.Millisecond, |
| 303 |
Max: 60000 * time.Millisecond, |
| 304 |
Multiplier: 1.30, |
| 305 |
}, |
| 306 |
http.StatusGatewayTimeout, |
| 307 |
http.StatusServiceUnavailable) |
| 308 |
}), |
| 309 |
}, |
| 310 |
ListModels: []gax.CallOption{ |
| 311 |
gax.WithTimeout(5000 * time.Millisecond), |
| 312 |
gax.WithRetry(func() gax.Retryer { |
| 313 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 314 |
Initial: 100 * time.Millisecond, |
| 315 |
Max: 60000 * time.Millisecond, |
| 316 |
Multiplier: 1.30, |
| 317 |
}, |
| 318 |
http.StatusGatewayTimeout, |
| 319 |
http.StatusServiceUnavailable) |
| 320 |
}), |
| 321 |
}, |
| 322 |
DeleteModel: []gax.CallOption{ |
| 323 |
gax.WithTimeout(5000 * time.Millisecond), |
| 324 |
gax.WithRetry(func() gax.Retryer { |
| 325 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 326 |
Initial: 100 * time.Millisecond, |
| 327 |
Max: 60000 * time.Millisecond, |
| 328 |
Multiplier: 1.30, |
| 329 |
}, |
| 330 |
http.StatusGatewayTimeout, |
| 331 |
http.StatusServiceUnavailable) |
| 332 |
}), |
| 333 |
}, |
| 334 |
UpdateModel: []gax.CallOption{ |
| 335 |
gax.WithTimeout(5000 * time.Millisecond), |
| 336 |
}, |
| 337 |
DeployModel: []gax.CallOption{ |
| 338 |
gax.WithTimeout(5000 * time.Millisecond), |
| 339 |
}, |
| 340 |
UndeployModel: []gax.CallOption{ |
| 341 |
gax.WithTimeout(5000 * time.Millisecond), |
| 342 |
}, |
| 343 |
ExportModel: []gax.CallOption{ |
| 344 |
gax.WithTimeout(5000 * time.Millisecond), |
| 345 |
}, |
| 346 |
GetModelEvaluation: []gax.CallOption{ |
| 347 |
gax.WithTimeout(5000 * time.Millisecond), |
| 348 |
gax.WithRetry(func() gax.Retryer { |
| 349 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 350 |
Initial: 100 * time.Millisecond, |
| 351 |
Max: 60000 * time.Millisecond, |
| 352 |
Multiplier: 1.30, |
| 353 |
}, |
| 354 |
http.StatusGatewayTimeout, |
| 355 |
http.StatusServiceUnavailable) |
| 356 |
}), |
| 357 |
}, |
| 358 |
ListModelEvaluations: []gax.CallOption{ |
| 359 |
gax.WithTimeout(5000 * time.Millisecond), |
| 360 |
gax.WithRetry(func() gax.Retryer { |
| 361 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 362 |
Initial: 100 * time.Millisecond, |
| 363 |
Max: 60000 * time.Millisecond, |
| 364 |
Multiplier: 1.30, |
| 365 |
}, |
| 366 |
http.StatusGatewayTimeout, |
| 367 |
http.StatusServiceUnavailable) |
| 368 |
}), |
| 369 |
}, |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
// internalClient is an interface that defines the methods available from Cloud AutoML API. |
| 374 |
type internalClient interface { |
| 375 |
Close() error |
| 376 |
setGoogleClientInfo(...string) |
| 377 |
Connection() *grpc.ClientConn |
| 378 |
CreateDataset(context.Context, *automlpb.CreateDatasetRequest, ...gax.CallOption) (*CreateDatasetOperation, error) |
| 379 |
CreateDatasetOperation(name string) *CreateDatasetOperation |
| 380 |
GetDataset(context.Context, *automlpb.GetDatasetRequest, ...gax.CallOption) (*automlpb.Dataset, error) |
| 381 |
ListDatasets(context.Context, *automlpb.ListDatasetsRequest, ...gax.CallOption) *DatasetIterator |
| 382 |
UpdateDataset(context.Context, *automlpb.UpdateDatasetRequest, ...gax.CallOption) (*automlpb.Dataset, error) |
| 383 |
DeleteDataset(context.Context, *automlpb.DeleteDatasetRequest, ...gax.CallOption) (*DeleteDatasetOperation, error) |
| 384 |
DeleteDatasetOperation(name string) *DeleteDatasetOperation |
| 385 |
ImportData(context.Context, *automlpb.ImportDataRequest, ...gax.CallOption) (*ImportDataOperation, error) |
| 386 |
ImportDataOperation(name string) *ImportDataOperation |
| 387 |
ExportData(context.Context, *automlpb.ExportDataRequest, ...gax.CallOption) (*ExportDataOperation, error) |
| 388 |
ExportDataOperation(name string) *ExportDataOperation |
| 389 |
GetAnnotationSpec(context.Context, *automlpb.GetAnnotationSpecRequest, ...gax.CallOption) (*automlpb.AnnotationSpec, error) |
| 390 |
CreateModel(context.Context, *automlpb.CreateModelRequest, ...gax.CallOption) (*CreateModelOperation, error) |
| 391 |
CreateModelOperation(name string) *CreateModelOperation |
| 392 |
GetModel(context.Context, *automlpb.GetModelRequest, ...gax.CallOption) (*automlpb.Model, error) |
| 393 |
ListModels(context.Context, *automlpb.ListModelsRequest, ...gax.CallOption) *ModelIterator |
| 394 |
DeleteModel(context.Context, *automlpb.DeleteModelRequest, ...gax.CallOption) (*DeleteModelOperation, error) |
| 395 |
DeleteModelOperation(name string) *DeleteModelOperation |
| 396 |
UpdateModel(context.Context, *automlpb.UpdateModelRequest, ...gax.CallOption) (*automlpb.Model, error) |
| 397 |
DeployModel(context.Context, *automlpb.DeployModelRequest, ...gax.CallOption) (*DeployModelOperation, error) |
| 398 |
DeployModelOperation(name string) *DeployModelOperation |
| 399 |
UndeployModel(context.Context, *automlpb.UndeployModelRequest, ...gax.CallOption) (*UndeployModelOperation, error) |
| 400 |
UndeployModelOperation(name string) *UndeployModelOperation |
| 401 |
ExportModel(context.Context, *automlpb.ExportModelRequest, ...gax.CallOption) (*ExportModelOperation, error) |
| 402 |
ExportModelOperation(name string) *ExportModelOperation |
| 403 |
GetModelEvaluation(context.Context, *automlpb.GetModelEvaluationRequest, ...gax.CallOption) (*automlpb.ModelEvaluation, error) |
| 404 |
ListModelEvaluations(context.Context, *automlpb.ListModelEvaluationsRequest, ...gax.CallOption) *ModelEvaluationIterator |
| 405 |
} |
| 406 |
|
| 407 |
// Client is a client for interacting with Cloud AutoML API. |
| 408 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 409 |
// |
| 410 |
// AutoML Server API. |
| 411 |
// |
| 412 |
// The resource names are assigned by the server. |
| 413 |
// The server never reuses names that it has created after the resources with |
| 414 |
// those names are deleted. |
| 415 |
// |
| 416 |
// An ID of a resource is the last element of the item’s resource name. For |
| 417 |
// projects/{project_id}/locations/{location_id}/datasets/{dataset_id}, then |
| 418 |
// the id for the item is {dataset_id}. |
| 419 |
// |
| 420 |
// Currently the only supported location_id is “us-central1”. |
| 421 |
// |
| 422 |
// On any input that is documented to expect a string parameter in |
| 423 |
// snake_case or dash-case, either of those cases is accepted. |
| 424 |
type Client struct { |
| 425 |
// The internal transport-dependent client. |
| 426 |
internalClient internalClient |
| 427 |
|
| 428 |
// The call options for this service. |
| 429 |
CallOptions *CallOptions |
| 430 |
|
| 431 |
// LROClient is used internally to handle long-running operations. |
| 432 |
// It is exposed so that its CallOptions can be modified if required. |
| 433 |
// Users should not Close this client. |
| 434 |
LROClient *lroauto.OperationsClient |
| 435 |
} |
| 436 |
|
| 437 |
// Wrapper methods routed to the internal client. |
| 438 |
|
| 439 |
// Close closes the connection to the API service. The user should invoke this when |
| 440 |
// the client is no longer required. |
| 441 |
func (c *Client) Close() error { |
| 442 |
return c.internalClient.Close() |
| 443 |
} |
| 444 |
|
| 445 |
// setGoogleClientInfo sets the name and version of the application in |
| 446 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 447 |
// use by Google-written clients. |
| 448 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 449 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 450 |
} |
| 451 |
|
| 452 |
// Connection returns a connection to the API service. |
| 453 |
// |
| 454 |
// Deprecated: Connections are now pooled so this method does not always |
| 455 |
// return the same resource. |
| 456 |
func (c *Client) Connection() *grpc.ClientConn { |
| 457 |
return c.internalClient.Connection() |
| 458 |
} |
| 459 |
|
| 460 |
// CreateDataset creates a dataset. |
| 461 |
func (c *Client) CreateDataset(ctx context.Context, req *automlpb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) { |
| 462 |
return c.internalClient.CreateDataset(ctx, req, opts...) |
| 463 |
} |
| 464 |
|
| 465 |
// CreateDatasetOperation returns a new CreateDatasetOperation from a given name. |
| 466 |
// The name must be that of a previously created CreateDatasetOperation, possibly from a different process. |
| 467 |
func (c *Client) CreateDatasetOperation(name string) *CreateDatasetOperation { |
| 468 |
return c.internalClient.CreateDatasetOperation(name) |
| 469 |
} |
| 470 |
|
| 471 |
// GetDataset gets a dataset. |
| 472 |
func (c *Client) GetDataset(ctx context.Context, req *automlpb.GetDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { |
| 473 |
return c.internalClient.GetDataset(ctx, req, opts...) |
| 474 |
} |
| 475 |
|
| 476 |
// ListDatasets lists datasets in a project. |
| 477 |
func (c *Client) ListDatasets(ctx context.Context, req *automlpb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator { |
| 478 |
return c.internalClient.ListDatasets(ctx, req, opts...) |
| 479 |
} |
| 480 |
|
| 481 |
// UpdateDataset updates a dataset. |
| 482 |
func (c *Client) UpdateDataset(ctx context.Context, req *automlpb.UpdateDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { |
| 483 |
return c.internalClient.UpdateDataset(ctx, req, opts...) |
| 484 |
} |
| 485 |
|
| 486 |
// DeleteDataset deletes a dataset and all of its contents. |
| 487 |
// Returns empty response in the |
| 488 |
// response field when it completes, |
| 489 |
// and delete_details in the |
| 490 |
// metadata field. |
| 491 |
func (c *Client) DeleteDataset(ctx context.Context, req *automlpb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) { |
| 492 |
return c.internalClient.DeleteDataset(ctx, req, opts...) |
| 493 |
} |
| 494 |
|
| 495 |
// DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name. |
| 496 |
// The name must be that of a previously created DeleteDatasetOperation, possibly from a different process. |
| 497 |
func (c *Client) DeleteDatasetOperation(name string) *DeleteDatasetOperation { |
| 498 |
return c.internalClient.DeleteDatasetOperation(name) |
| 499 |
} |
| 500 |
|
| 501 |
// ImportData imports data into a dataset. |
| 502 |
// For Tables this method can only be called on an empty Dataset. |
| 503 |
// |
| 504 |
// For Tables: |
| 505 |
// |
| 506 |
// A |
| 507 |
// schema_inference_version |
| 508 |
// parameter must be explicitly set. |
| 509 |
// Returns an empty response in the |
| 510 |
// response field when it completes. |
| 511 |
func (c *Client) ImportData(ctx context.Context, req *automlpb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) { |
| 512 |
return c.internalClient.ImportData(ctx, req, opts...) |
| 513 |
} |
| 514 |
|
| 515 |
// ImportDataOperation returns a new ImportDataOperation from a given name. |
| 516 |
// The name must be that of a previously created ImportDataOperation, possibly from a different process. |
| 517 |
func (c *Client) ImportDataOperation(name string) *ImportDataOperation { |
| 518 |
return c.internalClient.ImportDataOperation(name) |
| 519 |
} |
| 520 |
|
| 521 |
// ExportData exports dataset’s data to the provided output location. |
| 522 |
// Returns an empty response in the |
| 523 |
// response field when it completes. |
| 524 |
func (c *Client) ExportData(ctx context.Context, req *automlpb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) { |
| 525 |
return c.internalClient.ExportData(ctx, req, opts...) |
| 526 |
} |
| 527 |
|
| 528 |
// ExportDataOperation returns a new ExportDataOperation from a given name. |
| 529 |
// The name must be that of a previously created ExportDataOperation, possibly from a different process. |
| 530 |
func (c *Client) ExportDataOperation(name string) *ExportDataOperation { |
| 531 |
return c.internalClient.ExportDataOperation(name) |
| 532 |
} |
| 533 |
|
| 534 |
// GetAnnotationSpec gets an annotation spec. |
| 535 |
func (c *Client) GetAnnotationSpec(ctx context.Context, req *automlpb.GetAnnotationSpecRequest, opts ...gax.CallOption) (*automlpb.AnnotationSpec, error) { |
| 536 |
return c.internalClient.GetAnnotationSpec(ctx, req, opts...) |
| 537 |
} |
| 538 |
|
| 539 |
// CreateModel creates a model. |
| 540 |
// Returns a Model in the response |
| 541 |
// field when it completes. |
| 542 |
// When you create a model, several model evaluations are created for it: |
| 543 |
// a global evaluation, and one evaluation for each annotation spec. |
| 544 |
func (c *Client) CreateModel(ctx context.Context, req *automlpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { |
| 545 |
return c.internalClient.CreateModel(ctx, req, opts...) |
| 546 |
} |
| 547 |
|
| 548 |
// CreateModelOperation returns a new CreateModelOperation from a given name. |
| 549 |
// The name must be that of a previously created CreateModelOperation, possibly from a different process. |
| 550 |
func (c *Client) CreateModelOperation(name string) *CreateModelOperation { |
| 551 |
return c.internalClient.CreateModelOperation(name) |
| 552 |
} |
| 553 |
|
| 554 |
// GetModel gets a model. |
| 555 |
func (c *Client) GetModel(ctx context.Context, req *automlpb.GetModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { |
| 556 |
return c.internalClient.GetModel(ctx, req, opts...) |
| 557 |
} |
| 558 |
|
| 559 |
// ListModels lists models. |
| 560 |
func (c *Client) ListModels(ctx context.Context, req *automlpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { |
| 561 |
return c.internalClient.ListModels(ctx, req, opts...) |
| 562 |
} |
| 563 |
|
| 564 |
// DeleteModel deletes a model. |
| 565 |
// Returns google.protobuf.Empty in the |
| 566 |
// response field when it completes, |
| 567 |
// and delete_details in the |
| 568 |
// metadata field. |
| 569 |
func (c *Client) DeleteModel(ctx context.Context, req *automlpb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) { |
| 570 |
return c.internalClient.DeleteModel(ctx, req, opts...) |
| 571 |
} |
| 572 |
|
| 573 |
// DeleteModelOperation returns a new DeleteModelOperation from a given name. |
| 574 |
// The name must be that of a previously created DeleteModelOperation, possibly from a different process. |
| 575 |
func (c *Client) DeleteModelOperation(name string) *DeleteModelOperation { |
| 576 |
return c.internalClient.DeleteModelOperation(name) |
| 577 |
} |
| 578 |
|
| 579 |
// UpdateModel updates a model. |
| 580 |
func (c *Client) UpdateModel(ctx context.Context, req *automlpb.UpdateModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { |
| 581 |
return c.internalClient.UpdateModel(ctx, req, opts...) |
| 582 |
} |
| 583 |
|
| 584 |
// DeployModel deploys a model. If a model is already deployed, deploying it with the |
| 585 |
// same parameters has no effect. Deploying with different parametrs |
| 586 |
// (as e.g. changing |
| 587 |
// node_number) |
| 588 |
// will reset the deployment state without pausing the model’s availability. |
| 589 |
// |
| 590 |
// Only applicable for Text Classification, Image Object Detection , Tables, and Image Segmentation; all other domains manage |
| 591 |
// deployment automatically. |
| 592 |
// |
| 593 |
// Returns an empty response in the |
| 594 |
// response field when it completes. |
| 595 |
func (c *Client) DeployModel(ctx context.Context, req *automlpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { |
| 596 |
return c.internalClient.DeployModel(ctx, req, opts...) |
| 597 |
} |
| 598 |
|
| 599 |
// DeployModelOperation returns a new DeployModelOperation from a given name. |
| 600 |
// The name must be that of a previously created DeployModelOperation, possibly from a different process. |
| 601 |
func (c *Client) DeployModelOperation(name string) *DeployModelOperation { |
| 602 |
return c.internalClient.DeployModelOperation(name) |
| 603 |
} |
| 604 |
|
| 605 |
// UndeployModel undeploys a model. If the model is not deployed this method has no effect. |
| 606 |
// |
| 607 |
// Only applicable for Text Classification, Image Object Detection and Tables; |
| 608 |
// all other domains manage deployment automatically. |
| 609 |
// |
| 610 |
// Returns an empty response in the |
| 611 |
// response field when it completes. |
| 612 |
func (c *Client) UndeployModel(ctx context.Context, req *automlpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { |
| 613 |
return c.internalClient.UndeployModel(ctx, req, opts...) |
| 614 |
} |
| 615 |
|
| 616 |
// UndeployModelOperation returns a new UndeployModelOperation from a given name. |
| 617 |
// The name must be that of a previously created UndeployModelOperation, possibly from a different process. |
| 618 |
func (c *Client) UndeployModelOperation(name string) *UndeployModelOperation { |
| 619 |
return c.internalClient.UndeployModelOperation(name) |
| 620 |
} |
| 621 |
|
| 622 |
// ExportModel exports a trained, “export-able”, model to a user specified Google Cloud |
| 623 |
// Storage location. A model is considered export-able if and only if it has |
| 624 |
// an export format defined for it in |
| 625 |
// ModelExportOutputConfig. |
| 626 |
// |
| 627 |
// Returns an empty response in the |
| 628 |
// response field when it completes. |
| 629 |
func (c *Client) ExportModel(ctx context.Context, req *automlpb.ExportModelRequest, opts ...gax.CallOption) (*ExportModelOperation, error) { |
| 630 |
return c.internalClient.ExportModel(ctx, req, opts...) |
| 631 |
} |
| 632 |
|
| 633 |
// ExportModelOperation returns a new ExportModelOperation from a given name. |
| 634 |
// The name must be that of a previously created ExportModelOperation, possibly from a different process. |
| 635 |
func (c *Client) ExportModelOperation(name string) *ExportModelOperation { |
| 636 |
return c.internalClient.ExportModelOperation(name) |
| 637 |
} |
| 638 |
|
| 639 |
// GetModelEvaluation gets a model evaluation. |
| 640 |
func (c *Client) GetModelEvaluation(ctx context.Context, req *automlpb.GetModelEvaluationRequest, opts ...gax.CallOption) (*automlpb.ModelEvaluation, error) { |
| 641 |
return c.internalClient.GetModelEvaluation(ctx, req, opts...) |
| 642 |
} |
| 643 |
|
| 644 |
// ListModelEvaluations lists model evaluations. |
| 645 |
func (c *Client) ListModelEvaluations(ctx context.Context, req *automlpb.ListModelEvaluationsRequest, opts ...gax.CallOption) *ModelEvaluationIterator { |
| 646 |
return c.internalClient.ListModelEvaluations(ctx, req, opts...) |
| 647 |
} |
| 648 |
|
| 649 |
// gRPCClient is a client for interacting with Cloud AutoML API over gRPC transport. |
| 650 |
// |
| 651 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 652 |
type gRPCClient struct { |
| 653 |
// Connection pool of gRPC connections to the service. |
| 654 |
connPool gtransport.ConnPool |
| 655 |
|
| 656 |
// Points back to the CallOptions field of the containing Client |
| 657 |
CallOptions **CallOptions |
| 658 |
|
| 659 |
// The gRPC API client. |
| 660 |
client automlpb.AutoMlClient |
| 661 |
|
| 662 |
// LROClient is used internally to handle long-running operations. |
| 663 |
// It is exposed so that its CallOptions can be modified if required. |
| 664 |
// Users should not Close this client. |
| 665 |
LROClient **lroauto.OperationsClient |
| 666 |
|
| 667 |
// The x-goog-* metadata to be sent with each request. |
| 668 |
xGoogHeaders []string |
| 669 |
|
| 670 |
logger *slog.Logger |
| 671 |
} |
| 672 |
|
| 673 |
// NewClient creates a new auto ml client based on gRPC. |
| 674 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 675 |
// |
| 676 |
// AutoML Server API. |
| 677 |
// |
| 678 |
// The resource names are assigned by the server. |
| 679 |
// The server never reuses names that it has created after the resources with |
| 680 |
// those names are deleted. |
| 681 |
// |
| 682 |
// An ID of a resource is the last element of the item’s resource name. For |
| 683 |
// projects/{project_id}/locations/{location_id}/datasets/{dataset_id}, then |
| 684 |
// the id for the item is {dataset_id}. |
| 685 |
// |
| 686 |
// Currently the only supported location_id is “us-central1”. |
| 687 |
// |
| 688 |
// On any input that is documented to expect a string parameter in |
| 689 |
// snake_case or dash-case, either of those cases is accepted. |
| 690 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 691 |
clientOpts := defaultGRPCClientOptions() |
| 692 |
if newClientHook != nil { |
| 693 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 694 |
if err != nil { |
| 695 |
return nil, err |
| 696 |
} |
| 697 |
clientOpts = append(clientOpts, hookOpts...) |
| 698 |
} |
| 699 |
|
| 700 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 701 |
if err != nil { |
| 702 |
return nil, err |
| 703 |
} |
| 704 |
client := Client{CallOptions: defaultCallOptions()} |
| 705 |
|
| 706 |
c := &gRPCClient{ |
| 707 |
connPool: connPool, |
| 708 |
client: automlpb.NewAutoMlClient(connPool), |
| 709 |
CallOptions: &client.CallOptions, |
| 710 |
logger: internaloption.GetLogger(opts), |
| 711 |
} |
| 712 |
c.setGoogleClientInfo() |
| 713 |
|
| 714 |
client.internalClient = c |
| 715 |
|
| 716 |
client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) |
| 717 |
if err != nil { |
| 718 |
// This error "should not happen", since we are just reusing old connection pool |
| 719 |
// and never actually need to dial. |
| 720 |
// If this does happen, we could leak connp. However, we cannot close conn: |
| 721 |
// If the user invoked the constructor with option.WithGRPCConn, |
| 722 |
// we would close a connection that's still in use. |
| 723 |
// TODO: investigate error conditions. |
| 724 |
return nil, err |
| 725 |
} |
| 726 |
c.LROClient = &client.LROClient |
| 727 |
return &client, nil |
| 728 |
} |
| 729 |
|
| 730 |
// Connection returns a connection to the API service. |
| 731 |
// |
| 732 |
// Deprecated: Connections are now pooled so this method does not always |
| 733 |
// return the same resource. |
| 734 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 735 |
return c.connPool.Conn() |
| 736 |
} |
| 737 |
|
| 738 |
// setGoogleClientInfo sets the name and version of the application in |
| 739 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 740 |
// use by Google-written clients. |
| 741 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 742 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 743 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 744 |
c.xGoogHeaders = []string{ |
| 745 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
// Close closes the connection to the API service. The user should invoke this when |
| 750 |
// the client is no longer required. |
| 751 |
func (c *gRPCClient) Close() error { |
| 752 |
return c.connPool.Close() |
| 753 |
} |
| 754 |
|
| 755 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 756 |
type restClient struct { |
| 757 |
// The http endpoint to connect to. |
| 758 |
endpoint string |
| 759 |
|
| 760 |
// The http client. |
| 761 |
httpClient *http.Client |
| 762 |
|
| 763 |
// LROClient is used internally to handle long-running operations. |
| 764 |
// It is exposed so that its CallOptions can be modified if required. |
| 765 |
// Users should not Close this client. |
| 766 |
LROClient **lroauto.OperationsClient |
| 767 |
|
| 768 |
// The x-goog-* headers to be sent with each request. |
| 769 |
xGoogHeaders []string |
| 770 |
|
| 771 |
// Points back to the CallOptions field of the containing Client |
| 772 |
CallOptions **CallOptions |
| 773 |
|
| 774 |
logger *slog.Logger |
| 775 |
} |
| 776 |
|
| 777 |
// NewRESTClient creates a new auto ml rest client. |
| 778 |
// |
| 779 |
// AutoML Server API. |
| 780 |
// |
| 781 |
// The resource names are assigned by the server. |
| 782 |
// The server never reuses names that it has created after the resources with |
| 783 |
// those names are deleted. |
| 784 |
// |
| 785 |
// An ID of a resource is the last element of the item’s resource name. For |
| 786 |
// projects/{project_id}/locations/{location_id}/datasets/{dataset_id}, then |
| 787 |
// the id for the item is {dataset_id}. |
| 788 |
// |
| 789 |
// Currently the only supported location_id is “us-central1”. |
| 790 |
// |
| 791 |
// On any input that is documented to expect a string parameter in |
| 792 |
// snake_case or dash-case, either of those cases is accepted. |
| 793 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 794 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 795 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 796 |
if err != nil { |
| 797 |
return nil, err |
| 798 |
} |
| 799 |
|
| 800 |
callOpts := defaultRESTCallOptions() |
| 801 |
c := &restClient{ |
| 802 |
endpoint: endpoint, |
| 803 |
httpClient: httpClient, |
| 804 |
CallOptions: &callOpts, |
| 805 |
logger: internaloption.GetLogger(opts), |
| 806 |
} |
| 807 |
c.setGoogleClientInfo() |
| 808 |
|
| 809 |
lroOpts := []option.ClientOption{ |
| 810 |
option.WithHTTPClient(httpClient), |
| 811 |
option.WithEndpoint(endpoint), |
| 812 |
} |
| 813 |
opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) |
| 814 |
if err != nil { |
| 815 |
return nil, err |
| 816 |
} |
| 817 |
c.LROClient = &opClient |
| 818 |
|
| 819 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 820 |
} |
| 821 |
|
| 822 |
func defaultRESTClientOptions() []option.ClientOption { |
| 823 |
return []option.ClientOption{ |
| 824 |
internaloption.WithDefaultEndpoint("https://automl.googleapis.com"), |
| 825 |
internaloption.WithDefaultEndpointTemplate("https://automl.UNIVERSE_DOMAIN"), |
| 826 |
internaloption.WithDefaultMTLSEndpoint("https://automl.mtls.googleapis.com"), |
| 827 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 828 |
internaloption.WithDefaultAudience("https://automl.googleapis.com/"), |
| 829 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 830 |
internaloption.EnableNewAuthLibrary(), |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
// setGoogleClientInfo sets the name and version of the application in |
| 835 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 836 |
// use by Google-written clients. |
| 837 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 838 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 839 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 840 |
c.xGoogHeaders = []string{ |
| 841 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
// Close closes the connection to the API service. The user should invoke this when |
| 846 |
// the client is no longer required. |
| 847 |
func (c *restClient) Close() error { |
| 848 |
// Replace httpClient with nil to force cleanup. |
| 849 |
c.httpClient = nil |
| 850 |
return nil |
| 851 |
} |
| 852 |
|
| 853 |
// Connection returns a connection to the API service. |
| 854 |
// |
| 855 |
// Deprecated: This method always returns nil. |
| 856 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 857 |
return nil |
| 858 |
} |
| 859 |
func (c *gRPCClient) CreateDataset(ctx context.Context, req *automlpb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) { |
| 860 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 861 |
|
| 862 |
hds = append(c.xGoogHeaders, hds...) |
| 863 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 864 |
opts = append((*c.CallOptions).CreateDataset[0:len((*c.CallOptions).CreateDataset):len((*c.CallOptions).CreateDataset)], opts...) |
| 865 |
var resp *longrunningpb.Operation |
| 866 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 867 |
var err error |
| 868 |
resp, err = executeRPC(ctx, c.client.CreateDataset, req, settings.GRPC, c.logger, "CreateDataset") |
| 869 |
return err |
| 870 |
}, opts...) |
| 871 |
if err != nil { |
| 872 |
return nil, err |
| 873 |
} |
| 874 |
return &CreateDatasetOperation{ |
| 875 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 876 |
}, nil |
| 877 |
} |
| 878 |
|
| 879 |
func (c *gRPCClient) GetDataset(ctx context.Context, req *automlpb.GetDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { |
| 880 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 881 |
|
| 882 |
hds = append(c.xGoogHeaders, hds...) |
| 883 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 884 |
opts = append((*c.CallOptions).GetDataset[0:len((*c.CallOptions).GetDataset):len((*c.CallOptions).GetDataset)], opts...) |
| 885 |
var resp *automlpb.Dataset |
| 886 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 887 |
var err error |
| 888 |
resp, err = executeRPC(ctx, c.client.GetDataset, req, settings.GRPC, c.logger, "GetDataset") |
| 889 |
return err |
| 890 |
}, opts...) |
| 891 |
if err != nil { |
| 892 |
return nil, err |
| 893 |
} |
| 894 |
return resp, nil |
| 895 |
} |
| 896 |
|
| 897 |
func (c *gRPCClient) ListDatasets(ctx context.Context, req *automlpb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator { |
| 898 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 899 |
|
| 900 |
hds = append(c.xGoogHeaders, hds...) |
| 901 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 902 |
opts = append((*c.CallOptions).ListDatasets[0:len((*c.CallOptions).ListDatasets):len((*c.CallOptions).ListDatasets)], opts...) |
| 903 |
it := &DatasetIterator{} |
| 904 |
req = proto.Clone(req).(*automlpb.ListDatasetsRequest) |
| 905 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Dataset, string, error) { |
| 906 |
resp := &automlpb.ListDatasetsResponse{} |
| 907 |
if pageToken != "" { |
| 908 |
req.PageToken = pageToken |
| 909 |
} |
| 910 |
if pageSize > math.MaxInt32 { |
| 911 |
req.PageSize = math.MaxInt32 |
| 912 |
} else if pageSize != 0 { |
| 913 |
req.PageSize = int32(pageSize) |
| 914 |
} |
| 915 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 916 |
var err error |
| 917 |
resp, err = executeRPC(ctx, c.client.ListDatasets, req, settings.GRPC, c.logger, "ListDatasets") |
| 918 |
return err |
| 919 |
}, opts...) |
| 920 |
if err != nil { |
| 921 |
return nil, "", err |
| 922 |
} |
| 923 |
|
| 924 |
it.Response = resp |
| 925 |
return resp.GetDatasets(), resp.GetNextPageToken(), nil |
| 926 |
} |
| 927 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 928 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 929 |
if err != nil { |
| 930 |
return "", err |
| 931 |
} |
| 932 |
it.items = append(it.items, items...) |
| 933 |
return nextPageToken, nil |
| 934 |
} |
| 935 |
|
| 936 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 937 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 938 |
it.pageInfo.Token = req.GetPageToken() |
| 939 |
|
| 940 |
return it |
| 941 |
} |
| 942 |
|
| 943 |
func (c *gRPCClient) UpdateDataset(ctx context.Context, req *automlpb.UpdateDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { |
| 944 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dataset.name", url.QueryEscape(req.GetDataset().GetName()))} |
| 945 |
|
| 946 |
hds = append(c.xGoogHeaders, hds...) |
| 947 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 948 |
opts = append((*c.CallOptions).UpdateDataset[0:len((*c.CallOptions).UpdateDataset):len((*c.CallOptions).UpdateDataset)], opts...) |
| 949 |
var resp *automlpb.Dataset |
| 950 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 951 |
var err error |
| 952 |
resp, err = executeRPC(ctx, c.client.UpdateDataset, req, settings.GRPC, c.logger, "UpdateDataset") |
| 953 |
return err |
| 954 |
}, opts...) |
| 955 |
if err != nil { |
| 956 |
return nil, err |
| 957 |
} |
| 958 |
return resp, nil |
| 959 |
} |
| 960 |
|
| 961 |
func (c *gRPCClient) DeleteDataset(ctx context.Context, req *automlpb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) { |
| 962 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 963 |
|
| 964 |
hds = append(c.xGoogHeaders, hds...) |
| 965 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 966 |
opts = append((*c.CallOptions).DeleteDataset[0:len((*c.CallOptions).DeleteDataset):len((*c.CallOptions).DeleteDataset)], opts...) |
| 967 |
var resp *longrunningpb.Operation |
| 968 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 969 |
var err error |
| 970 |
resp, err = executeRPC(ctx, c.client.DeleteDataset, req, settings.GRPC, c.logger, "DeleteDataset") |
| 971 |
return err |
| 972 |
}, opts...) |
| 973 |
if err != nil { |
| 974 |
return nil, err |
| 975 |
} |
| 976 |
return &DeleteDatasetOperation{ |
| 977 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 978 |
}, nil |
| 979 |
} |
| 980 |
|
| 981 |
func (c *gRPCClient) ImportData(ctx context.Context, req *automlpb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) { |
| 982 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 983 |
|
| 984 |
hds = append(c.xGoogHeaders, hds...) |
| 985 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 986 |
opts = append((*c.CallOptions).ImportData[0:len((*c.CallOptions).ImportData):len((*c.CallOptions).ImportData)], opts...) |
| 987 |
var resp *longrunningpb.Operation |
| 988 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 989 |
var err error |
| 990 |
resp, err = executeRPC(ctx, c.client.ImportData, req, settings.GRPC, c.logger, "ImportData") |
| 991 |
return err |
| 992 |
}, opts...) |
| 993 |
if err != nil { |
| 994 |
return nil, err |
| 995 |
} |
| 996 |
return &ImportDataOperation{ |
| 997 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 998 |
}, nil |
| 999 |
} |
| 1000 |
|
| 1001 |
func (c *gRPCClient) ExportData(ctx context.Context, req *automlpb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) { |
| 1002 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1003 |
|
| 1004 |
hds = append(c.xGoogHeaders, hds...) |
| 1005 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1006 |
opts = append((*c.CallOptions).ExportData[0:len((*c.CallOptions).ExportData):len((*c.CallOptions).ExportData)], opts...) |
| 1007 |
var resp *longrunningpb.Operation |
| 1008 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1009 |
var err error |
| 1010 |
resp, err = executeRPC(ctx, c.client.ExportData, req, settings.GRPC, c.logger, "ExportData") |
| 1011 |
return err |
| 1012 |
}, opts...) |
| 1013 |
if err != nil { |
| 1014 |
return nil, err |
| 1015 |
} |
| 1016 |
return &ExportDataOperation{ |
| 1017 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1018 |
}, nil |
| 1019 |
} |
| 1020 |
|
| 1021 |
func (c *gRPCClient) GetAnnotationSpec(ctx context.Context, req *automlpb.GetAnnotationSpecRequest, opts ...gax.CallOption) (*automlpb.AnnotationSpec, error) { |
| 1022 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1023 |
|
| 1024 |
hds = append(c.xGoogHeaders, hds...) |
| 1025 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1026 |
opts = append((*c.CallOptions).GetAnnotationSpec[0:len((*c.CallOptions).GetAnnotationSpec):len((*c.CallOptions).GetAnnotationSpec)], opts...) |
| 1027 |
var resp *automlpb.AnnotationSpec |
| 1028 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1029 |
var err error |
| 1030 |
resp, err = executeRPC(ctx, c.client.GetAnnotationSpec, req, settings.GRPC, c.logger, "GetAnnotationSpec") |
| 1031 |
return err |
| 1032 |
}, opts...) |
| 1033 |
if err != nil { |
| 1034 |
return nil, err |
| 1035 |
} |
| 1036 |
return resp, nil |
| 1037 |
} |
| 1038 |
|
| 1039 |
func (c *gRPCClient) CreateModel(ctx context.Context, req *automlpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { |
| 1040 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1041 |
|
| 1042 |
hds = append(c.xGoogHeaders, hds...) |
| 1043 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1044 |
opts = append((*c.CallOptions).CreateModel[0:len((*c.CallOptions).CreateModel):len((*c.CallOptions).CreateModel)], opts...) |
| 1045 |
var resp *longrunningpb.Operation |
| 1046 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1047 |
var err error |
| 1048 |
resp, err = executeRPC(ctx, c.client.CreateModel, req, settings.GRPC, c.logger, "CreateModel") |
| 1049 |
return err |
| 1050 |
}, opts...) |
| 1051 |
if err != nil { |
| 1052 |
return nil, err |
| 1053 |
} |
| 1054 |
return &CreateModelOperation{ |
| 1055 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1056 |
}, nil |
| 1057 |
} |
| 1058 |
|
| 1059 |
func (c *gRPCClient) GetModel(ctx context.Context, req *automlpb.GetModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { |
| 1060 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1061 |
|
| 1062 |
hds = append(c.xGoogHeaders, hds...) |
| 1063 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1064 |
opts = append((*c.CallOptions).GetModel[0:len((*c.CallOptions).GetModel):len((*c.CallOptions).GetModel)], opts...) |
| 1065 |
var resp *automlpb.Model |
| 1066 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1067 |
var err error |
| 1068 |
resp, err = executeRPC(ctx, c.client.GetModel, req, settings.GRPC, c.logger, "GetModel") |
| 1069 |
return err |
| 1070 |
}, opts...) |
| 1071 |
if err != nil { |
| 1072 |
return nil, err |
| 1073 |
} |
| 1074 |
return resp, nil |
| 1075 |
} |
| 1076 |
|
| 1077 |
func (c *gRPCClient) ListModels(ctx context.Context, req *automlpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { |
| 1078 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1079 |
|
| 1080 |
hds = append(c.xGoogHeaders, hds...) |
| 1081 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1082 |
opts = append((*c.CallOptions).ListModels[0:len((*c.CallOptions).ListModels):len((*c.CallOptions).ListModels)], opts...) |
| 1083 |
it := &ModelIterator{} |
| 1084 |
req = proto.Clone(req).(*automlpb.ListModelsRequest) |
| 1085 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Model, string, error) { |
| 1086 |
resp := &automlpb.ListModelsResponse{} |
| 1087 |
if pageToken != "" { |
| 1088 |
req.PageToken = pageToken |
| 1089 |
} |
| 1090 |
if pageSize > math.MaxInt32 { |
| 1091 |
req.PageSize = math.MaxInt32 |
| 1092 |
} else if pageSize != 0 { |
| 1093 |
req.PageSize = int32(pageSize) |
| 1094 |
} |
| 1095 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1096 |
var err error |
| 1097 |
resp, err = executeRPC(ctx, c.client.ListModels, req, settings.GRPC, c.logger, "ListModels") |
| 1098 |
return err |
| 1099 |
}, opts...) |
| 1100 |
if err != nil { |
| 1101 |
return nil, "", err |
| 1102 |
} |
| 1103 |
|
| 1104 |
it.Response = resp |
| 1105 |
return resp.GetModel(), resp.GetNextPageToken(), nil |
| 1106 |
} |
| 1107 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1108 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1109 |
if err != nil { |
| 1110 |
return "", err |
| 1111 |
} |
| 1112 |
it.items = append(it.items, items...) |
| 1113 |
return nextPageToken, nil |
| 1114 |
} |
| 1115 |
|
| 1116 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1117 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1118 |
it.pageInfo.Token = req.GetPageToken() |
| 1119 |
|
| 1120 |
return it |
| 1121 |
} |
| 1122 |
|
| 1123 |
func (c *gRPCClient) DeleteModel(ctx context.Context, req *automlpb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) { |
| 1124 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1125 |
|
| 1126 |
hds = append(c.xGoogHeaders, hds...) |
| 1127 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1128 |
opts = append((*c.CallOptions).DeleteModel[0:len((*c.CallOptions).DeleteModel):len((*c.CallOptions).DeleteModel)], opts...) |
| 1129 |
var resp *longrunningpb.Operation |
| 1130 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1131 |
var err error |
| 1132 |
resp, err = executeRPC(ctx, c.client.DeleteModel, req, settings.GRPC, c.logger, "DeleteModel") |
| 1133 |
return err |
| 1134 |
}, opts...) |
| 1135 |
if err != nil { |
| 1136 |
return nil, err |
| 1137 |
} |
| 1138 |
return &DeleteModelOperation{ |
| 1139 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1140 |
}, nil |
| 1141 |
} |
| 1142 |
|
| 1143 |
func (c *gRPCClient) UpdateModel(ctx context.Context, req *automlpb.UpdateModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { |
| 1144 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "model.name", url.QueryEscape(req.GetModel().GetName()))} |
| 1145 |
|
| 1146 |
hds = append(c.xGoogHeaders, hds...) |
| 1147 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1148 |
opts = append((*c.CallOptions).UpdateModel[0:len((*c.CallOptions).UpdateModel):len((*c.CallOptions).UpdateModel)], opts...) |
| 1149 |
var resp *automlpb.Model |
| 1150 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1151 |
var err error |
| 1152 |
resp, err = executeRPC(ctx, c.client.UpdateModel, req, settings.GRPC, c.logger, "UpdateModel") |
| 1153 |
return err |
| 1154 |
}, opts...) |
| 1155 |
if err != nil { |
| 1156 |
return nil, err |
| 1157 |
} |
| 1158 |
return resp, nil |
| 1159 |
} |
| 1160 |
|
| 1161 |
func (c *gRPCClient) DeployModel(ctx context.Context, req *automlpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { |
| 1162 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1163 |
|
| 1164 |
hds = append(c.xGoogHeaders, hds...) |
| 1165 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1166 |
opts = append((*c.CallOptions).DeployModel[0:len((*c.CallOptions).DeployModel):len((*c.CallOptions).DeployModel)], opts...) |
| 1167 |
var resp *longrunningpb.Operation |
| 1168 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1169 |
var err error |
| 1170 |
resp, err = executeRPC(ctx, c.client.DeployModel, req, settings.GRPC, c.logger, "DeployModel") |
| 1171 |
return err |
| 1172 |
}, opts...) |
| 1173 |
if err != nil { |
| 1174 |
return nil, err |
| 1175 |
} |
| 1176 |
return &DeployModelOperation{ |
| 1177 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1178 |
}, nil |
| 1179 |
} |
| 1180 |
|
| 1181 |
func (c *gRPCClient) UndeployModel(ctx context.Context, req *automlpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { |
| 1182 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1183 |
|
| 1184 |
hds = append(c.xGoogHeaders, hds...) |
| 1185 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1186 |
opts = append((*c.CallOptions).UndeployModel[0:len((*c.CallOptions).UndeployModel):len((*c.CallOptions).UndeployModel)], opts...) |
| 1187 |
var resp *longrunningpb.Operation |
| 1188 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1189 |
var err error |
| 1190 |
resp, err = executeRPC(ctx, c.client.UndeployModel, req, settings.GRPC, c.logger, "UndeployModel") |
| 1191 |
return err |
| 1192 |
}, opts...) |
| 1193 |
if err != nil { |
| 1194 |
return nil, err |
| 1195 |
} |
| 1196 |
return &UndeployModelOperation{ |
| 1197 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1198 |
}, nil |
| 1199 |
} |
| 1200 |
|
| 1201 |
func (c *gRPCClient) ExportModel(ctx context.Context, req *automlpb.ExportModelRequest, opts ...gax.CallOption) (*ExportModelOperation, error) { |
| 1202 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1203 |
|
| 1204 |
hds = append(c.xGoogHeaders, hds...) |
| 1205 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1206 |
opts = append((*c.CallOptions).ExportModel[0:len((*c.CallOptions).ExportModel):len((*c.CallOptions).ExportModel)], opts...) |
| 1207 |
var resp *longrunningpb.Operation |
| 1208 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1209 |
var err error |
| 1210 |
resp, err = executeRPC(ctx, c.client.ExportModel, req, settings.GRPC, c.logger, "ExportModel") |
| 1211 |
return err |
| 1212 |
}, opts...) |
| 1213 |
if err != nil { |
| 1214 |
return nil, err |
| 1215 |
} |
| 1216 |
return &ExportModelOperation{ |
| 1217 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1218 |
}, nil |
| 1219 |
} |
| 1220 |
|
| 1221 |
func (c *gRPCClient) GetModelEvaluation(ctx context.Context, req *automlpb.GetModelEvaluationRequest, opts ...gax.CallOption) (*automlpb.ModelEvaluation, error) { |
| 1222 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1223 |
|
| 1224 |
hds = append(c.xGoogHeaders, hds...) |
| 1225 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1226 |
opts = append((*c.CallOptions).GetModelEvaluation[0:len((*c.CallOptions).GetModelEvaluation):len((*c.CallOptions).GetModelEvaluation)], opts...) |
| 1227 |
var resp *automlpb.ModelEvaluation |
| 1228 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1229 |
var err error |
| 1230 |
resp, err = executeRPC(ctx, c.client.GetModelEvaluation, req, settings.GRPC, c.logger, "GetModelEvaluation") |
| 1231 |
return err |
| 1232 |
}, opts...) |
| 1233 |
if err != nil { |
| 1234 |
return nil, err |
| 1235 |
} |
| 1236 |
return resp, nil |
| 1237 |
} |
| 1238 |
|
| 1239 |
func (c *gRPCClient) ListModelEvaluations(ctx context.Context, req *automlpb.ListModelEvaluationsRequest, opts ...gax.CallOption) *ModelEvaluationIterator { |
| 1240 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1241 |
|
| 1242 |
hds = append(c.xGoogHeaders, hds...) |
| 1243 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1244 |
opts = append((*c.CallOptions).ListModelEvaluations[0:len((*c.CallOptions).ListModelEvaluations):len((*c.CallOptions).ListModelEvaluations)], opts...) |
| 1245 |
it := &ModelEvaluationIterator{} |
| 1246 |
req = proto.Clone(req).(*automlpb.ListModelEvaluationsRequest) |
| 1247 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.ModelEvaluation, string, error) { |
| 1248 |
resp := &automlpb.ListModelEvaluationsResponse{} |
| 1249 |
if pageToken != "" { |
| 1250 |
req.PageToken = pageToken |
| 1251 |
} |
| 1252 |
if pageSize > math.MaxInt32 { |
| 1253 |
req.PageSize = math.MaxInt32 |
| 1254 |
} else if pageSize != 0 { |
| 1255 |
req.PageSize = int32(pageSize) |
| 1256 |
} |
| 1257 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1258 |
var err error |
| 1259 |
resp, err = executeRPC(ctx, c.client.ListModelEvaluations, req, settings.GRPC, c.logger, "ListModelEvaluations") |
| 1260 |
return err |
| 1261 |
}, opts...) |
| 1262 |
if err != nil { |
| 1263 |
return nil, "", err |
| 1264 |
} |
| 1265 |
|
| 1266 |
it.Response = resp |
| 1267 |
return resp.GetModelEvaluation(), resp.GetNextPageToken(), nil |
| 1268 |
} |
| 1269 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1270 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1271 |
if err != nil { |
| 1272 |
return "", err |
| 1273 |
} |
| 1274 |
it.items = append(it.items, items...) |
| 1275 |
return nextPageToken, nil |
| 1276 |
} |
| 1277 |
|
| 1278 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1279 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1280 |
it.pageInfo.Token = req.GetPageToken() |
| 1281 |
|
| 1282 |
return it |
| 1283 |
} |
| 1284 |
|
| 1285 |
// CreateDataset creates a dataset. |
| 1286 |
func (c *restClient) CreateDataset(ctx context.Context, req *automlpb.CreateDatasetRequest, opts ...gax.CallOption) (*CreateDatasetOperation, error) { |
| 1287 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1288 |
body := req.GetDataset() |
| 1289 |
jsonReq, err := m.Marshal(body) |
| 1290 |
if err != nil { |
| 1291 |
return nil, err |
| 1292 |
} |
| 1293 |
|
| 1294 |
baseUrl, err := url.Parse(c.endpoint) |
| 1295 |
if err != nil { |
| 1296 |
return nil, err |
| 1297 |
} |
| 1298 |
baseUrl.Path += fmt.Sprintf("/v1/%v/datasets", req.GetParent()) |
| 1299 |
|
| 1300 |
params := url.Values{} |
| 1301 |
params.Add("$alt", "json;enum-encoding=int") |
| 1302 |
|
| 1303 |
baseUrl.RawQuery = params.Encode() |
| 1304 |
|
| 1305 |
// Build HTTP headers from client and context metadata. |
| 1306 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1307 |
|
| 1308 |
hds = append(c.xGoogHeaders, hds...) |
| 1309 |
hds = append(hds, "Content-Type", "application/json") |
| 1310 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1311 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1312 |
resp := &longrunningpb.Operation{} |
| 1313 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1314 |
if settings.Path != "" { |
| 1315 |
baseUrl.Path = settings.Path |
| 1316 |
} |
| 1317 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1318 |
if err != nil { |
| 1319 |
return err |
| 1320 |
} |
| 1321 |
httpReq = httpReq.WithContext(ctx) |
| 1322 |
httpReq.Header = headers |
| 1323 |
|
| 1324 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDataset") |
| 1325 |
if err != nil { |
| 1326 |
return err |
| 1327 |
} |
| 1328 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1329 |
return err |
| 1330 |
} |
| 1331 |
|
| 1332 |
return nil |
| 1333 |
}, opts...) |
| 1334 |
if e != nil { |
| 1335 |
return nil, e |
| 1336 |
} |
| 1337 |
|
| 1338 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1339 |
return &CreateDatasetOperation{ |
| 1340 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1341 |
pollPath: override, |
| 1342 |
}, nil |
| 1343 |
} |
| 1344 |
|
| 1345 |
// GetDataset gets a dataset. |
| 1346 |
func (c *restClient) GetDataset(ctx context.Context, req *automlpb.GetDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { |
| 1347 |
baseUrl, err := url.Parse(c.endpoint) |
| 1348 |
if err != nil { |
| 1349 |
return nil, err |
| 1350 |
} |
| 1351 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1352 |
|
| 1353 |
params := url.Values{} |
| 1354 |
params.Add("$alt", "json;enum-encoding=int") |
| 1355 |
|
| 1356 |
baseUrl.RawQuery = params.Encode() |
| 1357 |
|
| 1358 |
// Build HTTP headers from client and context metadata. |
| 1359 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1360 |
|
| 1361 |
hds = append(c.xGoogHeaders, hds...) |
| 1362 |
hds = append(hds, "Content-Type", "application/json") |
| 1363 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1364 |
opts = append((*c.CallOptions).GetDataset[0:len((*c.CallOptions).GetDataset):len((*c.CallOptions).GetDataset)], opts...) |
| 1365 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1366 |
resp := &automlpb.Dataset{} |
| 1367 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1368 |
if settings.Path != "" { |
| 1369 |
baseUrl.Path = settings.Path |
| 1370 |
} |
| 1371 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1372 |
if err != nil { |
| 1373 |
return err |
| 1374 |
} |
| 1375 |
httpReq = httpReq.WithContext(ctx) |
| 1376 |
httpReq.Header = headers |
| 1377 |
|
| 1378 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDataset") |
| 1379 |
if err != nil { |
| 1380 |
return err |
| 1381 |
} |
| 1382 |
|
| 1383 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1384 |
return err |
| 1385 |
} |
| 1386 |
|
| 1387 |
return nil |
| 1388 |
}, opts...) |
| 1389 |
if e != nil { |
| 1390 |
return nil, e |
| 1391 |
} |
| 1392 |
return resp, nil |
| 1393 |
} |
| 1394 |
|
| 1395 |
// ListDatasets lists datasets in a project. |
| 1396 |
func (c *restClient) ListDatasets(ctx context.Context, req *automlpb.ListDatasetsRequest, opts ...gax.CallOption) *DatasetIterator { |
| 1397 |
it := &DatasetIterator{} |
| 1398 |
req = proto.Clone(req).(*automlpb.ListDatasetsRequest) |
| 1399 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1400 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Dataset, string, error) { |
| 1401 |
resp := &automlpb.ListDatasetsResponse{} |
| 1402 |
if pageToken != "" { |
| 1403 |
req.PageToken = pageToken |
| 1404 |
} |
| 1405 |
if pageSize > math.MaxInt32 { |
| 1406 |
req.PageSize = math.MaxInt32 |
| 1407 |
} else if pageSize != 0 { |
| 1408 |
req.PageSize = int32(pageSize) |
| 1409 |
} |
| 1410 |
baseUrl, err := url.Parse(c.endpoint) |
| 1411 |
if err != nil { |
| 1412 |
return nil, "", err |
| 1413 |
} |
| 1414 |
baseUrl.Path += fmt.Sprintf("/v1/%v/datasets", req.GetParent()) |
| 1415 |
|
| 1416 |
params := url.Values{} |
| 1417 |
params.Add("$alt", "json;enum-encoding=int") |
| 1418 |
if req.GetFilter() != "" { |
| 1419 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1420 |
} |
| 1421 |
if req.GetPageSize() != 0 { |
| 1422 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1423 |
} |
| 1424 |
if req.GetPageToken() != "" { |
| 1425 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1426 |
} |
| 1427 |
|
| 1428 |
baseUrl.RawQuery = params.Encode() |
| 1429 |
|
| 1430 |
// Build HTTP headers from client and context metadata. |
| 1431 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1432 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1433 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1434 |
if settings.Path != "" { |
| 1435 |
baseUrl.Path = settings.Path |
| 1436 |
} |
| 1437 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1438 |
if err != nil { |
| 1439 |
return err |
| 1440 |
} |
| 1441 |
httpReq.Header = headers |
| 1442 |
|
| 1443 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDatasets") |
| 1444 |
if err != nil { |
| 1445 |
return err |
| 1446 |
} |
| 1447 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1448 |
return err |
| 1449 |
} |
| 1450 |
|
| 1451 |
return nil |
| 1452 |
}, opts...) |
| 1453 |
if e != nil { |
| 1454 |
return nil, "", e |
| 1455 |
} |
| 1456 |
it.Response = resp |
| 1457 |
return resp.GetDatasets(), resp.GetNextPageToken(), nil |
| 1458 |
} |
| 1459 |
|
| 1460 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1461 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1462 |
if err != nil { |
| 1463 |
return "", err |
| 1464 |
} |
| 1465 |
it.items = append(it.items, items...) |
| 1466 |
return nextPageToken, nil |
| 1467 |
} |
| 1468 |
|
| 1469 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1470 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1471 |
it.pageInfo.Token = req.GetPageToken() |
| 1472 |
|
| 1473 |
return it |
| 1474 |
} |
| 1475 |
|
| 1476 |
// UpdateDataset updates a dataset. |
| 1477 |
func (c *restClient) UpdateDataset(ctx context.Context, req *automlpb.UpdateDatasetRequest, opts ...gax.CallOption) (*automlpb.Dataset, error) { |
| 1478 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1479 |
body := req.GetDataset() |
| 1480 |
jsonReq, err := m.Marshal(body) |
| 1481 |
if err != nil { |
| 1482 |
return nil, err |
| 1483 |
} |
| 1484 |
|
| 1485 |
baseUrl, err := url.Parse(c.endpoint) |
| 1486 |
if err != nil { |
| 1487 |
return nil, err |
| 1488 |
} |
| 1489 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetDataset().GetName()) |
| 1490 |
|
| 1491 |
params := url.Values{} |
| 1492 |
params.Add("$alt", "json;enum-encoding=int") |
| 1493 |
if req.GetUpdateMask() != nil { |
| 1494 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1495 |
if err != nil { |
| 1496 |
return nil, err |
| 1497 |
} |
| 1498 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1499 |
} |
| 1500 |
|
| 1501 |
baseUrl.RawQuery = params.Encode() |
| 1502 |
|
| 1503 |
// Build HTTP headers from client and context metadata. |
| 1504 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dataset.name", url.QueryEscape(req.GetDataset().GetName()))} |
| 1505 |
|
| 1506 |
hds = append(c.xGoogHeaders, hds...) |
| 1507 |
hds = append(hds, "Content-Type", "application/json") |
| 1508 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1509 |
opts = append((*c.CallOptions).UpdateDataset[0:len((*c.CallOptions).UpdateDataset):len((*c.CallOptions).UpdateDataset)], opts...) |
| 1510 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1511 |
resp := &automlpb.Dataset{} |
| 1512 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1513 |
if settings.Path != "" { |
| 1514 |
baseUrl.Path = settings.Path |
| 1515 |
} |
| 1516 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1517 |
if err != nil { |
| 1518 |
return err |
| 1519 |
} |
| 1520 |
httpReq = httpReq.WithContext(ctx) |
| 1521 |
httpReq.Header = headers |
| 1522 |
|
| 1523 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateDataset") |
| 1524 |
if err != nil { |
| 1525 |
return err |
| 1526 |
} |
| 1527 |
|
| 1528 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1529 |
return err |
| 1530 |
} |
| 1531 |
|
| 1532 |
return nil |
| 1533 |
}, opts...) |
| 1534 |
if e != nil { |
| 1535 |
return nil, e |
| 1536 |
} |
| 1537 |
return resp, nil |
| 1538 |
} |
| 1539 |
|
| 1540 |
// DeleteDataset deletes a dataset and all of its contents. |
| 1541 |
// Returns empty response in the |
| 1542 |
// response field when it completes, |
| 1543 |
// and delete_details in the |
| 1544 |
// metadata field. |
| 1545 |
func (c *restClient) DeleteDataset(ctx context.Context, req *automlpb.DeleteDatasetRequest, opts ...gax.CallOption) (*DeleteDatasetOperation, error) { |
| 1546 |
baseUrl, err := url.Parse(c.endpoint) |
| 1547 |
if err != nil { |
| 1548 |
return nil, err |
| 1549 |
} |
| 1550 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1551 |
|
| 1552 |
params := url.Values{} |
| 1553 |
params.Add("$alt", "json;enum-encoding=int") |
| 1554 |
|
| 1555 |
baseUrl.RawQuery = params.Encode() |
| 1556 |
|
| 1557 |
// Build HTTP headers from client and context metadata. |
| 1558 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1559 |
|
| 1560 |
hds = append(c.xGoogHeaders, hds...) |
| 1561 |
hds = append(hds, "Content-Type", "application/json") |
| 1562 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1563 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1564 |
resp := &longrunningpb.Operation{} |
| 1565 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1566 |
if settings.Path != "" { |
| 1567 |
baseUrl.Path = settings.Path |
| 1568 |
} |
| 1569 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1570 |
if err != nil { |
| 1571 |
return err |
| 1572 |
} |
| 1573 |
httpReq = httpReq.WithContext(ctx) |
| 1574 |
httpReq.Header = headers |
| 1575 |
|
| 1576 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDataset") |
| 1577 |
if err != nil { |
| 1578 |
return err |
| 1579 |
} |
| 1580 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1581 |
return err |
| 1582 |
} |
| 1583 |
|
| 1584 |
return nil |
| 1585 |
}, opts...) |
| 1586 |
if e != nil { |
| 1587 |
return nil, e |
| 1588 |
} |
| 1589 |
|
| 1590 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1591 |
return &DeleteDatasetOperation{ |
| 1592 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1593 |
pollPath: override, |
| 1594 |
}, nil |
| 1595 |
} |
| 1596 |
|
| 1597 |
// ImportData imports data into a dataset. |
| 1598 |
// For Tables this method can only be called on an empty Dataset. |
| 1599 |
// |
| 1600 |
// For Tables: |
| 1601 |
// |
| 1602 |
// A |
| 1603 |
// schema_inference_version |
| 1604 |
// parameter must be explicitly set. |
| 1605 |
// Returns an empty response in the |
| 1606 |
// response field when it completes. |
| 1607 |
func (c *restClient) ImportData(ctx context.Context, req *automlpb.ImportDataRequest, opts ...gax.CallOption) (*ImportDataOperation, error) { |
| 1608 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1609 |
jsonReq, err := m.Marshal(req) |
| 1610 |
if err != nil { |
| 1611 |
return nil, err |
| 1612 |
} |
| 1613 |
|
| 1614 |
baseUrl, err := url.Parse(c.endpoint) |
| 1615 |
if err != nil { |
| 1616 |
return nil, err |
| 1617 |
} |
| 1618 |
baseUrl.Path += fmt.Sprintf("/v1/%v:importData", req.GetName()) |
| 1619 |
|
| 1620 |
params := url.Values{} |
| 1621 |
params.Add("$alt", "json;enum-encoding=int") |
| 1622 |
|
| 1623 |
baseUrl.RawQuery = params.Encode() |
| 1624 |
|
| 1625 |
// Build HTTP headers from client and context metadata. |
| 1626 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1627 |
|
| 1628 |
hds = append(c.xGoogHeaders, hds...) |
| 1629 |
hds = append(hds, "Content-Type", "application/json") |
| 1630 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1631 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1632 |
resp := &longrunningpb.Operation{} |
| 1633 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1634 |
if settings.Path != "" { |
| 1635 |
baseUrl.Path = settings.Path |
| 1636 |
} |
| 1637 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1638 |
if err != nil { |
| 1639 |
return err |
| 1640 |
} |
| 1641 |
httpReq = httpReq.WithContext(ctx) |
| 1642 |
httpReq.Header = headers |
| 1643 |
|
| 1644 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportData") |
| 1645 |
if err != nil { |
| 1646 |
return err |
| 1647 |
} |
| 1648 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1649 |
return err |
| 1650 |
} |
| 1651 |
|
| 1652 |
return nil |
| 1653 |
}, opts...) |
| 1654 |
if e != nil { |
| 1655 |
return nil, e |
| 1656 |
} |
| 1657 |
|
| 1658 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1659 |
return &ImportDataOperation{ |
| 1660 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1661 |
pollPath: override, |
| 1662 |
}, nil |
| 1663 |
} |
| 1664 |
|
| 1665 |
// ExportData exports dataset’s data to the provided output location. |
| 1666 |
// Returns an empty response in the |
| 1667 |
// response field when it completes. |
| 1668 |
func (c *restClient) ExportData(ctx context.Context, req *automlpb.ExportDataRequest, opts ...gax.CallOption) (*ExportDataOperation, error) { |
| 1669 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1670 |
jsonReq, err := m.Marshal(req) |
| 1671 |
if err != nil { |
| 1672 |
return nil, err |
| 1673 |
} |
| 1674 |
|
| 1675 |
baseUrl, err := url.Parse(c.endpoint) |
| 1676 |
if err != nil { |
| 1677 |
return nil, err |
| 1678 |
} |
| 1679 |
baseUrl.Path += fmt.Sprintf("/v1/%v:exportData", req.GetName()) |
| 1680 |
|
| 1681 |
params := url.Values{} |
| 1682 |
params.Add("$alt", "json;enum-encoding=int") |
| 1683 |
|
| 1684 |
baseUrl.RawQuery = params.Encode() |
| 1685 |
|
| 1686 |
// Build HTTP headers from client and context metadata. |
| 1687 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1688 |
|
| 1689 |
hds = append(c.xGoogHeaders, hds...) |
| 1690 |
hds = append(hds, "Content-Type", "application/json") |
| 1691 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1692 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1693 |
resp := &longrunningpb.Operation{} |
| 1694 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1695 |
if settings.Path != "" { |
| 1696 |
baseUrl.Path = settings.Path |
| 1697 |
} |
| 1698 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1699 |
if err != nil { |
| 1700 |
return err |
| 1701 |
} |
| 1702 |
httpReq = httpReq.WithContext(ctx) |
| 1703 |
httpReq.Header = headers |
| 1704 |
|
| 1705 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ExportData") |
| 1706 |
if err != nil { |
| 1707 |
return err |
| 1708 |
} |
| 1709 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1710 |
return err |
| 1711 |
} |
| 1712 |
|
| 1713 |
return nil |
| 1714 |
}, opts...) |
| 1715 |
if e != nil { |
| 1716 |
return nil, e |
| 1717 |
} |
| 1718 |
|
| 1719 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1720 |
return &ExportDataOperation{ |
| 1721 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1722 |
pollPath: override, |
| 1723 |
}, nil |
| 1724 |
} |
| 1725 |
|
| 1726 |
// GetAnnotationSpec gets an annotation spec. |
| 1727 |
func (c *restClient) GetAnnotationSpec(ctx context.Context, req *automlpb.GetAnnotationSpecRequest, opts ...gax.CallOption) (*automlpb.AnnotationSpec, error) { |
| 1728 |
baseUrl, err := url.Parse(c.endpoint) |
| 1729 |
if err != nil { |
| 1730 |
return nil, err |
| 1731 |
} |
| 1732 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1733 |
|
| 1734 |
params := url.Values{} |
| 1735 |
params.Add("$alt", "json;enum-encoding=int") |
| 1736 |
|
| 1737 |
baseUrl.RawQuery = params.Encode() |
| 1738 |
|
| 1739 |
// Build HTTP headers from client and context metadata. |
| 1740 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1741 |
|
| 1742 |
hds = append(c.xGoogHeaders, hds...) |
| 1743 |
hds = append(hds, "Content-Type", "application/json") |
| 1744 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1745 |
opts = append((*c.CallOptions).GetAnnotationSpec[0:len((*c.CallOptions).GetAnnotationSpec):len((*c.CallOptions).GetAnnotationSpec)], opts...) |
| 1746 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1747 |
resp := &automlpb.AnnotationSpec{} |
| 1748 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1749 |
if settings.Path != "" { |
| 1750 |
baseUrl.Path = settings.Path |
| 1751 |
} |
| 1752 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1753 |
if err != nil { |
| 1754 |
return err |
| 1755 |
} |
| 1756 |
httpReq = httpReq.WithContext(ctx) |
| 1757 |
httpReq.Header = headers |
| 1758 |
|
| 1759 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAnnotationSpec") |
| 1760 |
if err != nil { |
| 1761 |
return err |
| 1762 |
} |
| 1763 |
|
| 1764 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1765 |
return err |
| 1766 |
} |
| 1767 |
|
| 1768 |
return nil |
| 1769 |
}, opts...) |
| 1770 |
if e != nil { |
| 1771 |
return nil, e |
| 1772 |
} |
| 1773 |
return resp, nil |
| 1774 |
} |
| 1775 |
|
| 1776 |
// CreateModel creates a model. |
| 1777 |
// Returns a Model in the response |
| 1778 |
// field when it completes. |
| 1779 |
// When you create a model, several model evaluations are created for it: |
| 1780 |
// a global evaluation, and one evaluation for each annotation spec. |
| 1781 |
func (c *restClient) CreateModel(ctx context.Context, req *automlpb.CreateModelRequest, opts ...gax.CallOption) (*CreateModelOperation, error) { |
| 1782 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1783 |
body := req.GetModel() |
| 1784 |
jsonReq, err := m.Marshal(body) |
| 1785 |
if err != nil { |
| 1786 |
return nil, err |
| 1787 |
} |
| 1788 |
|
| 1789 |
baseUrl, err := url.Parse(c.endpoint) |
| 1790 |
if err != nil { |
| 1791 |
return nil, err |
| 1792 |
} |
| 1793 |
baseUrl.Path += fmt.Sprintf("/v1/%v/models", req.GetParent()) |
| 1794 |
|
| 1795 |
params := url.Values{} |
| 1796 |
params.Add("$alt", "json;enum-encoding=int") |
| 1797 |
|
| 1798 |
baseUrl.RawQuery = params.Encode() |
| 1799 |
|
| 1800 |
// Build HTTP headers from client and context metadata. |
| 1801 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1802 |
|
| 1803 |
hds = append(c.xGoogHeaders, hds...) |
| 1804 |
hds = append(hds, "Content-Type", "application/json") |
| 1805 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1806 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1807 |
resp := &longrunningpb.Operation{} |
| 1808 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1809 |
if settings.Path != "" { |
| 1810 |
baseUrl.Path = settings.Path |
| 1811 |
} |
| 1812 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1813 |
if err != nil { |
| 1814 |
return err |
| 1815 |
} |
| 1816 |
httpReq = httpReq.WithContext(ctx) |
| 1817 |
httpReq.Header = headers |
| 1818 |
|
| 1819 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateModel") |
| 1820 |
if err != nil { |
| 1821 |
return err |
| 1822 |
} |
| 1823 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1824 |
return err |
| 1825 |
} |
| 1826 |
|
| 1827 |
return nil |
| 1828 |
}, opts...) |
| 1829 |
if e != nil { |
| 1830 |
return nil, e |
| 1831 |
} |
| 1832 |
|
| 1833 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1834 |
return &CreateModelOperation{ |
| 1835 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1836 |
pollPath: override, |
| 1837 |
}, nil |
| 1838 |
} |
| 1839 |
|
| 1840 |
// GetModel gets a model. |
| 1841 |
func (c *restClient) GetModel(ctx context.Context, req *automlpb.GetModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { |
| 1842 |
baseUrl, err := url.Parse(c.endpoint) |
| 1843 |
if err != nil { |
| 1844 |
return nil, err |
| 1845 |
} |
| 1846 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1847 |
|
| 1848 |
params := url.Values{} |
| 1849 |
params.Add("$alt", "json;enum-encoding=int") |
| 1850 |
|
| 1851 |
baseUrl.RawQuery = params.Encode() |
| 1852 |
|
| 1853 |
// Build HTTP headers from client and context metadata. |
| 1854 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1855 |
|
| 1856 |
hds = append(c.xGoogHeaders, hds...) |
| 1857 |
hds = append(hds, "Content-Type", "application/json") |
| 1858 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1859 |
opts = append((*c.CallOptions).GetModel[0:len((*c.CallOptions).GetModel):len((*c.CallOptions).GetModel)], opts...) |
| 1860 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1861 |
resp := &automlpb.Model{} |
| 1862 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1863 |
if settings.Path != "" { |
| 1864 |
baseUrl.Path = settings.Path |
| 1865 |
} |
| 1866 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1867 |
if err != nil { |
| 1868 |
return err |
| 1869 |
} |
| 1870 |
httpReq = httpReq.WithContext(ctx) |
| 1871 |
httpReq.Header = headers |
| 1872 |
|
| 1873 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetModel") |
| 1874 |
if err != nil { |
| 1875 |
return err |
| 1876 |
} |
| 1877 |
|
| 1878 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1879 |
return err |
| 1880 |
} |
| 1881 |
|
| 1882 |
return nil |
| 1883 |
}, opts...) |
| 1884 |
if e != nil { |
| 1885 |
return nil, e |
| 1886 |
} |
| 1887 |
return resp, nil |
| 1888 |
} |
| 1889 |
|
| 1890 |
// ListModels lists models. |
| 1891 |
func (c *restClient) ListModels(ctx context.Context, req *automlpb.ListModelsRequest, opts ...gax.CallOption) *ModelIterator { |
| 1892 |
it := &ModelIterator{} |
| 1893 |
req = proto.Clone(req).(*automlpb.ListModelsRequest) |
| 1894 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1895 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.Model, string, error) { |
| 1896 |
resp := &automlpb.ListModelsResponse{} |
| 1897 |
if pageToken != "" { |
| 1898 |
req.PageToken = pageToken |
| 1899 |
} |
| 1900 |
if pageSize > math.MaxInt32 { |
| 1901 |
req.PageSize = math.MaxInt32 |
| 1902 |
} else if pageSize != 0 { |
| 1903 |
req.PageSize = int32(pageSize) |
| 1904 |
} |
| 1905 |
baseUrl, err := url.Parse(c.endpoint) |
| 1906 |
if err != nil { |
| 1907 |
return nil, "", err |
| 1908 |
} |
| 1909 |
baseUrl.Path += fmt.Sprintf("/v1/%v/models", req.GetParent()) |
| 1910 |
|
| 1911 |
params := url.Values{} |
| 1912 |
params.Add("$alt", "json;enum-encoding=int") |
| 1913 |
if req.GetFilter() != "" { |
| 1914 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1915 |
} |
| 1916 |
if req.GetPageSize() != 0 { |
| 1917 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1918 |
} |
| 1919 |
if req.GetPageToken() != "" { |
| 1920 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1921 |
} |
| 1922 |
|
| 1923 |
baseUrl.RawQuery = params.Encode() |
| 1924 |
|
| 1925 |
// Build HTTP headers from client and context metadata. |
| 1926 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1927 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1928 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1929 |
if settings.Path != "" { |
| 1930 |
baseUrl.Path = settings.Path |
| 1931 |
} |
| 1932 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1933 |
if err != nil { |
| 1934 |
return err |
| 1935 |
} |
| 1936 |
httpReq.Header = headers |
| 1937 |
|
| 1938 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListModels") |
| 1939 |
if err != nil { |
| 1940 |
return err |
| 1941 |
} |
| 1942 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1943 |
return err |
| 1944 |
} |
| 1945 |
|
| 1946 |
return nil |
| 1947 |
}, opts...) |
| 1948 |
if e != nil { |
| 1949 |
return nil, "", e |
| 1950 |
} |
| 1951 |
it.Response = resp |
| 1952 |
return resp.GetModel(), resp.GetNextPageToken(), nil |
| 1953 |
} |
| 1954 |
|
| 1955 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1956 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1957 |
if err != nil { |
| 1958 |
return "", err |
| 1959 |
} |
| 1960 |
it.items = append(it.items, items...) |
| 1961 |
return nextPageToken, nil |
| 1962 |
} |
| 1963 |
|
| 1964 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1965 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1966 |
it.pageInfo.Token = req.GetPageToken() |
| 1967 |
|
| 1968 |
return it |
| 1969 |
} |
| 1970 |
|
| 1971 |
// DeleteModel deletes a model. |
| 1972 |
// Returns google.protobuf.Empty in the |
| 1973 |
// response field when it completes, |
| 1974 |
// and delete_details in the |
| 1975 |
// metadata field. |
| 1976 |
func (c *restClient) DeleteModel(ctx context.Context, req *automlpb.DeleteModelRequest, opts ...gax.CallOption) (*DeleteModelOperation, error) { |
| 1977 |
baseUrl, err := url.Parse(c.endpoint) |
| 1978 |
if err != nil { |
| 1979 |
return nil, err |
| 1980 |
} |
| 1981 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1982 |
|
| 1983 |
params := url.Values{} |
| 1984 |
params.Add("$alt", "json;enum-encoding=int") |
| 1985 |
|
| 1986 |
baseUrl.RawQuery = params.Encode() |
| 1987 |
|
| 1988 |
// Build HTTP headers from client and context metadata. |
| 1989 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1990 |
|
| 1991 |
hds = append(c.xGoogHeaders, hds...) |
| 1992 |
hds = append(hds, "Content-Type", "application/json") |
| 1993 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1994 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1995 |
resp := &longrunningpb.Operation{} |
| 1996 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1997 |
if settings.Path != "" { |
| 1998 |
baseUrl.Path = settings.Path |
| 1999 |
} |
| 2000 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 2001 |
if err != nil { |
| 2002 |
return err |
| 2003 |
} |
| 2004 |
httpReq = httpReq.WithContext(ctx) |
| 2005 |
httpReq.Header = headers |
| 2006 |
|
| 2007 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteModel") |
| 2008 |
if err != nil { |
| 2009 |
return err |
| 2010 |
} |
| 2011 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2012 |
return err |
| 2013 |
} |
| 2014 |
|
| 2015 |
return nil |
| 2016 |
}, opts...) |
| 2017 |
if e != nil { |
| 2018 |
return nil, e |
| 2019 |
} |
| 2020 |
|
| 2021 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 2022 |
return &DeleteModelOperation{ |
| 2023 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 2024 |
pollPath: override, |
| 2025 |
}, nil |
| 2026 |
} |
| 2027 |
|
| 2028 |
// UpdateModel updates a model. |
| 2029 |
func (c *restClient) UpdateModel(ctx context.Context, req *automlpb.UpdateModelRequest, opts ...gax.CallOption) (*automlpb.Model, error) { |
| 2030 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2031 |
body := req.GetModel() |
| 2032 |
jsonReq, err := m.Marshal(body) |
| 2033 |
if err != nil { |
| 2034 |
return nil, err |
| 2035 |
} |
| 2036 |
|
| 2037 |
baseUrl, err := url.Parse(c.endpoint) |
| 2038 |
if err != nil { |
| 2039 |
return nil, err |
| 2040 |
} |
| 2041 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetModel().GetName()) |
| 2042 |
|
| 2043 |
params := url.Values{} |
| 2044 |
params.Add("$alt", "json;enum-encoding=int") |
| 2045 |
if req.GetUpdateMask() != nil { |
| 2046 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2047 |
if err != nil { |
| 2048 |
return nil, err |
| 2049 |
} |
| 2050 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2051 |
} |
| 2052 |
|
| 2053 |
baseUrl.RawQuery = params.Encode() |
| 2054 |
|
| 2055 |
// Build HTTP headers from client and context metadata. |
| 2056 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "model.name", url.QueryEscape(req.GetModel().GetName()))} |
| 2057 |
|
| 2058 |
hds = append(c.xGoogHeaders, hds...) |
| 2059 |
hds = append(hds, "Content-Type", "application/json") |
| 2060 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2061 |
opts = append((*c.CallOptions).UpdateModel[0:len((*c.CallOptions).UpdateModel):len((*c.CallOptions).UpdateModel)], opts...) |
| 2062 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2063 |
resp := &automlpb.Model{} |
| 2064 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2065 |
if settings.Path != "" { |
| 2066 |
baseUrl.Path = settings.Path |
| 2067 |
} |
| 2068 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2069 |
if err != nil { |
| 2070 |
return err |
| 2071 |
} |
| 2072 |
httpReq = httpReq.WithContext(ctx) |
| 2073 |
httpReq.Header = headers |
| 2074 |
|
| 2075 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateModel") |
| 2076 |
if err != nil { |
| 2077 |
return err |
| 2078 |
} |
| 2079 |
|
| 2080 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2081 |
return err |
| 2082 |
} |
| 2083 |
|
| 2084 |
return nil |
| 2085 |
}, opts...) |
| 2086 |
if e != nil { |
| 2087 |
return nil, e |
| 2088 |
} |
| 2089 |
return resp, nil |
| 2090 |
} |
| 2091 |
|
| 2092 |
// DeployModel deploys a model. If a model is already deployed, deploying it with the |
| 2093 |
// same parameters has no effect. Deploying with different parametrs |
| 2094 |
// (as e.g. changing |
| 2095 |
// node_number) |
| 2096 |
// will reset the deployment state without pausing the model’s availability. |
| 2097 |
// |
| 2098 |
// Only applicable for Text Classification, Image Object Detection , Tables, and Image Segmentation; all other domains manage |
| 2099 |
// deployment automatically. |
| 2100 |
// |
| 2101 |
// Returns an empty response in the |
| 2102 |
// response field when it completes. |
| 2103 |
func (c *restClient) DeployModel(ctx context.Context, req *automlpb.DeployModelRequest, opts ...gax.CallOption) (*DeployModelOperation, error) { |
| 2104 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2105 |
jsonReq, err := m.Marshal(req) |
| 2106 |
if err != nil { |
| 2107 |
return nil, err |
| 2108 |
} |
| 2109 |
|
| 2110 |
baseUrl, err := url.Parse(c.endpoint) |
| 2111 |
if err != nil { |
| 2112 |
return nil, err |
| 2113 |
} |
| 2114 |
baseUrl.Path += fmt.Sprintf("/v1/%v:deploy", req.GetName()) |
| 2115 |
|
| 2116 |
params := url.Values{} |
| 2117 |
params.Add("$alt", "json;enum-encoding=int") |
| 2118 |
|
| 2119 |
baseUrl.RawQuery = params.Encode() |
| 2120 |
|
| 2121 |
// Build HTTP headers from client and context metadata. |
| 2122 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2123 |
|
| 2124 |
hds = append(c.xGoogHeaders, hds...) |
| 2125 |
hds = append(hds, "Content-Type", "application/json") |
| 2126 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2127 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2128 |
resp := &longrunningpb.Operation{} |
| 2129 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2130 |
if settings.Path != "" { |
| 2131 |
baseUrl.Path = settings.Path |
| 2132 |
} |
| 2133 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2134 |
if err != nil { |
| 2135 |
return err |
| 2136 |
} |
| 2137 |
httpReq = httpReq.WithContext(ctx) |
| 2138 |
httpReq.Header = headers |
| 2139 |
|
| 2140 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "DeployModel") |
| 2141 |
if err != nil { |
| 2142 |
return err |
| 2143 |
} |
| 2144 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2145 |
return err |
| 2146 |
} |
| 2147 |
|
| 2148 |
return nil |
| 2149 |
}, opts...) |
| 2150 |
if e != nil { |
| 2151 |
return nil, e |
| 2152 |
} |
| 2153 |
|
| 2154 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 2155 |
return &DeployModelOperation{ |
| 2156 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 2157 |
pollPath: override, |
| 2158 |
}, nil |
| 2159 |
} |
| 2160 |
|
| 2161 |
// UndeployModel undeploys a model. If the model is not deployed this method has no effect. |
| 2162 |
// |
| 2163 |
// Only applicable for Text Classification, Image Object Detection and Tables; |
| 2164 |
// all other domains manage deployment automatically. |
| 2165 |
// |
| 2166 |
// Returns an empty response in the |
| 2167 |
// response field when it completes. |
| 2168 |
func (c *restClient) UndeployModel(ctx context.Context, req *automlpb.UndeployModelRequest, opts ...gax.CallOption) (*UndeployModelOperation, error) { |
| 2169 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2170 |
jsonReq, err := m.Marshal(req) |
| 2171 |
if err != nil { |
| 2172 |
return nil, err |
| 2173 |
} |
| 2174 |
|
| 2175 |
baseUrl, err := url.Parse(c.endpoint) |
| 2176 |
if err != nil { |
| 2177 |
return nil, err |
| 2178 |
} |
| 2179 |
baseUrl.Path += fmt.Sprintf("/v1/%v:undeploy", req.GetName()) |
| 2180 |
|
| 2181 |
params := url.Values{} |
| 2182 |
params.Add("$alt", "json;enum-encoding=int") |
| 2183 |
|
| 2184 |
baseUrl.RawQuery = params.Encode() |
| 2185 |
|
| 2186 |
// Build HTTP headers from client and context metadata. |
| 2187 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2188 |
|
| 2189 |
hds = append(c.xGoogHeaders, hds...) |
| 2190 |
hds = append(hds, "Content-Type", "application/json") |
| 2191 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2192 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2193 |
resp := &longrunningpb.Operation{} |
| 2194 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2195 |
if settings.Path != "" { |
| 2196 |
baseUrl.Path = settings.Path |
| 2197 |
} |
| 2198 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2199 |
if err != nil { |
| 2200 |
return err |
| 2201 |
} |
| 2202 |
httpReq = httpReq.WithContext(ctx) |
| 2203 |
httpReq.Header = headers |
| 2204 |
|
| 2205 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UndeployModel") |
| 2206 |
if err != nil { |
| 2207 |
return err |
| 2208 |
} |
| 2209 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2210 |
return err |
| 2211 |
} |
| 2212 |
|
| 2213 |
return nil |
| 2214 |
}, opts...) |
| 2215 |
if e != nil { |
| 2216 |
return nil, e |
| 2217 |
} |
| 2218 |
|
| 2219 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 2220 |
return &UndeployModelOperation{ |
| 2221 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 2222 |
pollPath: override, |
| 2223 |
}, nil |
| 2224 |
} |
| 2225 |
|
| 2226 |
// ExportModel exports a trained, “export-able”, model to a user specified Google Cloud |
| 2227 |
// Storage location. A model is considered export-able if and only if it has |
| 2228 |
// an export format defined for it in |
| 2229 |
// ModelExportOutputConfig. |
| 2230 |
// |
| 2231 |
// Returns an empty response in the |
| 2232 |
// response field when it completes. |
| 2233 |
func (c *restClient) ExportModel(ctx context.Context, req *automlpb.ExportModelRequest, opts ...gax.CallOption) (*ExportModelOperation, error) { |
| 2234 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2235 |
jsonReq, err := m.Marshal(req) |
| 2236 |
if err != nil { |
| 2237 |
return nil, err |
| 2238 |
} |
| 2239 |
|
| 2240 |
baseUrl, err := url.Parse(c.endpoint) |
| 2241 |
if err != nil { |
| 2242 |
return nil, err |
| 2243 |
} |
| 2244 |
baseUrl.Path += fmt.Sprintf("/v1/%v:export", req.GetName()) |
| 2245 |
|
| 2246 |
params := url.Values{} |
| 2247 |
params.Add("$alt", "json;enum-encoding=int") |
| 2248 |
|
| 2249 |
baseUrl.RawQuery = params.Encode() |
| 2250 |
|
| 2251 |
// Build HTTP headers from client and context metadata. |
| 2252 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2253 |
|
| 2254 |
hds = append(c.xGoogHeaders, hds...) |
| 2255 |
hds = append(hds, "Content-Type", "application/json") |
| 2256 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2257 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2258 |
resp := &longrunningpb.Operation{} |
| 2259 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2260 |
if settings.Path != "" { |
| 2261 |
baseUrl.Path = settings.Path |
| 2262 |
} |
| 2263 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2264 |
if err != nil { |
| 2265 |
return err |
| 2266 |
} |
| 2267 |
httpReq = httpReq.WithContext(ctx) |
| 2268 |
httpReq.Header = headers |
| 2269 |
|
| 2270 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ExportModel") |
| 2271 |
if err != nil { |
| 2272 |
return err |
| 2273 |
} |
| 2274 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2275 |
return err |
| 2276 |
} |
| 2277 |
|
| 2278 |
return nil |
| 2279 |
}, opts...) |
| 2280 |
if e != nil { |
| 2281 |
return nil, e |
| 2282 |
} |
| 2283 |
|
| 2284 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 2285 |
return &ExportModelOperation{ |
| 2286 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 2287 |
pollPath: override, |
| 2288 |
}, nil |
| 2289 |
} |
| 2290 |
|
| 2291 |
// GetModelEvaluation gets a model evaluation. |
| 2292 |
func (c *restClient) GetModelEvaluation(ctx context.Context, req *automlpb.GetModelEvaluationRequest, opts ...gax.CallOption) (*automlpb.ModelEvaluation, error) { |
| 2293 |
baseUrl, err := url.Parse(c.endpoint) |
| 2294 |
if err != nil { |
| 2295 |
return nil, err |
| 2296 |
} |
| 2297 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2298 |
|
| 2299 |
params := url.Values{} |
| 2300 |
params.Add("$alt", "json;enum-encoding=int") |
| 2301 |
|
| 2302 |
baseUrl.RawQuery = params.Encode() |
| 2303 |
|
| 2304 |
// Build HTTP headers from client and context metadata. |
| 2305 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2306 |
|
| 2307 |
hds = append(c.xGoogHeaders, hds...) |
| 2308 |
hds = append(hds, "Content-Type", "application/json") |
| 2309 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2310 |
opts = append((*c.CallOptions).GetModelEvaluation[0:len((*c.CallOptions).GetModelEvaluation):len((*c.CallOptions).GetModelEvaluation)], opts...) |
| 2311 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2312 |
resp := &automlpb.ModelEvaluation{} |
| 2313 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2314 |
if settings.Path != "" { |
| 2315 |
baseUrl.Path = settings.Path |
| 2316 |
} |
| 2317 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2318 |
if err != nil { |
| 2319 |
return err |
| 2320 |
} |
| 2321 |
httpReq = httpReq.WithContext(ctx) |
| 2322 |
httpReq.Header = headers |
| 2323 |
|
| 2324 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetModelEvaluation") |
| 2325 |
if err != nil { |
| 2326 |
return err |
| 2327 |
} |
| 2328 |
|
| 2329 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2330 |
return err |
| 2331 |
} |
| 2332 |
|
| 2333 |
return nil |
| 2334 |
}, opts...) |
| 2335 |
if e != nil { |
| 2336 |
return nil, e |
| 2337 |
} |
| 2338 |
return resp, nil |
| 2339 |
} |
| 2340 |
|
| 2341 |
// ListModelEvaluations lists model evaluations. |
| 2342 |
func (c *restClient) ListModelEvaluations(ctx context.Context, req *automlpb.ListModelEvaluationsRequest, opts ...gax.CallOption) *ModelEvaluationIterator { |
| 2343 |
it := &ModelEvaluationIterator{} |
| 2344 |
req = proto.Clone(req).(*automlpb.ListModelEvaluationsRequest) |
| 2345 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2346 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*automlpb.ModelEvaluation, string, error) { |
| 2347 |
resp := &automlpb.ListModelEvaluationsResponse{} |
| 2348 |
if pageToken != "" { |
| 2349 |
req.PageToken = pageToken |
| 2350 |
} |
| 2351 |
if pageSize > math.MaxInt32 { |
| 2352 |
req.PageSize = math.MaxInt32 |
| 2353 |
} else if pageSize != 0 { |
| 2354 |
req.PageSize = int32(pageSize) |
| 2355 |
} |
| 2356 |
baseUrl, err := url.Parse(c.endpoint) |
| 2357 |
if err != nil { |
| 2358 |
return nil, "", err |
| 2359 |
} |
| 2360 |
baseUrl.Path += fmt.Sprintf("/v1/%v/modelEvaluations", req.GetParent()) |
| 2361 |
|
| 2362 |
params := url.Values{} |
| 2363 |
params.Add("$alt", "json;enum-encoding=int") |
| 2364 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 2365 |
if req.GetPageSize() != 0 { |
| 2366 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2367 |
} |
| 2368 |
if req.GetPageToken() != "" { |
| 2369 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2370 |
} |
| 2371 |
|
| 2372 |
baseUrl.RawQuery = params.Encode() |
| 2373 |
|
| 2374 |
// Build HTTP headers from client and context metadata. |
| 2375 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2376 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2377 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2378 |
if settings.Path != "" { |
| 2379 |
baseUrl.Path = settings.Path |
| 2380 |
} |
| 2381 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2382 |
if err != nil { |
| 2383 |
return err |
| 2384 |
} |
| 2385 |
httpReq.Header = headers |
| 2386 |
|
| 2387 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListModelEvaluations") |
| 2388 |
if err != nil { |
| 2389 |
return err |
| 2390 |
} |
| 2391 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2392 |
return err |
| 2393 |
} |
| 2394 |
|
| 2395 |
return nil |
| 2396 |
}, opts...) |
| 2397 |
if e != nil { |
| 2398 |
return nil, "", e |
| 2399 |
} |
| 2400 |
it.Response = resp |
| 2401 |
return resp.GetModelEvaluation(), resp.GetNextPageToken(), nil |
| 2402 |
} |
| 2403 |
|
| 2404 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2405 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2406 |
if err != nil { |
| 2407 |
return "", err |
| 2408 |
} |
| 2409 |
it.items = append(it.items, items...) |
| 2410 |
return nextPageToken, nil |
| 2411 |
} |
| 2412 |
|
| 2413 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2414 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2415 |
it.pageInfo.Token = req.GetPageToken() |
| 2416 |
|
| 2417 |
return it |
| 2418 |
} |
| 2419 |
|
| 2420 |
// CreateDatasetOperation returns a new CreateDatasetOperation from a given name. |
| 2421 |
// The name must be that of a previously created CreateDatasetOperation, possibly from a different process. |
| 2422 |
func (c *gRPCClient) CreateDatasetOperation(name string) *CreateDatasetOperation { |
| 2423 |
return &CreateDatasetOperation{ |
| 2424 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2425 |
} |
| 2426 |
} |
| 2427 |
|
| 2428 |
// CreateDatasetOperation returns a new CreateDatasetOperation from a given name. |
| 2429 |
// The name must be that of a previously created CreateDatasetOperation, possibly from a different process. |
| 2430 |
func (c *restClient) CreateDatasetOperation(name string) *CreateDatasetOperation { |
| 2431 |
override := fmt.Sprintf("/v1/%s", name) |
| 2432 |
return &CreateDatasetOperation{ |
| 2433 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2434 |
pollPath: override, |
| 2435 |
} |
| 2436 |
} |
| 2437 |
|
| 2438 |
// CreateModelOperation returns a new CreateModelOperation from a given name. |
| 2439 |
// The name must be that of a previously created CreateModelOperation, possibly from a different process. |
| 2440 |
func (c *gRPCClient) CreateModelOperation(name string) *CreateModelOperation { |
| 2441 |
return &CreateModelOperation{ |
| 2442 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2443 |
} |
| 2444 |
} |
| 2445 |
|
| 2446 |
// CreateModelOperation returns a new CreateModelOperation from a given name. |
| 2447 |
// The name must be that of a previously created CreateModelOperation, possibly from a different process. |
| 2448 |
func (c *restClient) CreateModelOperation(name string) *CreateModelOperation { |
| 2449 |
override := fmt.Sprintf("/v1/%s", name) |
| 2450 |
return &CreateModelOperation{ |
| 2451 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2452 |
pollPath: override, |
| 2453 |
} |
| 2454 |
} |
| 2455 |
|
| 2456 |
// DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name. |
| 2457 |
// The name must be that of a previously created DeleteDatasetOperation, possibly from a different process. |
| 2458 |
func (c *gRPCClient) DeleteDatasetOperation(name string) *DeleteDatasetOperation { |
| 2459 |
return &DeleteDatasetOperation{ |
| 2460 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2461 |
} |
| 2462 |
} |
| 2463 |
|
| 2464 |
// DeleteDatasetOperation returns a new DeleteDatasetOperation from a given name. |
| 2465 |
// The name must be that of a previously created DeleteDatasetOperation, possibly from a different process. |
| 2466 |
func (c *restClient) DeleteDatasetOperation(name string) *DeleteDatasetOperation { |
| 2467 |
override := fmt.Sprintf("/v1/%s", name) |
| 2468 |
return &DeleteDatasetOperation{ |
| 2469 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2470 |
pollPath: override, |
| 2471 |
} |
| 2472 |
} |
| 2473 |
|
| 2474 |
// DeleteModelOperation returns a new DeleteModelOperation from a given name. |
| 2475 |
// The name must be that of a previously created DeleteModelOperation, possibly from a different process. |
| 2476 |
func (c *gRPCClient) DeleteModelOperation(name string) *DeleteModelOperation { |
| 2477 |
return &DeleteModelOperation{ |
| 2478 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2479 |
} |
| 2480 |
} |
| 2481 |
|
| 2482 |
// DeleteModelOperation returns a new DeleteModelOperation from a given name. |
| 2483 |
// The name must be that of a previously created DeleteModelOperation, possibly from a different process. |
| 2484 |
func (c *restClient) DeleteModelOperation(name string) *DeleteModelOperation { |
| 2485 |
override := fmt.Sprintf("/v1/%s", name) |
| 2486 |
return &DeleteModelOperation{ |
| 2487 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2488 |
pollPath: override, |
| 2489 |
} |
| 2490 |
} |
| 2491 |
|
| 2492 |
// DeployModelOperation returns a new DeployModelOperation from a given name. |
| 2493 |
// The name must be that of a previously created DeployModelOperation, possibly from a different process. |
| 2494 |
func (c *gRPCClient) DeployModelOperation(name string) *DeployModelOperation { |
| 2495 |
return &DeployModelOperation{ |
| 2496 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2497 |
} |
| 2498 |
} |
| 2499 |
|
| 2500 |
// DeployModelOperation returns a new DeployModelOperation from a given name. |
| 2501 |
// The name must be that of a previously created DeployModelOperation, possibly from a different process. |
| 2502 |
func (c *restClient) DeployModelOperation(name string) *DeployModelOperation { |
| 2503 |
override := fmt.Sprintf("/v1/%s", name) |
| 2504 |
return &DeployModelOperation{ |
| 2505 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2506 |
pollPath: override, |
| 2507 |
} |
| 2508 |
} |
| 2509 |
|
| 2510 |
// ExportDataOperation returns a new ExportDataOperation from a given name. |
| 2511 |
// The name must be that of a previously created ExportDataOperation, possibly from a different process. |
| 2512 |
func (c *gRPCClient) ExportDataOperation(name string) *ExportDataOperation { |
| 2513 |
return &ExportDataOperation{ |
| 2514 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
// ExportDataOperation returns a new ExportDataOperation from a given name. |
| 2519 |
// The name must be that of a previously created ExportDataOperation, possibly from a different process. |
| 2520 |
func (c *restClient) ExportDataOperation(name string) *ExportDataOperation { |
| 2521 |
override := fmt.Sprintf("/v1/%s", name) |
| 2522 |
return &ExportDataOperation{ |
| 2523 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2524 |
pollPath: override, |
| 2525 |
} |
| 2526 |
} |
| 2527 |
|
| 2528 |
// ExportModelOperation returns a new ExportModelOperation from a given name. |
| 2529 |
// The name must be that of a previously created ExportModelOperation, possibly from a different process. |
| 2530 |
func (c *gRPCClient) ExportModelOperation(name string) *ExportModelOperation { |
| 2531 |
return &ExportModelOperation{ |
| 2532 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2533 |
} |
| 2534 |
} |
| 2535 |
|
| 2536 |
// ExportModelOperation returns a new ExportModelOperation from a given name. |
| 2537 |
// The name must be that of a previously created ExportModelOperation, possibly from a different process. |
| 2538 |
func (c *restClient) ExportModelOperation(name string) *ExportModelOperation { |
| 2539 |
override := fmt.Sprintf("/v1/%s", name) |
| 2540 |
return &ExportModelOperation{ |
| 2541 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2542 |
pollPath: override, |
| 2543 |
} |
| 2544 |
} |
| 2545 |
|
| 2546 |
// ImportDataOperation returns a new ImportDataOperation from a given name. |
| 2547 |
// The name must be that of a previously created ImportDataOperation, possibly from a different process. |
| 2548 |
func (c *gRPCClient) ImportDataOperation(name string) *ImportDataOperation { |
| 2549 |
return &ImportDataOperation{ |
| 2550 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2551 |
} |
| 2552 |
} |
| 2553 |
|
| 2554 |
// ImportDataOperation returns a new ImportDataOperation from a given name. |
| 2555 |
// The name must be that of a previously created ImportDataOperation, possibly from a different process. |
| 2556 |
func (c *restClient) ImportDataOperation(name string) *ImportDataOperation { |
| 2557 |
override := fmt.Sprintf("/v1/%s", name) |
| 2558 |
return &ImportDataOperation{ |
| 2559 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2560 |
pollPath: override, |
| 2561 |
} |
| 2562 |
} |
| 2563 |
|
| 2564 |
// UndeployModelOperation returns a new UndeployModelOperation from a given name. |
| 2565 |
// The name must be that of a previously created UndeployModelOperation, possibly from a different process. |
| 2566 |
func (c *gRPCClient) UndeployModelOperation(name string) *UndeployModelOperation { |
| 2567 |
return &UndeployModelOperation{ |
| 2568 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2569 |
} |
| 2570 |
} |
| 2571 |
|
| 2572 |
// UndeployModelOperation returns a new UndeployModelOperation from a given name. |
| 2573 |
// The name must be that of a previously created UndeployModelOperation, possibly from a different process. |
| 2574 |
func (c *restClient) UndeployModelOperation(name string) *UndeployModelOperation { |
| 2575 |
override := fmt.Sprintf("/v1/%s", name) |
| 2576 |
return &UndeployModelOperation{ |
| 2577 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2578 |
pollPath: override, |
| 2579 |
} |
| 2580 |
} |