| 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 rapidmigrationassessment |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
"cloud.google.com/go/longrunning" |
| 30 |
lroauto "cloud.google.com/go/longrunning/autogen" |
| 31 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 32 |
rapidmigrationassessmentpb "cloud.google.com/go/rapidmigrationassessment/apiv1/rapidmigrationassessmentpb" |
| 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 |
locationpb "google.golang.org/genproto/googleapis/cloud/location" |
| 40 |
"google.golang.org/grpc" |
| 41 |
"google.golang.org/grpc/codes" |
| 42 |
"google.golang.org/protobuf/encoding/protojson" |
| 43 |
"google.golang.org/protobuf/proto" |
| 44 |
) |
| 45 |
|
| 46 |
var newClientHook clientHook |
| 47 |
|
| 48 |
// CallOptions contains the retry settings for each method of Client. |
| 49 |
type CallOptions struct { |
| 50 |
CreateCollector []gax.CallOption |
| 51 |
CreateAnnotation []gax.CallOption |
| 52 |
GetAnnotation []gax.CallOption |
| 53 |
ListCollectors []gax.CallOption |
| 54 |
GetCollector []gax.CallOption |
| 55 |
UpdateCollector []gax.CallOption |
| 56 |
DeleteCollector []gax.CallOption |
| 57 |
ResumeCollector []gax.CallOption |
| 58 |
RegisterCollector []gax.CallOption |
| 59 |
PauseCollector []gax.CallOption |
| 60 |
GetLocation []gax.CallOption |
| 61 |
ListLocations []gax.CallOption |
| 62 |
CancelOperation []gax.CallOption |
| 63 |
DeleteOperation []gax.CallOption |
| 64 |
GetOperation []gax.CallOption |
| 65 |
ListOperations []gax.CallOption |
| 66 |
} |
| 67 |
|
| 68 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 69 |
return []option.ClientOption{ |
| 70 |
internaloption.WithDefaultEndpoint("rapidmigrationassessment.googleapis.com:443"), |
| 71 |
internaloption.WithDefaultEndpointTemplate("rapidmigrationassessment.UNIVERSE_DOMAIN:443"), |
| 72 |
internaloption.WithDefaultMTLSEndpoint("rapidmigrationassessment.mtls.googleapis.com:443"), |
| 73 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 74 |
internaloption.WithDefaultAudience("https://rapidmigrationassessment.googleapis.com/"), |
| 75 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 76 |
internaloption.EnableJwtWithScope(), |
| 77 |
internaloption.EnableNewAuthLibrary(), |
| 78 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 79 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
func defaultCallOptions() *CallOptions { |
| 84 |
return &CallOptions{ |
| 85 |
CreateCollector: []gax.CallOption{ |
| 86 |
gax.WithTimeout(60000 * time.Millisecond), |
| 87 |
}, |
| 88 |
CreateAnnotation: []gax.CallOption{ |
| 89 |
gax.WithTimeout(60000 * time.Millisecond), |
| 90 |
}, |
| 91 |
GetAnnotation: []gax.CallOption{ |
| 92 |
gax.WithTimeout(60000 * time.Millisecond), |
| 93 |
gax.WithRetry(func() gax.Retryer { |
| 94 |
return gax.OnCodes([]codes.Code{ |
| 95 |
codes.Unavailable, |
| 96 |
codes.DeadlineExceeded, |
| 97 |
}, gax.Backoff{ |
| 98 |
Initial: 1000 * time.Millisecond, |
| 99 |
Max: 10000 * time.Millisecond, |
| 100 |
Multiplier: 1.30, |
| 101 |
}) |
| 102 |
}), |
| 103 |
}, |
| 104 |
ListCollectors: []gax.CallOption{ |
| 105 |
gax.WithTimeout(60000 * time.Millisecond), |
| 106 |
gax.WithRetry(func() gax.Retryer { |
| 107 |
return gax.OnCodes([]codes.Code{ |
| 108 |
codes.Unavailable, |
| 109 |
codes.DeadlineExceeded, |
| 110 |
}, gax.Backoff{ |
| 111 |
Initial: 1000 * time.Millisecond, |
| 112 |
Max: 10000 * time.Millisecond, |
| 113 |
Multiplier: 1.30, |
| 114 |
}) |
| 115 |
}), |
| 116 |
}, |
| 117 |
GetCollector: []gax.CallOption{ |
| 118 |
gax.WithTimeout(60000 * time.Millisecond), |
| 119 |
gax.WithRetry(func() gax.Retryer { |
| 120 |
return gax.OnCodes([]codes.Code{ |
| 121 |
codes.Unavailable, |
| 122 |
codes.DeadlineExceeded, |
| 123 |
}, gax.Backoff{ |
| 124 |
Initial: 1000 * time.Millisecond, |
| 125 |
Max: 10000 * time.Millisecond, |
| 126 |
Multiplier: 1.30, |
| 127 |
}) |
| 128 |
}), |
| 129 |
}, |
| 130 |
UpdateCollector: []gax.CallOption{ |
| 131 |
gax.WithTimeout(60000 * time.Millisecond), |
| 132 |
}, |
| 133 |
DeleteCollector: []gax.CallOption{ |
| 134 |
gax.WithTimeout(60000 * time.Millisecond), |
| 135 |
}, |
| 136 |
ResumeCollector: []gax.CallOption{ |
| 137 |
gax.WithTimeout(60000 * time.Millisecond), |
| 138 |
}, |
| 139 |
RegisterCollector: []gax.CallOption{ |
| 140 |
gax.WithTimeout(60000 * time.Millisecond), |
| 141 |
}, |
| 142 |
PauseCollector: []gax.CallOption{ |
| 143 |
gax.WithTimeout(60000 * time.Millisecond), |
| 144 |
}, |
| 145 |
GetLocation: []gax.CallOption{}, |
| 146 |
ListLocations: []gax.CallOption{}, |
| 147 |
CancelOperation: []gax.CallOption{}, |
| 148 |
DeleteOperation: []gax.CallOption{}, |
| 149 |
GetOperation: []gax.CallOption{}, |
| 150 |
ListOperations: []gax.CallOption{}, |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
func defaultRESTCallOptions() *CallOptions { |
| 155 |
return &CallOptions{ |
| 156 |
CreateCollector: []gax.CallOption{ |
| 157 |
gax.WithTimeout(60000 * time.Millisecond), |
| 158 |
}, |
| 159 |
CreateAnnotation: []gax.CallOption{ |
| 160 |
gax.WithTimeout(60000 * time.Millisecond), |
| 161 |
}, |
| 162 |
GetAnnotation: []gax.CallOption{ |
| 163 |
gax.WithTimeout(60000 * time.Millisecond), |
| 164 |
gax.WithRetry(func() gax.Retryer { |
| 165 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 166 |
Initial: 1000 * time.Millisecond, |
| 167 |
Max: 10000 * time.Millisecond, |
| 168 |
Multiplier: 1.30, |
| 169 |
}, |
| 170 |
http.StatusServiceUnavailable, |
| 171 |
http.StatusGatewayTimeout) |
| 172 |
}), |
| 173 |
}, |
| 174 |
ListCollectors: []gax.CallOption{ |
| 175 |
gax.WithTimeout(60000 * time.Millisecond), |
| 176 |
gax.WithRetry(func() gax.Retryer { |
| 177 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 178 |
Initial: 1000 * time.Millisecond, |
| 179 |
Max: 10000 * time.Millisecond, |
| 180 |
Multiplier: 1.30, |
| 181 |
}, |
| 182 |
http.StatusServiceUnavailable, |
| 183 |
http.StatusGatewayTimeout) |
| 184 |
}), |
| 185 |
}, |
| 186 |
GetCollector: []gax.CallOption{ |
| 187 |
gax.WithTimeout(60000 * time.Millisecond), |
| 188 |
gax.WithRetry(func() gax.Retryer { |
| 189 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 190 |
Initial: 1000 * time.Millisecond, |
| 191 |
Max: 10000 * time.Millisecond, |
| 192 |
Multiplier: 1.30, |
| 193 |
}, |
| 194 |
http.StatusServiceUnavailable, |
| 195 |
http.StatusGatewayTimeout) |
| 196 |
}), |
| 197 |
}, |
| 198 |
UpdateCollector: []gax.CallOption{ |
| 199 |
gax.WithTimeout(60000 * time.Millisecond), |
| 200 |
}, |
| 201 |
DeleteCollector: []gax.CallOption{ |
| 202 |
gax.WithTimeout(60000 * time.Millisecond), |
| 203 |
}, |
| 204 |
ResumeCollector: []gax.CallOption{ |
| 205 |
gax.WithTimeout(60000 * time.Millisecond), |
| 206 |
}, |
| 207 |
RegisterCollector: []gax.CallOption{ |
| 208 |
gax.WithTimeout(60000 * time.Millisecond), |
| 209 |
}, |
| 210 |
PauseCollector: []gax.CallOption{ |
| 211 |
gax.WithTimeout(60000 * time.Millisecond), |
| 212 |
}, |
| 213 |
GetLocation: []gax.CallOption{}, |
| 214 |
ListLocations: []gax.CallOption{}, |
| 215 |
CancelOperation: []gax.CallOption{}, |
| 216 |
DeleteOperation: []gax.CallOption{}, |
| 217 |
GetOperation: []gax.CallOption{}, |
| 218 |
ListOperations: []gax.CallOption{}, |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
// internalClient is an interface that defines the methods available from Rapid Migration Assessment API. |
| 223 |
type internalClient interface { |
| 224 |
Close() error |
| 225 |
setGoogleClientInfo(...string) |
| 226 |
Connection() *grpc.ClientConn |
| 227 |
CreateCollector(context.Context, *rapidmigrationassessmentpb.CreateCollectorRequest, ...gax.CallOption) (*CreateCollectorOperation, error) |
| 228 |
CreateCollectorOperation(name string) *CreateCollectorOperation |
| 229 |
CreateAnnotation(context.Context, *rapidmigrationassessmentpb.CreateAnnotationRequest, ...gax.CallOption) (*CreateAnnotationOperation, error) |
| 230 |
CreateAnnotationOperation(name string) *CreateAnnotationOperation |
| 231 |
GetAnnotation(context.Context, *rapidmigrationassessmentpb.GetAnnotationRequest, ...gax.CallOption) (*rapidmigrationassessmentpb.Annotation, error) |
| 232 |
ListCollectors(context.Context, *rapidmigrationassessmentpb.ListCollectorsRequest, ...gax.CallOption) *CollectorIterator |
| 233 |
GetCollector(context.Context, *rapidmigrationassessmentpb.GetCollectorRequest, ...gax.CallOption) (*rapidmigrationassessmentpb.Collector, error) |
| 234 |
UpdateCollector(context.Context, *rapidmigrationassessmentpb.UpdateCollectorRequest, ...gax.CallOption) (*UpdateCollectorOperation, error) |
| 235 |
UpdateCollectorOperation(name string) *UpdateCollectorOperation |
| 236 |
DeleteCollector(context.Context, *rapidmigrationassessmentpb.DeleteCollectorRequest, ...gax.CallOption) (*DeleteCollectorOperation, error) |
| 237 |
DeleteCollectorOperation(name string) *DeleteCollectorOperation |
| 238 |
ResumeCollector(context.Context, *rapidmigrationassessmentpb.ResumeCollectorRequest, ...gax.CallOption) (*ResumeCollectorOperation, error) |
| 239 |
ResumeCollectorOperation(name string) *ResumeCollectorOperation |
| 240 |
RegisterCollector(context.Context, *rapidmigrationassessmentpb.RegisterCollectorRequest, ...gax.CallOption) (*RegisterCollectorOperation, error) |
| 241 |
RegisterCollectorOperation(name string) *RegisterCollectorOperation |
| 242 |
PauseCollector(context.Context, *rapidmigrationassessmentpb.PauseCollectorRequest, ...gax.CallOption) (*PauseCollectorOperation, error) |
| 243 |
PauseCollectorOperation(name string) *PauseCollectorOperation |
| 244 |
GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) |
| 245 |
ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator |
| 246 |
CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error |
| 247 |
DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error |
| 248 |
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) |
| 249 |
ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator |
| 250 |
} |
| 251 |
|
| 252 |
// Client is a client for interacting with Rapid Migration Assessment API. |
| 253 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 254 |
// |
| 255 |
// Service describing handlers for resources. |
| 256 |
type Client struct { |
| 257 |
// The internal transport-dependent client. |
| 258 |
internalClient internalClient |
| 259 |
|
| 260 |
// The call options for this service. |
| 261 |
CallOptions *CallOptions |
| 262 |
|
| 263 |
// LROClient is used internally to handle long-running operations. |
| 264 |
// It is exposed so that its CallOptions can be modified if required. |
| 265 |
// Users should not Close this client. |
| 266 |
LROClient *lroauto.OperationsClient |
| 267 |
} |
| 268 |
|
| 269 |
// Wrapper methods routed to the internal client. |
| 270 |
|
| 271 |
// Close closes the connection to the API service. The user should invoke this when |
| 272 |
// the client is no longer required. |
| 273 |
func (c *Client) Close() error { |
| 274 |
return c.internalClient.Close() |
| 275 |
} |
| 276 |
|
| 277 |
// setGoogleClientInfo sets the name and version of the application in |
| 278 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 279 |
// use by Google-written clients. |
| 280 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 281 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 282 |
} |
| 283 |
|
| 284 |
// Connection returns a connection to the API service. |
| 285 |
// |
| 286 |
// Deprecated: Connections are now pooled so this method does not always |
| 287 |
// return the same resource. |
| 288 |
func (c *Client) Connection() *grpc.ClientConn { |
| 289 |
return c.internalClient.Connection() |
| 290 |
} |
| 291 |
|
| 292 |
// CreateCollector create a Collector to manage the on-prem appliance which collects |
| 293 |
// information about Customer assets. |
| 294 |
func (c *Client) CreateCollector(ctx context.Context, req *rapidmigrationassessmentpb.CreateCollectorRequest, opts ...gax.CallOption) (*CreateCollectorOperation, error) { |
| 295 |
return c.internalClient.CreateCollector(ctx, req, opts...) |
| 296 |
} |
| 297 |
|
| 298 |
// CreateCollectorOperation returns a new CreateCollectorOperation from a given name. |
| 299 |
// The name must be that of a previously created CreateCollectorOperation, possibly from a different process. |
| 300 |
func (c *Client) CreateCollectorOperation(name string) *CreateCollectorOperation { |
| 301 |
return c.internalClient.CreateCollectorOperation(name) |
| 302 |
} |
| 303 |
|
| 304 |
// CreateAnnotation creates an Annotation |
| 305 |
func (c *Client) CreateAnnotation(ctx context.Context, req *rapidmigrationassessmentpb.CreateAnnotationRequest, opts ...gax.CallOption) (*CreateAnnotationOperation, error) { |
| 306 |
return c.internalClient.CreateAnnotation(ctx, req, opts...) |
| 307 |
} |
| 308 |
|
| 309 |
// CreateAnnotationOperation returns a new CreateAnnotationOperation from a given name. |
| 310 |
// The name must be that of a previously created CreateAnnotationOperation, possibly from a different process. |
| 311 |
func (c *Client) CreateAnnotationOperation(name string) *CreateAnnotationOperation { |
| 312 |
return c.internalClient.CreateAnnotationOperation(name) |
| 313 |
} |
| 314 |
|
| 315 |
// GetAnnotation gets details of a single Annotation. |
| 316 |
func (c *Client) GetAnnotation(ctx context.Context, req *rapidmigrationassessmentpb.GetAnnotationRequest, opts ...gax.CallOption) (*rapidmigrationassessmentpb.Annotation, error) { |
| 317 |
return c.internalClient.GetAnnotation(ctx, req, opts...) |
| 318 |
} |
| 319 |
|
| 320 |
// ListCollectors lists Collectors in a given project and location. |
| 321 |
func (c *Client) ListCollectors(ctx context.Context, req *rapidmigrationassessmentpb.ListCollectorsRequest, opts ...gax.CallOption) *CollectorIterator { |
| 322 |
return c.internalClient.ListCollectors(ctx, req, opts...) |
| 323 |
} |
| 324 |
|
| 325 |
// GetCollector gets details of a single Collector. |
| 326 |
func (c *Client) GetCollector(ctx context.Context, req *rapidmigrationassessmentpb.GetCollectorRequest, opts ...gax.CallOption) (*rapidmigrationassessmentpb.Collector, error) { |
| 327 |
return c.internalClient.GetCollector(ctx, req, opts...) |
| 328 |
} |
| 329 |
|
| 330 |
// UpdateCollector updates the parameters of a single Collector. |
| 331 |
func (c *Client) UpdateCollector(ctx context.Context, req *rapidmigrationassessmentpb.UpdateCollectorRequest, opts ...gax.CallOption) (*UpdateCollectorOperation, error) { |
| 332 |
return c.internalClient.UpdateCollector(ctx, req, opts...) |
| 333 |
} |
| 334 |
|
| 335 |
// UpdateCollectorOperation returns a new UpdateCollectorOperation from a given name. |
| 336 |
// The name must be that of a previously created UpdateCollectorOperation, possibly from a different process. |
| 337 |
func (c *Client) UpdateCollectorOperation(name string) *UpdateCollectorOperation { |
| 338 |
return c.internalClient.UpdateCollectorOperation(name) |
| 339 |
} |
| 340 |
|
| 341 |
// DeleteCollector deletes a single Collector - changes state of collector to “Deleting”. |
| 342 |
// Background jobs does final deletion through producer API. |
| 343 |
func (c *Client) DeleteCollector(ctx context.Context, req *rapidmigrationassessmentpb.DeleteCollectorRequest, opts ...gax.CallOption) (*DeleteCollectorOperation, error) { |
| 344 |
return c.internalClient.DeleteCollector(ctx, req, opts...) |
| 345 |
} |
| 346 |
|
| 347 |
// DeleteCollectorOperation returns a new DeleteCollectorOperation from a given name. |
| 348 |
// The name must be that of a previously created DeleteCollectorOperation, possibly from a different process. |
| 349 |
func (c *Client) DeleteCollectorOperation(name string) *DeleteCollectorOperation { |
| 350 |
return c.internalClient.DeleteCollectorOperation(name) |
| 351 |
} |
| 352 |
|
| 353 |
// ResumeCollector resumes the given collector. |
| 354 |
func (c *Client) ResumeCollector(ctx context.Context, req *rapidmigrationassessmentpb.ResumeCollectorRequest, opts ...gax.CallOption) (*ResumeCollectorOperation, error) { |
| 355 |
return c.internalClient.ResumeCollector(ctx, req, opts...) |
| 356 |
} |
| 357 |
|
| 358 |
// ResumeCollectorOperation returns a new ResumeCollectorOperation from a given name. |
| 359 |
// The name must be that of a previously created ResumeCollectorOperation, possibly from a different process. |
| 360 |
func (c *Client) ResumeCollectorOperation(name string) *ResumeCollectorOperation { |
| 361 |
return c.internalClient.ResumeCollectorOperation(name) |
| 362 |
} |
| 363 |
|
| 364 |
// RegisterCollector registers the given collector. |
| 365 |
func (c *Client) RegisterCollector(ctx context.Context, req *rapidmigrationassessmentpb.RegisterCollectorRequest, opts ...gax.CallOption) (*RegisterCollectorOperation, error) { |
| 366 |
return c.internalClient.RegisterCollector(ctx, req, opts...) |
| 367 |
} |
| 368 |
|
| 369 |
// RegisterCollectorOperation returns a new RegisterCollectorOperation from a given name. |
| 370 |
// The name must be that of a previously created RegisterCollectorOperation, possibly from a different process. |
| 371 |
func (c *Client) RegisterCollectorOperation(name string) *RegisterCollectorOperation { |
| 372 |
return c.internalClient.RegisterCollectorOperation(name) |
| 373 |
} |
| 374 |
|
| 375 |
// PauseCollector pauses the given collector. |
| 376 |
func (c *Client) PauseCollector(ctx context.Context, req *rapidmigrationassessmentpb.PauseCollectorRequest, opts ...gax.CallOption) (*PauseCollectorOperation, error) { |
| 377 |
return c.internalClient.PauseCollector(ctx, req, opts...) |
| 378 |
} |
| 379 |
|
| 380 |
// PauseCollectorOperation returns a new PauseCollectorOperation from a given name. |
| 381 |
// The name must be that of a previously created PauseCollectorOperation, possibly from a different process. |
| 382 |
func (c *Client) PauseCollectorOperation(name string) *PauseCollectorOperation { |
| 383 |
return c.internalClient.PauseCollectorOperation(name) |
| 384 |
} |
| 385 |
|
| 386 |
// GetLocation gets information about a location. |
| 387 |
func (c *Client) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 388 |
return c.internalClient.GetLocation(ctx, req, opts...) |
| 389 |
} |
| 390 |
|
| 391 |
// ListLocations lists information about the supported locations for this service. |
| 392 |
func (c *Client) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 393 |
return c.internalClient.ListLocations(ctx, req, opts...) |
| 394 |
} |
| 395 |
|
| 396 |
// CancelOperation is a utility method from google.longrunning.Operations. |
| 397 |
func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 398 |
return c.internalClient.CancelOperation(ctx, req, opts...) |
| 399 |
} |
| 400 |
|
| 401 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 402 |
func (c *Client) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 403 |
return c.internalClient.DeleteOperation(ctx, req, opts...) |
| 404 |
} |
| 405 |
|
| 406 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 407 |
func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 408 |
return c.internalClient.GetOperation(ctx, req, opts...) |
| 409 |
} |
| 410 |
|
| 411 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 412 |
func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 413 |
return c.internalClient.ListOperations(ctx, req, opts...) |
| 414 |
} |
| 415 |
|
| 416 |
// gRPCClient is a client for interacting with Rapid Migration Assessment API over gRPC transport. |
| 417 |
// |
| 418 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 419 |
type gRPCClient struct { |
| 420 |
// Connection pool of gRPC connections to the service. |
| 421 |
connPool gtransport.ConnPool |
| 422 |
|
| 423 |
// Points back to the CallOptions field of the containing Client |
| 424 |
CallOptions **CallOptions |
| 425 |
|
| 426 |
// The gRPC API client. |
| 427 |
client rapidmigrationassessmentpb.RapidMigrationAssessmentClient |
| 428 |
|
| 429 |
// LROClient is used internally to handle long-running operations. |
| 430 |
// It is exposed so that its CallOptions can be modified if required. |
| 431 |
// Users should not Close this client. |
| 432 |
LROClient **lroauto.OperationsClient |
| 433 |
|
| 434 |
operationsClient longrunningpb.OperationsClient |
| 435 |
|
| 436 |
locationsClient locationpb.LocationsClient |
| 437 |
|
| 438 |
// The x-goog-* metadata to be sent with each request. |
| 439 |
xGoogHeaders []string |
| 440 |
|
| 441 |
logger *slog.Logger |
| 442 |
} |
| 443 |
|
| 444 |
// NewClient creates a new rapid migration assessment client based on gRPC. |
| 445 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 446 |
// |
| 447 |
// Service describing handlers for resources. |
| 448 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 449 |
clientOpts := defaultGRPCClientOptions() |
| 450 |
if newClientHook != nil { |
| 451 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 452 |
if err != nil { |
| 453 |
return nil, err |
| 454 |
} |
| 455 |
clientOpts = append(clientOpts, hookOpts...) |
| 456 |
} |
| 457 |
|
| 458 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 459 |
if err != nil { |
| 460 |
return nil, err |
| 461 |
} |
| 462 |
client := Client{CallOptions: defaultCallOptions()} |
| 463 |
|
| 464 |
c := &gRPCClient{ |
| 465 |
connPool: connPool, |
| 466 |
client: rapidmigrationassessmentpb.NewRapidMigrationAssessmentClient(connPool), |
| 467 |
CallOptions: &client.CallOptions, |
| 468 |
logger: internaloption.GetLogger(opts), |
| 469 |
operationsClient: longrunningpb.NewOperationsClient(connPool), |
| 470 |
locationsClient: locationpb.NewLocationsClient(connPool), |
| 471 |
} |
| 472 |
c.setGoogleClientInfo() |
| 473 |
|
| 474 |
client.internalClient = c |
| 475 |
|
| 476 |
client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) |
| 477 |
if err != nil { |
| 478 |
// This error "should not happen", since we are just reusing old connection pool |
| 479 |
// and never actually need to dial. |
| 480 |
// If this does happen, we could leak connp. However, we cannot close conn: |
| 481 |
// If the user invoked the constructor with option.WithGRPCConn, |
| 482 |
// we would close a connection that's still in use. |
| 483 |
// TODO: investigate error conditions. |
| 484 |
return nil, err |
| 485 |
} |
| 486 |
c.LROClient = &client.LROClient |
| 487 |
return &client, nil |
| 488 |
} |
| 489 |
|
| 490 |
// Connection returns a connection to the API service. |
| 491 |
// |
| 492 |
// Deprecated: Connections are now pooled so this method does not always |
| 493 |
// return the same resource. |
| 494 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 495 |
return c.connPool.Conn() |
| 496 |
} |
| 497 |
|
| 498 |
// setGoogleClientInfo sets the name and version of the application in |
| 499 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 500 |
// use by Google-written clients. |
| 501 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 502 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 503 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 504 |
c.xGoogHeaders = []string{ |
| 505 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
// Close closes the connection to the API service. The user should invoke this when |
| 510 |
// the client is no longer required. |
| 511 |
func (c *gRPCClient) Close() error { |
| 512 |
return c.connPool.Close() |
| 513 |
} |
| 514 |
|
| 515 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 516 |
type restClient struct { |
| 517 |
// The http endpoint to connect to. |
| 518 |
endpoint string |
| 519 |
|
| 520 |
// The http client. |
| 521 |
httpClient *http.Client |
| 522 |
|
| 523 |
// LROClient is used internally to handle long-running operations. |
| 524 |
// It is exposed so that its CallOptions can be modified if required. |
| 525 |
// Users should not Close this client. |
| 526 |
LROClient **lroauto.OperationsClient |
| 527 |
|
| 528 |
// The x-goog-* headers to be sent with each request. |
| 529 |
xGoogHeaders []string |
| 530 |
|
| 531 |
// Points back to the CallOptions field of the containing Client |
| 532 |
CallOptions **CallOptions |
| 533 |
|
| 534 |
logger *slog.Logger |
| 535 |
} |
| 536 |
|
| 537 |
// NewRESTClient creates a new rapid migration assessment rest client. |
| 538 |
// |
| 539 |
// Service describing handlers for resources. |
| 540 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 541 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 542 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 543 |
if err != nil { |
| 544 |
return nil, err |
| 545 |
} |
| 546 |
|
| 547 |
callOpts := defaultRESTCallOptions() |
| 548 |
c := &restClient{ |
| 549 |
endpoint: endpoint, |
| 550 |
httpClient: httpClient, |
| 551 |
CallOptions: &callOpts, |
| 552 |
logger: internaloption.GetLogger(opts), |
| 553 |
} |
| 554 |
c.setGoogleClientInfo() |
| 555 |
|
| 556 |
lroOpts := []option.ClientOption{ |
| 557 |
option.WithHTTPClient(httpClient), |
| 558 |
option.WithEndpoint(endpoint), |
| 559 |
} |
| 560 |
opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) |
| 561 |
if err != nil { |
| 562 |
return nil, err |
| 563 |
} |
| 564 |
c.LROClient = &opClient |
| 565 |
|
| 566 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 567 |
} |
| 568 |
|
| 569 |
func defaultRESTClientOptions() []option.ClientOption { |
| 570 |
return []option.ClientOption{ |
| 571 |
internaloption.WithDefaultEndpoint("https://rapidmigrationassessment.googleapis.com"), |
| 572 |
internaloption.WithDefaultEndpointTemplate("https://rapidmigrationassessment.UNIVERSE_DOMAIN"), |
| 573 |
internaloption.WithDefaultMTLSEndpoint("https://rapidmigrationassessment.mtls.googleapis.com"), |
| 574 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 575 |
internaloption.WithDefaultAudience("https://rapidmigrationassessment.googleapis.com/"), |
| 576 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 577 |
internaloption.EnableNewAuthLibrary(), |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
// setGoogleClientInfo sets the name and version of the application in |
| 582 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 583 |
// use by Google-written clients. |
| 584 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 585 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 586 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 587 |
c.xGoogHeaders = []string{ |
| 588 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
// Close closes the connection to the API service. The user should invoke this when |
| 593 |
// the client is no longer required. |
| 594 |
func (c *restClient) Close() error { |
| 595 |
// Replace httpClient with nil to force cleanup. |
| 596 |
c.httpClient = nil |
| 597 |
return nil |
| 598 |
} |
| 599 |
|
| 600 |
// Connection returns a connection to the API service. |
| 601 |
// |
| 602 |
// Deprecated: This method always returns nil. |
| 603 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 604 |
return nil |
| 605 |
} |
| 606 |
func (c *gRPCClient) CreateCollector(ctx context.Context, req *rapidmigrationassessmentpb.CreateCollectorRequest, opts ...gax.CallOption) (*CreateCollectorOperation, error) { |
| 607 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 608 |
|
| 609 |
hds = append(c.xGoogHeaders, hds...) |
| 610 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 611 |
opts = append((*c.CallOptions).CreateCollector[0:len((*c.CallOptions).CreateCollector):len((*c.CallOptions).CreateCollector)], opts...) |
| 612 |
var resp *longrunningpb.Operation |
| 613 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 614 |
var err error |
| 615 |
resp, err = executeRPC(ctx, c.client.CreateCollector, req, settings.GRPC, c.logger, "CreateCollector") |
| 616 |
return err |
| 617 |
}, opts...) |
| 618 |
if err != nil { |
| 619 |
return nil, err |
| 620 |
} |
| 621 |
return &CreateCollectorOperation{ |
| 622 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 623 |
}, nil |
| 624 |
} |
| 625 |
|
| 626 |
func (c *gRPCClient) CreateAnnotation(ctx context.Context, req *rapidmigrationassessmentpb.CreateAnnotationRequest, opts ...gax.CallOption) (*CreateAnnotationOperation, error) { |
| 627 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 628 |
|
| 629 |
hds = append(c.xGoogHeaders, hds...) |
| 630 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 631 |
opts = append((*c.CallOptions).CreateAnnotation[0:len((*c.CallOptions).CreateAnnotation):len((*c.CallOptions).CreateAnnotation)], opts...) |
| 632 |
var resp *longrunningpb.Operation |
| 633 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 634 |
var err error |
| 635 |
resp, err = executeRPC(ctx, c.client.CreateAnnotation, req, settings.GRPC, c.logger, "CreateAnnotation") |
| 636 |
return err |
| 637 |
}, opts...) |
| 638 |
if err != nil { |
| 639 |
return nil, err |
| 640 |
} |
| 641 |
return &CreateAnnotationOperation{ |
| 642 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 643 |
}, nil |
| 644 |
} |
| 645 |
|
| 646 |
func (c *gRPCClient) GetAnnotation(ctx context.Context, req *rapidmigrationassessmentpb.GetAnnotationRequest, opts ...gax.CallOption) (*rapidmigrationassessmentpb.Annotation, error) { |
| 647 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 648 |
|
| 649 |
hds = append(c.xGoogHeaders, hds...) |
| 650 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 651 |
opts = append((*c.CallOptions).GetAnnotation[0:len((*c.CallOptions).GetAnnotation):len((*c.CallOptions).GetAnnotation)], opts...) |
| 652 |
var resp *rapidmigrationassessmentpb.Annotation |
| 653 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 654 |
var err error |
| 655 |
resp, err = executeRPC(ctx, c.client.GetAnnotation, req, settings.GRPC, c.logger, "GetAnnotation") |
| 656 |
return err |
| 657 |
}, opts...) |
| 658 |
if err != nil { |
| 659 |
return nil, err |
| 660 |
} |
| 661 |
return resp, nil |
| 662 |
} |
| 663 |
|
| 664 |
func (c *gRPCClient) ListCollectors(ctx context.Context, req *rapidmigrationassessmentpb.ListCollectorsRequest, opts ...gax.CallOption) *CollectorIterator { |
| 665 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 666 |
|
| 667 |
hds = append(c.xGoogHeaders, hds...) |
| 668 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 669 |
opts = append((*c.CallOptions).ListCollectors[0:len((*c.CallOptions).ListCollectors):len((*c.CallOptions).ListCollectors)], opts...) |
| 670 |
it := &CollectorIterator{} |
| 671 |
req = proto.Clone(req).(*rapidmigrationassessmentpb.ListCollectorsRequest) |
| 672 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*rapidmigrationassessmentpb.Collector, string, error) { |
| 673 |
resp := &rapidmigrationassessmentpb.ListCollectorsResponse{} |
| 674 |
if pageToken != "" { |
| 675 |
req.PageToken = pageToken |
| 676 |
} |
| 677 |
if pageSize > math.MaxInt32 { |
| 678 |
req.PageSize = math.MaxInt32 |
| 679 |
} else if pageSize != 0 { |
| 680 |
req.PageSize = int32(pageSize) |
| 681 |
} |
| 682 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 683 |
var err error |
| 684 |
resp, err = executeRPC(ctx, c.client.ListCollectors, req, settings.GRPC, c.logger, "ListCollectors") |
| 685 |
return err |
| 686 |
}, opts...) |
| 687 |
if err != nil { |
| 688 |
return nil, "", err |
| 689 |
} |
| 690 |
|
| 691 |
it.Response = resp |
| 692 |
return resp.GetCollectors(), resp.GetNextPageToken(), nil |
| 693 |
} |
| 694 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 695 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 696 |
if err != nil { |
| 697 |
return "", err |
| 698 |
} |
| 699 |
it.items = append(it.items, items...) |
| 700 |
return nextPageToken, nil |
| 701 |
} |
| 702 |
|
| 703 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 704 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 705 |
it.pageInfo.Token = req.GetPageToken() |
| 706 |
|
| 707 |
return it |
| 708 |
} |
| 709 |
|
| 710 |
func (c *gRPCClient) GetCollector(ctx context.Context, req *rapidmigrationassessmentpb.GetCollectorRequest, opts ...gax.CallOption) (*rapidmigrationassessmentpb.Collector, error) { |
| 711 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 712 |
|
| 713 |
hds = append(c.xGoogHeaders, hds...) |
| 714 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 715 |
opts = append((*c.CallOptions).GetCollector[0:len((*c.CallOptions).GetCollector):len((*c.CallOptions).GetCollector)], opts...) |
| 716 |
var resp *rapidmigrationassessmentpb.Collector |
| 717 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 718 |
var err error |
| 719 |
resp, err = executeRPC(ctx, c.client.GetCollector, req, settings.GRPC, c.logger, "GetCollector") |
| 720 |
return err |
| 721 |
}, opts...) |
| 722 |
if err != nil { |
| 723 |
return nil, err |
| 724 |
} |
| 725 |
return resp, nil |
| 726 |
} |
| 727 |
|
| 728 |
func (c *gRPCClient) UpdateCollector(ctx context.Context, req *rapidmigrationassessmentpb.UpdateCollectorRequest, opts ...gax.CallOption) (*UpdateCollectorOperation, error) { |
| 729 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "collector.name", url.QueryEscape(req.GetCollector().GetName()))} |
| 730 |
|
| 731 |
hds = append(c.xGoogHeaders, hds...) |
| 732 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 733 |
opts = append((*c.CallOptions).UpdateCollector[0:len((*c.CallOptions).UpdateCollector):len((*c.CallOptions).UpdateCollector)], opts...) |
| 734 |
var resp *longrunningpb.Operation |
| 735 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 736 |
var err error |
| 737 |
resp, err = executeRPC(ctx, c.client.UpdateCollector, req, settings.GRPC, c.logger, "UpdateCollector") |
| 738 |
return err |
| 739 |
}, opts...) |
| 740 |
if err != nil { |
| 741 |
return nil, err |
| 742 |
} |
| 743 |
return &UpdateCollectorOperation{ |
| 744 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 745 |
}, nil |
| 746 |
} |
| 747 |
|
| 748 |
func (c *gRPCClient) DeleteCollector(ctx context.Context, req *rapidmigrationassessmentpb.DeleteCollectorRequest, opts ...gax.CallOption) (*DeleteCollectorOperation, error) { |
| 749 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 750 |
|
| 751 |
hds = append(c.xGoogHeaders, hds...) |
| 752 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 753 |
opts = append((*c.CallOptions).DeleteCollector[0:len((*c.CallOptions).DeleteCollector):len((*c.CallOptions).DeleteCollector)], opts...) |
| 754 |
var resp *longrunningpb.Operation |
| 755 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 756 |
var err error |
| 757 |
resp, err = executeRPC(ctx, c.client.DeleteCollector, req, settings.GRPC, c.logger, "DeleteCollector") |
| 758 |
return err |
| 759 |
}, opts...) |
| 760 |
if err != nil { |
| 761 |
return nil, err |
| 762 |
} |
| 763 |
return &DeleteCollectorOperation{ |
| 764 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 765 |
}, nil |
| 766 |
} |
| 767 |
|
| 768 |
func (c *gRPCClient) ResumeCollector(ctx context.Context, req *rapidmigrationassessmentpb.ResumeCollectorRequest, opts ...gax.CallOption) (*ResumeCollectorOperation, error) { |
| 769 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 770 |
|
| 771 |
hds = append(c.xGoogHeaders, hds...) |
| 772 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 773 |
opts = append((*c.CallOptions).ResumeCollector[0:len((*c.CallOptions).ResumeCollector):len((*c.CallOptions).ResumeCollector)], opts...) |
| 774 |
var resp *longrunningpb.Operation |
| 775 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 776 |
var err error |
| 777 |
resp, err = executeRPC(ctx, c.client.ResumeCollector, req, settings.GRPC, c.logger, "ResumeCollector") |
| 778 |
return err |
| 779 |
}, opts...) |
| 780 |
if err != nil { |
| 781 |
return nil, err |
| 782 |
} |
| 783 |
return &ResumeCollectorOperation{ |
| 784 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 785 |
}, nil |
| 786 |
} |
| 787 |
|
| 788 |
func (c *gRPCClient) RegisterCollector(ctx context.Context, req *rapidmigrationassessmentpb.RegisterCollectorRequest, opts ...gax.CallOption) (*RegisterCollectorOperation, error) { |
| 789 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 790 |
|
| 791 |
hds = append(c.xGoogHeaders, hds...) |
| 792 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 793 |
opts = append((*c.CallOptions).RegisterCollector[0:len((*c.CallOptions).RegisterCollector):len((*c.CallOptions).RegisterCollector)], opts...) |
| 794 |
var resp *longrunningpb.Operation |
| 795 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 796 |
var err error |
| 797 |
resp, err = executeRPC(ctx, c.client.RegisterCollector, req, settings.GRPC, c.logger, "RegisterCollector") |
| 798 |
return err |
| 799 |
}, opts...) |
| 800 |
if err != nil { |
| 801 |
return nil, err |
| 802 |
} |
| 803 |
return &RegisterCollectorOperation{ |
| 804 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 805 |
}, nil |
| 806 |
} |
| 807 |
|
| 808 |
func (c *gRPCClient) PauseCollector(ctx context.Context, req *rapidmigrationassessmentpb.PauseCollectorRequest, opts ...gax.CallOption) (*PauseCollectorOperation, error) { |
| 809 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 810 |
|
| 811 |
hds = append(c.xGoogHeaders, hds...) |
| 812 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 813 |
opts = append((*c.CallOptions).PauseCollector[0:len((*c.CallOptions).PauseCollector):len((*c.CallOptions).PauseCollector)], opts...) |
| 814 |
var resp *longrunningpb.Operation |
| 815 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 816 |
var err error |
| 817 |
resp, err = executeRPC(ctx, c.client.PauseCollector, req, settings.GRPC, c.logger, "PauseCollector") |
| 818 |
return err |
| 819 |
}, opts...) |
| 820 |
if err != nil { |
| 821 |
return nil, err |
| 822 |
} |
| 823 |
return &PauseCollectorOperation{ |
| 824 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 825 |
}, nil |
| 826 |
} |
| 827 |
|
| 828 |
func (c *gRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 829 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 830 |
|
| 831 |
hds = append(c.xGoogHeaders, hds...) |
| 832 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 833 |
opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) |
| 834 |
var resp *locationpb.Location |
| 835 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 836 |
var err error |
| 837 |
resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") |
| 838 |
return err |
| 839 |
}, opts...) |
| 840 |
if err != nil { |
| 841 |
return nil, err |
| 842 |
} |
| 843 |
return resp, nil |
| 844 |
} |
| 845 |
|
| 846 |
func (c *gRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 847 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 848 |
|
| 849 |
hds = append(c.xGoogHeaders, hds...) |
| 850 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 851 |
opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) |
| 852 |
it := &LocationIterator{} |
| 853 |
req = proto.Clone(req).(*locationpb.ListLocationsRequest) |
| 854 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { |
| 855 |
resp := &locationpb.ListLocationsResponse{} |
| 856 |
if pageToken != "" { |
| 857 |
req.PageToken = pageToken |
| 858 |
} |
| 859 |
if pageSize > math.MaxInt32 { |
| 860 |
req.PageSize = math.MaxInt32 |
| 861 |
} else if pageSize != 0 { |
| 862 |
req.PageSize = int32(pageSize) |
| 863 |
} |
| 864 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 865 |
var err error |
| 866 |
resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") |
| 867 |
return err |
| 868 |
}, opts...) |
| 869 |
if err != nil { |
| 870 |
return nil, "", err |
| 871 |
} |
| 872 |
|
| 873 |
it.Response = resp |
| 874 |
return resp.GetLocations(), resp.GetNextPageToken(), nil |
| 875 |
} |
| 876 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 877 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 878 |
if err != nil { |
| 879 |
return "", err |
| 880 |
} |
| 881 |
it.items = append(it.items, items...) |
| 882 |
return nextPageToken, nil |
| 883 |
} |
| 884 |
|
| 885 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 886 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 887 |
it.pageInfo.Token = req.GetPageToken() |
| 888 |
|
| 889 |
return it |
| 890 |
} |
| 891 |
|
| 892 |
func (c *gRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 893 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 894 |
|
| 895 |
hds = append(c.xGoogHeaders, hds...) |
| 896 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 897 |
opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) |
| 898 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 899 |
var err error |
| 900 |
_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") |
| 901 |
return err |
| 902 |
}, opts...) |
| 903 |
return err |
| 904 |
} |
| 905 |
|
| 906 |
func (c *gRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 907 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 908 |
|
| 909 |
hds = append(c.xGoogHeaders, hds...) |
| 910 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 911 |
opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) |
| 912 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 913 |
var err error |
| 914 |
_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") |
| 915 |
return err |
| 916 |
}, opts...) |
| 917 |
return err |
| 918 |
} |
| 919 |
|
| 920 |
func (c *gRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 921 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 922 |
|
| 923 |
hds = append(c.xGoogHeaders, hds...) |
| 924 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 925 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 926 |
var resp *longrunningpb.Operation |
| 927 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 928 |
var err error |
| 929 |
resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") |
| 930 |
return err |
| 931 |
}, opts...) |
| 932 |
if err != nil { |
| 933 |
return nil, err |
| 934 |
} |
| 935 |
return resp, nil |
| 936 |
} |
| 937 |
|
| 938 |
func (c *gRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 939 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 940 |
|
| 941 |
hds = append(c.xGoogHeaders, hds...) |
| 942 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 943 |
opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) |
| 944 |
it := &OperationIterator{} |
| 945 |
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| 946 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| 947 |
resp := &longrunningpb.ListOperationsResponse{} |
| 948 |
if pageToken != "" { |
| 949 |
req.PageToken = pageToken |
| 950 |
} |
| 951 |
if pageSize > math.MaxInt32 { |
| 952 |
req.PageSize = math.MaxInt32 |
| 953 |
} else if pageSize != 0 { |
| 954 |
req.PageSize = int32(pageSize) |
| 955 |
} |
| 956 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 957 |
var err error |
| 958 |
resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") |
| 959 |
return err |
| 960 |
}, opts...) |
| 961 |
if err != nil { |
| 962 |
return nil, "", err |
| 963 |
} |
| 964 |
|
| 965 |
it.Response = resp |
| 966 |
return resp.GetOperations(), resp.GetNextPageToken(), nil |
| 967 |
} |
| 968 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 969 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 970 |
if err != nil { |
| 971 |
return "", err |
| 972 |
} |
| 973 |
it.items = append(it.items, items...) |
| 974 |
return nextPageToken, nil |
| 975 |
} |
| 976 |
|
| 977 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 978 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 979 |
it.pageInfo.Token = req.GetPageToken() |
| 980 |
|
| 981 |
return it |
| 982 |
} |
| 983 |
|
| 984 |
// CreateCollector create a Collector to manage the on-prem appliance which collects |
| 985 |
// information about Customer assets. |
| 986 |
func (c *restClient) CreateCollector(ctx context.Context, req *rapidmigrationassessmentpb.CreateCollectorRequest, opts ...gax.CallOption) (*CreateCollectorOperation, error) { |
| 987 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 988 |
body := req.GetCollector() |
| 989 |
jsonReq, err := m.Marshal(body) |
| 990 |
if err != nil { |
| 991 |
return nil, err |
| 992 |
} |
| 993 |
|
| 994 |
baseUrl, err := url.Parse(c.endpoint) |
| 995 |
if err != nil { |
| 996 |
return nil, err |
| 997 |
} |
| 998 |
baseUrl.Path += fmt.Sprintf("/v1/%v/collectors", req.GetParent()) |
| 999 |
|
| 1000 |
params := url.Values{} |
| 1001 |
params.Add("$alt", "json;enum-encoding=int") |
| 1002 |
params.Add("collectorId", fmt.Sprintf("%v", req.GetCollectorId())) |
| 1003 |
if req.GetRequestId() != "" { |
| 1004 |
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) |
| 1005 |
} |
| 1006 |
|
| 1007 |
baseUrl.RawQuery = params.Encode() |
| 1008 |
|
| 1009 |
// Build HTTP headers from client and context metadata. |
| 1010 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1011 |
|
| 1012 |
hds = append(c.xGoogHeaders, hds...) |
| 1013 |
hds = append(hds, "Content-Type", "application/json") |
| 1014 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1015 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1016 |
resp := &longrunningpb.Operation{} |
| 1017 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1018 |
if settings.Path != "" { |
| 1019 |
baseUrl.Path = settings.Path |
| 1020 |
} |
| 1021 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1022 |
if err != nil { |
| 1023 |
return err |
| 1024 |
} |
| 1025 |
httpReq = httpReq.WithContext(ctx) |
| 1026 |
httpReq.Header = headers |
| 1027 |
|
| 1028 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateCollector") |
| 1029 |
if err != nil { |
| 1030 |
return err |
| 1031 |
} |
| 1032 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1033 |
return err |
| 1034 |
} |
| 1035 |
|
| 1036 |
return nil |
| 1037 |
}, opts...) |
| 1038 |
if e != nil { |
| 1039 |
return nil, e |
| 1040 |
} |
| 1041 |
|
| 1042 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1043 |
return &CreateCollectorOperation{ |
| 1044 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1045 |
pollPath: override, |
| 1046 |
}, nil |
| 1047 |
} |
| 1048 |
|
| 1049 |
// CreateAnnotation creates an Annotation |
| 1050 |
func (c *restClient) CreateAnnotation(ctx context.Context, req *rapidmigrationassessmentpb.CreateAnnotationRequest, opts ...gax.CallOption) (*CreateAnnotationOperation, error) { |
| 1051 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1052 |
body := req.GetAnnotation() |
| 1053 |
jsonReq, err := m.Marshal(body) |
| 1054 |
if err != nil { |
| 1055 |
return nil, err |
| 1056 |
} |
| 1057 |
|
| 1058 |
baseUrl, err := url.Parse(c.endpoint) |
| 1059 |
if err != nil { |
| 1060 |
return nil, err |
| 1061 |
} |
| 1062 |
baseUrl.Path += fmt.Sprintf("/v1/%v/annotations", req.GetParent()) |
| 1063 |
|
| 1064 |
params := url.Values{} |
| 1065 |
params.Add("$alt", "json;enum-encoding=int") |
| 1066 |
if req.GetRequestId() != "" { |
| 1067 |
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) |
| 1068 |
} |
| 1069 |
|
| 1070 |
baseUrl.RawQuery = params.Encode() |
| 1071 |
|
| 1072 |
// Build HTTP headers from client and context metadata. |
| 1073 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1074 |
|
| 1075 |
hds = append(c.xGoogHeaders, hds...) |
| 1076 |
hds = append(hds, "Content-Type", "application/json") |
| 1077 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1078 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1079 |
resp := &longrunningpb.Operation{} |
| 1080 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1081 |
if settings.Path != "" { |
| 1082 |
baseUrl.Path = settings.Path |
| 1083 |
} |
| 1084 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1085 |
if err != nil { |
| 1086 |
return err |
| 1087 |
} |
| 1088 |
httpReq = httpReq.WithContext(ctx) |
| 1089 |
httpReq.Header = headers |
| 1090 |
|
| 1091 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAnnotation") |
| 1092 |
if err != nil { |
| 1093 |
return err |
| 1094 |
} |
| 1095 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1096 |
return err |
| 1097 |
} |
| 1098 |
|
| 1099 |
return nil |
| 1100 |
}, opts...) |
| 1101 |
if e != nil { |
| 1102 |
return nil, e |
| 1103 |
} |
| 1104 |
|
| 1105 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1106 |
return &CreateAnnotationOperation{ |
| 1107 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1108 |
pollPath: override, |
| 1109 |
}, nil |
| 1110 |
} |
| 1111 |
|
| 1112 |
// GetAnnotation gets details of a single Annotation. |
| 1113 |
func (c *restClient) GetAnnotation(ctx context.Context, req *rapidmigrationassessmentpb.GetAnnotationRequest, opts ...gax.CallOption) (*rapidmigrationassessmentpb.Annotation, error) { |
| 1114 |
baseUrl, err := url.Parse(c.endpoint) |
| 1115 |
if err != nil { |
| 1116 |
return nil, err |
| 1117 |
} |
| 1118 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1119 |
|
| 1120 |
params := url.Values{} |
| 1121 |
params.Add("$alt", "json;enum-encoding=int") |
| 1122 |
|
| 1123 |
baseUrl.RawQuery = params.Encode() |
| 1124 |
|
| 1125 |
// Build HTTP headers from client and context metadata. |
| 1126 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1127 |
|
| 1128 |
hds = append(c.xGoogHeaders, hds...) |
| 1129 |
hds = append(hds, "Content-Type", "application/json") |
| 1130 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1131 |
opts = append((*c.CallOptions).GetAnnotation[0:len((*c.CallOptions).GetAnnotation):len((*c.CallOptions).GetAnnotation)], opts...) |
| 1132 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1133 |
resp := &rapidmigrationassessmentpb.Annotation{} |
| 1134 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1135 |
if settings.Path != "" { |
| 1136 |
baseUrl.Path = settings.Path |
| 1137 |
} |
| 1138 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1139 |
if err != nil { |
| 1140 |
return err |
| 1141 |
} |
| 1142 |
httpReq = httpReq.WithContext(ctx) |
| 1143 |
httpReq.Header = headers |
| 1144 |
|
| 1145 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAnnotation") |
| 1146 |
if err != nil { |
| 1147 |
return err |
| 1148 |
} |
| 1149 |
|
| 1150 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1151 |
return err |
| 1152 |
} |
| 1153 |
|
| 1154 |
return nil |
| 1155 |
}, opts...) |
| 1156 |
if e != nil { |
| 1157 |
return nil, e |
| 1158 |
} |
| 1159 |
return resp, nil |
| 1160 |
} |
| 1161 |
|
| 1162 |
// ListCollectors lists Collectors in a given project and location. |
| 1163 |
func (c *restClient) ListCollectors(ctx context.Context, req *rapidmigrationassessmentpb.ListCollectorsRequest, opts ...gax.CallOption) *CollectorIterator { |
| 1164 |
it := &CollectorIterator{} |
| 1165 |
req = proto.Clone(req).(*rapidmigrationassessmentpb.ListCollectorsRequest) |
| 1166 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1167 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*rapidmigrationassessmentpb.Collector, string, error) { |
| 1168 |
resp := &rapidmigrationassessmentpb.ListCollectorsResponse{} |
| 1169 |
if pageToken != "" { |
| 1170 |
req.PageToken = pageToken |
| 1171 |
} |
| 1172 |
if pageSize > math.MaxInt32 { |
| 1173 |
req.PageSize = math.MaxInt32 |
| 1174 |
} else if pageSize != 0 { |
| 1175 |
req.PageSize = int32(pageSize) |
| 1176 |
} |
| 1177 |
baseUrl, err := url.Parse(c.endpoint) |
| 1178 |
if err != nil { |
| 1179 |
return nil, "", err |
| 1180 |
} |
| 1181 |
baseUrl.Path += fmt.Sprintf("/v1/%v/collectors", req.GetParent()) |
| 1182 |
|
| 1183 |
params := url.Values{} |
| 1184 |
params.Add("$alt", "json;enum-encoding=int") |
| 1185 |
if req.GetFilter() != "" { |
| 1186 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1187 |
} |
| 1188 |
if req.GetOrderBy() != "" { |
| 1189 |
params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) |
| 1190 |
} |
| 1191 |
if req.GetPageSize() != 0 { |
| 1192 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1193 |
} |
| 1194 |
if req.GetPageToken() != "" { |
| 1195 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1196 |
} |
| 1197 |
|
| 1198 |
baseUrl.RawQuery = params.Encode() |
| 1199 |
|
| 1200 |
// Build HTTP headers from client and context metadata. |
| 1201 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1202 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1203 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1204 |
if settings.Path != "" { |
| 1205 |
baseUrl.Path = settings.Path |
| 1206 |
} |
| 1207 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1208 |
if err != nil { |
| 1209 |
return err |
| 1210 |
} |
| 1211 |
httpReq.Header = headers |
| 1212 |
|
| 1213 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCollectors") |
| 1214 |
if err != nil { |
| 1215 |
return err |
| 1216 |
} |
| 1217 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1218 |
return err |
| 1219 |
} |
| 1220 |
|
| 1221 |
return nil |
| 1222 |
}, opts...) |
| 1223 |
if e != nil { |
| 1224 |
return nil, "", e |
| 1225 |
} |
| 1226 |
it.Response = resp |
| 1227 |
return resp.GetCollectors(), resp.GetNextPageToken(), nil |
| 1228 |
} |
| 1229 |
|
| 1230 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1231 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1232 |
if err != nil { |
| 1233 |
return "", err |
| 1234 |
} |
| 1235 |
it.items = append(it.items, items...) |
| 1236 |
return nextPageToken, nil |
| 1237 |
} |
| 1238 |
|
| 1239 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1240 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1241 |
it.pageInfo.Token = req.GetPageToken() |
| 1242 |
|
| 1243 |
return it |
| 1244 |
} |
| 1245 |
|
| 1246 |
// GetCollector gets details of a single Collector. |
| 1247 |
func (c *restClient) GetCollector(ctx context.Context, req *rapidmigrationassessmentpb.GetCollectorRequest, opts ...gax.CallOption) (*rapidmigrationassessmentpb.Collector, error) { |
| 1248 |
baseUrl, err := url.Parse(c.endpoint) |
| 1249 |
if err != nil { |
| 1250 |
return nil, err |
| 1251 |
} |
| 1252 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1253 |
|
| 1254 |
params := url.Values{} |
| 1255 |
params.Add("$alt", "json;enum-encoding=int") |
| 1256 |
|
| 1257 |
baseUrl.RawQuery = params.Encode() |
| 1258 |
|
| 1259 |
// Build HTTP headers from client and context metadata. |
| 1260 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1261 |
|
| 1262 |
hds = append(c.xGoogHeaders, hds...) |
| 1263 |
hds = append(hds, "Content-Type", "application/json") |
| 1264 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1265 |
opts = append((*c.CallOptions).GetCollector[0:len((*c.CallOptions).GetCollector):len((*c.CallOptions).GetCollector)], opts...) |
| 1266 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1267 |
resp := &rapidmigrationassessmentpb.Collector{} |
| 1268 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1269 |
if settings.Path != "" { |
| 1270 |
baseUrl.Path = settings.Path |
| 1271 |
} |
| 1272 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1273 |
if err != nil { |
| 1274 |
return err |
| 1275 |
} |
| 1276 |
httpReq = httpReq.WithContext(ctx) |
| 1277 |
httpReq.Header = headers |
| 1278 |
|
| 1279 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCollector") |
| 1280 |
if err != nil { |
| 1281 |
return err |
| 1282 |
} |
| 1283 |
|
| 1284 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1285 |
return err |
| 1286 |
} |
| 1287 |
|
| 1288 |
return nil |
| 1289 |
}, opts...) |
| 1290 |
if e != nil { |
| 1291 |
return nil, e |
| 1292 |
} |
| 1293 |
return resp, nil |
| 1294 |
} |
| 1295 |
|
| 1296 |
// UpdateCollector updates the parameters of a single Collector. |
| 1297 |
func (c *restClient) UpdateCollector(ctx context.Context, req *rapidmigrationassessmentpb.UpdateCollectorRequest, opts ...gax.CallOption) (*UpdateCollectorOperation, error) { |
| 1298 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1299 |
body := req.GetCollector() |
| 1300 |
jsonReq, err := m.Marshal(body) |
| 1301 |
if err != nil { |
| 1302 |
return nil, err |
| 1303 |
} |
| 1304 |
|
| 1305 |
baseUrl, err := url.Parse(c.endpoint) |
| 1306 |
if err != nil { |
| 1307 |
return nil, err |
| 1308 |
} |
| 1309 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetCollector().GetName()) |
| 1310 |
|
| 1311 |
params := url.Values{} |
| 1312 |
params.Add("$alt", "json;enum-encoding=int") |
| 1313 |
if req.GetRequestId() != "" { |
| 1314 |
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) |
| 1315 |
} |
| 1316 |
if req.GetUpdateMask() != nil { |
| 1317 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1318 |
if err != nil { |
| 1319 |
return nil, err |
| 1320 |
} |
| 1321 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1322 |
} |
| 1323 |
|
| 1324 |
baseUrl.RawQuery = params.Encode() |
| 1325 |
|
| 1326 |
// Build HTTP headers from client and context metadata. |
| 1327 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "collector.name", url.QueryEscape(req.GetCollector().GetName()))} |
| 1328 |
|
| 1329 |
hds = append(c.xGoogHeaders, hds...) |
| 1330 |
hds = append(hds, "Content-Type", "application/json") |
| 1331 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1332 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1333 |
resp := &longrunningpb.Operation{} |
| 1334 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1335 |
if settings.Path != "" { |
| 1336 |
baseUrl.Path = settings.Path |
| 1337 |
} |
| 1338 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1339 |
if err != nil { |
| 1340 |
return err |
| 1341 |
} |
| 1342 |
httpReq = httpReq.WithContext(ctx) |
| 1343 |
httpReq.Header = headers |
| 1344 |
|
| 1345 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCollector") |
| 1346 |
if err != nil { |
| 1347 |
return err |
| 1348 |
} |
| 1349 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1350 |
return err |
| 1351 |
} |
| 1352 |
|
| 1353 |
return nil |
| 1354 |
}, opts...) |
| 1355 |
if e != nil { |
| 1356 |
return nil, e |
| 1357 |
} |
| 1358 |
|
| 1359 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1360 |
return &UpdateCollectorOperation{ |
| 1361 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1362 |
pollPath: override, |
| 1363 |
}, nil |
| 1364 |
} |
| 1365 |
|
| 1366 |
// DeleteCollector deletes a single Collector - changes state of collector to “Deleting”. |
| 1367 |
// Background jobs does final deletion through producer API. |
| 1368 |
func (c *restClient) DeleteCollector(ctx context.Context, req *rapidmigrationassessmentpb.DeleteCollectorRequest, opts ...gax.CallOption) (*DeleteCollectorOperation, error) { |
| 1369 |
baseUrl, err := url.Parse(c.endpoint) |
| 1370 |
if err != nil { |
| 1371 |
return nil, err |
| 1372 |
} |
| 1373 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1374 |
|
| 1375 |
params := url.Values{} |
| 1376 |
params.Add("$alt", "json;enum-encoding=int") |
| 1377 |
if req.GetRequestId() != "" { |
| 1378 |
params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) |
| 1379 |
} |
| 1380 |
|
| 1381 |
baseUrl.RawQuery = params.Encode() |
| 1382 |
|
| 1383 |
// Build HTTP headers from client and context metadata. |
| 1384 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1385 |
|
| 1386 |
hds = append(c.xGoogHeaders, hds...) |
| 1387 |
hds = append(hds, "Content-Type", "application/json") |
| 1388 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1389 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1390 |
resp := &longrunningpb.Operation{} |
| 1391 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1392 |
if settings.Path != "" { |
| 1393 |
baseUrl.Path = settings.Path |
| 1394 |
} |
| 1395 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1396 |
if err != nil { |
| 1397 |
return err |
| 1398 |
} |
| 1399 |
httpReq = httpReq.WithContext(ctx) |
| 1400 |
httpReq.Header = headers |
| 1401 |
|
| 1402 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCollector") |
| 1403 |
if err != nil { |
| 1404 |
return err |
| 1405 |
} |
| 1406 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1407 |
return err |
| 1408 |
} |
| 1409 |
|
| 1410 |
return nil |
| 1411 |
}, opts...) |
| 1412 |
if e != nil { |
| 1413 |
return nil, e |
| 1414 |
} |
| 1415 |
|
| 1416 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1417 |
return &DeleteCollectorOperation{ |
| 1418 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1419 |
pollPath: override, |
| 1420 |
}, nil |
| 1421 |
} |
| 1422 |
|
| 1423 |
// ResumeCollector resumes the given collector. |
| 1424 |
func (c *restClient) ResumeCollector(ctx context.Context, req *rapidmigrationassessmentpb.ResumeCollectorRequest, opts ...gax.CallOption) (*ResumeCollectorOperation, error) { |
| 1425 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1426 |
jsonReq, err := m.Marshal(req) |
| 1427 |
if err != nil { |
| 1428 |
return nil, err |
| 1429 |
} |
| 1430 |
|
| 1431 |
baseUrl, err := url.Parse(c.endpoint) |
| 1432 |
if err != nil { |
| 1433 |
return nil, err |
| 1434 |
} |
| 1435 |
baseUrl.Path += fmt.Sprintf("/v1/%v:resume", req.GetName()) |
| 1436 |
|
| 1437 |
params := url.Values{} |
| 1438 |
params.Add("$alt", "json;enum-encoding=int") |
| 1439 |
|
| 1440 |
baseUrl.RawQuery = params.Encode() |
| 1441 |
|
| 1442 |
// Build HTTP headers from client and context metadata. |
| 1443 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1444 |
|
| 1445 |
hds = append(c.xGoogHeaders, hds...) |
| 1446 |
hds = append(hds, "Content-Type", "application/json") |
| 1447 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1448 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1449 |
resp := &longrunningpb.Operation{} |
| 1450 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1451 |
if settings.Path != "" { |
| 1452 |
baseUrl.Path = settings.Path |
| 1453 |
} |
| 1454 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1455 |
if err != nil { |
| 1456 |
return err |
| 1457 |
} |
| 1458 |
httpReq = httpReq.WithContext(ctx) |
| 1459 |
httpReq.Header = headers |
| 1460 |
|
| 1461 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResumeCollector") |
| 1462 |
if err != nil { |
| 1463 |
return err |
| 1464 |
} |
| 1465 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1466 |
return err |
| 1467 |
} |
| 1468 |
|
| 1469 |
return nil |
| 1470 |
}, opts...) |
| 1471 |
if e != nil { |
| 1472 |
return nil, e |
| 1473 |
} |
| 1474 |
|
| 1475 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1476 |
return &ResumeCollectorOperation{ |
| 1477 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1478 |
pollPath: override, |
| 1479 |
}, nil |
| 1480 |
} |
| 1481 |
|
| 1482 |
// RegisterCollector registers the given collector. |
| 1483 |
func (c *restClient) RegisterCollector(ctx context.Context, req *rapidmigrationassessmentpb.RegisterCollectorRequest, opts ...gax.CallOption) (*RegisterCollectorOperation, error) { |
| 1484 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1485 |
jsonReq, err := m.Marshal(req) |
| 1486 |
if err != nil { |
| 1487 |
return nil, err |
| 1488 |
} |
| 1489 |
|
| 1490 |
baseUrl, err := url.Parse(c.endpoint) |
| 1491 |
if err != nil { |
| 1492 |
return nil, err |
| 1493 |
} |
| 1494 |
baseUrl.Path += fmt.Sprintf("/v1/%v:register", req.GetName()) |
| 1495 |
|
| 1496 |
params := url.Values{} |
| 1497 |
params.Add("$alt", "json;enum-encoding=int") |
| 1498 |
|
| 1499 |
baseUrl.RawQuery = params.Encode() |
| 1500 |
|
| 1501 |
// Build HTTP headers from client and context metadata. |
| 1502 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1503 |
|
| 1504 |
hds = append(c.xGoogHeaders, hds...) |
| 1505 |
hds = append(hds, "Content-Type", "application/json") |
| 1506 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1507 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1508 |
resp := &longrunningpb.Operation{} |
| 1509 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1510 |
if settings.Path != "" { |
| 1511 |
baseUrl.Path = settings.Path |
| 1512 |
} |
| 1513 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1514 |
if err != nil { |
| 1515 |
return err |
| 1516 |
} |
| 1517 |
httpReq = httpReq.WithContext(ctx) |
| 1518 |
httpReq.Header = headers |
| 1519 |
|
| 1520 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RegisterCollector") |
| 1521 |
if err != nil { |
| 1522 |
return err |
| 1523 |
} |
| 1524 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1525 |
return err |
| 1526 |
} |
| 1527 |
|
| 1528 |
return nil |
| 1529 |
}, opts...) |
| 1530 |
if e != nil { |
| 1531 |
return nil, e |
| 1532 |
} |
| 1533 |
|
| 1534 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1535 |
return &RegisterCollectorOperation{ |
| 1536 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1537 |
pollPath: override, |
| 1538 |
}, nil |
| 1539 |
} |
| 1540 |
|
| 1541 |
// PauseCollector pauses the given collector. |
| 1542 |
func (c *restClient) PauseCollector(ctx context.Context, req *rapidmigrationassessmentpb.PauseCollectorRequest, opts ...gax.CallOption) (*PauseCollectorOperation, error) { |
| 1543 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1544 |
jsonReq, err := m.Marshal(req) |
| 1545 |
if err != nil { |
| 1546 |
return nil, err |
| 1547 |
} |
| 1548 |
|
| 1549 |
baseUrl, err := url.Parse(c.endpoint) |
| 1550 |
if err != nil { |
| 1551 |
return nil, err |
| 1552 |
} |
| 1553 |
baseUrl.Path += fmt.Sprintf("/v1/%v:pause", req.GetName()) |
| 1554 |
|
| 1555 |
params := url.Values{} |
| 1556 |
params.Add("$alt", "json;enum-encoding=int") |
| 1557 |
|
| 1558 |
baseUrl.RawQuery = params.Encode() |
| 1559 |
|
| 1560 |
// Build HTTP headers from client and context metadata. |
| 1561 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1562 |
|
| 1563 |
hds = append(c.xGoogHeaders, hds...) |
| 1564 |
hds = append(hds, "Content-Type", "application/json") |
| 1565 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1566 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1567 |
resp := &longrunningpb.Operation{} |
| 1568 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1569 |
if settings.Path != "" { |
| 1570 |
baseUrl.Path = settings.Path |
| 1571 |
} |
| 1572 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1573 |
if err != nil { |
| 1574 |
return err |
| 1575 |
} |
| 1576 |
httpReq = httpReq.WithContext(ctx) |
| 1577 |
httpReq.Header = headers |
| 1578 |
|
| 1579 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PauseCollector") |
| 1580 |
if err != nil { |
| 1581 |
return err |
| 1582 |
} |
| 1583 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1584 |
return err |
| 1585 |
} |
| 1586 |
|
| 1587 |
return nil |
| 1588 |
}, opts...) |
| 1589 |
if e != nil { |
| 1590 |
return nil, e |
| 1591 |
} |
| 1592 |
|
| 1593 |
override := fmt.Sprintf("/v1/%s", resp.GetName()) |
| 1594 |
return &PauseCollectorOperation{ |
| 1595 |
lro: longrunning.InternalNewOperation(*c.LROClient, resp), |
| 1596 |
pollPath: override, |
| 1597 |
}, nil |
| 1598 |
} |
| 1599 |
|
| 1600 |
// GetLocation gets information about a location. |
| 1601 |
func (c *restClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { |
| 1602 |
baseUrl, err := url.Parse(c.endpoint) |
| 1603 |
if err != nil { |
| 1604 |
return nil, err |
| 1605 |
} |
| 1606 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1607 |
|
| 1608 |
params := url.Values{} |
| 1609 |
params.Add("$alt", "json;enum-encoding=int") |
| 1610 |
|
| 1611 |
baseUrl.RawQuery = params.Encode() |
| 1612 |
|
| 1613 |
// Build HTTP headers from client and context metadata. |
| 1614 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1615 |
|
| 1616 |
hds = append(c.xGoogHeaders, hds...) |
| 1617 |
hds = append(hds, "Content-Type", "application/json") |
| 1618 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1619 |
opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) |
| 1620 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1621 |
resp := &locationpb.Location{} |
| 1622 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1623 |
if settings.Path != "" { |
| 1624 |
baseUrl.Path = settings.Path |
| 1625 |
} |
| 1626 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1627 |
if err != nil { |
| 1628 |
return err |
| 1629 |
} |
| 1630 |
httpReq = httpReq.WithContext(ctx) |
| 1631 |
httpReq.Header = headers |
| 1632 |
|
| 1633 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") |
| 1634 |
if err != nil { |
| 1635 |
return err |
| 1636 |
} |
| 1637 |
|
| 1638 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1639 |
return err |
| 1640 |
} |
| 1641 |
|
| 1642 |
return nil |
| 1643 |
}, opts...) |
| 1644 |
if e != nil { |
| 1645 |
return nil, e |
| 1646 |
} |
| 1647 |
return resp, nil |
| 1648 |
} |
| 1649 |
|
| 1650 |
// ListLocations lists information about the supported locations for this service. |
| 1651 |
func (c *restClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { |
| 1652 |
it := &LocationIterator{} |
| 1653 |
req = proto.Clone(req).(*locationpb.ListLocationsRequest) |
| 1654 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1655 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { |
| 1656 |
resp := &locationpb.ListLocationsResponse{} |
| 1657 |
if pageToken != "" { |
| 1658 |
req.PageToken = pageToken |
| 1659 |
} |
| 1660 |
if pageSize > math.MaxInt32 { |
| 1661 |
req.PageSize = math.MaxInt32 |
| 1662 |
} else if pageSize != 0 { |
| 1663 |
req.PageSize = int32(pageSize) |
| 1664 |
} |
| 1665 |
baseUrl, err := url.Parse(c.endpoint) |
| 1666 |
if err != nil { |
| 1667 |
return nil, "", err |
| 1668 |
} |
| 1669 |
baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName()) |
| 1670 |
|
| 1671 |
params := url.Values{} |
| 1672 |
params.Add("$alt", "json;enum-encoding=int") |
| 1673 |
if req.GetFilter() != "" { |
| 1674 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1675 |
} |
| 1676 |
if req.GetPageSize() != 0 { |
| 1677 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1678 |
} |
| 1679 |
if req.GetPageToken() != "" { |
| 1680 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1681 |
} |
| 1682 |
|
| 1683 |
baseUrl.RawQuery = params.Encode() |
| 1684 |
|
| 1685 |
// Build HTTP headers from client and context metadata. |
| 1686 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1687 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1688 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1689 |
if settings.Path != "" { |
| 1690 |
baseUrl.Path = settings.Path |
| 1691 |
} |
| 1692 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1693 |
if err != nil { |
| 1694 |
return err |
| 1695 |
} |
| 1696 |
httpReq.Header = headers |
| 1697 |
|
| 1698 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") |
| 1699 |
if err != nil { |
| 1700 |
return err |
| 1701 |
} |
| 1702 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1703 |
return err |
| 1704 |
} |
| 1705 |
|
| 1706 |
return nil |
| 1707 |
}, opts...) |
| 1708 |
if e != nil { |
| 1709 |
return nil, "", e |
| 1710 |
} |
| 1711 |
it.Response = resp |
| 1712 |
return resp.GetLocations(), resp.GetNextPageToken(), nil |
| 1713 |
} |
| 1714 |
|
| 1715 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1716 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1717 |
if err != nil { |
| 1718 |
return "", err |
| 1719 |
} |
| 1720 |
it.items = append(it.items, items...) |
| 1721 |
return nextPageToken, nil |
| 1722 |
} |
| 1723 |
|
| 1724 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1725 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1726 |
it.pageInfo.Token = req.GetPageToken() |
| 1727 |
|
| 1728 |
return it |
| 1729 |
} |
| 1730 |
|
| 1731 |
// CancelOperation is a utility method from google.longrunning.Operations. |
| 1732 |
func (c *restClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { |
| 1733 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1734 |
jsonReq, err := m.Marshal(req) |
| 1735 |
if err != nil { |
| 1736 |
return err |
| 1737 |
} |
| 1738 |
|
| 1739 |
baseUrl, err := url.Parse(c.endpoint) |
| 1740 |
if err != nil { |
| 1741 |
return err |
| 1742 |
} |
| 1743 |
baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName()) |
| 1744 |
|
| 1745 |
params := url.Values{} |
| 1746 |
params.Add("$alt", "json;enum-encoding=int") |
| 1747 |
|
| 1748 |
baseUrl.RawQuery = params.Encode() |
| 1749 |
|
| 1750 |
// Build HTTP headers from client and context metadata. |
| 1751 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1752 |
|
| 1753 |
hds = append(c.xGoogHeaders, hds...) |
| 1754 |
hds = append(hds, "Content-Type", "application/json") |
| 1755 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1756 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1757 |
if settings.Path != "" { |
| 1758 |
baseUrl.Path = settings.Path |
| 1759 |
} |
| 1760 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1761 |
if err != nil { |
| 1762 |
return err |
| 1763 |
} |
| 1764 |
httpReq = httpReq.WithContext(ctx) |
| 1765 |
httpReq.Header = headers |
| 1766 |
|
| 1767 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation") |
| 1768 |
return err |
| 1769 |
}, opts...) |
| 1770 |
} |
| 1771 |
|
| 1772 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 1773 |
func (c *restClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 1774 |
baseUrl, err := url.Parse(c.endpoint) |
| 1775 |
if err != nil { |
| 1776 |
return err |
| 1777 |
} |
| 1778 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1779 |
|
| 1780 |
params := url.Values{} |
| 1781 |
params.Add("$alt", "json;enum-encoding=int") |
| 1782 |
|
| 1783 |
baseUrl.RawQuery = params.Encode() |
| 1784 |
|
| 1785 |
// Build HTTP headers from client and context metadata. |
| 1786 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1787 |
|
| 1788 |
hds = append(c.xGoogHeaders, hds...) |
| 1789 |
hds = append(hds, "Content-Type", "application/json") |
| 1790 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1791 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1792 |
if settings.Path != "" { |
| 1793 |
baseUrl.Path = settings.Path |
| 1794 |
} |
| 1795 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1796 |
if err != nil { |
| 1797 |
return err |
| 1798 |
} |
| 1799 |
httpReq = httpReq.WithContext(ctx) |
| 1800 |
httpReq.Header = headers |
| 1801 |
|
| 1802 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") |
| 1803 |
return err |
| 1804 |
}, opts...) |
| 1805 |
} |
| 1806 |
|
| 1807 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 1808 |
func (c *restClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 1809 |
baseUrl, err := url.Parse(c.endpoint) |
| 1810 |
if err != nil { |
| 1811 |
return nil, err |
| 1812 |
} |
| 1813 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1814 |
|
| 1815 |
params := url.Values{} |
| 1816 |
params.Add("$alt", "json;enum-encoding=int") |
| 1817 |
|
| 1818 |
baseUrl.RawQuery = params.Encode() |
| 1819 |
|
| 1820 |
// Build HTTP headers from client and context metadata. |
| 1821 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1822 |
|
| 1823 |
hds = append(c.xGoogHeaders, hds...) |
| 1824 |
hds = append(hds, "Content-Type", "application/json") |
| 1825 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1826 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 1827 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1828 |
resp := &longrunningpb.Operation{} |
| 1829 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1830 |
if settings.Path != "" { |
| 1831 |
baseUrl.Path = settings.Path |
| 1832 |
} |
| 1833 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1834 |
if err != nil { |
| 1835 |
return err |
| 1836 |
} |
| 1837 |
httpReq = httpReq.WithContext(ctx) |
| 1838 |
httpReq.Header = headers |
| 1839 |
|
| 1840 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") |
| 1841 |
if err != nil { |
| 1842 |
return err |
| 1843 |
} |
| 1844 |
|
| 1845 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1846 |
return err |
| 1847 |
} |
| 1848 |
|
| 1849 |
return nil |
| 1850 |
}, opts...) |
| 1851 |
if e != nil { |
| 1852 |
return nil, e |
| 1853 |
} |
| 1854 |
return resp, nil |
| 1855 |
} |
| 1856 |
|
| 1857 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 1858 |
func (c *restClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 1859 |
it := &OperationIterator{} |
| 1860 |
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| 1861 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1862 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| 1863 |
resp := &longrunningpb.ListOperationsResponse{} |
| 1864 |
if pageToken != "" { |
| 1865 |
req.PageToken = pageToken |
| 1866 |
} |
| 1867 |
if pageSize > math.MaxInt32 { |
| 1868 |
req.PageSize = math.MaxInt32 |
| 1869 |
} else if pageSize != 0 { |
| 1870 |
req.PageSize = int32(pageSize) |
| 1871 |
} |
| 1872 |
baseUrl, err := url.Parse(c.endpoint) |
| 1873 |
if err != nil { |
| 1874 |
return nil, "", err |
| 1875 |
} |
| 1876 |
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName()) |
| 1877 |
|
| 1878 |
params := url.Values{} |
| 1879 |
params.Add("$alt", "json;enum-encoding=int") |
| 1880 |
if req.GetFilter() != "" { |
| 1881 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 1882 |
} |
| 1883 |
if req.GetPageSize() != 0 { |
| 1884 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1885 |
} |
| 1886 |
if req.GetPageToken() != "" { |
| 1887 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1888 |
} |
| 1889 |
|
| 1890 |
baseUrl.RawQuery = params.Encode() |
| 1891 |
|
| 1892 |
// Build HTTP headers from client and context metadata. |
| 1893 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1894 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1895 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1896 |
if settings.Path != "" { |
| 1897 |
baseUrl.Path = settings.Path |
| 1898 |
} |
| 1899 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1900 |
if err != nil { |
| 1901 |
return err |
| 1902 |
} |
| 1903 |
httpReq.Header = headers |
| 1904 |
|
| 1905 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") |
| 1906 |
if err != nil { |
| 1907 |
return err |
| 1908 |
} |
| 1909 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1910 |
return err |
| 1911 |
} |
| 1912 |
|
| 1913 |
return nil |
| 1914 |
}, opts...) |
| 1915 |
if e != nil { |
| 1916 |
return nil, "", e |
| 1917 |
} |
| 1918 |
it.Response = resp |
| 1919 |
return resp.GetOperations(), resp.GetNextPageToken(), nil |
| 1920 |
} |
| 1921 |
|
| 1922 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1923 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1924 |
if err != nil { |
| 1925 |
return "", err |
| 1926 |
} |
| 1927 |
it.items = append(it.items, items...) |
| 1928 |
return nextPageToken, nil |
| 1929 |
} |
| 1930 |
|
| 1931 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1932 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1933 |
it.pageInfo.Token = req.GetPageToken() |
| 1934 |
|
| 1935 |
return it |
| 1936 |
} |
| 1937 |
|
| 1938 |
// CreateAnnotationOperation returns a new CreateAnnotationOperation from a given name. |
| 1939 |
// The name must be that of a previously created CreateAnnotationOperation, possibly from a different process. |
| 1940 |
func (c *gRPCClient) CreateAnnotationOperation(name string) *CreateAnnotationOperation { |
| 1941 |
return &CreateAnnotationOperation{ |
| 1942 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1943 |
} |
| 1944 |
} |
| 1945 |
|
| 1946 |
// CreateAnnotationOperation returns a new CreateAnnotationOperation from a given name. |
| 1947 |
// The name must be that of a previously created CreateAnnotationOperation, possibly from a different process. |
| 1948 |
func (c *restClient) CreateAnnotationOperation(name string) *CreateAnnotationOperation { |
| 1949 |
override := fmt.Sprintf("/v1/%s", name) |
| 1950 |
return &CreateAnnotationOperation{ |
| 1951 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1952 |
pollPath: override, |
| 1953 |
} |
| 1954 |
} |
| 1955 |
|
| 1956 |
// CreateCollectorOperation returns a new CreateCollectorOperation from a given name. |
| 1957 |
// The name must be that of a previously created CreateCollectorOperation, possibly from a different process. |
| 1958 |
func (c *gRPCClient) CreateCollectorOperation(name string) *CreateCollectorOperation { |
| 1959 |
return &CreateCollectorOperation{ |
| 1960 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1961 |
} |
| 1962 |
} |
| 1963 |
|
| 1964 |
// CreateCollectorOperation returns a new CreateCollectorOperation from a given name. |
| 1965 |
// The name must be that of a previously created CreateCollectorOperation, possibly from a different process. |
| 1966 |
func (c *restClient) CreateCollectorOperation(name string) *CreateCollectorOperation { |
| 1967 |
override := fmt.Sprintf("/v1/%s", name) |
| 1968 |
return &CreateCollectorOperation{ |
| 1969 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1970 |
pollPath: override, |
| 1971 |
} |
| 1972 |
} |
| 1973 |
|
| 1974 |
// DeleteCollectorOperation returns a new DeleteCollectorOperation from a given name. |
| 1975 |
// The name must be that of a previously created DeleteCollectorOperation, possibly from a different process. |
| 1976 |
func (c *gRPCClient) DeleteCollectorOperation(name string) *DeleteCollectorOperation { |
| 1977 |
return &DeleteCollectorOperation{ |
| 1978 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1979 |
} |
| 1980 |
} |
| 1981 |
|
| 1982 |
// DeleteCollectorOperation returns a new DeleteCollectorOperation from a given name. |
| 1983 |
// The name must be that of a previously created DeleteCollectorOperation, possibly from a different process. |
| 1984 |
func (c *restClient) DeleteCollectorOperation(name string) *DeleteCollectorOperation { |
| 1985 |
override := fmt.Sprintf("/v1/%s", name) |
| 1986 |
return &DeleteCollectorOperation{ |
| 1987 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1988 |
pollPath: override, |
| 1989 |
} |
| 1990 |
} |
| 1991 |
|
| 1992 |
// PauseCollectorOperation returns a new PauseCollectorOperation from a given name. |
| 1993 |
// The name must be that of a previously created PauseCollectorOperation, possibly from a different process. |
| 1994 |
func (c *gRPCClient) PauseCollectorOperation(name string) *PauseCollectorOperation { |
| 1995 |
return &PauseCollectorOperation{ |
| 1996 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 1997 |
} |
| 1998 |
} |
| 1999 |
|
| 2000 |
// PauseCollectorOperation returns a new PauseCollectorOperation from a given name. |
| 2001 |
// The name must be that of a previously created PauseCollectorOperation, possibly from a different process. |
| 2002 |
func (c *restClient) PauseCollectorOperation(name string) *PauseCollectorOperation { |
| 2003 |
override := fmt.Sprintf("/v1/%s", name) |
| 2004 |
return &PauseCollectorOperation{ |
| 2005 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2006 |
pollPath: override, |
| 2007 |
} |
| 2008 |
} |
| 2009 |
|
| 2010 |
// RegisterCollectorOperation returns a new RegisterCollectorOperation from a given name. |
| 2011 |
// The name must be that of a previously created RegisterCollectorOperation, possibly from a different process. |
| 2012 |
func (c *gRPCClient) RegisterCollectorOperation(name string) *RegisterCollectorOperation { |
| 2013 |
return &RegisterCollectorOperation{ |
| 2014 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2015 |
} |
| 2016 |
} |
| 2017 |
|
| 2018 |
// RegisterCollectorOperation returns a new RegisterCollectorOperation from a given name. |
| 2019 |
// The name must be that of a previously created RegisterCollectorOperation, possibly from a different process. |
| 2020 |
func (c *restClient) RegisterCollectorOperation(name string) *RegisterCollectorOperation { |
| 2021 |
override := fmt.Sprintf("/v1/%s", name) |
| 2022 |
return &RegisterCollectorOperation{ |
| 2023 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2024 |
pollPath: override, |
| 2025 |
} |
| 2026 |
} |
| 2027 |
|
| 2028 |
// ResumeCollectorOperation returns a new ResumeCollectorOperation from a given name. |
| 2029 |
// The name must be that of a previously created ResumeCollectorOperation, possibly from a different process. |
| 2030 |
func (c *gRPCClient) ResumeCollectorOperation(name string) *ResumeCollectorOperation { |
| 2031 |
return &ResumeCollectorOperation{ |
| 2032 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2033 |
} |
| 2034 |
} |
| 2035 |
|
| 2036 |
// ResumeCollectorOperation returns a new ResumeCollectorOperation from a given name. |
| 2037 |
// The name must be that of a previously created ResumeCollectorOperation, possibly from a different process. |
| 2038 |
func (c *restClient) ResumeCollectorOperation(name string) *ResumeCollectorOperation { |
| 2039 |
override := fmt.Sprintf("/v1/%s", name) |
| 2040 |
return &ResumeCollectorOperation{ |
| 2041 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2042 |
pollPath: override, |
| 2043 |
} |
| 2044 |
} |
| 2045 |
|
| 2046 |
// UpdateCollectorOperation returns a new UpdateCollectorOperation from a given name. |
| 2047 |
// The name must be that of a previously created UpdateCollectorOperation, possibly from a different process. |
| 2048 |
func (c *gRPCClient) UpdateCollectorOperation(name string) *UpdateCollectorOperation { |
| 2049 |
return &UpdateCollectorOperation{ |
| 2050 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
// UpdateCollectorOperation returns a new UpdateCollectorOperation from a given name. |
| 2055 |
// The name must be that of a previously created UpdateCollectorOperation, possibly from a different process. |
| 2056 |
func (c *restClient) UpdateCollectorOperation(name string) *UpdateCollectorOperation { |
| 2057 |
override := fmt.Sprintf("/v1/%s", name) |
| 2058 |
return &UpdateCollectorOperation{ |
| 2059 |
lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), |
| 2060 |
pollPath: override, |
| 2061 |
} |
| 2062 |
} |