1// Copyright 2021 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package admin 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "cloud.google.com/go/longrunning" 27 lroauto "cloud.google.com/go/longrunning/autogen" 28 gax "github.com/googleapis/gax-go/v2" 29 "google.golang.org/api/iterator" 30 "google.golang.org/api/option" 31 "google.golang.org/api/option/internaloption" 32 gtransport "google.golang.org/api/transport/grpc" 33 adminpb "google.golang.org/genproto/googleapis/datastore/admin/v1" 34 longrunningpb "google.golang.org/genproto/googleapis/longrunning" 35 "google.golang.org/grpc" 36 "google.golang.org/grpc/codes" 37 "google.golang.org/grpc/metadata" 38 "google.golang.org/protobuf/proto" 39) 40 41var newDatastoreAdminClientHook clientHook 42 43// DatastoreAdminCallOptions contains the retry settings for each method of DatastoreAdminClient. 44type DatastoreAdminCallOptions struct { 45 ExportEntities []gax.CallOption 46 ImportEntities []gax.CallOption 47 CreateIndex []gax.CallOption 48 DeleteIndex []gax.CallOption 49 GetIndex []gax.CallOption 50 ListIndexes []gax.CallOption 51} 52 53func defaultDatastoreAdminGRPCClientOptions() []option.ClientOption { 54 return []option.ClientOption{ 55 internaloption.WithDefaultEndpoint("datastore.googleapis.com:443"), 56 internaloption.WithDefaultMTLSEndpoint("datastore.mtls.googleapis.com:443"), 57 internaloption.WithDefaultAudience("https://datastore.googleapis.com/"), 58 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 59 internaloption.EnableJwtWithScope(), 60 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 61 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 62 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 63 } 64} 65 66func defaultDatastoreAdminCallOptions() *DatastoreAdminCallOptions { 67 return &DatastoreAdminCallOptions{ 68 ExportEntities: []gax.CallOption{}, 69 ImportEntities: []gax.CallOption{}, 70 CreateIndex: []gax.CallOption{}, 71 DeleteIndex: []gax.CallOption{}, 72 GetIndex: []gax.CallOption{ 73 gax.WithRetry(func() gax.Retryer { 74 return gax.OnCodes([]codes.Code{ 75 codes.Unavailable, 76 codes.DeadlineExceeded, 77 }, gax.Backoff{ 78 Initial: 100 * time.Millisecond, 79 Max: 60000 * time.Millisecond, 80 Multiplier: 1.30, 81 }) 82 }), 83 }, 84 ListIndexes: []gax.CallOption{ 85 gax.WithRetry(func() gax.Retryer { 86 return gax.OnCodes([]codes.Code{ 87 codes.Unavailable, 88 codes.DeadlineExceeded, 89 }, gax.Backoff{ 90 Initial: 100 * time.Millisecond, 91 Max: 60000 * time.Millisecond, 92 Multiplier: 1.30, 93 }) 94 }), 95 }, 96 } 97} 98 99// internalDatastoreAdminClient is an interface that defines the methods availaible from Cloud Datastore API. 100type internalDatastoreAdminClient interface { 101 Close() error 102 setGoogleClientInfo(...string) 103 Connection() *grpc.ClientConn 104 ExportEntities(context.Context, *adminpb.ExportEntitiesRequest, ...gax.CallOption) (*ExportEntitiesOperation, error) 105 ExportEntitiesOperation(name string) *ExportEntitiesOperation 106 ImportEntities(context.Context, *adminpb.ImportEntitiesRequest, ...gax.CallOption) (*ImportEntitiesOperation, error) 107 ImportEntitiesOperation(name string) *ImportEntitiesOperation 108 CreateIndex(context.Context, *adminpb.CreateIndexRequest, ...gax.CallOption) (*CreateIndexOperation, error) 109 CreateIndexOperation(name string) *CreateIndexOperation 110 DeleteIndex(context.Context, *adminpb.DeleteIndexRequest, ...gax.CallOption) (*DeleteIndexOperation, error) 111 DeleteIndexOperation(name string) *DeleteIndexOperation 112 GetIndex(context.Context, *adminpb.GetIndexRequest, ...gax.CallOption) (*adminpb.Index, error) 113 ListIndexes(context.Context, *adminpb.ListIndexesRequest, ...gax.CallOption) *IndexIterator 114} 115 116// DatastoreAdminClient is a client for interacting with Cloud Datastore API. 117// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 118// 119// Google Cloud Datastore Admin API 120// 121// The Datastore Admin API provides several admin services for Cloud Datastore. 122// 123// ConceptsProject, namespace, kind, and entity as defined in the Google Cloud Datastore 124// API. 125// 126// Operation: An Operation represents work being performed in the background. 127// 128// EntityFilter: Allows specifying a subset of entities in a project. This is 129// specified as a combination of kinds and namespaces (either or both of which 130// may be all). 131// 132// ServicesExport/ImportThe Export/Import service provides the ability to copy all or a subset of 133// entities to/from Google Cloud Storage. 134// 135// Exported data may be imported into Cloud Datastore for any Google Cloud 136// Platform project. It is not restricted to the export source project. It is 137// possible to export from one project and then import into another. 138// 139// Exported data can also be loaded into Google BigQuery for analysis. 140// 141// Exports and imports are performed asynchronously. An Operation resource is 142// created for each export/import. The state (including any errors encountered) 143// of the export/import may be queried via the Operation resource. 144// 145// IndexThe index service manages Cloud Datastore composite indexes. 146// 147// Index creation and deletion are performed asynchronously. 148// An Operation resource is created for each such asynchronous operation. 149// The state of the operation (including any errors encountered) 150// may be queried via the Operation resource. 151// 152// OperationThe Operations collection provides a record of actions performed for the 153// specified project (including any operations in progress). Operations are not 154// created directly but through calls on other collections or resources. 155// 156// An operation that is not yet done may be cancelled. The request to cancel is 157// asynchronous and the operation may continue to run for some time after the 158// request to cancel is made. 159// 160// An operation that is done may be deleted so that it is no longer listed as 161// part of the Operation collection. 162// 163// ListOperations returns all pending operations, but not completed operations. 164// 165// Operations are created by service DatastoreAdmin, 166// but are accessed via service google.longrunning.Operations. 167type DatastoreAdminClient struct { 168 // The internal transport-dependent client. 169 internalClient internalDatastoreAdminClient 170 171 // The call options for this service. 172 CallOptions *DatastoreAdminCallOptions 173 174 // LROClient is used internally to handle long-running operations. 175 // It is exposed so that its CallOptions can be modified if required. 176 // Users should not Close this client. 177 LROClient *lroauto.OperationsClient 178} 179 180// Wrapper methods routed to the internal client. 181 182// Close closes the connection to the API service. The user should invoke this when 183// the client is no longer required. 184func (c *DatastoreAdminClient) Close() error { 185 return c.internalClient.Close() 186} 187 188// setGoogleClientInfo sets the name and version of the application in 189// the `x-goog-api-client` header passed on each request. Intended for 190// use by Google-written clients. 191func (c *DatastoreAdminClient) setGoogleClientInfo(keyval ...string) { 192 c.internalClient.setGoogleClientInfo(keyval...) 193} 194 195// Connection returns a connection to the API service. 196// 197// Deprecated. 198func (c *DatastoreAdminClient) Connection() *grpc.ClientConn { 199 return c.internalClient.Connection() 200} 201 202// ExportEntities exports a copy of all or a subset of entities from Google Cloud Datastore 203// to another storage system, such as Google Cloud Storage. Recent updates to 204// entities may not be reflected in the export. The export occurs in the 205// background and its progress can be monitored and managed via the 206// Operation resource that is created. The output of an export may only be 207// used once the associated operation is done. If an export operation is 208// cancelled before completion it may leave partial data behind in Google 209// Cloud Storage. 210func (c *DatastoreAdminClient) ExportEntities(ctx context.Context, req *adminpb.ExportEntitiesRequest, opts ...gax.CallOption) (*ExportEntitiesOperation, error) { 211 return c.internalClient.ExportEntities(ctx, req, opts...) 212} 213 214// ExportEntitiesOperation returns a new ExportEntitiesOperation from a given name. 215// The name must be that of a previously created ExportEntitiesOperation, possibly from a different process. 216func (c *DatastoreAdminClient) ExportEntitiesOperation(name string) *ExportEntitiesOperation { 217 return c.internalClient.ExportEntitiesOperation(name) 218} 219 220// ImportEntities imports entities into Google Cloud Datastore. Existing entities with the 221// same key are overwritten. The import occurs in the background and its 222// progress can be monitored and managed via the Operation resource that is 223// created. If an ImportEntities operation is cancelled, it is possible 224// that a subset of the data has already been imported to Cloud Datastore. 225func (c *DatastoreAdminClient) ImportEntities(ctx context.Context, req *adminpb.ImportEntitiesRequest, opts ...gax.CallOption) (*ImportEntitiesOperation, error) { 226 return c.internalClient.ImportEntities(ctx, req, opts...) 227} 228 229// ImportEntitiesOperation returns a new ImportEntitiesOperation from a given name. 230// The name must be that of a previously created ImportEntitiesOperation, possibly from a different process. 231func (c *DatastoreAdminClient) ImportEntitiesOperation(name string) *ImportEntitiesOperation { 232 return c.internalClient.ImportEntitiesOperation(name) 233} 234 235// CreateIndex creates the specified index. 236// A newly created index’s initial state is CREATING. On completion of the 237// returned google.longrunning.Operation, the state will be READY. 238// If the index already exists, the call will return an ALREADY_EXISTS 239// status. 240// 241// During index creation, the process could result in an error, in which 242// case the index will move to the ERROR state. The process can be recovered 243// by fixing the data that caused the error, removing the index with 244// delete, then 245// re-creating the index with [create] 246// [google.datastore.admin.v1.DatastoreAdmin.CreateIndex]. 247// 248// Indexes with a single property cannot be created. 249func (c *DatastoreAdminClient) CreateIndex(ctx context.Context, req *adminpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) { 250 return c.internalClient.CreateIndex(ctx, req, opts...) 251} 252 253// CreateIndexOperation returns a new CreateIndexOperation from a given name. 254// The name must be that of a previously created CreateIndexOperation, possibly from a different process. 255func (c *DatastoreAdminClient) CreateIndexOperation(name string) *CreateIndexOperation { 256 return c.internalClient.CreateIndexOperation(name) 257} 258 259// DeleteIndex deletes an existing index. 260// An index can only be deleted if it is in a READY or ERROR state. On 261// successful execution of the request, the index will be in a DELETING 262// state. And on completion of the 263// returned google.longrunning.Operation, the index will be removed. 264// 265// During index deletion, the process could result in an error, in which 266// case the index will move to the ERROR state. The process can be recovered 267// by fixing the data that caused the error, followed by calling 268// delete again. 269func (c *DatastoreAdminClient) DeleteIndex(ctx context.Context, req *adminpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) { 270 return c.internalClient.DeleteIndex(ctx, req, opts...) 271} 272 273// DeleteIndexOperation returns a new DeleteIndexOperation from a given name. 274// The name must be that of a previously created DeleteIndexOperation, possibly from a different process. 275func (c *DatastoreAdminClient) DeleteIndexOperation(name string) *DeleteIndexOperation { 276 return c.internalClient.DeleteIndexOperation(name) 277} 278 279// GetIndex gets an index. 280func (c *DatastoreAdminClient) GetIndex(ctx context.Context, req *adminpb.GetIndexRequest, opts ...gax.CallOption) (*adminpb.Index, error) { 281 return c.internalClient.GetIndex(ctx, req, opts...) 282} 283 284// ListIndexes lists the indexes that match the specified filters. Datastore uses an 285// eventually consistent query to fetch the list of indexes and may 286// occasionally return stale results. 287func (c *DatastoreAdminClient) ListIndexes(ctx context.Context, req *adminpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator { 288 return c.internalClient.ListIndexes(ctx, req, opts...) 289} 290 291// datastoreAdminGRPCClient is a client for interacting with Cloud Datastore API over gRPC transport. 292// 293// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 294type datastoreAdminGRPCClient struct { 295 // Connection pool of gRPC connections to the service. 296 connPool gtransport.ConnPool 297 298 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 299 disableDeadlines bool 300 301 // Points back to the CallOptions field of the containing DatastoreAdminClient 302 CallOptions **DatastoreAdminCallOptions 303 304 // The gRPC API client. 305 datastoreAdminClient adminpb.DatastoreAdminClient 306 307 // LROClient is used internally to handle long-running operations. 308 // It is exposed so that its CallOptions can be modified if required. 309 // Users should not Close this client. 310 LROClient **lroauto.OperationsClient 311 312 // The x-goog-* metadata to be sent with each request. 313 xGoogMetadata metadata.MD 314} 315 316// NewDatastoreAdminClient creates a new datastore admin client based on gRPC. 317// The returned client must be Closed when it is done being used to clean up its underlying connections. 318// 319// Google Cloud Datastore Admin API 320// 321// The Datastore Admin API provides several admin services for Cloud Datastore. 322// 323// ConceptsProject, namespace, kind, and entity as defined in the Google Cloud Datastore 324// API. 325// 326// Operation: An Operation represents work being performed in the background. 327// 328// EntityFilter: Allows specifying a subset of entities in a project. This is 329// specified as a combination of kinds and namespaces (either or both of which 330// may be all). 331// 332// ServicesExport/ImportThe Export/Import service provides the ability to copy all or a subset of 333// entities to/from Google Cloud Storage. 334// 335// Exported data may be imported into Cloud Datastore for any Google Cloud 336// Platform project. It is not restricted to the export source project. It is 337// possible to export from one project and then import into another. 338// 339// Exported data can also be loaded into Google BigQuery for analysis. 340// 341// Exports and imports are performed asynchronously. An Operation resource is 342// created for each export/import. The state (including any errors encountered) 343// of the export/import may be queried via the Operation resource. 344// 345// IndexThe index service manages Cloud Datastore composite indexes. 346// 347// Index creation and deletion are performed asynchronously. 348// An Operation resource is created for each such asynchronous operation. 349// The state of the operation (including any errors encountered) 350// may be queried via the Operation resource. 351// 352// OperationThe Operations collection provides a record of actions performed for the 353// specified project (including any operations in progress). Operations are not 354// created directly but through calls on other collections or resources. 355// 356// An operation that is not yet done may be cancelled. The request to cancel is 357// asynchronous and the operation may continue to run for some time after the 358// request to cancel is made. 359// 360// An operation that is done may be deleted so that it is no longer listed as 361// part of the Operation collection. 362// 363// ListOperations returns all pending operations, but not completed operations. 364// 365// Operations are created by service DatastoreAdmin, 366// but are accessed via service google.longrunning.Operations. 367func NewDatastoreAdminClient(ctx context.Context, opts ...option.ClientOption) (*DatastoreAdminClient, error) { 368 clientOpts := defaultDatastoreAdminGRPCClientOptions() 369 if newDatastoreAdminClientHook != nil { 370 hookOpts, err := newDatastoreAdminClientHook(ctx, clientHookParams{}) 371 if err != nil { 372 return nil, err 373 } 374 clientOpts = append(clientOpts, hookOpts...) 375 } 376 377 disableDeadlines, err := checkDisableDeadlines() 378 if err != nil { 379 return nil, err 380 } 381 382 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 383 if err != nil { 384 return nil, err 385 } 386 client := DatastoreAdminClient{CallOptions: defaultDatastoreAdminCallOptions()} 387 388 c := &datastoreAdminGRPCClient{ 389 connPool: connPool, 390 disableDeadlines: disableDeadlines, 391 datastoreAdminClient: adminpb.NewDatastoreAdminClient(connPool), 392 CallOptions: &client.CallOptions, 393 } 394 c.setGoogleClientInfo() 395 396 client.internalClient = c 397 398 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 399 if err != nil { 400 // This error "should not happen", since we are just reusing old connection pool 401 // and never actually need to dial. 402 // If this does happen, we could leak connp. However, we cannot close conn: 403 // If the user invoked the constructor with option.WithGRPCConn, 404 // we would close a connection that's still in use. 405 // TODO: investigate error conditions. 406 return nil, err 407 } 408 c.LROClient = &client.LROClient 409 return &client, nil 410} 411 412// Connection returns a connection to the API service. 413// 414// Deprecated. 415func (c *datastoreAdminGRPCClient) Connection() *grpc.ClientConn { 416 return c.connPool.Conn() 417} 418 419// setGoogleClientInfo sets the name and version of the application in 420// the `x-goog-api-client` header passed on each request. Intended for 421// use by Google-written clients. 422func (c *datastoreAdminGRPCClient) setGoogleClientInfo(keyval ...string) { 423 kv := append([]string{"gl-go", versionGo()}, keyval...) 424 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 425 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 426} 427 428// Close closes the connection to the API service. The user should invoke this when 429// the client is no longer required. 430func (c *datastoreAdminGRPCClient) Close() error { 431 return c.connPool.Close() 432} 433 434func (c *datastoreAdminGRPCClient) ExportEntities(ctx context.Context, req *adminpb.ExportEntitiesRequest, opts ...gax.CallOption) (*ExportEntitiesOperation, error) { 435 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 436 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 437 defer cancel() 438 ctx = cctx 439 } 440 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))) 441 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 442 opts = append((*c.CallOptions).ExportEntities[0:len((*c.CallOptions).ExportEntities):len((*c.CallOptions).ExportEntities)], opts...) 443 var resp *longrunningpb.Operation 444 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 445 var err error 446 resp, err = c.datastoreAdminClient.ExportEntities(ctx, req, settings.GRPC...) 447 return err 448 }, opts...) 449 if err != nil { 450 return nil, err 451 } 452 return &ExportEntitiesOperation{ 453 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 454 }, nil 455} 456 457func (c *datastoreAdminGRPCClient) ImportEntities(ctx context.Context, req *adminpb.ImportEntitiesRequest, opts ...gax.CallOption) (*ImportEntitiesOperation, error) { 458 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 459 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 460 defer cancel() 461 ctx = cctx 462 } 463 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))) 464 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 465 opts = append((*c.CallOptions).ImportEntities[0:len((*c.CallOptions).ImportEntities):len((*c.CallOptions).ImportEntities)], opts...) 466 var resp *longrunningpb.Operation 467 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 468 var err error 469 resp, err = c.datastoreAdminClient.ImportEntities(ctx, req, settings.GRPC...) 470 return err 471 }, opts...) 472 if err != nil { 473 return nil, err 474 } 475 return &ImportEntitiesOperation{ 476 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 477 }, nil 478} 479 480func (c *datastoreAdminGRPCClient) CreateIndex(ctx context.Context, req *adminpb.CreateIndexRequest, opts ...gax.CallOption) (*CreateIndexOperation, error) { 481 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 482 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 483 defer cancel() 484 ctx = cctx 485 } 486 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))) 487 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 488 opts = append((*c.CallOptions).CreateIndex[0:len((*c.CallOptions).CreateIndex):len((*c.CallOptions).CreateIndex)], opts...) 489 var resp *longrunningpb.Operation 490 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 491 var err error 492 resp, err = c.datastoreAdminClient.CreateIndex(ctx, req, settings.GRPC...) 493 return err 494 }, opts...) 495 if err != nil { 496 return nil, err 497 } 498 return &CreateIndexOperation{ 499 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 500 }, nil 501} 502 503func (c *datastoreAdminGRPCClient) DeleteIndex(ctx context.Context, req *adminpb.DeleteIndexRequest, opts ...gax.CallOption) (*DeleteIndexOperation, error) { 504 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 505 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 506 defer cancel() 507 ctx = cctx 508 } 509 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "index_id", url.QueryEscape(req.GetIndexId()))) 510 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 511 opts = append((*c.CallOptions).DeleteIndex[0:len((*c.CallOptions).DeleteIndex):len((*c.CallOptions).DeleteIndex)], opts...) 512 var resp *longrunningpb.Operation 513 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 514 var err error 515 resp, err = c.datastoreAdminClient.DeleteIndex(ctx, req, settings.GRPC...) 516 return err 517 }, opts...) 518 if err != nil { 519 return nil, err 520 } 521 return &DeleteIndexOperation{ 522 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 523 }, nil 524} 525 526func (c *datastoreAdminGRPCClient) GetIndex(ctx context.Context, req *adminpb.GetIndexRequest, opts ...gax.CallOption) (*adminpb.Index, error) { 527 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 528 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 529 defer cancel() 530 ctx = cctx 531 } 532 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "index_id", url.QueryEscape(req.GetIndexId()))) 533 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 534 opts = append((*c.CallOptions).GetIndex[0:len((*c.CallOptions).GetIndex):len((*c.CallOptions).GetIndex)], opts...) 535 var resp *adminpb.Index 536 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 537 var err error 538 resp, err = c.datastoreAdminClient.GetIndex(ctx, req, settings.GRPC...) 539 return err 540 }, opts...) 541 if err != nil { 542 return nil, err 543 } 544 return resp, nil 545} 546 547func (c *datastoreAdminGRPCClient) ListIndexes(ctx context.Context, req *adminpb.ListIndexesRequest, opts ...gax.CallOption) *IndexIterator { 548 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))) 549 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 550 opts = append((*c.CallOptions).ListIndexes[0:len((*c.CallOptions).ListIndexes):len((*c.CallOptions).ListIndexes)], opts...) 551 it := &IndexIterator{} 552 req = proto.Clone(req).(*adminpb.ListIndexesRequest) 553 it.InternalFetch = func(pageSize int, pageToken string) ([]*adminpb.Index, string, error) { 554 resp := &adminpb.ListIndexesResponse{} 555 if pageToken != "" { 556 req.PageToken = pageToken 557 } 558 if pageSize > math.MaxInt32 { 559 req.PageSize = math.MaxInt32 560 } else if pageSize != 0 { 561 req.PageSize = int32(pageSize) 562 } 563 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 564 var err error 565 resp, err = c.datastoreAdminClient.ListIndexes(ctx, req, settings.GRPC...) 566 return err 567 }, opts...) 568 if err != nil { 569 return nil, "", err 570 } 571 572 it.Response = resp 573 return resp.GetIndexes(), resp.GetNextPageToken(), nil 574 } 575 fetch := func(pageSize int, pageToken string) (string, error) { 576 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 577 if err != nil { 578 return "", err 579 } 580 it.items = append(it.items, items...) 581 return nextPageToken, nil 582 } 583 584 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 585 it.pageInfo.MaxSize = int(req.GetPageSize()) 586 it.pageInfo.Token = req.GetPageToken() 587 588 return it 589} 590 591// CreateIndexOperation manages a long-running operation from CreateIndex. 592type CreateIndexOperation struct { 593 lro *longrunning.Operation 594} 595 596// CreateIndexOperation returns a new CreateIndexOperation from a given name. 597// The name must be that of a previously created CreateIndexOperation, possibly from a different process. 598func (c *datastoreAdminGRPCClient) CreateIndexOperation(name string) *CreateIndexOperation { 599 return &CreateIndexOperation{ 600 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 601 } 602} 603 604// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 605// 606// See documentation of Poll for error-handling information. 607func (op *CreateIndexOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*adminpb.Index, error) { 608 var resp adminpb.Index 609 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 610 return nil, err 611 } 612 return &resp, nil 613} 614 615// Poll fetches the latest state of the long-running operation. 616// 617// Poll also fetches the latest metadata, which can be retrieved by Metadata. 618// 619// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 620// the operation has completed with failure, the error is returned and op.Done will return true. 621// If Poll succeeds and the operation has completed successfully, 622// op.Done will return true, and the response of the operation is returned. 623// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 624func (op *CreateIndexOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*adminpb.Index, error) { 625 var resp adminpb.Index 626 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 627 return nil, err 628 } 629 if !op.Done() { 630 return nil, nil 631 } 632 return &resp, nil 633} 634 635// Metadata returns metadata associated with the long-running operation. 636// Metadata itself does not contact the server, but Poll does. 637// To get the latest metadata, call this method after a successful call to Poll. 638// If the metadata is not available, the returned metadata and error are both nil. 639func (op *CreateIndexOperation) Metadata() (*adminpb.IndexOperationMetadata, error) { 640 var meta adminpb.IndexOperationMetadata 641 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 642 return nil, nil 643 } else if err != nil { 644 return nil, err 645 } 646 return &meta, nil 647} 648 649// Done reports whether the long-running operation has completed. 650func (op *CreateIndexOperation) Done() bool { 651 return op.lro.Done() 652} 653 654// Name returns the name of the long-running operation. 655// The name is assigned by the server and is unique within the service from which the operation is created. 656func (op *CreateIndexOperation) Name() string { 657 return op.lro.Name() 658} 659 660// DeleteIndexOperation manages a long-running operation from DeleteIndex. 661type DeleteIndexOperation struct { 662 lro *longrunning.Operation 663} 664 665// DeleteIndexOperation returns a new DeleteIndexOperation from a given name. 666// The name must be that of a previously created DeleteIndexOperation, possibly from a different process. 667func (c *datastoreAdminGRPCClient) DeleteIndexOperation(name string) *DeleteIndexOperation { 668 return &DeleteIndexOperation{ 669 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 670 } 671} 672 673// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 674// 675// See documentation of Poll for error-handling information. 676func (op *DeleteIndexOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*adminpb.Index, error) { 677 var resp adminpb.Index 678 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 679 return nil, err 680 } 681 return &resp, nil 682} 683 684// Poll fetches the latest state of the long-running operation. 685// 686// Poll also fetches the latest metadata, which can be retrieved by Metadata. 687// 688// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 689// the operation has completed with failure, the error is returned and op.Done will return true. 690// If Poll succeeds and the operation has completed successfully, 691// op.Done will return true, and the response of the operation is returned. 692// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 693func (op *DeleteIndexOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*adminpb.Index, error) { 694 var resp adminpb.Index 695 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 696 return nil, err 697 } 698 if !op.Done() { 699 return nil, nil 700 } 701 return &resp, nil 702} 703 704// Metadata returns metadata associated with the long-running operation. 705// Metadata itself does not contact the server, but Poll does. 706// To get the latest metadata, call this method after a successful call to Poll. 707// If the metadata is not available, the returned metadata and error are both nil. 708func (op *DeleteIndexOperation) Metadata() (*adminpb.IndexOperationMetadata, error) { 709 var meta adminpb.IndexOperationMetadata 710 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 711 return nil, nil 712 } else if err != nil { 713 return nil, err 714 } 715 return &meta, nil 716} 717 718// Done reports whether the long-running operation has completed. 719func (op *DeleteIndexOperation) Done() bool { 720 return op.lro.Done() 721} 722 723// Name returns the name of the long-running operation. 724// The name is assigned by the server and is unique within the service from which the operation is created. 725func (op *DeleteIndexOperation) Name() string { 726 return op.lro.Name() 727} 728 729// ExportEntitiesOperation manages a long-running operation from ExportEntities. 730type ExportEntitiesOperation struct { 731 lro *longrunning.Operation 732} 733 734// ExportEntitiesOperation returns a new ExportEntitiesOperation from a given name. 735// The name must be that of a previously created ExportEntitiesOperation, possibly from a different process. 736func (c *datastoreAdminGRPCClient) ExportEntitiesOperation(name string) *ExportEntitiesOperation { 737 return &ExportEntitiesOperation{ 738 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 739 } 740} 741 742// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 743// 744// See documentation of Poll for error-handling information. 745func (op *ExportEntitiesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*adminpb.ExportEntitiesResponse, error) { 746 var resp adminpb.ExportEntitiesResponse 747 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { 748 return nil, err 749 } 750 return &resp, nil 751} 752 753// Poll fetches the latest state of the long-running operation. 754// 755// Poll also fetches the latest metadata, which can be retrieved by Metadata. 756// 757// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 758// the operation has completed with failure, the error is returned and op.Done will return true. 759// If Poll succeeds and the operation has completed successfully, 760// op.Done will return true, and the response of the operation is returned. 761// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 762func (op *ExportEntitiesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*adminpb.ExportEntitiesResponse, error) { 763 var resp adminpb.ExportEntitiesResponse 764 if err := op.lro.Poll(ctx, &resp, opts...); err != nil { 765 return nil, err 766 } 767 if !op.Done() { 768 return nil, nil 769 } 770 return &resp, nil 771} 772 773// Metadata returns metadata associated with the long-running operation. 774// Metadata itself does not contact the server, but Poll does. 775// To get the latest metadata, call this method after a successful call to Poll. 776// If the metadata is not available, the returned metadata and error are both nil. 777func (op *ExportEntitiesOperation) Metadata() (*adminpb.ExportEntitiesMetadata, error) { 778 var meta adminpb.ExportEntitiesMetadata 779 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 780 return nil, nil 781 } else if err != nil { 782 return nil, err 783 } 784 return &meta, nil 785} 786 787// Done reports whether the long-running operation has completed. 788func (op *ExportEntitiesOperation) Done() bool { 789 return op.lro.Done() 790} 791 792// Name returns the name of the long-running operation. 793// The name is assigned by the server and is unique within the service from which the operation is created. 794func (op *ExportEntitiesOperation) Name() string { 795 return op.lro.Name() 796} 797 798// ImportEntitiesOperation manages a long-running operation from ImportEntities. 799type ImportEntitiesOperation struct { 800 lro *longrunning.Operation 801} 802 803// ImportEntitiesOperation returns a new ImportEntitiesOperation from a given name. 804// The name must be that of a previously created ImportEntitiesOperation, possibly from a different process. 805func (c *datastoreAdminGRPCClient) ImportEntitiesOperation(name string) *ImportEntitiesOperation { 806 return &ImportEntitiesOperation{ 807 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 808 } 809} 810 811// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. 812// 813// See documentation of Poll for error-handling information. 814func (op *ImportEntitiesOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { 815 return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) 816} 817 818// Poll fetches the latest state of the long-running operation. 819// 820// Poll also fetches the latest metadata, which can be retrieved by Metadata. 821// 822// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and 823// the operation has completed with failure, the error is returned and op.Done will return true. 824// If Poll succeeds and the operation has completed successfully, 825// op.Done will return true, and the response of the operation is returned. 826// If Poll succeeds and the operation has not completed, the returned response and error are both nil. 827func (op *ImportEntitiesOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { 828 return op.lro.Poll(ctx, nil, opts...) 829} 830 831// Metadata returns metadata associated with the long-running operation. 832// Metadata itself does not contact the server, but Poll does. 833// To get the latest metadata, call this method after a successful call to Poll. 834// If the metadata is not available, the returned metadata and error are both nil. 835func (op *ImportEntitiesOperation) Metadata() (*adminpb.ImportEntitiesMetadata, error) { 836 var meta adminpb.ImportEntitiesMetadata 837 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { 838 return nil, nil 839 } else if err != nil { 840 return nil, err 841 } 842 return &meta, nil 843} 844 845// Done reports whether the long-running operation has completed. 846func (op *ImportEntitiesOperation) Done() bool { 847 return op.lro.Done() 848} 849 850// Name returns the name of the long-running operation. 851// The name is assigned by the server and is unique within the service from which the operation is created. 852func (op *ImportEntitiesOperation) Name() string { 853 return op.lro.Name() 854} 855 856// IndexIterator manages a stream of *adminpb.Index. 857type IndexIterator struct { 858 items []*adminpb.Index 859 pageInfo *iterator.PageInfo 860 nextFunc func() error 861 862 // Response is the raw response for the current page. 863 // It must be cast to the RPC response type. 864 // Calling Next() or InternalFetch() updates this value. 865 Response interface{} 866 867 // InternalFetch is for use by the Google Cloud Libraries only. 868 // It is not part of the stable interface of this package. 869 // 870 // InternalFetch returns results from a single call to the underlying RPC. 871 // The number of results is no greater than pageSize. 872 // If there are no more results, nextPageToken is empty and err is nil. 873 InternalFetch func(pageSize int, pageToken string) (results []*adminpb.Index, nextPageToken string, err error) 874} 875 876// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 877func (it *IndexIterator) PageInfo() *iterator.PageInfo { 878 return it.pageInfo 879} 880 881// Next returns the next result. Its second return value is iterator.Done if there are no more 882// results. Once Next returns Done, all subsequent calls will return Done. 883func (it *IndexIterator) Next() (*adminpb.Index, error) { 884 var item *adminpb.Index 885 if err := it.nextFunc(); err != nil { 886 return item, err 887 } 888 item = it.items[0] 889 it.items = it.items[1:] 890 return item, nil 891} 892 893func (it *IndexIterator) bufLen() int { 894 return len(it.items) 895} 896 897func (it *IndexIterator) takeBuf() interface{} { 898 b := it.items 899 it.items = nil 900 return b 901} 902