Skip to content

Commit

Permalink
feat: add support for Cross region backup proto changes (googleapis#691)
Browse files Browse the repository at this point in the history
* Synchronize new proto/yaml changes.

PiperOrigin-RevId: 436114471

Source-Link: googleapis/googleapis@6379d5f

Source-Link: https://github.com/googleapis/googleapis-gen/commit/a59984b4cb711eeb186bca4f5b35adbfe60825df
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTU5OTg0YjRjYjcxMWVlYjE4NmJjYTRmNWIzNWFkYmZlNjA4MjVkZiJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and vi3k6i5 committed Mar 29, 2022
1 parent 11459e1 commit 1c33bdc
Show file tree
Hide file tree
Showing 15 changed files with 1,050 additions and 7 deletions.
6 changes: 6 additions & 0 deletions google/cloud/spanner_admin_database_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from .types.backup import Backup
from .types.backup import BackupInfo
from .types.backup import CopyBackupEncryptionConfig
from .types.backup import CopyBackupMetadata
from .types.backup import CopyBackupRequest
from .types.backup import CreateBackupEncryptionConfig
from .types.backup import CreateBackupMetadata
from .types.backup import CreateBackupRequest
Expand Down Expand Up @@ -60,6 +63,9 @@
"DatabaseAdminAsyncClient",
"Backup",
"BackupInfo",
"CopyBackupEncryptionConfig",
"CopyBackupMetadata",
"CopyBackupRequest",
"CreateBackupEncryptionConfig",
"CreateBackupMetadata",
"CreateBackupRequest",
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/spanner_admin_database_v1/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"grpc": {
"libraryClient": "DatabaseAdminClient",
"rpcs": {
"CopyBackup": {
"methods": [
"copy_backup"
]
},
"CreateBackup": {
"methods": [
"create_backup"
Expand Down Expand Up @@ -105,6 +110,11 @@
"grpc-async": {
"libraryClient": "DatabaseAdminAsyncClient",
"rpcs": {
"CopyBackup": {
"methods": [
"copy_backup"
]
},
"CreateBackup": {
"methods": [
"create_backup"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,168 @@ def sample_create_backup():
# Done; return the response.
return response

async def copy_backup(
self,
request: Union[backup.CopyBackupRequest, dict] = None,
*,
parent: str = None,
backup_id: str = None,
source_backup: str = None,
expire_time: timestamp_pb2.Timestamp = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation_async.AsyncOperation:
r"""Starts copying a Cloud Spanner Backup. The returned backup
[long-running operation][google.longrunning.Operation] will have
a name of the format
``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>``
and can be used to track copying of the backup. The operation is
associated with the destination backup. The
[metadata][google.longrunning.Operation.metadata] field type is
[CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata].
The [response][google.longrunning.Operation.response] field type
is [Backup][google.spanner.admin.database.v1.Backup], if
successful. Cancelling the returned operation will stop the
copying and delete the backup. Concurrent CopyBackup requests
can run on the same source backup.
.. code-block:: python
from google.cloud import spanner_admin_database_v1
def sample_copy_backup():
# Create a client
client = spanner_admin_database_v1.DatabaseAdminClient()
# Initialize request argument(s)
request = spanner_admin_database_v1.CopyBackupRequest(
parent="parent_value",
backup_id="backup_id_value",
source_backup="source_backup_value",
)
# Make the request
operation = client.copy_backup(request=request)
print("Waiting for operation to complete...")
response = operation.result()
# Handle the response
print(response)
Args:
request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]):
The request object. The request for
[CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup].
parent (:class:`str`):
Required. The name of the destination instance that will
contain the backup copy. Values are of the form:
``projects/<project>/instances/<instance>``.
This corresponds to the ``parent`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
backup_id (:class:`str`):
Required. The id of the backup copy. The ``backup_id``
appended to ``parent`` forms the full backup_uri of the
form
``projects/<project>/instances/<instance>/backups/<backup>``.
This corresponds to the ``backup_id`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
source_backup (:class:`str`):
Required. The source backup to be copied. The source
backup needs to be in READY state for it to be copied.
Once CopyBackup is in progress, the source backup cannot
be deleted or cleaned up on expiration until CopyBackup
is finished. Values are of the form:
``projects/<project>/instances/<instance>/backups/<backup>``.
This corresponds to the ``source_backup`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
expire_time (:class:`google.protobuf.timestamp_pb2.Timestamp`):
Required. The expiration time of the backup in
microsecond granularity. The expiration time must be at
least 6 hours and at most 366 days from the
``create_time`` of the source backup. Once the
``expire_time`` has passed, the backup is eligible to be
automatically deleted by Cloud Spanner to free the
resources used by the backup.
This corresponds to the ``expire_time`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.api_core.operation_async.AsyncOperation:
An object representing a long-running operation.
The result type for the operation will be
:class:`google.cloud.spanner_admin_database_v1.types.Backup`
A backup of a Cloud Spanner database.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent, backup_id, source_backup, expire_time])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = backup.CopyBackupRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent
if backup_id is not None:
request.backup_id = backup_id
if source_backup is not None:
request.source_backup = source_backup
if expire_time is not None:
request.expire_time = expire_time

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.copy_backup,
default_timeout=3600.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# Wrap the response in an operation future.
response = operation_async.from_gapic(
response,
self._client._transport.operations_client,
backup.Backup,
metadata_type=backup.CopyBackupMetadata,
)

# Done; return the response.
return response

async def get_backup(
self,
request: Union[backup.GetBackupRequest, dict] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,168 @@ def sample_create_backup():
# Done; return the response.
return response

def copy_backup(
self,
request: Union[backup.CopyBackupRequest, dict] = None,
*,
parent: str = None,
backup_id: str = None,
source_backup: str = None,
expire_time: timestamp_pb2.Timestamp = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation.Operation:
r"""Starts copying a Cloud Spanner Backup. The returned backup
[long-running operation][google.longrunning.Operation] will have
a name of the format
``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>``
and can be used to track copying of the backup. The operation is
associated with the destination backup. The
[metadata][google.longrunning.Operation.metadata] field type is
[CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata].
The [response][google.longrunning.Operation.response] field type
is [Backup][google.spanner.admin.database.v1.Backup], if
successful. Cancelling the returned operation will stop the
copying and delete the backup. Concurrent CopyBackup requests
can run on the same source backup.
.. code-block:: python
from google.cloud import spanner_admin_database_v1
def sample_copy_backup():
# Create a client
client = spanner_admin_database_v1.DatabaseAdminClient()
# Initialize request argument(s)
request = spanner_admin_database_v1.CopyBackupRequest(
parent="parent_value",
backup_id="backup_id_value",
source_backup="source_backup_value",
)
# Make the request
operation = client.copy_backup(request=request)
print("Waiting for operation to complete...")
response = operation.result()
# Handle the response
print(response)
Args:
request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]):
The request object. The request for
[CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup].
parent (str):
Required. The name of the destination instance that will
contain the backup copy. Values are of the form:
``projects/<project>/instances/<instance>``.
This corresponds to the ``parent`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
backup_id (str):
Required. The id of the backup copy. The ``backup_id``
appended to ``parent`` forms the full backup_uri of the
form
``projects/<project>/instances/<instance>/backups/<backup>``.
This corresponds to the ``backup_id`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
source_backup (str):
Required. The source backup to be copied. The source
backup needs to be in READY state for it to be copied.
Once CopyBackup is in progress, the source backup cannot
be deleted or cleaned up on expiration until CopyBackup
is finished. Values are of the form:
``projects/<project>/instances/<instance>/backups/<backup>``.
This corresponds to the ``source_backup`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
expire_time (google.protobuf.timestamp_pb2.Timestamp):
Required. The expiration time of the backup in
microsecond granularity. The expiration time must be at
least 6 hours and at most 366 days from the
``create_time`` of the source backup. Once the
``expire_time`` has passed, the backup is eligible to be
automatically deleted by Cloud Spanner to free the
resources used by the backup.
This corresponds to the ``expire_time`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.api_core.operation.Operation:
An object representing a long-running operation.
The result type for the operation will be
:class:`google.cloud.spanner_admin_database_v1.types.Backup`
A backup of a Cloud Spanner database.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent, backup_id, source_backup, expire_time])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a backup.CopyBackupRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, backup.CopyBackupRequest):
request = backup.CopyBackupRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent
if backup_id is not None:
request.backup_id = backup_id
if source_backup is not None:
request.source_backup = source_backup
if expire_time is not None:
request.expire_time = expire_time

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.copy_backup]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# Wrap the response in an operation future.
response = operation.from_gapic(
response,
self._transport.operations_client,
backup.Backup,
metadata_type=backup.CopyBackupMetadata,
)

# Done; return the response.
return response

def get_backup(
self,
request: Union[backup.GetBackupRequest, dict] = None,
Expand Down
Loading

0 comments on commit 1c33bdc

Please sign in to comment.