-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding helpers to parse Bigtable create cluster operation.
A CreateCluster request response doesn't actual indicate success or failure. Rather it returns a cluster object with the validated request parts inside and a `current_operation` attached. We implement `_process_operation` so that we can determine the ID of that long-running operation (so it can be checked for completion / success, if desired by the user). In addition we seek to notify the user when the request began. From the [service definition][1] we know that the `current_operation` is a [long-running operation][2] and that: > The embedded operation's "metadata" field type is `CreateClusterMetadata`, > The embedded operation's "response" field type is `Cluster`, if successful. The [`Operation` metadata][3] is of type [`Any`][4] (which uses a `type_url` and raw bytes to provide **any** protobuf message type in a single field, but still allow it to be parsed into it's true type after the fact). So we expect `CreateCluster` responses to have long-running operations with a type URL matching [`CreateClusterMetadata`][5]. As a result, we introduce a utility (`_parse_pb_any_to_native`) for parsing an `Any` field into the native protobuf type specified by the type URL. Since we know we need to handle `CreateClusterMetadata` values, we add a default mapping (`_TYPE_URL_MAP`) from the corresponding type url for that message type to the native Python type. The `CreateClusterMetadata` type has `request_time` and `finish_time` fields of type [`Timestamp`][6] so we also add the `_pb_timestamp_to_datetime` helper for converting protobuf messages into native Python `datetime.datetime` objects. [1]: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/8e363d72eb39d921dfdf5daf4a36032aa9d003e2/bigtable-protos/src/main/proto/google/bigtable/admin/cluster/v1/bigtable_cluster_service.proto#L64 [2]: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/8e363d72eb39d921dfdf5daf4a36032aa9d003e2/bigtable-protos/src/main/proto/google/bigtable/admin/cluster/v1/bigtable_cluster_data.proto#L74 [3]: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/8e363d72eb39d921dfdf5daf4a36032aa9d003e2/bigtable-protos/src/main/proto/google/longrunning/operations.proto#L82 [4]: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/8e363d72eb39d921dfdf5daf4a36032aa9d003e2/bigtable-protos/src/main/proto/google/protobuf/any.proto#L58 [5]: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/8e363d72eb39d921dfdf5daf4a36032aa9d003e2/bigtable-protos/src/main/proto/google/bigtable/admin/cluster/v1/bigtable_cluster_service_messages.proto#L83-L92 [6]: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/8e363d72eb39d921dfdf5daf4a36032aa9d003e2/bigtable-protos/src/main/proto/google/protobuf/timestamp.proto#L78
- Loading branch information
Showing
2 changed files
with
265 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters