Skip to content

Commit 21b8661

Browse files
authored
Fix missing get_backup method for Dataproc Metastore (#20326)
Found during #19891 fixing (yay! MyPy actually found some real errors). The `get_backup` method was missing in Dataproc Metastore implementation.
1 parent cdaa9a2 commit 21b8661

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

β€Žairflow/providers/google/cloud/hooks/dataproc_metastore.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,53 @@ def get_service(
453453
)
454454
return result
455455

456+
@GoogleBaseHook.fallback_to_default_project_id
457+
def get_backup(
458+
self,
459+
project_id: str,
460+
region: str,
461+
service_id: str,
462+
backup_id: str,
463+
retry: Optional[Retry] = None,
464+
timeout: Optional[float] = None,
465+
metadata: Sequence[Tuple[str, str]] = (),
466+
) -> Backup:
467+
"""
468+
Get backup from a service.
469+
470+
:param project_id: Required. The ID of the Google Cloud project that the service belongs to.
471+
:type project_id: str
472+
:param region: Required. The ID of the Google Cloud region that the service belongs to.
473+
:type region: str
474+
:param service_id: Required. The ID of the metastore service, which is used as the final component of
475+
the metastore service's name. This value must be between 2 and 63 characters long inclusive, begin
476+
with a letter, end with a letter or number, and consist of alphanumeric ASCII characters or
477+
hyphens.
478+
479+
This corresponds to the ``service_id`` field on the ``request`` instance; if ``request`` is
480+
provided, this should not be set.
481+
:type service_id: str
482+
:param backup_id: Required. The ID of the metastore service backup to restore from
483+
:type backup_id: str
484+
:param retry: Designation of what errors, if any, should be retried.
485+
:type retry: google.api_core.retry.Retry
486+
:param timeout: The timeout for this request.
487+
:type timeout: float
488+
:param metadata: Strings which should be sent along with the request as metadata.
489+
:type metadata: Sequence[Tuple[str, str]]
490+
"""
491+
backup = f'projects/{project_id}/locations/{region}/services/{service_id}/backups/{backup_id}'
492+
client = self.get_dataproc_metastore_client()
493+
result = client.get_backup(
494+
request={
495+
'name': backup,
496+
},
497+
retry=retry,
498+
timeout=timeout,
499+
metadata=metadata,
500+
)
501+
return result
502+
456503
@GoogleBaseHook.fallback_to_default_project_id
457504
def list_backups(
458505
self,

β€Žtests/providers/google/cloud/hooks/test_dataproc_metastore.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ def test_create_service(self, mock_client) -> None:
129129
timeout=None,
130130
)
131131

132+
@mock.patch(DATAPROC_METASTORE_STRING.format("DataprocMetastoreHook.get_dataproc_metastore_client"))
133+
def test_get_backup(self, mock_client) -> None:
134+
self.hook.get_backup(
135+
project_id=TEST_PROJECT_ID,
136+
region=TEST_REGION,
137+
service_id=TEST_SERVICE_ID,
138+
backup_id=TEST_BACKUP_ID,
139+
)
140+
mock_client.assert_called_once()
141+
mock_client.return_value.get_backup.assert_called_once_with(
142+
request=dict(
143+
name=TEST_NAME_BACKUPS.format(TEST_PROJECT_ID, TEST_REGION, TEST_SERVICE_ID, TEST_BACKUP_ID),
144+
),
145+
metadata=(),
146+
retry=None,
147+
timeout=None,
148+
)
149+
132150
@mock.patch(DATAPROC_METASTORE_STRING.format("DataprocMetastoreHook.get_dataproc_metastore_client"))
133151
def test_delete_backup(self, mock_client) -> None:
134152
self.hook.delete_backup(

0 commit comments

Comments
 (0)