| 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 reservation |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
reservationpb "cloud.google.com/go/bigquery/reservation/apiv1/reservationpb" |
| 30 |
gax "github.com/googleapis/gax-go/v2" |
| 31 |
"google.golang.org/api/iterator" |
| 32 |
"google.golang.org/api/option" |
| 33 |
"google.golang.org/api/option/internaloption" |
| 34 |
gtransport "google.golang.org/api/transport/grpc" |
| 35 |
httptransport "google.golang.org/api/transport/http" |
| 36 |
"google.golang.org/grpc" |
| 37 |
"google.golang.org/grpc/codes" |
| 38 |
"google.golang.org/protobuf/encoding/protojson" |
| 39 |
"google.golang.org/protobuf/proto" |
| 40 |
) |
| 41 |
|
| 42 |
var newClientHook clientHook |
| 43 |
|
| 44 |
// CallOptions contains the retry settings for each method of Client. |
| 45 |
type CallOptions struct { |
| 46 |
CreateReservation []gax.CallOption |
| 47 |
ListReservations []gax.CallOption |
| 48 |
GetReservation []gax.CallOption |
| 49 |
DeleteReservation []gax.CallOption |
| 50 |
UpdateReservation []gax.CallOption |
| 51 |
FailoverReservation []gax.CallOption |
| 52 |
CreateCapacityCommitment []gax.CallOption |
| 53 |
ListCapacityCommitments []gax.CallOption |
| 54 |
GetCapacityCommitment []gax.CallOption |
| 55 |
DeleteCapacityCommitment []gax.CallOption |
| 56 |
UpdateCapacityCommitment []gax.CallOption |
| 57 |
SplitCapacityCommitment []gax.CallOption |
| 58 |
MergeCapacityCommitments []gax.CallOption |
| 59 |
CreateAssignment []gax.CallOption |
| 60 |
ListAssignments []gax.CallOption |
| 61 |
DeleteAssignment []gax.CallOption |
| 62 |
SearchAssignments []gax.CallOption |
| 63 |
SearchAllAssignments []gax.CallOption |
| 64 |
MoveAssignment []gax.CallOption |
| 65 |
UpdateAssignment []gax.CallOption |
| 66 |
GetBiReservation []gax.CallOption |
| 67 |
UpdateBiReservation []gax.CallOption |
| 68 |
} |
| 69 |
|
| 70 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 71 |
return []option.ClientOption{ |
| 72 |
internaloption.WithDefaultEndpoint("bigqueryreservation.googleapis.com:443"), |
| 73 |
internaloption.WithDefaultEndpointTemplate("bigqueryreservation.UNIVERSE_DOMAIN:443"), |
| 74 |
internaloption.WithDefaultMTLSEndpoint("bigqueryreservation.mtls.googleapis.com:443"), |
| 75 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 76 |
internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"), |
| 77 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 78 |
internaloption.EnableJwtWithScope(), |
| 79 |
internaloption.EnableNewAuthLibrary(), |
| 80 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 81 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
func defaultCallOptions() *CallOptions { |
| 86 |
return &CallOptions{ |
| 87 |
CreateReservation: []gax.CallOption{ |
| 88 |
gax.WithTimeout(300000 * time.Millisecond), |
| 89 |
}, |
| 90 |
ListReservations: []gax.CallOption{ |
| 91 |
gax.WithTimeout(300000 * time.Millisecond), |
| 92 |
gax.WithRetry(func() gax.Retryer { |
| 93 |
return gax.OnCodes([]codes.Code{ |
| 94 |
codes.DeadlineExceeded, |
| 95 |
codes.Unavailable, |
| 96 |
}, gax.Backoff{ |
| 97 |
Initial: 100 * time.Millisecond, |
| 98 |
Max: 60000 * time.Millisecond, |
| 99 |
Multiplier: 1.30, |
| 100 |
}) |
| 101 |
}), |
| 102 |
}, |
| 103 |
GetReservation: []gax.CallOption{ |
| 104 |
gax.WithTimeout(300000 * time.Millisecond), |
| 105 |
gax.WithRetry(func() gax.Retryer { |
| 106 |
return gax.OnCodes([]codes.Code{ |
| 107 |
codes.DeadlineExceeded, |
| 108 |
codes.Unavailable, |
| 109 |
}, gax.Backoff{ |
| 110 |
Initial: 100 * time.Millisecond, |
| 111 |
Max: 60000 * time.Millisecond, |
| 112 |
Multiplier: 1.30, |
| 113 |
}) |
| 114 |
}), |
| 115 |
}, |
| 116 |
DeleteReservation: []gax.CallOption{ |
| 117 |
gax.WithTimeout(300000 * time.Millisecond), |
| 118 |
gax.WithRetry(func() gax.Retryer { |
| 119 |
return gax.OnCodes([]codes.Code{ |
| 120 |
codes.DeadlineExceeded, |
| 121 |
codes.Unavailable, |
| 122 |
}, gax.Backoff{ |
| 123 |
Initial: 100 * time.Millisecond, |
| 124 |
Max: 60000 * time.Millisecond, |
| 125 |
Multiplier: 1.30, |
| 126 |
}) |
| 127 |
}), |
| 128 |
}, |
| 129 |
UpdateReservation: []gax.CallOption{ |
| 130 |
gax.WithTimeout(300000 * time.Millisecond), |
| 131 |
}, |
| 132 |
FailoverReservation: []gax.CallOption{ |
| 133 |
gax.WithTimeout(300000 * time.Millisecond), |
| 134 |
}, |
| 135 |
CreateCapacityCommitment: []gax.CallOption{ |
| 136 |
gax.WithTimeout(300000 * time.Millisecond), |
| 137 |
}, |
| 138 |
ListCapacityCommitments: []gax.CallOption{ |
| 139 |
gax.WithTimeout(300000 * time.Millisecond), |
| 140 |
gax.WithRetry(func() gax.Retryer { |
| 141 |
return gax.OnCodes([]codes.Code{ |
| 142 |
codes.DeadlineExceeded, |
| 143 |
codes.Unavailable, |
| 144 |
}, gax.Backoff{ |
| 145 |
Initial: 100 * time.Millisecond, |
| 146 |
Max: 60000 * time.Millisecond, |
| 147 |
Multiplier: 1.30, |
| 148 |
}) |
| 149 |
}), |
| 150 |
}, |
| 151 |
GetCapacityCommitment: []gax.CallOption{ |
| 152 |
gax.WithTimeout(300000 * time.Millisecond), |
| 153 |
gax.WithRetry(func() gax.Retryer { |
| 154 |
return gax.OnCodes([]codes.Code{ |
| 155 |
codes.DeadlineExceeded, |
| 156 |
codes.Unavailable, |
| 157 |
}, gax.Backoff{ |
| 158 |
Initial: 100 * time.Millisecond, |
| 159 |
Max: 60000 * time.Millisecond, |
| 160 |
Multiplier: 1.30, |
| 161 |
}) |
| 162 |
}), |
| 163 |
}, |
| 164 |
DeleteCapacityCommitment: []gax.CallOption{ |
| 165 |
gax.WithTimeout(300000 * time.Millisecond), |
| 166 |
gax.WithRetry(func() gax.Retryer { |
| 167 |
return gax.OnCodes([]codes.Code{ |
| 168 |
codes.DeadlineExceeded, |
| 169 |
codes.Unavailable, |
| 170 |
}, gax.Backoff{ |
| 171 |
Initial: 100 * time.Millisecond, |
| 172 |
Max: 60000 * time.Millisecond, |
| 173 |
Multiplier: 1.30, |
| 174 |
}) |
| 175 |
}), |
| 176 |
}, |
| 177 |
UpdateCapacityCommitment: []gax.CallOption{ |
| 178 |
gax.WithTimeout(300000 * time.Millisecond), |
| 179 |
}, |
| 180 |
SplitCapacityCommitment: []gax.CallOption{ |
| 181 |
gax.WithTimeout(300000 * time.Millisecond), |
| 182 |
}, |
| 183 |
MergeCapacityCommitments: []gax.CallOption{ |
| 184 |
gax.WithTimeout(300000 * time.Millisecond), |
| 185 |
}, |
| 186 |
CreateAssignment: []gax.CallOption{ |
| 187 |
gax.WithTimeout(300000 * time.Millisecond), |
| 188 |
}, |
| 189 |
ListAssignments: []gax.CallOption{ |
| 190 |
gax.WithTimeout(300000 * time.Millisecond), |
| 191 |
gax.WithRetry(func() gax.Retryer { |
| 192 |
return gax.OnCodes([]codes.Code{ |
| 193 |
codes.DeadlineExceeded, |
| 194 |
codes.Unavailable, |
| 195 |
}, gax.Backoff{ |
| 196 |
Initial: 100 * time.Millisecond, |
| 197 |
Max: 60000 * time.Millisecond, |
| 198 |
Multiplier: 1.30, |
| 199 |
}) |
| 200 |
}), |
| 201 |
}, |
| 202 |
DeleteAssignment: []gax.CallOption{ |
| 203 |
gax.WithTimeout(300000 * time.Millisecond), |
| 204 |
gax.WithRetry(func() gax.Retryer { |
| 205 |
return gax.OnCodes([]codes.Code{ |
| 206 |
codes.DeadlineExceeded, |
| 207 |
codes.Unavailable, |
| 208 |
}, gax.Backoff{ |
| 209 |
Initial: 100 * time.Millisecond, |
| 210 |
Max: 60000 * time.Millisecond, |
| 211 |
Multiplier: 1.30, |
| 212 |
}) |
| 213 |
}), |
| 214 |
}, |
| 215 |
SearchAssignments: []gax.CallOption{ |
| 216 |
gax.WithTimeout(300000 * time.Millisecond), |
| 217 |
gax.WithRetry(func() gax.Retryer { |
| 218 |
return gax.OnCodes([]codes.Code{ |
| 219 |
codes.DeadlineExceeded, |
| 220 |
codes.Unavailable, |
| 221 |
}, gax.Backoff{ |
| 222 |
Initial: 100 * time.Millisecond, |
| 223 |
Max: 60000 * time.Millisecond, |
| 224 |
Multiplier: 1.30, |
| 225 |
}) |
| 226 |
}), |
| 227 |
}, |
| 228 |
SearchAllAssignments: []gax.CallOption{}, |
| 229 |
MoveAssignment: []gax.CallOption{ |
| 230 |
gax.WithTimeout(300000 * time.Millisecond), |
| 231 |
}, |
| 232 |
UpdateAssignment: []gax.CallOption{}, |
| 233 |
GetBiReservation: []gax.CallOption{ |
| 234 |
gax.WithTimeout(300000 * time.Millisecond), |
| 235 |
gax.WithRetry(func() gax.Retryer { |
| 236 |
return gax.OnCodes([]codes.Code{ |
| 237 |
codes.DeadlineExceeded, |
| 238 |
codes.Unavailable, |
| 239 |
}, gax.Backoff{ |
| 240 |
Initial: 100 * time.Millisecond, |
| 241 |
Max: 60000 * time.Millisecond, |
| 242 |
Multiplier: 1.30, |
| 243 |
}) |
| 244 |
}), |
| 245 |
}, |
| 246 |
UpdateBiReservation: []gax.CallOption{ |
| 247 |
gax.WithTimeout(300000 * time.Millisecond), |
| 248 |
}, |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
func defaultRESTCallOptions() *CallOptions { |
| 253 |
return &CallOptions{ |
| 254 |
CreateReservation: []gax.CallOption{ |
| 255 |
gax.WithTimeout(300000 * time.Millisecond), |
| 256 |
}, |
| 257 |
ListReservations: []gax.CallOption{ |
| 258 |
gax.WithTimeout(300000 * time.Millisecond), |
| 259 |
gax.WithRetry(func() gax.Retryer { |
| 260 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 261 |
Initial: 100 * time.Millisecond, |
| 262 |
Max: 60000 * time.Millisecond, |
| 263 |
Multiplier: 1.30, |
| 264 |
}, |
| 265 |
http.StatusGatewayTimeout, |
| 266 |
http.StatusServiceUnavailable) |
| 267 |
}), |
| 268 |
}, |
| 269 |
GetReservation: []gax.CallOption{ |
| 270 |
gax.WithTimeout(300000 * time.Millisecond), |
| 271 |
gax.WithRetry(func() gax.Retryer { |
| 272 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 273 |
Initial: 100 * time.Millisecond, |
| 274 |
Max: 60000 * time.Millisecond, |
| 275 |
Multiplier: 1.30, |
| 276 |
}, |
| 277 |
http.StatusGatewayTimeout, |
| 278 |
http.StatusServiceUnavailable) |
| 279 |
}), |
| 280 |
}, |
| 281 |
DeleteReservation: []gax.CallOption{ |
| 282 |
gax.WithTimeout(300000 * time.Millisecond), |
| 283 |
gax.WithRetry(func() gax.Retryer { |
| 284 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 285 |
Initial: 100 * time.Millisecond, |
| 286 |
Max: 60000 * time.Millisecond, |
| 287 |
Multiplier: 1.30, |
| 288 |
}, |
| 289 |
http.StatusGatewayTimeout, |
| 290 |
http.StatusServiceUnavailable) |
| 291 |
}), |
| 292 |
}, |
| 293 |
UpdateReservation: []gax.CallOption{ |
| 294 |
gax.WithTimeout(300000 * time.Millisecond), |
| 295 |
}, |
| 296 |
FailoverReservation: []gax.CallOption{ |
| 297 |
gax.WithTimeout(300000 * time.Millisecond), |
| 298 |
}, |
| 299 |
CreateCapacityCommitment: []gax.CallOption{ |
| 300 |
gax.WithTimeout(300000 * time.Millisecond), |
| 301 |
}, |
| 302 |
ListCapacityCommitments: []gax.CallOption{ |
| 303 |
gax.WithTimeout(300000 * time.Millisecond), |
| 304 |
gax.WithRetry(func() gax.Retryer { |
| 305 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 306 |
Initial: 100 * time.Millisecond, |
| 307 |
Max: 60000 * time.Millisecond, |
| 308 |
Multiplier: 1.30, |
| 309 |
}, |
| 310 |
http.StatusGatewayTimeout, |
| 311 |
http.StatusServiceUnavailable) |
| 312 |
}), |
| 313 |
}, |
| 314 |
GetCapacityCommitment: []gax.CallOption{ |
| 315 |
gax.WithTimeout(300000 * time.Millisecond), |
| 316 |
gax.WithRetry(func() gax.Retryer { |
| 317 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 318 |
Initial: 100 * time.Millisecond, |
| 319 |
Max: 60000 * time.Millisecond, |
| 320 |
Multiplier: 1.30, |
| 321 |
}, |
| 322 |
http.StatusGatewayTimeout, |
| 323 |
http.StatusServiceUnavailable) |
| 324 |
}), |
| 325 |
}, |
| 326 |
DeleteCapacityCommitment: []gax.CallOption{ |
| 327 |
gax.WithTimeout(300000 * time.Millisecond), |
| 328 |
gax.WithRetry(func() gax.Retryer { |
| 329 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 330 |
Initial: 100 * time.Millisecond, |
| 331 |
Max: 60000 * time.Millisecond, |
| 332 |
Multiplier: 1.30, |
| 333 |
}, |
| 334 |
http.StatusGatewayTimeout, |
| 335 |
http.StatusServiceUnavailable) |
| 336 |
}), |
| 337 |
}, |
| 338 |
UpdateCapacityCommitment: []gax.CallOption{ |
| 339 |
gax.WithTimeout(300000 * time.Millisecond), |
| 340 |
}, |
| 341 |
SplitCapacityCommitment: []gax.CallOption{ |
| 342 |
gax.WithTimeout(300000 * time.Millisecond), |
| 343 |
}, |
| 344 |
MergeCapacityCommitments: []gax.CallOption{ |
| 345 |
gax.WithTimeout(300000 * time.Millisecond), |
| 346 |
}, |
| 347 |
CreateAssignment: []gax.CallOption{ |
| 348 |
gax.WithTimeout(300000 * time.Millisecond), |
| 349 |
}, |
| 350 |
ListAssignments: []gax.CallOption{ |
| 351 |
gax.WithTimeout(300000 * time.Millisecond), |
| 352 |
gax.WithRetry(func() gax.Retryer { |
| 353 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 354 |
Initial: 100 * time.Millisecond, |
| 355 |
Max: 60000 * time.Millisecond, |
| 356 |
Multiplier: 1.30, |
| 357 |
}, |
| 358 |
http.StatusGatewayTimeout, |
| 359 |
http.StatusServiceUnavailable) |
| 360 |
}), |
| 361 |
}, |
| 362 |
DeleteAssignment: []gax.CallOption{ |
| 363 |
gax.WithTimeout(300000 * time.Millisecond), |
| 364 |
gax.WithRetry(func() gax.Retryer { |
| 365 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 366 |
Initial: 100 * time.Millisecond, |
| 367 |
Max: 60000 * time.Millisecond, |
| 368 |
Multiplier: 1.30, |
| 369 |
}, |
| 370 |
http.StatusGatewayTimeout, |
| 371 |
http.StatusServiceUnavailable) |
| 372 |
}), |
| 373 |
}, |
| 374 |
SearchAssignments: []gax.CallOption{ |
| 375 |
gax.WithTimeout(300000 * time.Millisecond), |
| 376 |
gax.WithRetry(func() gax.Retryer { |
| 377 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 378 |
Initial: 100 * time.Millisecond, |
| 379 |
Max: 60000 * time.Millisecond, |
| 380 |
Multiplier: 1.30, |
| 381 |
}, |
| 382 |
http.StatusGatewayTimeout, |
| 383 |
http.StatusServiceUnavailable) |
| 384 |
}), |
| 385 |
}, |
| 386 |
SearchAllAssignments: []gax.CallOption{}, |
| 387 |
MoveAssignment: []gax.CallOption{ |
| 388 |
gax.WithTimeout(300000 * time.Millisecond), |
| 389 |
}, |
| 390 |
UpdateAssignment: []gax.CallOption{}, |
| 391 |
GetBiReservation: []gax.CallOption{ |
| 392 |
gax.WithTimeout(300000 * time.Millisecond), |
| 393 |
gax.WithRetry(func() gax.Retryer { |
| 394 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 395 |
Initial: 100 * time.Millisecond, |
| 396 |
Max: 60000 * time.Millisecond, |
| 397 |
Multiplier: 1.30, |
| 398 |
}, |
| 399 |
http.StatusGatewayTimeout, |
| 400 |
http.StatusServiceUnavailable) |
| 401 |
}), |
| 402 |
}, |
| 403 |
UpdateBiReservation: []gax.CallOption{ |
| 404 |
gax.WithTimeout(300000 * time.Millisecond), |
| 405 |
}, |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
// internalClient is an interface that defines the methods available from BigQuery Reservation API. |
| 410 |
type internalClient interface { |
| 411 |
Close() error |
| 412 |
setGoogleClientInfo(...string) |
| 413 |
Connection() *grpc.ClientConn |
| 414 |
CreateReservation(context.Context, *reservationpb.CreateReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error) |
| 415 |
ListReservations(context.Context, *reservationpb.ListReservationsRequest, ...gax.CallOption) *ReservationIterator |
| 416 |
GetReservation(context.Context, *reservationpb.GetReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error) |
| 417 |
DeleteReservation(context.Context, *reservationpb.DeleteReservationRequest, ...gax.CallOption) error |
| 418 |
UpdateReservation(context.Context, *reservationpb.UpdateReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error) |
| 419 |
FailoverReservation(context.Context, *reservationpb.FailoverReservationRequest, ...gax.CallOption) (*reservationpb.Reservation, error) |
| 420 |
CreateCapacityCommitment(context.Context, *reservationpb.CreateCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error) |
| 421 |
ListCapacityCommitments(context.Context, *reservationpb.ListCapacityCommitmentsRequest, ...gax.CallOption) *CapacityCommitmentIterator |
| 422 |
GetCapacityCommitment(context.Context, *reservationpb.GetCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error) |
| 423 |
DeleteCapacityCommitment(context.Context, *reservationpb.DeleteCapacityCommitmentRequest, ...gax.CallOption) error |
| 424 |
UpdateCapacityCommitment(context.Context, *reservationpb.UpdateCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error) |
| 425 |
SplitCapacityCommitment(context.Context, *reservationpb.SplitCapacityCommitmentRequest, ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) |
| 426 |
MergeCapacityCommitments(context.Context, *reservationpb.MergeCapacityCommitmentsRequest, ...gax.CallOption) (*reservationpb.CapacityCommitment, error) |
| 427 |
CreateAssignment(context.Context, *reservationpb.CreateAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error) |
| 428 |
ListAssignments(context.Context, *reservationpb.ListAssignmentsRequest, ...gax.CallOption) *AssignmentIterator |
| 429 |
DeleteAssignment(context.Context, *reservationpb.DeleteAssignmentRequest, ...gax.CallOption) error |
| 430 |
SearchAssignments(context.Context, *reservationpb.SearchAssignmentsRequest, ...gax.CallOption) *AssignmentIterator |
| 431 |
SearchAllAssignments(context.Context, *reservationpb.SearchAllAssignmentsRequest, ...gax.CallOption) *AssignmentIterator |
| 432 |
MoveAssignment(context.Context, *reservationpb.MoveAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error) |
| 433 |
UpdateAssignment(context.Context, *reservationpb.UpdateAssignmentRequest, ...gax.CallOption) (*reservationpb.Assignment, error) |
| 434 |
GetBiReservation(context.Context, *reservationpb.GetBiReservationRequest, ...gax.CallOption) (*reservationpb.BiReservation, error) |
| 435 |
UpdateBiReservation(context.Context, *reservationpb.UpdateBiReservationRequest, ...gax.CallOption) (*reservationpb.BiReservation, error) |
| 436 |
} |
| 437 |
|
| 438 |
// Client is a client for interacting with BigQuery Reservation API. |
| 439 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 440 |
// |
| 441 |
// This API allows users to manage their BigQuery reservations. |
| 442 |
// |
| 443 |
// A reservation provides computational resource guarantees, in the form of |
| 444 |
// slots (at https://cloud.google.com/bigquery/docs/slots), to users. A slot is a |
| 445 |
// unit of computational power in BigQuery, and serves as the basic unit of |
| 446 |
// parallelism. In a scan of a multi-partitioned table, a single slot operates |
| 447 |
// on a single partition of the table. A reservation resource exists as a child |
| 448 |
// resource of the admin project and location, e.g.: |
| 449 |
// projects/myproject/locations/US/reservations/reservationName. |
| 450 |
// |
| 451 |
// A capacity commitment is a way to purchase compute capacity for BigQuery jobs |
| 452 |
// (in the form of slots) with some committed period of usage. A capacity |
| 453 |
// commitment resource exists as a child resource of the admin project and |
| 454 |
// location, e.g.: |
| 455 |
// projects/myproject/locations/US/capacityCommitments/id. |
| 456 |
type Client struct { |
| 457 |
// The internal transport-dependent client. |
| 458 |
internalClient internalClient |
| 459 |
|
| 460 |
// The call options for this service. |
| 461 |
CallOptions *CallOptions |
| 462 |
} |
| 463 |
|
| 464 |
// Wrapper methods routed to the internal client. |
| 465 |
|
| 466 |
// Close closes the connection to the API service. The user should invoke this when |
| 467 |
// the client is no longer required. |
| 468 |
func (c *Client) Close() error { |
| 469 |
return c.internalClient.Close() |
| 470 |
} |
| 471 |
|
| 472 |
// setGoogleClientInfo sets the name and version of the application in |
| 473 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 474 |
// use by Google-written clients. |
| 475 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 476 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 477 |
} |
| 478 |
|
| 479 |
// Connection returns a connection to the API service. |
| 480 |
// |
| 481 |
// Deprecated: Connections are now pooled so this method does not always |
| 482 |
// return the same resource. |
| 483 |
func (c *Client) Connection() *grpc.ClientConn { |
| 484 |
return c.internalClient.Connection() |
| 485 |
} |
| 486 |
|
| 487 |
// CreateReservation creates a new reservation resource. |
| 488 |
func (c *Client) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 489 |
return c.internalClient.CreateReservation(ctx, req, opts...) |
| 490 |
} |
| 491 |
|
| 492 |
// ListReservations lists all the reservations for the project in the specified location. |
| 493 |
func (c *Client) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator { |
| 494 |
return c.internalClient.ListReservations(ctx, req, opts...) |
| 495 |
} |
| 496 |
|
| 497 |
// GetReservation returns information about the reservation. |
| 498 |
func (c *Client) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 499 |
return c.internalClient.GetReservation(ctx, req, opts...) |
| 500 |
} |
| 501 |
|
| 502 |
// DeleteReservation deletes a reservation. |
| 503 |
// Returns google.rpc.Code.FAILED_PRECONDITION when reservation has |
| 504 |
// assignments. |
| 505 |
func (c *Client) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error { |
| 506 |
return c.internalClient.DeleteReservation(ctx, req, opts...) |
| 507 |
} |
| 508 |
|
| 509 |
// UpdateReservation updates an existing reservation resource. |
| 510 |
func (c *Client) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 511 |
return c.internalClient.UpdateReservation(ctx, req, opts...) |
| 512 |
} |
| 513 |
|
| 514 |
// FailoverReservation fail over a reservation to the secondary location. The operation should be |
| 515 |
// done in the current secondary location, which will be promoted to the |
| 516 |
// new primary location for the reservation. |
| 517 |
// Attempting to failover a reservation in the current primary location will |
| 518 |
// fail with the error code google.rpc.Code.FAILED_PRECONDITION. |
| 519 |
func (c *Client) FailoverReservation(ctx context.Context, req *reservationpb.FailoverReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 520 |
return c.internalClient.FailoverReservation(ctx, req, opts...) |
| 521 |
} |
| 522 |
|
| 523 |
// CreateCapacityCommitment creates a new capacity commitment resource. |
| 524 |
func (c *Client) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 525 |
return c.internalClient.CreateCapacityCommitment(ctx, req, opts...) |
| 526 |
} |
| 527 |
|
| 528 |
// ListCapacityCommitments lists all the capacity commitments for the admin project. |
| 529 |
func (c *Client) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator { |
| 530 |
return c.internalClient.ListCapacityCommitments(ctx, req, opts...) |
| 531 |
} |
| 532 |
|
| 533 |
// GetCapacityCommitment returns information about the capacity commitment. |
| 534 |
func (c *Client) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 535 |
return c.internalClient.GetCapacityCommitment(ctx, req, opts...) |
| 536 |
} |
| 537 |
|
| 538 |
// DeleteCapacityCommitment deletes a capacity commitment. Attempting to delete capacity commitment |
| 539 |
// before its commitment_end_time will fail with the error code |
| 540 |
// google.rpc.Code.FAILED_PRECONDITION. |
| 541 |
func (c *Client) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error { |
| 542 |
return c.internalClient.DeleteCapacityCommitment(ctx, req, opts...) |
| 543 |
} |
| 544 |
|
| 545 |
// UpdateCapacityCommitment updates an existing capacity commitment. |
| 546 |
// |
| 547 |
// Only plan and renewal_plan fields can be updated. |
| 548 |
// |
| 549 |
// Plan can only be changed to a plan of a longer commitment period. |
| 550 |
// Attempting to change to a plan with shorter commitment period will fail |
| 551 |
// with the error code google.rpc.Code.FAILED_PRECONDITION. |
| 552 |
func (c *Client) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 553 |
return c.internalClient.UpdateCapacityCommitment(ctx, req, opts...) |
| 554 |
} |
| 555 |
|
| 556 |
// SplitCapacityCommitment splits capacity commitment to two commitments of the same plan and |
| 557 |
// commitment_end_time. |
| 558 |
// |
| 559 |
// A common use case is to enable downgrading commitments. |
| 560 |
// |
| 561 |
// For example, in order to downgrade from 10000 slots to 8000, you might |
| 562 |
// split a 10000 capacity commitment into commitments of 2000 and 8000. Then, |
| 563 |
// you delete the first one after the commitment end time passes. |
| 564 |
func (c *Client) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) { |
| 565 |
return c.internalClient.SplitCapacityCommitment(ctx, req, opts...) |
| 566 |
} |
| 567 |
|
| 568 |
// MergeCapacityCommitments merges capacity commitments of the same plan into a single commitment. |
| 569 |
// |
| 570 |
// The resulting capacity commitment has the greater commitment_end_time |
| 571 |
// out of the to-be-merged capacity commitments. |
| 572 |
// |
| 573 |
// Attempting to merge capacity commitments of different plan will fail |
| 574 |
// with the error code google.rpc.Code.FAILED_PRECONDITION. |
| 575 |
func (c *Client) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 576 |
return c.internalClient.MergeCapacityCommitments(ctx, req, opts...) |
| 577 |
} |
| 578 |
|
| 579 |
// CreateAssignment creates an assignment object which allows the given project to submit jobs |
| 580 |
// of a certain type using slots from the specified reservation. |
| 581 |
// |
| 582 |
// Currently a |
| 583 |
// resource (project, folder, organization) can only have one assignment per |
| 584 |
// each (job_type, location) combination, and that reservation will be used |
| 585 |
// for all jobs of the matching type. |
| 586 |
// |
| 587 |
// Different assignments can be created on different levels of the |
| 588 |
// projects, folders or organization hierarchy. During query execution, |
| 589 |
// the assignment is looked up at the project, folder and organization levels |
| 590 |
// in that order. The first assignment found is applied to the query. |
| 591 |
// |
| 592 |
// When creating assignments, it does not matter if other assignments exist at |
| 593 |
// higher levels. |
| 594 |
// |
| 595 |
// Example: |
| 596 |
// |
| 597 |
// The organization organizationA contains two projects, project1 |
| 598 |
// and project2. |
| 599 |
// |
| 600 |
// Assignments for all three entities (organizationA, project1, and |
| 601 |
// project2) could all be created and mapped to the same or different |
| 602 |
// reservations. |
| 603 |
// |
| 604 |
// “None” assignments represent an absence of the assignment. Projects |
| 605 |
// assigned to None use on-demand pricing. To create a “None” assignment, use |
| 606 |
// “none” as a reservation_id in the parent. Example parent: |
| 607 |
// projects/myproject/locations/US/reservations/none. |
| 608 |
// |
| 609 |
// Returns google.rpc.Code.PERMISSION_DENIED if user does not have |
| 610 |
// ‘bigquery.admin’ permissions on the project using the reservation |
| 611 |
// and the project that owns this reservation. |
| 612 |
// |
| 613 |
// Returns google.rpc.Code.INVALID_ARGUMENT when location of the assignment |
| 614 |
// does not match location of the reservation. |
| 615 |
func (c *Client) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 616 |
return c.internalClient.CreateAssignment(ctx, req, opts...) |
| 617 |
} |
| 618 |
|
| 619 |
// ListAssignments lists assignments. |
| 620 |
// |
| 621 |
// Only explicitly created assignments will be returned. |
| 622 |
// |
| 623 |
// Example: |
| 624 |
// |
| 625 |
// Organization organizationA contains two projects, project1 and |
| 626 |
// project2. |
| 627 |
// |
| 628 |
// Reservation res1 exists and was created previously. |
| 629 |
// |
| 630 |
// CreateAssignment was used previously to define the following |
| 631 |
// associations between entities and reservations: <organizationA, res1> |
| 632 |
// and <project1, res1> |
| 633 |
// |
| 634 |
// In this example, ListAssignments will just return the above two assignments |
| 635 |
// for reservation res1, and no expansion/merge will happen. |
| 636 |
// |
| 637 |
// The wildcard “-” can be used for |
| 638 |
// reservations in the request. In that case all assignments belongs to the |
| 639 |
// specified project and location will be listed. |
| 640 |
// |
| 641 |
// Note "-" cannot be used for projects nor locations. |
| 642 |
func (c *Client) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 643 |
return c.internalClient.ListAssignments(ctx, req, opts...) |
| 644 |
} |
| 645 |
|
| 646 |
// DeleteAssignment deletes a assignment. No expansion will happen. |
| 647 |
// |
| 648 |
// Example: |
| 649 |
// |
| 650 |
// Organization organizationA contains two projects, project1 and |
| 651 |
// project2. |
| 652 |
// |
| 653 |
// Reservation res1 exists and was created previously. |
| 654 |
// |
| 655 |
// CreateAssignment was used previously to define the following |
| 656 |
// associations between entities and reservations: <organizationA, res1> |
| 657 |
// and <project1, res1> |
| 658 |
// |
| 659 |
// In this example, deletion of the <organizationA, res1> assignment won’t |
| 660 |
// affect the other assignment <project1, res1>. After said deletion, |
| 661 |
// queries from project1 will still use res1 while queries from |
| 662 |
// project2 will switch to use on-demand mode. |
| 663 |
func (c *Client) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error { |
| 664 |
return c.internalClient.DeleteAssignment(ctx, req, opts...) |
| 665 |
} |
| 666 |
|
| 667 |
// SearchAssignments deprecated: Looks up assignments for a specified resource for a particular |
| 668 |
// region. If the request is about a project: |
| 669 |
// |
| 670 |
// Assignments created on the project will be returned if they exist. |
| 671 |
// |
| 672 |
// Otherwise assignments created on the closest ancestor will be |
| 673 |
// returned. |
| 674 |
// |
| 675 |
// Assignments for different JobTypes will all be returned. |
| 676 |
// |
| 677 |
// The same logic applies if the request is about a folder. |
| 678 |
// |
| 679 |
// If the request is about an organization, then assignments created on the |
| 680 |
// organization will be returned (organization doesn’t have ancestors). |
| 681 |
// |
| 682 |
// Comparing to ListAssignments, there are some behavior |
| 683 |
// differences: |
| 684 |
// |
| 685 |
// permission on the assignee will be verified in this API. |
| 686 |
// |
| 687 |
// Hierarchy lookup (project->folder->organization) happens in this API. |
| 688 |
// |
| 689 |
// Parent here is projects/*/locations/*, instead of |
| 690 |
// projects/*/locations/*reservations/*. |
| 691 |
// |
| 692 |
// Note "-" cannot be used for projects |
| 693 |
// nor locations. |
| 694 |
// |
| 695 |
// Deprecated: SearchAssignments may be removed in a future version. |
| 696 |
func (c *Client) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 697 |
return c.internalClient.SearchAssignments(ctx, req, opts...) |
| 698 |
} |
| 699 |
|
| 700 |
// SearchAllAssignments looks up assignments for a specified resource for a particular region. |
| 701 |
// If the request is about a project: |
| 702 |
// |
| 703 |
// Assignments created on the project will be returned if they exist. |
| 704 |
// |
| 705 |
// Otherwise assignments created on the closest ancestor will be |
| 706 |
// returned. |
| 707 |
// |
| 708 |
// Assignments for different JobTypes will all be returned. |
| 709 |
// |
| 710 |
// The same logic applies if the request is about a folder. |
| 711 |
// |
| 712 |
// If the request is about an organization, then assignments created on the |
| 713 |
// organization will be returned (organization doesn’t have ancestors). |
| 714 |
// |
| 715 |
// Comparing to ListAssignments, there are some behavior |
| 716 |
// differences: |
| 717 |
// |
| 718 |
// permission on the assignee will be verified in this API. |
| 719 |
// |
| 720 |
// Hierarchy lookup (project->folder->organization) happens in this API. |
| 721 |
// |
| 722 |
// Parent here is projects/*/locations/*, instead of |
| 723 |
// projects/*/locations/*reservations/*. |
| 724 |
func (c *Client) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 725 |
return c.internalClient.SearchAllAssignments(ctx, req, opts...) |
| 726 |
} |
| 727 |
|
| 728 |
// MoveAssignment moves an assignment under a new reservation. |
| 729 |
// |
| 730 |
// This differs from removing an existing assignment and recreating a new one |
| 731 |
// by providing a transactional change that ensures an assignee always has an |
| 732 |
// associated reservation. |
| 733 |
func (c *Client) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 734 |
return c.internalClient.MoveAssignment(ctx, req, opts...) |
| 735 |
} |
| 736 |
|
| 737 |
// UpdateAssignment updates an existing assignment. |
| 738 |
// |
| 739 |
// Only the priority field can be updated. |
| 740 |
func (c *Client) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 741 |
return c.internalClient.UpdateAssignment(ctx, req, opts...) |
| 742 |
} |
| 743 |
|
| 744 |
// GetBiReservation retrieves a BI reservation. |
| 745 |
func (c *Client) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) { |
| 746 |
return c.internalClient.GetBiReservation(ctx, req, opts...) |
| 747 |
} |
| 748 |
|
| 749 |
// UpdateBiReservation updates a BI reservation. |
| 750 |
// |
| 751 |
// Only fields specified in the field_mask are updated. |
| 752 |
// |
| 753 |
// A singleton BI reservation always exists with default size 0. |
| 754 |
// In order to reserve BI capacity it needs to be updated to an amount |
| 755 |
// greater than 0. In order to release BI capacity reservation size |
| 756 |
// must be set to 0. |
| 757 |
func (c *Client) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) { |
| 758 |
return c.internalClient.UpdateBiReservation(ctx, req, opts...) |
| 759 |
} |
| 760 |
|
| 761 |
// gRPCClient is a client for interacting with BigQuery Reservation API over gRPC transport. |
| 762 |
// |
| 763 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 764 |
type gRPCClient struct { |
| 765 |
// Connection pool of gRPC connections to the service. |
| 766 |
connPool gtransport.ConnPool |
| 767 |
|
| 768 |
// Points back to the CallOptions field of the containing Client |
| 769 |
CallOptions **CallOptions |
| 770 |
|
| 771 |
// The gRPC API client. |
| 772 |
client reservationpb.ReservationServiceClient |
| 773 |
|
| 774 |
// The x-goog-* metadata to be sent with each request. |
| 775 |
xGoogHeaders []string |
| 776 |
|
| 777 |
logger *slog.Logger |
| 778 |
} |
| 779 |
|
| 780 |
// NewClient creates a new reservation service client based on gRPC. |
| 781 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 782 |
// |
| 783 |
// This API allows users to manage their BigQuery reservations. |
| 784 |
// |
| 785 |
// A reservation provides computational resource guarantees, in the form of |
| 786 |
// slots (at https://cloud.google.com/bigquery/docs/slots), to users. A slot is a |
| 787 |
// unit of computational power in BigQuery, and serves as the basic unit of |
| 788 |
// parallelism. In a scan of a multi-partitioned table, a single slot operates |
| 789 |
// on a single partition of the table. A reservation resource exists as a child |
| 790 |
// resource of the admin project and location, e.g.: |
| 791 |
// projects/myproject/locations/US/reservations/reservationName. |
| 792 |
// |
| 793 |
// A capacity commitment is a way to purchase compute capacity for BigQuery jobs |
| 794 |
// (in the form of slots) with some committed period of usage. A capacity |
| 795 |
// commitment resource exists as a child resource of the admin project and |
| 796 |
// location, e.g.: |
| 797 |
// projects/myproject/locations/US/capacityCommitments/id. |
| 798 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 799 |
clientOpts := defaultGRPCClientOptions() |
| 800 |
if newClientHook != nil { |
| 801 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 802 |
if err != nil { |
| 803 |
return nil, err |
| 804 |
} |
| 805 |
clientOpts = append(clientOpts, hookOpts...) |
| 806 |
} |
| 807 |
|
| 808 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 809 |
if err != nil { |
| 810 |
return nil, err |
| 811 |
} |
| 812 |
client := Client{CallOptions: defaultCallOptions()} |
| 813 |
|
| 814 |
c := &gRPCClient{ |
| 815 |
connPool: connPool, |
| 816 |
client: reservationpb.NewReservationServiceClient(connPool), |
| 817 |
CallOptions: &client.CallOptions, |
| 818 |
logger: internaloption.GetLogger(opts), |
| 819 |
} |
| 820 |
c.setGoogleClientInfo() |
| 821 |
|
| 822 |
client.internalClient = c |
| 823 |
|
| 824 |
return &client, nil |
| 825 |
} |
| 826 |
|
| 827 |
// Connection returns a connection to the API service. |
| 828 |
// |
| 829 |
// Deprecated: Connections are now pooled so this method does not always |
| 830 |
// return the same resource. |
| 831 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 832 |
return c.connPool.Conn() |
| 833 |
} |
| 834 |
|
| 835 |
// setGoogleClientInfo sets the name and version of the application in |
| 836 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 837 |
// use by Google-written clients. |
| 838 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 839 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 840 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 841 |
c.xGoogHeaders = []string{ |
| 842 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
// Close closes the connection to the API service. The user should invoke this when |
| 847 |
// the client is no longer required. |
| 848 |
func (c *gRPCClient) Close() error { |
| 849 |
return c.connPool.Close() |
| 850 |
} |
| 851 |
|
| 852 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 853 |
type restClient struct { |
| 854 |
// The http endpoint to connect to. |
| 855 |
endpoint string |
| 856 |
|
| 857 |
// The http client. |
| 858 |
httpClient *http.Client |
| 859 |
|
| 860 |
// The x-goog-* headers to be sent with each request. |
| 861 |
xGoogHeaders []string |
| 862 |
|
| 863 |
// Points back to the CallOptions field of the containing Client |
| 864 |
CallOptions **CallOptions |
| 865 |
|
| 866 |
logger *slog.Logger |
| 867 |
} |
| 868 |
|
| 869 |
// NewRESTClient creates a new reservation service rest client. |
| 870 |
// |
| 871 |
// This API allows users to manage their BigQuery reservations. |
| 872 |
// |
| 873 |
// A reservation provides computational resource guarantees, in the form of |
| 874 |
// slots (at https://cloud.google.com/bigquery/docs/slots), to users. A slot is a |
| 875 |
// unit of computational power in BigQuery, and serves as the basic unit of |
| 876 |
// parallelism. In a scan of a multi-partitioned table, a single slot operates |
| 877 |
// on a single partition of the table. A reservation resource exists as a child |
| 878 |
// resource of the admin project and location, e.g.: |
| 879 |
// projects/myproject/locations/US/reservations/reservationName. |
| 880 |
// |
| 881 |
// A capacity commitment is a way to purchase compute capacity for BigQuery jobs |
| 882 |
// (in the form of slots) with some committed period of usage. A capacity |
| 883 |
// commitment resource exists as a child resource of the admin project and |
| 884 |
// location, e.g.: |
| 885 |
// projects/myproject/locations/US/capacityCommitments/id. |
| 886 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 887 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 888 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 889 |
if err != nil { |
| 890 |
return nil, err |
| 891 |
} |
| 892 |
|
| 893 |
callOpts := defaultRESTCallOptions() |
| 894 |
c := &restClient{ |
| 895 |
endpoint: endpoint, |
| 896 |
httpClient: httpClient, |
| 897 |
CallOptions: &callOpts, |
| 898 |
logger: internaloption.GetLogger(opts), |
| 899 |
} |
| 900 |
c.setGoogleClientInfo() |
| 901 |
|
| 902 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 903 |
} |
| 904 |
|
| 905 |
func defaultRESTClientOptions() []option.ClientOption { |
| 906 |
return []option.ClientOption{ |
| 907 |
internaloption.WithDefaultEndpoint("https://bigqueryreservation.googleapis.com"), |
| 908 |
internaloption.WithDefaultEndpointTemplate("https://bigqueryreservation.UNIVERSE_DOMAIN"), |
| 909 |
internaloption.WithDefaultMTLSEndpoint("https://bigqueryreservation.mtls.googleapis.com"), |
| 910 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 911 |
internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"), |
| 912 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 913 |
internaloption.EnableNewAuthLibrary(), |
| 914 |
} |
| 915 |
} |
| 916 |
|
| 917 |
// setGoogleClientInfo sets the name and version of the application in |
| 918 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 919 |
// use by Google-written clients. |
| 920 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 921 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 922 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 923 |
c.xGoogHeaders = []string{ |
| 924 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
// Close closes the connection to the API service. The user should invoke this when |
| 929 |
// the client is no longer required. |
| 930 |
func (c *restClient) Close() error { |
| 931 |
// Replace httpClient with nil to force cleanup. |
| 932 |
c.httpClient = nil |
| 933 |
return nil |
| 934 |
} |
| 935 |
|
| 936 |
// Connection returns a connection to the API service. |
| 937 |
// |
| 938 |
// Deprecated: This method always returns nil. |
| 939 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 940 |
return nil |
| 941 |
} |
| 942 |
func (c *gRPCClient) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 943 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 944 |
|
| 945 |
hds = append(c.xGoogHeaders, hds...) |
| 946 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 947 |
opts = append((*c.CallOptions).CreateReservation[0:len((*c.CallOptions).CreateReservation):len((*c.CallOptions).CreateReservation)], opts...) |
| 948 |
var resp *reservationpb.Reservation |
| 949 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 950 |
var err error |
| 951 |
resp, err = executeRPC(ctx, c.client.CreateReservation, req, settings.GRPC, c.logger, "CreateReservation") |
| 952 |
return err |
| 953 |
}, opts...) |
| 954 |
if err != nil { |
| 955 |
return nil, err |
| 956 |
} |
| 957 |
return resp, nil |
| 958 |
} |
| 959 |
|
| 960 |
func (c *gRPCClient) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator { |
| 961 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 962 |
|
| 963 |
hds = append(c.xGoogHeaders, hds...) |
| 964 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 965 |
opts = append((*c.CallOptions).ListReservations[0:len((*c.CallOptions).ListReservations):len((*c.CallOptions).ListReservations)], opts...) |
| 966 |
it := &ReservationIterator{} |
| 967 |
req = proto.Clone(req).(*reservationpb.ListReservationsRequest) |
| 968 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Reservation, string, error) { |
| 969 |
resp := &reservationpb.ListReservationsResponse{} |
| 970 |
if pageToken != "" { |
| 971 |
req.PageToken = pageToken |
| 972 |
} |
| 973 |
if pageSize > math.MaxInt32 { |
| 974 |
req.PageSize = math.MaxInt32 |
| 975 |
} else if pageSize != 0 { |
| 976 |
req.PageSize = int32(pageSize) |
| 977 |
} |
| 978 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 979 |
var err error |
| 980 |
resp, err = executeRPC(ctx, c.client.ListReservations, req, settings.GRPC, c.logger, "ListReservations") |
| 981 |
return err |
| 982 |
}, opts...) |
| 983 |
if err != nil { |
| 984 |
return nil, "", err |
| 985 |
} |
| 986 |
|
| 987 |
it.Response = resp |
| 988 |
return resp.GetReservations(), resp.GetNextPageToken(), nil |
| 989 |
} |
| 990 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 991 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 992 |
if err != nil { |
| 993 |
return "", err |
| 994 |
} |
| 995 |
it.items = append(it.items, items...) |
| 996 |
return nextPageToken, nil |
| 997 |
} |
| 998 |
|
| 999 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1000 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1001 |
it.pageInfo.Token = req.GetPageToken() |
| 1002 |
|
| 1003 |
return it |
| 1004 |
} |
| 1005 |
|
| 1006 |
func (c *gRPCClient) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1007 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1008 |
|
| 1009 |
hds = append(c.xGoogHeaders, hds...) |
| 1010 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1011 |
opts = append((*c.CallOptions).GetReservation[0:len((*c.CallOptions).GetReservation):len((*c.CallOptions).GetReservation)], opts...) |
| 1012 |
var resp *reservationpb.Reservation |
| 1013 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1014 |
var err error |
| 1015 |
resp, err = executeRPC(ctx, c.client.GetReservation, req, settings.GRPC, c.logger, "GetReservation") |
| 1016 |
return err |
| 1017 |
}, opts...) |
| 1018 |
if err != nil { |
| 1019 |
return nil, err |
| 1020 |
} |
| 1021 |
return resp, nil |
| 1022 |
} |
| 1023 |
|
| 1024 |
func (c *gRPCClient) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error { |
| 1025 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1026 |
|
| 1027 |
hds = append(c.xGoogHeaders, hds...) |
| 1028 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1029 |
opts = append((*c.CallOptions).DeleteReservation[0:len((*c.CallOptions).DeleteReservation):len((*c.CallOptions).DeleteReservation)], opts...) |
| 1030 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1031 |
var err error |
| 1032 |
_, err = executeRPC(ctx, c.client.DeleteReservation, req, settings.GRPC, c.logger, "DeleteReservation") |
| 1033 |
return err |
| 1034 |
}, opts...) |
| 1035 |
return err |
| 1036 |
} |
| 1037 |
|
| 1038 |
func (c *gRPCClient) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1039 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "reservation.name", url.QueryEscape(req.GetReservation().GetName()))} |
| 1040 |
|
| 1041 |
hds = append(c.xGoogHeaders, hds...) |
| 1042 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1043 |
opts = append((*c.CallOptions).UpdateReservation[0:len((*c.CallOptions).UpdateReservation):len((*c.CallOptions).UpdateReservation)], opts...) |
| 1044 |
var resp *reservationpb.Reservation |
| 1045 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1046 |
var err error |
| 1047 |
resp, err = executeRPC(ctx, c.client.UpdateReservation, req, settings.GRPC, c.logger, "UpdateReservation") |
| 1048 |
return err |
| 1049 |
}, opts...) |
| 1050 |
if err != nil { |
| 1051 |
return nil, err |
| 1052 |
} |
| 1053 |
return resp, nil |
| 1054 |
} |
| 1055 |
|
| 1056 |
func (c *gRPCClient) FailoverReservation(ctx context.Context, req *reservationpb.FailoverReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1057 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1058 |
|
| 1059 |
hds = append(c.xGoogHeaders, hds...) |
| 1060 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1061 |
opts = append((*c.CallOptions).FailoverReservation[0:len((*c.CallOptions).FailoverReservation):len((*c.CallOptions).FailoverReservation)], opts...) |
| 1062 |
var resp *reservationpb.Reservation |
| 1063 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1064 |
var err error |
| 1065 |
resp, err = executeRPC(ctx, c.client.FailoverReservation, req, settings.GRPC, c.logger, "FailoverReservation") |
| 1066 |
return err |
| 1067 |
}, opts...) |
| 1068 |
if err != nil { |
| 1069 |
return nil, err |
| 1070 |
} |
| 1071 |
return resp, nil |
| 1072 |
} |
| 1073 |
|
| 1074 |
func (c *gRPCClient) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 1075 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1076 |
|
| 1077 |
hds = append(c.xGoogHeaders, hds...) |
| 1078 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1079 |
opts = append((*c.CallOptions).CreateCapacityCommitment[0:len((*c.CallOptions).CreateCapacityCommitment):len((*c.CallOptions).CreateCapacityCommitment)], opts...) |
| 1080 |
var resp *reservationpb.CapacityCommitment |
| 1081 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1082 |
var err error |
| 1083 |
resp, err = executeRPC(ctx, c.client.CreateCapacityCommitment, req, settings.GRPC, c.logger, "CreateCapacityCommitment") |
| 1084 |
return err |
| 1085 |
}, opts...) |
| 1086 |
if err != nil { |
| 1087 |
return nil, err |
| 1088 |
} |
| 1089 |
return resp, nil |
| 1090 |
} |
| 1091 |
|
| 1092 |
func (c *gRPCClient) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator { |
| 1093 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1094 |
|
| 1095 |
hds = append(c.xGoogHeaders, hds...) |
| 1096 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1097 |
opts = append((*c.CallOptions).ListCapacityCommitments[0:len((*c.CallOptions).ListCapacityCommitments):len((*c.CallOptions).ListCapacityCommitments)], opts...) |
| 1098 |
it := &CapacityCommitmentIterator{} |
| 1099 |
req = proto.Clone(req).(*reservationpb.ListCapacityCommitmentsRequest) |
| 1100 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.CapacityCommitment, string, error) { |
| 1101 |
resp := &reservationpb.ListCapacityCommitmentsResponse{} |
| 1102 |
if pageToken != "" { |
| 1103 |
req.PageToken = pageToken |
| 1104 |
} |
| 1105 |
if pageSize > math.MaxInt32 { |
| 1106 |
req.PageSize = math.MaxInt32 |
| 1107 |
} else if pageSize != 0 { |
| 1108 |
req.PageSize = int32(pageSize) |
| 1109 |
} |
| 1110 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1111 |
var err error |
| 1112 |
resp, err = executeRPC(ctx, c.client.ListCapacityCommitments, req, settings.GRPC, c.logger, "ListCapacityCommitments") |
| 1113 |
return err |
| 1114 |
}, opts...) |
| 1115 |
if err != nil { |
| 1116 |
return nil, "", err |
| 1117 |
} |
| 1118 |
|
| 1119 |
it.Response = resp |
| 1120 |
return resp.GetCapacityCommitments(), resp.GetNextPageToken(), nil |
| 1121 |
} |
| 1122 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1123 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1124 |
if err != nil { |
| 1125 |
return "", err |
| 1126 |
} |
| 1127 |
it.items = append(it.items, items...) |
| 1128 |
return nextPageToken, nil |
| 1129 |
} |
| 1130 |
|
| 1131 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1132 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1133 |
it.pageInfo.Token = req.GetPageToken() |
| 1134 |
|
| 1135 |
return it |
| 1136 |
} |
| 1137 |
|
| 1138 |
func (c *gRPCClient) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 1139 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1140 |
|
| 1141 |
hds = append(c.xGoogHeaders, hds...) |
| 1142 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1143 |
opts = append((*c.CallOptions).GetCapacityCommitment[0:len((*c.CallOptions).GetCapacityCommitment):len((*c.CallOptions).GetCapacityCommitment)], opts...) |
| 1144 |
var resp *reservationpb.CapacityCommitment |
| 1145 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1146 |
var err error |
| 1147 |
resp, err = executeRPC(ctx, c.client.GetCapacityCommitment, req, settings.GRPC, c.logger, "GetCapacityCommitment") |
| 1148 |
return err |
| 1149 |
}, opts...) |
| 1150 |
if err != nil { |
| 1151 |
return nil, err |
| 1152 |
} |
| 1153 |
return resp, nil |
| 1154 |
} |
| 1155 |
|
| 1156 |
func (c *gRPCClient) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error { |
| 1157 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1158 |
|
| 1159 |
hds = append(c.xGoogHeaders, hds...) |
| 1160 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1161 |
opts = append((*c.CallOptions).DeleteCapacityCommitment[0:len((*c.CallOptions).DeleteCapacityCommitment):len((*c.CallOptions).DeleteCapacityCommitment)], opts...) |
| 1162 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1163 |
var err error |
| 1164 |
_, err = executeRPC(ctx, c.client.DeleteCapacityCommitment, req, settings.GRPC, c.logger, "DeleteCapacityCommitment") |
| 1165 |
return err |
| 1166 |
}, opts...) |
| 1167 |
return err |
| 1168 |
} |
| 1169 |
|
| 1170 |
func (c *gRPCClient) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 1171 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "capacity_commitment.name", url.QueryEscape(req.GetCapacityCommitment().GetName()))} |
| 1172 |
|
| 1173 |
hds = append(c.xGoogHeaders, hds...) |
| 1174 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1175 |
opts = append((*c.CallOptions).UpdateCapacityCommitment[0:len((*c.CallOptions).UpdateCapacityCommitment):len((*c.CallOptions).UpdateCapacityCommitment)], opts...) |
| 1176 |
var resp *reservationpb.CapacityCommitment |
| 1177 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1178 |
var err error |
| 1179 |
resp, err = executeRPC(ctx, c.client.UpdateCapacityCommitment, req, settings.GRPC, c.logger, "UpdateCapacityCommitment") |
| 1180 |
return err |
| 1181 |
}, opts...) |
| 1182 |
if err != nil { |
| 1183 |
return nil, err |
| 1184 |
} |
| 1185 |
return resp, nil |
| 1186 |
} |
| 1187 |
|
| 1188 |
func (c *gRPCClient) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) { |
| 1189 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1190 |
|
| 1191 |
hds = append(c.xGoogHeaders, hds...) |
| 1192 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1193 |
opts = append((*c.CallOptions).SplitCapacityCommitment[0:len((*c.CallOptions).SplitCapacityCommitment):len((*c.CallOptions).SplitCapacityCommitment)], opts...) |
| 1194 |
var resp *reservationpb.SplitCapacityCommitmentResponse |
| 1195 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1196 |
var err error |
| 1197 |
resp, err = executeRPC(ctx, c.client.SplitCapacityCommitment, req, settings.GRPC, c.logger, "SplitCapacityCommitment") |
| 1198 |
return err |
| 1199 |
}, opts...) |
| 1200 |
if err != nil { |
| 1201 |
return nil, err |
| 1202 |
} |
| 1203 |
return resp, nil |
| 1204 |
} |
| 1205 |
|
| 1206 |
func (c *gRPCClient) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 1207 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1208 |
|
| 1209 |
hds = append(c.xGoogHeaders, hds...) |
| 1210 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1211 |
opts = append((*c.CallOptions).MergeCapacityCommitments[0:len((*c.CallOptions).MergeCapacityCommitments):len((*c.CallOptions).MergeCapacityCommitments)], opts...) |
| 1212 |
var resp *reservationpb.CapacityCommitment |
| 1213 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1214 |
var err error |
| 1215 |
resp, err = executeRPC(ctx, c.client.MergeCapacityCommitments, req, settings.GRPC, c.logger, "MergeCapacityCommitments") |
| 1216 |
return err |
| 1217 |
}, opts...) |
| 1218 |
if err != nil { |
| 1219 |
return nil, err |
| 1220 |
} |
| 1221 |
return resp, nil |
| 1222 |
} |
| 1223 |
|
| 1224 |
func (c *gRPCClient) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 1225 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1226 |
|
| 1227 |
hds = append(c.xGoogHeaders, hds...) |
| 1228 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1229 |
opts = append((*c.CallOptions).CreateAssignment[0:len((*c.CallOptions).CreateAssignment):len((*c.CallOptions).CreateAssignment)], opts...) |
| 1230 |
var resp *reservationpb.Assignment |
| 1231 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1232 |
var err error |
| 1233 |
resp, err = executeRPC(ctx, c.client.CreateAssignment, req, settings.GRPC, c.logger, "CreateAssignment") |
| 1234 |
return err |
| 1235 |
}, opts...) |
| 1236 |
if err != nil { |
| 1237 |
return nil, err |
| 1238 |
} |
| 1239 |
return resp, nil |
| 1240 |
} |
| 1241 |
|
| 1242 |
func (c *gRPCClient) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 1243 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1244 |
|
| 1245 |
hds = append(c.xGoogHeaders, hds...) |
| 1246 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1247 |
opts = append((*c.CallOptions).ListAssignments[0:len((*c.CallOptions).ListAssignments):len((*c.CallOptions).ListAssignments)], opts...) |
| 1248 |
it := &AssignmentIterator{} |
| 1249 |
req = proto.Clone(req).(*reservationpb.ListAssignmentsRequest) |
| 1250 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) { |
| 1251 |
resp := &reservationpb.ListAssignmentsResponse{} |
| 1252 |
if pageToken != "" { |
| 1253 |
req.PageToken = pageToken |
| 1254 |
} |
| 1255 |
if pageSize > math.MaxInt32 { |
| 1256 |
req.PageSize = math.MaxInt32 |
| 1257 |
} else if pageSize != 0 { |
| 1258 |
req.PageSize = int32(pageSize) |
| 1259 |
} |
| 1260 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1261 |
var err error |
| 1262 |
resp, err = executeRPC(ctx, c.client.ListAssignments, req, settings.GRPC, c.logger, "ListAssignments") |
| 1263 |
return err |
| 1264 |
}, opts...) |
| 1265 |
if err != nil { |
| 1266 |
return nil, "", err |
| 1267 |
} |
| 1268 |
|
| 1269 |
it.Response = resp |
| 1270 |
return resp.GetAssignments(), resp.GetNextPageToken(), nil |
| 1271 |
} |
| 1272 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1273 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1274 |
if err != nil { |
| 1275 |
return "", err |
| 1276 |
} |
| 1277 |
it.items = append(it.items, items...) |
| 1278 |
return nextPageToken, nil |
| 1279 |
} |
| 1280 |
|
| 1281 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1282 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1283 |
it.pageInfo.Token = req.GetPageToken() |
| 1284 |
|
| 1285 |
return it |
| 1286 |
} |
| 1287 |
|
| 1288 |
func (c *gRPCClient) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error { |
| 1289 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1290 |
|
| 1291 |
hds = append(c.xGoogHeaders, hds...) |
| 1292 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1293 |
opts = append((*c.CallOptions).DeleteAssignment[0:len((*c.CallOptions).DeleteAssignment):len((*c.CallOptions).DeleteAssignment)], opts...) |
| 1294 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1295 |
var err error |
| 1296 |
_, err = executeRPC(ctx, c.client.DeleteAssignment, req, settings.GRPC, c.logger, "DeleteAssignment") |
| 1297 |
return err |
| 1298 |
}, opts...) |
| 1299 |
return err |
| 1300 |
} |
| 1301 |
|
| 1302 |
func (c *gRPCClient) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 1303 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1304 |
|
| 1305 |
hds = append(c.xGoogHeaders, hds...) |
| 1306 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1307 |
opts = append((*c.CallOptions).SearchAssignments[0:len((*c.CallOptions).SearchAssignments):len((*c.CallOptions).SearchAssignments)], opts...) |
| 1308 |
it := &AssignmentIterator{} |
| 1309 |
req = proto.Clone(req).(*reservationpb.SearchAssignmentsRequest) |
| 1310 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) { |
| 1311 |
resp := &reservationpb.SearchAssignmentsResponse{} |
| 1312 |
if pageToken != "" { |
| 1313 |
req.PageToken = pageToken |
| 1314 |
} |
| 1315 |
if pageSize > math.MaxInt32 { |
| 1316 |
req.PageSize = math.MaxInt32 |
| 1317 |
} else if pageSize != 0 { |
| 1318 |
req.PageSize = int32(pageSize) |
| 1319 |
} |
| 1320 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1321 |
var err error |
| 1322 |
resp, err = executeRPC(ctx, c.client.SearchAssignments, req, settings.GRPC, c.logger, "SearchAssignments") |
| 1323 |
return err |
| 1324 |
}, opts...) |
| 1325 |
if err != nil { |
| 1326 |
return nil, "", err |
| 1327 |
} |
| 1328 |
|
| 1329 |
it.Response = resp |
| 1330 |
return resp.GetAssignments(), resp.GetNextPageToken(), nil |
| 1331 |
} |
| 1332 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1333 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1334 |
if err != nil { |
| 1335 |
return "", err |
| 1336 |
} |
| 1337 |
it.items = append(it.items, items...) |
| 1338 |
return nextPageToken, nil |
| 1339 |
} |
| 1340 |
|
| 1341 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1342 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1343 |
it.pageInfo.Token = req.GetPageToken() |
| 1344 |
|
| 1345 |
return it |
| 1346 |
} |
| 1347 |
|
| 1348 |
func (c *gRPCClient) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 1349 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1350 |
|
| 1351 |
hds = append(c.xGoogHeaders, hds...) |
| 1352 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1353 |
opts = append((*c.CallOptions).SearchAllAssignments[0:len((*c.CallOptions).SearchAllAssignments):len((*c.CallOptions).SearchAllAssignments)], opts...) |
| 1354 |
it := &AssignmentIterator{} |
| 1355 |
req = proto.Clone(req).(*reservationpb.SearchAllAssignmentsRequest) |
| 1356 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) { |
| 1357 |
resp := &reservationpb.SearchAllAssignmentsResponse{} |
| 1358 |
if pageToken != "" { |
| 1359 |
req.PageToken = pageToken |
| 1360 |
} |
| 1361 |
if pageSize > math.MaxInt32 { |
| 1362 |
req.PageSize = math.MaxInt32 |
| 1363 |
} else if pageSize != 0 { |
| 1364 |
req.PageSize = int32(pageSize) |
| 1365 |
} |
| 1366 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1367 |
var err error |
| 1368 |
resp, err = executeRPC(ctx, c.client.SearchAllAssignments, req, settings.GRPC, c.logger, "SearchAllAssignments") |
| 1369 |
return err |
| 1370 |
}, opts...) |
| 1371 |
if err != nil { |
| 1372 |
return nil, "", err |
| 1373 |
} |
| 1374 |
|
| 1375 |
it.Response = resp |
| 1376 |
return resp.GetAssignments(), resp.GetNextPageToken(), nil |
| 1377 |
} |
| 1378 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1379 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1380 |
if err != nil { |
| 1381 |
return "", err |
| 1382 |
} |
| 1383 |
it.items = append(it.items, items...) |
| 1384 |
return nextPageToken, nil |
| 1385 |
} |
| 1386 |
|
| 1387 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1388 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1389 |
it.pageInfo.Token = req.GetPageToken() |
| 1390 |
|
| 1391 |
return it |
| 1392 |
} |
| 1393 |
|
| 1394 |
func (c *gRPCClient) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 1395 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1396 |
|
| 1397 |
hds = append(c.xGoogHeaders, hds...) |
| 1398 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1399 |
opts = append((*c.CallOptions).MoveAssignment[0:len((*c.CallOptions).MoveAssignment):len((*c.CallOptions).MoveAssignment)], opts...) |
| 1400 |
var resp *reservationpb.Assignment |
| 1401 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1402 |
var err error |
| 1403 |
resp, err = executeRPC(ctx, c.client.MoveAssignment, req, settings.GRPC, c.logger, "MoveAssignment") |
| 1404 |
return err |
| 1405 |
}, opts...) |
| 1406 |
if err != nil { |
| 1407 |
return nil, err |
| 1408 |
} |
| 1409 |
return resp, nil |
| 1410 |
} |
| 1411 |
|
| 1412 |
func (c *gRPCClient) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 1413 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "assignment.name", url.QueryEscape(req.GetAssignment().GetName()))} |
| 1414 |
|
| 1415 |
hds = append(c.xGoogHeaders, hds...) |
| 1416 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1417 |
opts = append((*c.CallOptions).UpdateAssignment[0:len((*c.CallOptions).UpdateAssignment):len((*c.CallOptions).UpdateAssignment)], opts...) |
| 1418 |
var resp *reservationpb.Assignment |
| 1419 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1420 |
var err error |
| 1421 |
resp, err = executeRPC(ctx, c.client.UpdateAssignment, req, settings.GRPC, c.logger, "UpdateAssignment") |
| 1422 |
return err |
| 1423 |
}, opts...) |
| 1424 |
if err != nil { |
| 1425 |
return nil, err |
| 1426 |
} |
| 1427 |
return resp, nil |
| 1428 |
} |
| 1429 |
|
| 1430 |
func (c *gRPCClient) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) { |
| 1431 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1432 |
|
| 1433 |
hds = append(c.xGoogHeaders, hds...) |
| 1434 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1435 |
opts = append((*c.CallOptions).GetBiReservation[0:len((*c.CallOptions).GetBiReservation):len((*c.CallOptions).GetBiReservation)], opts...) |
| 1436 |
var resp *reservationpb.BiReservation |
| 1437 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1438 |
var err error |
| 1439 |
resp, err = executeRPC(ctx, c.client.GetBiReservation, req, settings.GRPC, c.logger, "GetBiReservation") |
| 1440 |
return err |
| 1441 |
}, opts...) |
| 1442 |
if err != nil { |
| 1443 |
return nil, err |
| 1444 |
} |
| 1445 |
return resp, nil |
| 1446 |
} |
| 1447 |
|
| 1448 |
func (c *gRPCClient) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) { |
| 1449 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "bi_reservation.name", url.QueryEscape(req.GetBiReservation().GetName()))} |
| 1450 |
|
| 1451 |
hds = append(c.xGoogHeaders, hds...) |
| 1452 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 1453 |
opts = append((*c.CallOptions).UpdateBiReservation[0:len((*c.CallOptions).UpdateBiReservation):len((*c.CallOptions).UpdateBiReservation)], opts...) |
| 1454 |
var resp *reservationpb.BiReservation |
| 1455 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1456 |
var err error |
| 1457 |
resp, err = executeRPC(ctx, c.client.UpdateBiReservation, req, settings.GRPC, c.logger, "UpdateBiReservation") |
| 1458 |
return err |
| 1459 |
}, opts...) |
| 1460 |
if err != nil { |
| 1461 |
return nil, err |
| 1462 |
} |
| 1463 |
return resp, nil |
| 1464 |
} |
| 1465 |
|
| 1466 |
// CreateReservation creates a new reservation resource. |
| 1467 |
func (c *restClient) CreateReservation(ctx context.Context, req *reservationpb.CreateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1468 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1469 |
body := req.GetReservation() |
| 1470 |
jsonReq, err := m.Marshal(body) |
| 1471 |
if err != nil { |
| 1472 |
return nil, err |
| 1473 |
} |
| 1474 |
|
| 1475 |
baseUrl, err := url.Parse(c.endpoint) |
| 1476 |
if err != nil { |
| 1477 |
return nil, err |
| 1478 |
} |
| 1479 |
baseUrl.Path += fmt.Sprintf("/v1/%v/reservations", req.GetParent()) |
| 1480 |
|
| 1481 |
params := url.Values{} |
| 1482 |
params.Add("$alt", "json;enum-encoding=int") |
| 1483 |
if req.GetReservationId() != "" { |
| 1484 |
params.Add("reservationId", fmt.Sprintf("%v", req.GetReservationId())) |
| 1485 |
} |
| 1486 |
|
| 1487 |
baseUrl.RawQuery = params.Encode() |
| 1488 |
|
| 1489 |
// Build HTTP headers from client and context metadata. |
| 1490 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1491 |
|
| 1492 |
hds = append(c.xGoogHeaders, hds...) |
| 1493 |
hds = append(hds, "Content-Type", "application/json") |
| 1494 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1495 |
opts = append((*c.CallOptions).CreateReservation[0:len((*c.CallOptions).CreateReservation):len((*c.CallOptions).CreateReservation)], opts...) |
| 1496 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1497 |
resp := &reservationpb.Reservation{} |
| 1498 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1499 |
if settings.Path != "" { |
| 1500 |
baseUrl.Path = settings.Path |
| 1501 |
} |
| 1502 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1503 |
if err != nil { |
| 1504 |
return err |
| 1505 |
} |
| 1506 |
httpReq = httpReq.WithContext(ctx) |
| 1507 |
httpReq.Header = headers |
| 1508 |
|
| 1509 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateReservation") |
| 1510 |
if err != nil { |
| 1511 |
return err |
| 1512 |
} |
| 1513 |
|
| 1514 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1515 |
return err |
| 1516 |
} |
| 1517 |
|
| 1518 |
return nil |
| 1519 |
}, opts...) |
| 1520 |
if e != nil { |
| 1521 |
return nil, e |
| 1522 |
} |
| 1523 |
return resp, nil |
| 1524 |
} |
| 1525 |
|
| 1526 |
// ListReservations lists all the reservations for the project in the specified location. |
| 1527 |
func (c *restClient) ListReservations(ctx context.Context, req *reservationpb.ListReservationsRequest, opts ...gax.CallOption) *ReservationIterator { |
| 1528 |
it := &ReservationIterator{} |
| 1529 |
req = proto.Clone(req).(*reservationpb.ListReservationsRequest) |
| 1530 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1531 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Reservation, string, error) { |
| 1532 |
resp := &reservationpb.ListReservationsResponse{} |
| 1533 |
if pageToken != "" { |
| 1534 |
req.PageToken = pageToken |
| 1535 |
} |
| 1536 |
if pageSize > math.MaxInt32 { |
| 1537 |
req.PageSize = math.MaxInt32 |
| 1538 |
} else if pageSize != 0 { |
| 1539 |
req.PageSize = int32(pageSize) |
| 1540 |
} |
| 1541 |
baseUrl, err := url.Parse(c.endpoint) |
| 1542 |
if err != nil { |
| 1543 |
return nil, "", err |
| 1544 |
} |
| 1545 |
baseUrl.Path += fmt.Sprintf("/v1/%v/reservations", req.GetParent()) |
| 1546 |
|
| 1547 |
params := url.Values{} |
| 1548 |
params.Add("$alt", "json;enum-encoding=int") |
| 1549 |
if req.GetPageSize() != 0 { |
| 1550 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1551 |
} |
| 1552 |
if req.GetPageToken() != "" { |
| 1553 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1554 |
} |
| 1555 |
|
| 1556 |
baseUrl.RawQuery = params.Encode() |
| 1557 |
|
| 1558 |
// Build HTTP headers from client and context metadata. |
| 1559 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1560 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1561 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1562 |
if settings.Path != "" { |
| 1563 |
baseUrl.Path = settings.Path |
| 1564 |
} |
| 1565 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1566 |
if err != nil { |
| 1567 |
return err |
| 1568 |
} |
| 1569 |
httpReq.Header = headers |
| 1570 |
|
| 1571 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListReservations") |
| 1572 |
if err != nil { |
| 1573 |
return err |
| 1574 |
} |
| 1575 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1576 |
return err |
| 1577 |
} |
| 1578 |
|
| 1579 |
return nil |
| 1580 |
}, opts...) |
| 1581 |
if e != nil { |
| 1582 |
return nil, "", e |
| 1583 |
} |
| 1584 |
it.Response = resp |
| 1585 |
return resp.GetReservations(), resp.GetNextPageToken(), nil |
| 1586 |
} |
| 1587 |
|
| 1588 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1589 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1590 |
if err != nil { |
| 1591 |
return "", err |
| 1592 |
} |
| 1593 |
it.items = append(it.items, items...) |
| 1594 |
return nextPageToken, nil |
| 1595 |
} |
| 1596 |
|
| 1597 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1598 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1599 |
it.pageInfo.Token = req.GetPageToken() |
| 1600 |
|
| 1601 |
return it |
| 1602 |
} |
| 1603 |
|
| 1604 |
// GetReservation returns information about the reservation. |
| 1605 |
func (c *restClient) GetReservation(ctx context.Context, req *reservationpb.GetReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1606 |
baseUrl, err := url.Parse(c.endpoint) |
| 1607 |
if err != nil { |
| 1608 |
return nil, err |
| 1609 |
} |
| 1610 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1611 |
|
| 1612 |
params := url.Values{} |
| 1613 |
params.Add("$alt", "json;enum-encoding=int") |
| 1614 |
|
| 1615 |
baseUrl.RawQuery = params.Encode() |
| 1616 |
|
| 1617 |
// Build HTTP headers from client and context metadata. |
| 1618 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1619 |
|
| 1620 |
hds = append(c.xGoogHeaders, hds...) |
| 1621 |
hds = append(hds, "Content-Type", "application/json") |
| 1622 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1623 |
opts = append((*c.CallOptions).GetReservation[0:len((*c.CallOptions).GetReservation):len((*c.CallOptions).GetReservation)], opts...) |
| 1624 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1625 |
resp := &reservationpb.Reservation{} |
| 1626 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1627 |
if settings.Path != "" { |
| 1628 |
baseUrl.Path = settings.Path |
| 1629 |
} |
| 1630 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1631 |
if err != nil { |
| 1632 |
return err |
| 1633 |
} |
| 1634 |
httpReq = httpReq.WithContext(ctx) |
| 1635 |
httpReq.Header = headers |
| 1636 |
|
| 1637 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetReservation") |
| 1638 |
if err != nil { |
| 1639 |
return err |
| 1640 |
} |
| 1641 |
|
| 1642 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1643 |
return err |
| 1644 |
} |
| 1645 |
|
| 1646 |
return nil |
| 1647 |
}, opts...) |
| 1648 |
if e != nil { |
| 1649 |
return nil, e |
| 1650 |
} |
| 1651 |
return resp, nil |
| 1652 |
} |
| 1653 |
|
| 1654 |
// DeleteReservation deletes a reservation. |
| 1655 |
// Returns google.rpc.Code.FAILED_PRECONDITION when reservation has |
| 1656 |
// assignments. |
| 1657 |
func (c *restClient) DeleteReservation(ctx context.Context, req *reservationpb.DeleteReservationRequest, opts ...gax.CallOption) error { |
| 1658 |
baseUrl, err := url.Parse(c.endpoint) |
| 1659 |
if err != nil { |
| 1660 |
return err |
| 1661 |
} |
| 1662 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1663 |
|
| 1664 |
params := url.Values{} |
| 1665 |
params.Add("$alt", "json;enum-encoding=int") |
| 1666 |
|
| 1667 |
baseUrl.RawQuery = params.Encode() |
| 1668 |
|
| 1669 |
// Build HTTP headers from client and context metadata. |
| 1670 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1671 |
|
| 1672 |
hds = append(c.xGoogHeaders, hds...) |
| 1673 |
hds = append(hds, "Content-Type", "application/json") |
| 1674 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1675 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1676 |
if settings.Path != "" { |
| 1677 |
baseUrl.Path = settings.Path |
| 1678 |
} |
| 1679 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 1680 |
if err != nil { |
| 1681 |
return err |
| 1682 |
} |
| 1683 |
httpReq = httpReq.WithContext(ctx) |
| 1684 |
httpReq.Header = headers |
| 1685 |
|
| 1686 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteReservation") |
| 1687 |
return err |
| 1688 |
}, opts...) |
| 1689 |
} |
| 1690 |
|
| 1691 |
// UpdateReservation updates an existing reservation resource. |
| 1692 |
func (c *restClient) UpdateReservation(ctx context.Context, req *reservationpb.UpdateReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1693 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1694 |
body := req.GetReservation() |
| 1695 |
jsonReq, err := m.Marshal(body) |
| 1696 |
if err != nil { |
| 1697 |
return nil, err |
| 1698 |
} |
| 1699 |
|
| 1700 |
baseUrl, err := url.Parse(c.endpoint) |
| 1701 |
if err != nil { |
| 1702 |
return nil, err |
| 1703 |
} |
| 1704 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetReservation().GetName()) |
| 1705 |
|
| 1706 |
params := url.Values{} |
| 1707 |
params.Add("$alt", "json;enum-encoding=int") |
| 1708 |
if req.GetUpdateMask() != nil { |
| 1709 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 1710 |
if err != nil { |
| 1711 |
return nil, err |
| 1712 |
} |
| 1713 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 1714 |
} |
| 1715 |
|
| 1716 |
baseUrl.RawQuery = params.Encode() |
| 1717 |
|
| 1718 |
// Build HTTP headers from client and context metadata. |
| 1719 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "reservation.name", url.QueryEscape(req.GetReservation().GetName()))} |
| 1720 |
|
| 1721 |
hds = append(c.xGoogHeaders, hds...) |
| 1722 |
hds = append(hds, "Content-Type", "application/json") |
| 1723 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1724 |
opts = append((*c.CallOptions).UpdateReservation[0:len((*c.CallOptions).UpdateReservation):len((*c.CallOptions).UpdateReservation)], opts...) |
| 1725 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1726 |
resp := &reservationpb.Reservation{} |
| 1727 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1728 |
if settings.Path != "" { |
| 1729 |
baseUrl.Path = settings.Path |
| 1730 |
} |
| 1731 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1732 |
if err != nil { |
| 1733 |
return err |
| 1734 |
} |
| 1735 |
httpReq = httpReq.WithContext(ctx) |
| 1736 |
httpReq.Header = headers |
| 1737 |
|
| 1738 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateReservation") |
| 1739 |
if err != nil { |
| 1740 |
return err |
| 1741 |
} |
| 1742 |
|
| 1743 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1744 |
return err |
| 1745 |
} |
| 1746 |
|
| 1747 |
return nil |
| 1748 |
}, opts...) |
| 1749 |
if e != nil { |
| 1750 |
return nil, e |
| 1751 |
} |
| 1752 |
return resp, nil |
| 1753 |
} |
| 1754 |
|
| 1755 |
// FailoverReservation fail over a reservation to the secondary location. The operation should be |
| 1756 |
// done in the current secondary location, which will be promoted to the |
| 1757 |
// new primary location for the reservation. |
| 1758 |
// Attempting to failover a reservation in the current primary location will |
| 1759 |
// fail with the error code google.rpc.Code.FAILED_PRECONDITION. |
| 1760 |
func (c *restClient) FailoverReservation(ctx context.Context, req *reservationpb.FailoverReservationRequest, opts ...gax.CallOption) (*reservationpb.Reservation, error) { |
| 1761 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1762 |
jsonReq, err := m.Marshal(req) |
| 1763 |
if err != nil { |
| 1764 |
return nil, err |
| 1765 |
} |
| 1766 |
|
| 1767 |
baseUrl, err := url.Parse(c.endpoint) |
| 1768 |
if err != nil { |
| 1769 |
return nil, err |
| 1770 |
} |
| 1771 |
baseUrl.Path += fmt.Sprintf("/v1/%v:failoverReservation", req.GetName()) |
| 1772 |
|
| 1773 |
params := url.Values{} |
| 1774 |
params.Add("$alt", "json;enum-encoding=int") |
| 1775 |
|
| 1776 |
baseUrl.RawQuery = params.Encode() |
| 1777 |
|
| 1778 |
// Build HTTP headers from client and context metadata. |
| 1779 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1780 |
|
| 1781 |
hds = append(c.xGoogHeaders, hds...) |
| 1782 |
hds = append(hds, "Content-Type", "application/json") |
| 1783 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1784 |
opts = append((*c.CallOptions).FailoverReservation[0:len((*c.CallOptions).FailoverReservation):len((*c.CallOptions).FailoverReservation)], opts...) |
| 1785 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1786 |
resp := &reservationpb.Reservation{} |
| 1787 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1788 |
if settings.Path != "" { |
| 1789 |
baseUrl.Path = settings.Path |
| 1790 |
} |
| 1791 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1792 |
if err != nil { |
| 1793 |
return err |
| 1794 |
} |
| 1795 |
httpReq = httpReq.WithContext(ctx) |
| 1796 |
httpReq.Header = headers |
| 1797 |
|
| 1798 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "FailoverReservation") |
| 1799 |
if err != nil { |
| 1800 |
return err |
| 1801 |
} |
| 1802 |
|
| 1803 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1804 |
return err |
| 1805 |
} |
| 1806 |
|
| 1807 |
return nil |
| 1808 |
}, opts...) |
| 1809 |
if e != nil { |
| 1810 |
return nil, e |
| 1811 |
} |
| 1812 |
return resp, nil |
| 1813 |
} |
| 1814 |
|
| 1815 |
// CreateCapacityCommitment creates a new capacity commitment resource. |
| 1816 |
func (c *restClient) CreateCapacityCommitment(ctx context.Context, req *reservationpb.CreateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 1817 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 1818 |
body := req.GetCapacityCommitment() |
| 1819 |
jsonReq, err := m.Marshal(body) |
| 1820 |
if err != nil { |
| 1821 |
return nil, err |
| 1822 |
} |
| 1823 |
|
| 1824 |
baseUrl, err := url.Parse(c.endpoint) |
| 1825 |
if err != nil { |
| 1826 |
return nil, err |
| 1827 |
} |
| 1828 |
baseUrl.Path += fmt.Sprintf("/v1/%v/capacityCommitments", req.GetParent()) |
| 1829 |
|
| 1830 |
params := url.Values{} |
| 1831 |
params.Add("$alt", "json;enum-encoding=int") |
| 1832 |
if req.GetCapacityCommitmentId() != "" { |
| 1833 |
params.Add("capacityCommitmentId", fmt.Sprintf("%v", req.GetCapacityCommitmentId())) |
| 1834 |
} |
| 1835 |
if req.GetEnforceSingleAdminProjectPerOrg() { |
| 1836 |
params.Add("enforceSingleAdminProjectPerOrg", fmt.Sprintf("%v", req.GetEnforceSingleAdminProjectPerOrg())) |
| 1837 |
} |
| 1838 |
|
| 1839 |
baseUrl.RawQuery = params.Encode() |
| 1840 |
|
| 1841 |
// Build HTTP headers from client and context metadata. |
| 1842 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 1843 |
|
| 1844 |
hds = append(c.xGoogHeaders, hds...) |
| 1845 |
hds = append(hds, "Content-Type", "application/json") |
| 1846 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1847 |
opts = append((*c.CallOptions).CreateCapacityCommitment[0:len((*c.CallOptions).CreateCapacityCommitment):len((*c.CallOptions).CreateCapacityCommitment)], opts...) |
| 1848 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1849 |
resp := &reservationpb.CapacityCommitment{} |
| 1850 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1851 |
if settings.Path != "" { |
| 1852 |
baseUrl.Path = settings.Path |
| 1853 |
} |
| 1854 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 1855 |
if err != nil { |
| 1856 |
return err |
| 1857 |
} |
| 1858 |
httpReq = httpReq.WithContext(ctx) |
| 1859 |
httpReq.Header = headers |
| 1860 |
|
| 1861 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateCapacityCommitment") |
| 1862 |
if err != nil { |
| 1863 |
return err |
| 1864 |
} |
| 1865 |
|
| 1866 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1867 |
return err |
| 1868 |
} |
| 1869 |
|
| 1870 |
return nil |
| 1871 |
}, opts...) |
| 1872 |
if e != nil { |
| 1873 |
return nil, e |
| 1874 |
} |
| 1875 |
return resp, nil |
| 1876 |
} |
| 1877 |
|
| 1878 |
// ListCapacityCommitments lists all the capacity commitments for the admin project. |
| 1879 |
func (c *restClient) ListCapacityCommitments(ctx context.Context, req *reservationpb.ListCapacityCommitmentsRequest, opts ...gax.CallOption) *CapacityCommitmentIterator { |
| 1880 |
it := &CapacityCommitmentIterator{} |
| 1881 |
req = proto.Clone(req).(*reservationpb.ListCapacityCommitmentsRequest) |
| 1882 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1883 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.CapacityCommitment, string, error) { |
| 1884 |
resp := &reservationpb.ListCapacityCommitmentsResponse{} |
| 1885 |
if pageToken != "" { |
| 1886 |
req.PageToken = pageToken |
| 1887 |
} |
| 1888 |
if pageSize > math.MaxInt32 { |
| 1889 |
req.PageSize = math.MaxInt32 |
| 1890 |
} else if pageSize != 0 { |
| 1891 |
req.PageSize = int32(pageSize) |
| 1892 |
} |
| 1893 |
baseUrl, err := url.Parse(c.endpoint) |
| 1894 |
if err != nil { |
| 1895 |
return nil, "", err |
| 1896 |
} |
| 1897 |
baseUrl.Path += fmt.Sprintf("/v1/%v/capacityCommitments", req.GetParent()) |
| 1898 |
|
| 1899 |
params := url.Values{} |
| 1900 |
params.Add("$alt", "json;enum-encoding=int") |
| 1901 |
if req.GetPageSize() != 0 { |
| 1902 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 1903 |
} |
| 1904 |
if req.GetPageToken() != "" { |
| 1905 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 1906 |
} |
| 1907 |
|
| 1908 |
baseUrl.RawQuery = params.Encode() |
| 1909 |
|
| 1910 |
// Build HTTP headers from client and context metadata. |
| 1911 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 1912 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1913 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1914 |
if settings.Path != "" { |
| 1915 |
baseUrl.Path = settings.Path |
| 1916 |
} |
| 1917 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1918 |
if err != nil { |
| 1919 |
return err |
| 1920 |
} |
| 1921 |
httpReq.Header = headers |
| 1922 |
|
| 1923 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCapacityCommitments") |
| 1924 |
if err != nil { |
| 1925 |
return err |
| 1926 |
} |
| 1927 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1928 |
return err |
| 1929 |
} |
| 1930 |
|
| 1931 |
return nil |
| 1932 |
}, opts...) |
| 1933 |
if e != nil { |
| 1934 |
return nil, "", e |
| 1935 |
} |
| 1936 |
it.Response = resp |
| 1937 |
return resp.GetCapacityCommitments(), resp.GetNextPageToken(), nil |
| 1938 |
} |
| 1939 |
|
| 1940 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 1941 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 1942 |
if err != nil { |
| 1943 |
return "", err |
| 1944 |
} |
| 1945 |
it.items = append(it.items, items...) |
| 1946 |
return nextPageToken, nil |
| 1947 |
} |
| 1948 |
|
| 1949 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 1950 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 1951 |
it.pageInfo.Token = req.GetPageToken() |
| 1952 |
|
| 1953 |
return it |
| 1954 |
} |
| 1955 |
|
| 1956 |
// GetCapacityCommitment returns information about the capacity commitment. |
| 1957 |
func (c *restClient) GetCapacityCommitment(ctx context.Context, req *reservationpb.GetCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 1958 |
baseUrl, err := url.Parse(c.endpoint) |
| 1959 |
if err != nil { |
| 1960 |
return nil, err |
| 1961 |
} |
| 1962 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 1963 |
|
| 1964 |
params := url.Values{} |
| 1965 |
params.Add("$alt", "json;enum-encoding=int") |
| 1966 |
|
| 1967 |
baseUrl.RawQuery = params.Encode() |
| 1968 |
|
| 1969 |
// Build HTTP headers from client and context metadata. |
| 1970 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 1971 |
|
| 1972 |
hds = append(c.xGoogHeaders, hds...) |
| 1973 |
hds = append(hds, "Content-Type", "application/json") |
| 1974 |
headers := gax.BuildHeaders(ctx, hds...) |
| 1975 |
opts = append((*c.CallOptions).GetCapacityCommitment[0:len((*c.CallOptions).GetCapacityCommitment):len((*c.CallOptions).GetCapacityCommitment)], opts...) |
| 1976 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 1977 |
resp := &reservationpb.CapacityCommitment{} |
| 1978 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 1979 |
if settings.Path != "" { |
| 1980 |
baseUrl.Path = settings.Path |
| 1981 |
} |
| 1982 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 1983 |
if err != nil { |
| 1984 |
return err |
| 1985 |
} |
| 1986 |
httpReq = httpReq.WithContext(ctx) |
| 1987 |
httpReq.Header = headers |
| 1988 |
|
| 1989 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCapacityCommitment") |
| 1990 |
if err != nil { |
| 1991 |
return err |
| 1992 |
} |
| 1993 |
|
| 1994 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 1995 |
return err |
| 1996 |
} |
| 1997 |
|
| 1998 |
return nil |
| 1999 |
}, opts...) |
| 2000 |
if e != nil { |
| 2001 |
return nil, e |
| 2002 |
} |
| 2003 |
return resp, nil |
| 2004 |
} |
| 2005 |
|
| 2006 |
// DeleteCapacityCommitment deletes a capacity commitment. Attempting to delete capacity commitment |
| 2007 |
// before its commitment_end_time will fail with the error code |
| 2008 |
// google.rpc.Code.FAILED_PRECONDITION. |
| 2009 |
func (c *restClient) DeleteCapacityCommitment(ctx context.Context, req *reservationpb.DeleteCapacityCommitmentRequest, opts ...gax.CallOption) error { |
| 2010 |
baseUrl, err := url.Parse(c.endpoint) |
| 2011 |
if err != nil { |
| 2012 |
return err |
| 2013 |
} |
| 2014 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2015 |
|
| 2016 |
params := url.Values{} |
| 2017 |
params.Add("$alt", "json;enum-encoding=int") |
| 2018 |
if req.GetForce() { |
| 2019 |
params.Add("force", fmt.Sprintf("%v", req.GetForce())) |
| 2020 |
} |
| 2021 |
|
| 2022 |
baseUrl.RawQuery = params.Encode() |
| 2023 |
|
| 2024 |
// Build HTTP headers from client and context metadata. |
| 2025 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2026 |
|
| 2027 |
hds = append(c.xGoogHeaders, hds...) |
| 2028 |
hds = append(hds, "Content-Type", "application/json") |
| 2029 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2030 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2031 |
if settings.Path != "" { |
| 2032 |
baseUrl.Path = settings.Path |
| 2033 |
} |
| 2034 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 2035 |
if err != nil { |
| 2036 |
return err |
| 2037 |
} |
| 2038 |
httpReq = httpReq.WithContext(ctx) |
| 2039 |
httpReq.Header = headers |
| 2040 |
|
| 2041 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCapacityCommitment") |
| 2042 |
return err |
| 2043 |
}, opts...) |
| 2044 |
} |
| 2045 |
|
| 2046 |
// UpdateCapacityCommitment updates an existing capacity commitment. |
| 2047 |
// |
| 2048 |
// Only plan and renewal_plan fields can be updated. |
| 2049 |
// |
| 2050 |
// Plan can only be changed to a plan of a longer commitment period. |
| 2051 |
// Attempting to change to a plan with shorter commitment period will fail |
| 2052 |
// with the error code google.rpc.Code.FAILED_PRECONDITION. |
| 2053 |
func (c *restClient) UpdateCapacityCommitment(ctx context.Context, req *reservationpb.UpdateCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 2054 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2055 |
body := req.GetCapacityCommitment() |
| 2056 |
jsonReq, err := m.Marshal(body) |
| 2057 |
if err != nil { |
| 2058 |
return nil, err |
| 2059 |
} |
| 2060 |
|
| 2061 |
baseUrl, err := url.Parse(c.endpoint) |
| 2062 |
if err != nil { |
| 2063 |
return nil, err |
| 2064 |
} |
| 2065 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetCapacityCommitment().GetName()) |
| 2066 |
|
| 2067 |
params := url.Values{} |
| 2068 |
params.Add("$alt", "json;enum-encoding=int") |
| 2069 |
if req.GetUpdateMask() != nil { |
| 2070 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2071 |
if err != nil { |
| 2072 |
return nil, err |
| 2073 |
} |
| 2074 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2075 |
} |
| 2076 |
|
| 2077 |
baseUrl.RawQuery = params.Encode() |
| 2078 |
|
| 2079 |
// Build HTTP headers from client and context metadata. |
| 2080 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "capacity_commitment.name", url.QueryEscape(req.GetCapacityCommitment().GetName()))} |
| 2081 |
|
| 2082 |
hds = append(c.xGoogHeaders, hds...) |
| 2083 |
hds = append(hds, "Content-Type", "application/json") |
| 2084 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2085 |
opts = append((*c.CallOptions).UpdateCapacityCommitment[0:len((*c.CallOptions).UpdateCapacityCommitment):len((*c.CallOptions).UpdateCapacityCommitment)], opts...) |
| 2086 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2087 |
resp := &reservationpb.CapacityCommitment{} |
| 2088 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2089 |
if settings.Path != "" { |
| 2090 |
baseUrl.Path = settings.Path |
| 2091 |
} |
| 2092 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2093 |
if err != nil { |
| 2094 |
return err |
| 2095 |
} |
| 2096 |
httpReq = httpReq.WithContext(ctx) |
| 2097 |
httpReq.Header = headers |
| 2098 |
|
| 2099 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCapacityCommitment") |
| 2100 |
if err != nil { |
| 2101 |
return err |
| 2102 |
} |
| 2103 |
|
| 2104 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2105 |
return err |
| 2106 |
} |
| 2107 |
|
| 2108 |
return nil |
| 2109 |
}, opts...) |
| 2110 |
if e != nil { |
| 2111 |
return nil, e |
| 2112 |
} |
| 2113 |
return resp, nil |
| 2114 |
} |
| 2115 |
|
| 2116 |
// SplitCapacityCommitment splits capacity commitment to two commitments of the same plan and |
| 2117 |
// commitment_end_time. |
| 2118 |
// |
| 2119 |
// A common use case is to enable downgrading commitments. |
| 2120 |
// |
| 2121 |
// For example, in order to downgrade from 10000 slots to 8000, you might |
| 2122 |
// split a 10000 capacity commitment into commitments of 2000 and 8000. Then, |
| 2123 |
// you delete the first one after the commitment end time passes. |
| 2124 |
func (c *restClient) SplitCapacityCommitment(ctx context.Context, req *reservationpb.SplitCapacityCommitmentRequest, opts ...gax.CallOption) (*reservationpb.SplitCapacityCommitmentResponse, error) { |
| 2125 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2126 |
jsonReq, err := m.Marshal(req) |
| 2127 |
if err != nil { |
| 2128 |
return nil, err |
| 2129 |
} |
| 2130 |
|
| 2131 |
baseUrl, err := url.Parse(c.endpoint) |
| 2132 |
if err != nil { |
| 2133 |
return nil, err |
| 2134 |
} |
| 2135 |
baseUrl.Path += fmt.Sprintf("/v1/%v:split", req.GetName()) |
| 2136 |
|
| 2137 |
params := url.Values{} |
| 2138 |
params.Add("$alt", "json;enum-encoding=int") |
| 2139 |
|
| 2140 |
baseUrl.RawQuery = params.Encode() |
| 2141 |
|
| 2142 |
// Build HTTP headers from client and context metadata. |
| 2143 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2144 |
|
| 2145 |
hds = append(c.xGoogHeaders, hds...) |
| 2146 |
hds = append(hds, "Content-Type", "application/json") |
| 2147 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2148 |
opts = append((*c.CallOptions).SplitCapacityCommitment[0:len((*c.CallOptions).SplitCapacityCommitment):len((*c.CallOptions).SplitCapacityCommitment)], opts...) |
| 2149 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2150 |
resp := &reservationpb.SplitCapacityCommitmentResponse{} |
| 2151 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2152 |
if settings.Path != "" { |
| 2153 |
baseUrl.Path = settings.Path |
| 2154 |
} |
| 2155 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2156 |
if err != nil { |
| 2157 |
return err |
| 2158 |
} |
| 2159 |
httpReq = httpReq.WithContext(ctx) |
| 2160 |
httpReq.Header = headers |
| 2161 |
|
| 2162 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SplitCapacityCommitment") |
| 2163 |
if err != nil { |
| 2164 |
return err |
| 2165 |
} |
| 2166 |
|
| 2167 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2168 |
return err |
| 2169 |
} |
| 2170 |
|
| 2171 |
return nil |
| 2172 |
}, opts...) |
| 2173 |
if e != nil { |
| 2174 |
return nil, e |
| 2175 |
} |
| 2176 |
return resp, nil |
| 2177 |
} |
| 2178 |
|
| 2179 |
// MergeCapacityCommitments merges capacity commitments of the same plan into a single commitment. |
| 2180 |
// |
| 2181 |
// The resulting capacity commitment has the greater commitment_end_time |
| 2182 |
// out of the to-be-merged capacity commitments. |
| 2183 |
// |
| 2184 |
// Attempting to merge capacity commitments of different plan will fail |
| 2185 |
// with the error code google.rpc.Code.FAILED_PRECONDITION. |
| 2186 |
func (c *restClient) MergeCapacityCommitments(ctx context.Context, req *reservationpb.MergeCapacityCommitmentsRequest, opts ...gax.CallOption) (*reservationpb.CapacityCommitment, error) { |
| 2187 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2188 |
jsonReq, err := m.Marshal(req) |
| 2189 |
if err != nil { |
| 2190 |
return nil, err |
| 2191 |
} |
| 2192 |
|
| 2193 |
baseUrl, err := url.Parse(c.endpoint) |
| 2194 |
if err != nil { |
| 2195 |
return nil, err |
| 2196 |
} |
| 2197 |
baseUrl.Path += fmt.Sprintf("/v1/%v/capacityCommitments:merge", req.GetParent()) |
| 2198 |
|
| 2199 |
params := url.Values{} |
| 2200 |
params.Add("$alt", "json;enum-encoding=int") |
| 2201 |
|
| 2202 |
baseUrl.RawQuery = params.Encode() |
| 2203 |
|
| 2204 |
// Build HTTP headers from client and context metadata. |
| 2205 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 2206 |
|
| 2207 |
hds = append(c.xGoogHeaders, hds...) |
| 2208 |
hds = append(hds, "Content-Type", "application/json") |
| 2209 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2210 |
opts = append((*c.CallOptions).MergeCapacityCommitments[0:len((*c.CallOptions).MergeCapacityCommitments):len((*c.CallOptions).MergeCapacityCommitments)], opts...) |
| 2211 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2212 |
resp := &reservationpb.CapacityCommitment{} |
| 2213 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2214 |
if settings.Path != "" { |
| 2215 |
baseUrl.Path = settings.Path |
| 2216 |
} |
| 2217 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2218 |
if err != nil { |
| 2219 |
return err |
| 2220 |
} |
| 2221 |
httpReq = httpReq.WithContext(ctx) |
| 2222 |
httpReq.Header = headers |
| 2223 |
|
| 2224 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "MergeCapacityCommitments") |
| 2225 |
if err != nil { |
| 2226 |
return err |
| 2227 |
} |
| 2228 |
|
| 2229 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2230 |
return err |
| 2231 |
} |
| 2232 |
|
| 2233 |
return nil |
| 2234 |
}, opts...) |
| 2235 |
if e != nil { |
| 2236 |
return nil, e |
| 2237 |
} |
| 2238 |
return resp, nil |
| 2239 |
} |
| 2240 |
|
| 2241 |
// CreateAssignment creates an assignment object which allows the given project to submit jobs |
| 2242 |
// of a certain type using slots from the specified reservation. |
| 2243 |
// |
| 2244 |
// Currently a |
| 2245 |
// resource (project, folder, organization) can only have one assignment per |
| 2246 |
// each (job_type, location) combination, and that reservation will be used |
| 2247 |
// for all jobs of the matching type. |
| 2248 |
// |
| 2249 |
// Different assignments can be created on different levels of the |
| 2250 |
// projects, folders or organization hierarchy. During query execution, |
| 2251 |
// the assignment is looked up at the project, folder and organization levels |
| 2252 |
// in that order. The first assignment found is applied to the query. |
| 2253 |
// |
| 2254 |
// When creating assignments, it does not matter if other assignments exist at |
| 2255 |
// higher levels. |
| 2256 |
// |
| 2257 |
// Example: |
| 2258 |
// |
| 2259 |
// The organization organizationA contains two projects, project1 |
| 2260 |
// and project2. |
| 2261 |
// |
| 2262 |
// Assignments for all three entities (organizationA, project1, and |
| 2263 |
// project2) could all be created and mapped to the same or different |
| 2264 |
// reservations. |
| 2265 |
// |
| 2266 |
// “None” assignments represent an absence of the assignment. Projects |
| 2267 |
// assigned to None use on-demand pricing. To create a “None” assignment, use |
| 2268 |
// “none” as a reservation_id in the parent. Example parent: |
| 2269 |
// projects/myproject/locations/US/reservations/none. |
| 2270 |
// |
| 2271 |
// Returns google.rpc.Code.PERMISSION_DENIED if user does not have |
| 2272 |
// ‘bigquery.admin’ permissions on the project using the reservation |
| 2273 |
// and the project that owns this reservation. |
| 2274 |
// |
| 2275 |
// Returns google.rpc.Code.INVALID_ARGUMENT when location of the assignment |
| 2276 |
// does not match location of the reservation. |
| 2277 |
func (c *restClient) CreateAssignment(ctx context.Context, req *reservationpb.CreateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 2278 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2279 |
body := req.GetAssignment() |
| 2280 |
jsonReq, err := m.Marshal(body) |
| 2281 |
if err != nil { |
| 2282 |
return nil, err |
| 2283 |
} |
| 2284 |
|
| 2285 |
baseUrl, err := url.Parse(c.endpoint) |
| 2286 |
if err != nil { |
| 2287 |
return nil, err |
| 2288 |
} |
| 2289 |
baseUrl.Path += fmt.Sprintf("/v1/%v/assignments", req.GetParent()) |
| 2290 |
|
| 2291 |
params := url.Values{} |
| 2292 |
params.Add("$alt", "json;enum-encoding=int") |
| 2293 |
if req.GetAssignmentId() != "" { |
| 2294 |
params.Add("assignmentId", fmt.Sprintf("%v", req.GetAssignmentId())) |
| 2295 |
} |
| 2296 |
|
| 2297 |
baseUrl.RawQuery = params.Encode() |
| 2298 |
|
| 2299 |
// Build HTTP headers from client and context metadata. |
| 2300 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 2301 |
|
| 2302 |
hds = append(c.xGoogHeaders, hds...) |
| 2303 |
hds = append(hds, "Content-Type", "application/json") |
| 2304 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2305 |
opts = append((*c.CallOptions).CreateAssignment[0:len((*c.CallOptions).CreateAssignment):len((*c.CallOptions).CreateAssignment)], opts...) |
| 2306 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2307 |
resp := &reservationpb.Assignment{} |
| 2308 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2309 |
if settings.Path != "" { |
| 2310 |
baseUrl.Path = settings.Path |
| 2311 |
} |
| 2312 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2313 |
if err != nil { |
| 2314 |
return err |
| 2315 |
} |
| 2316 |
httpReq = httpReq.WithContext(ctx) |
| 2317 |
httpReq.Header = headers |
| 2318 |
|
| 2319 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAssignment") |
| 2320 |
if err != nil { |
| 2321 |
return err |
| 2322 |
} |
| 2323 |
|
| 2324 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2325 |
return err |
| 2326 |
} |
| 2327 |
|
| 2328 |
return nil |
| 2329 |
}, opts...) |
| 2330 |
if e != nil { |
| 2331 |
return nil, e |
| 2332 |
} |
| 2333 |
return resp, nil |
| 2334 |
} |
| 2335 |
|
| 2336 |
// ListAssignments lists assignments. |
| 2337 |
// |
| 2338 |
// Only explicitly created assignments will be returned. |
| 2339 |
// |
| 2340 |
// Example: |
| 2341 |
// |
| 2342 |
// Organization organizationA contains two projects, project1 and |
| 2343 |
// project2. |
| 2344 |
// |
| 2345 |
// Reservation res1 exists and was created previously. |
| 2346 |
// |
| 2347 |
// CreateAssignment was used previously to define the following |
| 2348 |
// associations between entities and reservations: <organizationA, res1> |
| 2349 |
// and <project1, res1> |
| 2350 |
// |
| 2351 |
// In this example, ListAssignments will just return the above two assignments |
| 2352 |
// for reservation res1, and no expansion/merge will happen. |
| 2353 |
// |
| 2354 |
// The wildcard “-” can be used for |
| 2355 |
// reservations in the request. In that case all assignments belongs to the |
| 2356 |
// specified project and location will be listed. |
| 2357 |
// |
| 2358 |
// Note "-" cannot be used for projects nor locations. |
| 2359 |
func (c *restClient) ListAssignments(ctx context.Context, req *reservationpb.ListAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 2360 |
it := &AssignmentIterator{} |
| 2361 |
req = proto.Clone(req).(*reservationpb.ListAssignmentsRequest) |
| 2362 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2363 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) { |
| 2364 |
resp := &reservationpb.ListAssignmentsResponse{} |
| 2365 |
if pageToken != "" { |
| 2366 |
req.PageToken = pageToken |
| 2367 |
} |
| 2368 |
if pageSize > math.MaxInt32 { |
| 2369 |
req.PageSize = math.MaxInt32 |
| 2370 |
} else if pageSize != 0 { |
| 2371 |
req.PageSize = int32(pageSize) |
| 2372 |
} |
| 2373 |
baseUrl, err := url.Parse(c.endpoint) |
| 2374 |
if err != nil { |
| 2375 |
return nil, "", err |
| 2376 |
} |
| 2377 |
baseUrl.Path += fmt.Sprintf("/v1/%v/assignments", req.GetParent()) |
| 2378 |
|
| 2379 |
params := url.Values{} |
| 2380 |
params.Add("$alt", "json;enum-encoding=int") |
| 2381 |
if req.GetPageSize() != 0 { |
| 2382 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2383 |
} |
| 2384 |
if req.GetPageToken() != "" { |
| 2385 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2386 |
} |
| 2387 |
|
| 2388 |
baseUrl.RawQuery = params.Encode() |
| 2389 |
|
| 2390 |
// Build HTTP headers from client and context metadata. |
| 2391 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2392 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2393 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2394 |
if settings.Path != "" { |
| 2395 |
baseUrl.Path = settings.Path |
| 2396 |
} |
| 2397 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2398 |
if err != nil { |
| 2399 |
return err |
| 2400 |
} |
| 2401 |
httpReq.Header = headers |
| 2402 |
|
| 2403 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAssignments") |
| 2404 |
if err != nil { |
| 2405 |
return err |
| 2406 |
} |
| 2407 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2408 |
return err |
| 2409 |
} |
| 2410 |
|
| 2411 |
return nil |
| 2412 |
}, opts...) |
| 2413 |
if e != nil { |
| 2414 |
return nil, "", e |
| 2415 |
} |
| 2416 |
it.Response = resp |
| 2417 |
return resp.GetAssignments(), resp.GetNextPageToken(), nil |
| 2418 |
} |
| 2419 |
|
| 2420 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2421 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2422 |
if err != nil { |
| 2423 |
return "", err |
| 2424 |
} |
| 2425 |
it.items = append(it.items, items...) |
| 2426 |
return nextPageToken, nil |
| 2427 |
} |
| 2428 |
|
| 2429 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2430 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2431 |
it.pageInfo.Token = req.GetPageToken() |
| 2432 |
|
| 2433 |
return it |
| 2434 |
} |
| 2435 |
|
| 2436 |
// DeleteAssignment deletes a assignment. No expansion will happen. |
| 2437 |
// |
| 2438 |
// Example: |
| 2439 |
// |
| 2440 |
// Organization organizationA contains two projects, project1 and |
| 2441 |
// project2. |
| 2442 |
// |
| 2443 |
// Reservation res1 exists and was created previously. |
| 2444 |
// |
| 2445 |
// CreateAssignment was used previously to define the following |
| 2446 |
// associations between entities and reservations: <organizationA, res1> |
| 2447 |
// and <project1, res1> |
| 2448 |
// |
| 2449 |
// In this example, deletion of the <organizationA, res1> assignment won’t |
| 2450 |
// affect the other assignment <project1, res1>. After said deletion, |
| 2451 |
// queries from project1 will still use res1 while queries from |
| 2452 |
// project2 will switch to use on-demand mode. |
| 2453 |
func (c *restClient) DeleteAssignment(ctx context.Context, req *reservationpb.DeleteAssignmentRequest, opts ...gax.CallOption) error { |
| 2454 |
baseUrl, err := url.Parse(c.endpoint) |
| 2455 |
if err != nil { |
| 2456 |
return err |
| 2457 |
} |
| 2458 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2459 |
|
| 2460 |
params := url.Values{} |
| 2461 |
params.Add("$alt", "json;enum-encoding=int") |
| 2462 |
|
| 2463 |
baseUrl.RawQuery = params.Encode() |
| 2464 |
|
| 2465 |
// Build HTTP headers from client and context metadata. |
| 2466 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2467 |
|
| 2468 |
hds = append(c.xGoogHeaders, hds...) |
| 2469 |
hds = append(hds, "Content-Type", "application/json") |
| 2470 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2471 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2472 |
if settings.Path != "" { |
| 2473 |
baseUrl.Path = settings.Path |
| 2474 |
} |
| 2475 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 2476 |
if err != nil { |
| 2477 |
return err |
| 2478 |
} |
| 2479 |
httpReq = httpReq.WithContext(ctx) |
| 2480 |
httpReq.Header = headers |
| 2481 |
|
| 2482 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAssignment") |
| 2483 |
return err |
| 2484 |
}, opts...) |
| 2485 |
} |
| 2486 |
|
| 2487 |
// SearchAssignments deprecated: Looks up assignments for a specified resource for a particular |
| 2488 |
// region. If the request is about a project: |
| 2489 |
// |
| 2490 |
// Assignments created on the project will be returned if they exist. |
| 2491 |
// |
| 2492 |
// Otherwise assignments created on the closest ancestor will be |
| 2493 |
// returned. |
| 2494 |
// |
| 2495 |
// Assignments for different JobTypes will all be returned. |
| 2496 |
// |
| 2497 |
// The same logic applies if the request is about a folder. |
| 2498 |
// |
| 2499 |
// If the request is about an organization, then assignments created on the |
| 2500 |
// organization will be returned (organization doesn’t have ancestors). |
| 2501 |
// |
| 2502 |
// Comparing to ListAssignments, there are some behavior |
| 2503 |
// differences: |
| 2504 |
// |
| 2505 |
// permission on the assignee will be verified in this API. |
| 2506 |
// |
| 2507 |
// Hierarchy lookup (project->folder->organization) happens in this API. |
| 2508 |
// |
| 2509 |
// Parent here is projects/*/locations/*, instead of |
| 2510 |
// projects/*/locations/*reservations/*. |
| 2511 |
// |
| 2512 |
// Note "-" cannot be used for projects |
| 2513 |
// nor locations. |
| 2514 |
// |
| 2515 |
// Deprecated: SearchAssignments may be removed in a future version. |
| 2516 |
func (c *restClient) SearchAssignments(ctx context.Context, req *reservationpb.SearchAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 2517 |
it := &AssignmentIterator{} |
| 2518 |
req = proto.Clone(req).(*reservationpb.SearchAssignmentsRequest) |
| 2519 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2520 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) { |
| 2521 |
resp := &reservationpb.SearchAssignmentsResponse{} |
| 2522 |
if pageToken != "" { |
| 2523 |
req.PageToken = pageToken |
| 2524 |
} |
| 2525 |
if pageSize > math.MaxInt32 { |
| 2526 |
req.PageSize = math.MaxInt32 |
| 2527 |
} else if pageSize != 0 { |
| 2528 |
req.PageSize = int32(pageSize) |
| 2529 |
} |
| 2530 |
baseUrl, err := url.Parse(c.endpoint) |
| 2531 |
if err != nil { |
| 2532 |
return nil, "", err |
| 2533 |
} |
| 2534 |
baseUrl.Path += fmt.Sprintf("/v1/%v:searchAssignments", req.GetParent()) |
| 2535 |
|
| 2536 |
params := url.Values{} |
| 2537 |
params.Add("$alt", "json;enum-encoding=int") |
| 2538 |
if req.GetPageSize() != 0 { |
| 2539 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2540 |
} |
| 2541 |
if req.GetPageToken() != "" { |
| 2542 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2543 |
} |
| 2544 |
if req.GetQuery() != "" { |
| 2545 |
params.Add("query", fmt.Sprintf("%v", req.GetQuery())) |
| 2546 |
} |
| 2547 |
|
| 2548 |
baseUrl.RawQuery = params.Encode() |
| 2549 |
|
| 2550 |
// Build HTTP headers from client and context metadata. |
| 2551 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2552 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2553 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2554 |
if settings.Path != "" { |
| 2555 |
baseUrl.Path = settings.Path |
| 2556 |
} |
| 2557 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2558 |
if err != nil { |
| 2559 |
return err |
| 2560 |
} |
| 2561 |
httpReq.Header = headers |
| 2562 |
|
| 2563 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "SearchAssignments") |
| 2564 |
if err != nil { |
| 2565 |
return err |
| 2566 |
} |
| 2567 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2568 |
return err |
| 2569 |
} |
| 2570 |
|
| 2571 |
return nil |
| 2572 |
}, opts...) |
| 2573 |
if e != nil { |
| 2574 |
return nil, "", e |
| 2575 |
} |
| 2576 |
it.Response = resp |
| 2577 |
return resp.GetAssignments(), resp.GetNextPageToken(), nil |
| 2578 |
} |
| 2579 |
|
| 2580 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2581 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2582 |
if err != nil { |
| 2583 |
return "", err |
| 2584 |
} |
| 2585 |
it.items = append(it.items, items...) |
| 2586 |
return nextPageToken, nil |
| 2587 |
} |
| 2588 |
|
| 2589 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2590 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2591 |
it.pageInfo.Token = req.GetPageToken() |
| 2592 |
|
| 2593 |
return it |
| 2594 |
} |
| 2595 |
|
| 2596 |
// SearchAllAssignments looks up assignments for a specified resource for a particular region. |
| 2597 |
// If the request is about a project: |
| 2598 |
// |
| 2599 |
// Assignments created on the project will be returned if they exist. |
| 2600 |
// |
| 2601 |
// Otherwise assignments created on the closest ancestor will be |
| 2602 |
// returned. |
| 2603 |
// |
| 2604 |
// Assignments for different JobTypes will all be returned. |
| 2605 |
// |
| 2606 |
// The same logic applies if the request is about a folder. |
| 2607 |
// |
| 2608 |
// If the request is about an organization, then assignments created on the |
| 2609 |
// organization will be returned (organization doesn’t have ancestors). |
| 2610 |
// |
| 2611 |
// Comparing to ListAssignments, there are some behavior |
| 2612 |
// differences: |
| 2613 |
// |
| 2614 |
// permission on the assignee will be verified in this API. |
| 2615 |
// |
| 2616 |
// Hierarchy lookup (project->folder->organization) happens in this API. |
| 2617 |
// |
| 2618 |
// Parent here is projects/*/locations/*, instead of |
| 2619 |
// projects/*/locations/*reservations/*. |
| 2620 |
func (c *restClient) SearchAllAssignments(ctx context.Context, req *reservationpb.SearchAllAssignmentsRequest, opts ...gax.CallOption) *AssignmentIterator { |
| 2621 |
it := &AssignmentIterator{} |
| 2622 |
req = proto.Clone(req).(*reservationpb.SearchAllAssignmentsRequest) |
| 2623 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2624 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*reservationpb.Assignment, string, error) { |
| 2625 |
resp := &reservationpb.SearchAllAssignmentsResponse{} |
| 2626 |
if pageToken != "" { |
| 2627 |
req.PageToken = pageToken |
| 2628 |
} |
| 2629 |
if pageSize > math.MaxInt32 { |
| 2630 |
req.PageSize = math.MaxInt32 |
| 2631 |
} else if pageSize != 0 { |
| 2632 |
req.PageSize = int32(pageSize) |
| 2633 |
} |
| 2634 |
baseUrl, err := url.Parse(c.endpoint) |
| 2635 |
if err != nil { |
| 2636 |
return nil, "", err |
| 2637 |
} |
| 2638 |
baseUrl.Path += fmt.Sprintf("/v1/%v:searchAllAssignments", req.GetParent()) |
| 2639 |
|
| 2640 |
params := url.Values{} |
| 2641 |
params.Add("$alt", "json;enum-encoding=int") |
| 2642 |
if req.GetPageSize() != 0 { |
| 2643 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 2644 |
} |
| 2645 |
if req.GetPageToken() != "" { |
| 2646 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 2647 |
} |
| 2648 |
if req.GetQuery() != "" { |
| 2649 |
params.Add("query", fmt.Sprintf("%v", req.GetQuery())) |
| 2650 |
} |
| 2651 |
|
| 2652 |
baseUrl.RawQuery = params.Encode() |
| 2653 |
|
| 2654 |
// Build HTTP headers from client and context metadata. |
| 2655 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 2656 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2657 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2658 |
if settings.Path != "" { |
| 2659 |
baseUrl.Path = settings.Path |
| 2660 |
} |
| 2661 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2662 |
if err != nil { |
| 2663 |
return err |
| 2664 |
} |
| 2665 |
httpReq.Header = headers |
| 2666 |
|
| 2667 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "SearchAllAssignments") |
| 2668 |
if err != nil { |
| 2669 |
return err |
| 2670 |
} |
| 2671 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2672 |
return err |
| 2673 |
} |
| 2674 |
|
| 2675 |
return nil |
| 2676 |
}, opts...) |
| 2677 |
if e != nil { |
| 2678 |
return nil, "", e |
| 2679 |
} |
| 2680 |
it.Response = resp |
| 2681 |
return resp.GetAssignments(), resp.GetNextPageToken(), nil |
| 2682 |
} |
| 2683 |
|
| 2684 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 2685 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 2686 |
if err != nil { |
| 2687 |
return "", err |
| 2688 |
} |
| 2689 |
it.items = append(it.items, items...) |
| 2690 |
return nextPageToken, nil |
| 2691 |
} |
| 2692 |
|
| 2693 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 2694 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 2695 |
it.pageInfo.Token = req.GetPageToken() |
| 2696 |
|
| 2697 |
return it |
| 2698 |
} |
| 2699 |
|
| 2700 |
// MoveAssignment moves an assignment under a new reservation. |
| 2701 |
// |
| 2702 |
// This differs from removing an existing assignment and recreating a new one |
| 2703 |
// by providing a transactional change that ensures an assignee always has an |
| 2704 |
// associated reservation. |
| 2705 |
func (c *restClient) MoveAssignment(ctx context.Context, req *reservationpb.MoveAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 2706 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2707 |
jsonReq, err := m.Marshal(req) |
| 2708 |
if err != nil { |
| 2709 |
return nil, err |
| 2710 |
} |
| 2711 |
|
| 2712 |
baseUrl, err := url.Parse(c.endpoint) |
| 2713 |
if err != nil { |
| 2714 |
return nil, err |
| 2715 |
} |
| 2716 |
baseUrl.Path += fmt.Sprintf("/v1/%v:move", req.GetName()) |
| 2717 |
|
| 2718 |
params := url.Values{} |
| 2719 |
params.Add("$alt", "json;enum-encoding=int") |
| 2720 |
|
| 2721 |
baseUrl.RawQuery = params.Encode() |
| 2722 |
|
| 2723 |
// Build HTTP headers from client and context metadata. |
| 2724 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2725 |
|
| 2726 |
hds = append(c.xGoogHeaders, hds...) |
| 2727 |
hds = append(hds, "Content-Type", "application/json") |
| 2728 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2729 |
opts = append((*c.CallOptions).MoveAssignment[0:len((*c.CallOptions).MoveAssignment):len((*c.CallOptions).MoveAssignment)], opts...) |
| 2730 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2731 |
resp := &reservationpb.Assignment{} |
| 2732 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2733 |
if settings.Path != "" { |
| 2734 |
baseUrl.Path = settings.Path |
| 2735 |
} |
| 2736 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2737 |
if err != nil { |
| 2738 |
return err |
| 2739 |
} |
| 2740 |
httpReq = httpReq.WithContext(ctx) |
| 2741 |
httpReq.Header = headers |
| 2742 |
|
| 2743 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "MoveAssignment") |
| 2744 |
if err != nil { |
| 2745 |
return err |
| 2746 |
} |
| 2747 |
|
| 2748 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2749 |
return err |
| 2750 |
} |
| 2751 |
|
| 2752 |
return nil |
| 2753 |
}, opts...) |
| 2754 |
if e != nil { |
| 2755 |
return nil, e |
| 2756 |
} |
| 2757 |
return resp, nil |
| 2758 |
} |
| 2759 |
|
| 2760 |
// UpdateAssignment updates an existing assignment. |
| 2761 |
// |
| 2762 |
// Only the priority field can be updated. |
| 2763 |
func (c *restClient) UpdateAssignment(ctx context.Context, req *reservationpb.UpdateAssignmentRequest, opts ...gax.CallOption) (*reservationpb.Assignment, error) { |
| 2764 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2765 |
body := req.GetAssignment() |
| 2766 |
jsonReq, err := m.Marshal(body) |
| 2767 |
if err != nil { |
| 2768 |
return nil, err |
| 2769 |
} |
| 2770 |
|
| 2771 |
baseUrl, err := url.Parse(c.endpoint) |
| 2772 |
if err != nil { |
| 2773 |
return nil, err |
| 2774 |
} |
| 2775 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetAssignment().GetName()) |
| 2776 |
|
| 2777 |
params := url.Values{} |
| 2778 |
params.Add("$alt", "json;enum-encoding=int") |
| 2779 |
if req.GetUpdateMask() != nil { |
| 2780 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2781 |
if err != nil { |
| 2782 |
return nil, err |
| 2783 |
} |
| 2784 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2785 |
} |
| 2786 |
|
| 2787 |
baseUrl.RawQuery = params.Encode() |
| 2788 |
|
| 2789 |
// Build HTTP headers from client and context metadata. |
| 2790 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "assignment.name", url.QueryEscape(req.GetAssignment().GetName()))} |
| 2791 |
|
| 2792 |
hds = append(c.xGoogHeaders, hds...) |
| 2793 |
hds = append(hds, "Content-Type", "application/json") |
| 2794 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2795 |
opts = append((*c.CallOptions).UpdateAssignment[0:len((*c.CallOptions).UpdateAssignment):len((*c.CallOptions).UpdateAssignment)], opts...) |
| 2796 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2797 |
resp := &reservationpb.Assignment{} |
| 2798 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2799 |
if settings.Path != "" { |
| 2800 |
baseUrl.Path = settings.Path |
| 2801 |
} |
| 2802 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2803 |
if err != nil { |
| 2804 |
return err |
| 2805 |
} |
| 2806 |
httpReq = httpReq.WithContext(ctx) |
| 2807 |
httpReq.Header = headers |
| 2808 |
|
| 2809 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAssignment") |
| 2810 |
if err != nil { |
| 2811 |
return err |
| 2812 |
} |
| 2813 |
|
| 2814 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2815 |
return err |
| 2816 |
} |
| 2817 |
|
| 2818 |
return nil |
| 2819 |
}, opts...) |
| 2820 |
if e != nil { |
| 2821 |
return nil, e |
| 2822 |
} |
| 2823 |
return resp, nil |
| 2824 |
} |
| 2825 |
|
| 2826 |
// GetBiReservation retrieves a BI reservation. |
| 2827 |
func (c *restClient) GetBiReservation(ctx context.Context, req *reservationpb.GetBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) { |
| 2828 |
baseUrl, err := url.Parse(c.endpoint) |
| 2829 |
if err != nil { |
| 2830 |
return nil, err |
| 2831 |
} |
| 2832 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 2833 |
|
| 2834 |
params := url.Values{} |
| 2835 |
params.Add("$alt", "json;enum-encoding=int") |
| 2836 |
|
| 2837 |
baseUrl.RawQuery = params.Encode() |
| 2838 |
|
| 2839 |
// Build HTTP headers from client and context metadata. |
| 2840 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 2841 |
|
| 2842 |
hds = append(c.xGoogHeaders, hds...) |
| 2843 |
hds = append(hds, "Content-Type", "application/json") |
| 2844 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2845 |
opts = append((*c.CallOptions).GetBiReservation[0:len((*c.CallOptions).GetBiReservation):len((*c.CallOptions).GetBiReservation)], opts...) |
| 2846 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2847 |
resp := &reservationpb.BiReservation{} |
| 2848 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2849 |
if settings.Path != "" { |
| 2850 |
baseUrl.Path = settings.Path |
| 2851 |
} |
| 2852 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 2853 |
if err != nil { |
| 2854 |
return err |
| 2855 |
} |
| 2856 |
httpReq = httpReq.WithContext(ctx) |
| 2857 |
httpReq.Header = headers |
| 2858 |
|
| 2859 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetBiReservation") |
| 2860 |
if err != nil { |
| 2861 |
return err |
| 2862 |
} |
| 2863 |
|
| 2864 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2865 |
return err |
| 2866 |
} |
| 2867 |
|
| 2868 |
return nil |
| 2869 |
}, opts...) |
| 2870 |
if e != nil { |
| 2871 |
return nil, e |
| 2872 |
} |
| 2873 |
return resp, nil |
| 2874 |
} |
| 2875 |
|
| 2876 |
// UpdateBiReservation updates a BI reservation. |
| 2877 |
// |
| 2878 |
// Only fields specified in the field_mask are updated. |
| 2879 |
// |
| 2880 |
// A singleton BI reservation always exists with default size 0. |
| 2881 |
// In order to reserve BI capacity it needs to be updated to an amount |
| 2882 |
// greater than 0. In order to release BI capacity reservation size |
| 2883 |
// must be set to 0. |
| 2884 |
func (c *restClient) UpdateBiReservation(ctx context.Context, req *reservationpb.UpdateBiReservationRequest, opts ...gax.CallOption) (*reservationpb.BiReservation, error) { |
| 2885 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 2886 |
body := req.GetBiReservation() |
| 2887 |
jsonReq, err := m.Marshal(body) |
| 2888 |
if err != nil { |
| 2889 |
return nil, err |
| 2890 |
} |
| 2891 |
|
| 2892 |
baseUrl, err := url.Parse(c.endpoint) |
| 2893 |
if err != nil { |
| 2894 |
return nil, err |
| 2895 |
} |
| 2896 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetBiReservation().GetName()) |
| 2897 |
|
| 2898 |
params := url.Values{} |
| 2899 |
params.Add("$alt", "json;enum-encoding=int") |
| 2900 |
if req.GetUpdateMask() != nil { |
| 2901 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 2902 |
if err != nil { |
| 2903 |
return nil, err |
| 2904 |
} |
| 2905 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 2906 |
} |
| 2907 |
|
| 2908 |
baseUrl.RawQuery = params.Encode() |
| 2909 |
|
| 2910 |
// Build HTTP headers from client and context metadata. |
| 2911 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "bi_reservation.name", url.QueryEscape(req.GetBiReservation().GetName()))} |
| 2912 |
|
| 2913 |
hds = append(c.xGoogHeaders, hds...) |
| 2914 |
hds = append(hds, "Content-Type", "application/json") |
| 2915 |
headers := gax.BuildHeaders(ctx, hds...) |
| 2916 |
opts = append((*c.CallOptions).UpdateBiReservation[0:len((*c.CallOptions).UpdateBiReservation):len((*c.CallOptions).UpdateBiReservation)], opts...) |
| 2917 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 2918 |
resp := &reservationpb.BiReservation{} |
| 2919 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 2920 |
if settings.Path != "" { |
| 2921 |
baseUrl.Path = settings.Path |
| 2922 |
} |
| 2923 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 2924 |
if err != nil { |
| 2925 |
return err |
| 2926 |
} |
| 2927 |
httpReq = httpReq.WithContext(ctx) |
| 2928 |
httpReq.Header = headers |
| 2929 |
|
| 2930 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateBiReservation") |
| 2931 |
if err != nil { |
| 2932 |
return err |
| 2933 |
} |
| 2934 |
|
| 2935 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 2936 |
return err |
| 2937 |
} |
| 2938 |
|
| 2939 |
return nil |
| 2940 |
}, opts...) |
| 2941 |
if e != nil { |
| 2942 |
return nil, e |
| 2943 |
} |
| 2944 |
return resp, nil |
| 2945 |
} |