Skip to content

Commit 1933498

Browse files
yoshi-automationtseaver
authored andcommitted
Add support for instance import / export / failover (via synth). (#7423)
1 parent 2d6a3f8 commit 1933498

9 files changed

Lines changed: 1494 additions & 49 deletions

File tree

redis/google/cloud/redis_v1/gapic/cloud_redis_client.py

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,265 @@ def delete_instance(
642642
empty_pb2.Empty,
643643
metadata_type=cloud_redis_pb2.OperationMetadata,
644644
)
645+
646+
def import_instance(
647+
self,
648+
name,
649+
input_config,
650+
retry=google.api_core.gapic_v1.method.DEFAULT,
651+
timeout=google.api_core.gapic_v1.method.DEFAULT,
652+
metadata=None,
653+
):
654+
"""
655+
Import a Redis RDB snapshot file from GCS into a Redis instance.
656+
657+
Redis may stop serving during this operation. Instance state will be
658+
IMPORTING for entire operation. When complete, the instance will contain
659+
only data from the imported file.
660+
661+
The returned operation is automatically deleted after a few hours, so
662+
there is no need to call DeleteOperation.
663+
664+
Example:
665+
>>> from google.cloud import redis_v1
666+
>>>
667+
>>> client = redis_v1.CloudRedisClient()
668+
>>>
669+
>>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]')
670+
>>>
671+
>>> # TODO: Initialize `input_config`:
672+
>>> input_config = {}
673+
>>>
674+
>>> response = client.import_instance(name, input_config)
675+
>>>
676+
>>> def callback(operation_future):
677+
... # Handle result.
678+
... result = operation_future.result()
679+
>>>
680+
>>> response.add_done_callback(callback)
681+
>>>
682+
>>> # Handle metadata.
683+
>>> metadata = response.metadata()
684+
685+
Args:
686+
name (str): Required. Redis instance resource name using the form:
687+
``projects/{project_id}/locations/{location_id}/instances/{instance_id}``
688+
where ``location_id`` refers to a GCP region
689+
input_config (Union[dict, ~google.cloud.redis_v1.types.InputConfig]): Required. Specify data to be imported.
690+
691+
If a dict is provided, it must be of the same form as the protobuf
692+
message :class:`~google.cloud.redis_v1.types.InputConfig`
693+
retry (Optional[google.api_core.retry.Retry]): A retry object used
694+
to retry requests. If ``None`` is specified, requests will not
695+
be retried.
696+
timeout (Optional[float]): The amount of time, in seconds, to wait
697+
for the request to complete. Note that if ``retry`` is
698+
specified, the timeout applies to each individual attempt.
699+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
700+
that is provided to the method.
701+
702+
Returns:
703+
A :class:`~google.cloud.redis_v1.types._OperationFuture` instance.
704+
705+
Raises:
706+
google.api_core.exceptions.GoogleAPICallError: If the request
707+
failed for any reason.
708+
google.api_core.exceptions.RetryError: If the request failed due
709+
to a retryable error and retry attempts failed.
710+
ValueError: If the parameters are invalid.
711+
"""
712+
# Wrap the transport method to add retry and timeout logic.
713+
if "import_instance" not in self._inner_api_calls:
714+
self._inner_api_calls[
715+
"import_instance"
716+
] = google.api_core.gapic_v1.method.wrap_method(
717+
self.transport.import_instance,
718+
default_retry=self._method_configs["ImportInstance"].retry,
719+
default_timeout=self._method_configs["ImportInstance"].timeout,
720+
client_info=self._client_info,
721+
)
722+
723+
request = cloud_redis_pb2.ImportInstanceRequest(
724+
name=name, input_config=input_config
725+
)
726+
operation = self._inner_api_calls["import_instance"](
727+
request, retry=retry, timeout=timeout, metadata=metadata
728+
)
729+
return google.api_core.operation.from_gapic(
730+
operation,
731+
self.transport._operations_client,
732+
cloud_redis_pb2.Instance,
733+
metadata_type=cloud_redis_pb2.OperationMetadata,
734+
)
735+
736+
def export_instance(
737+
self,
738+
name,
739+
output_config,
740+
retry=google.api_core.gapic_v1.method.DEFAULT,
741+
timeout=google.api_core.gapic_v1.method.DEFAULT,
742+
metadata=None,
743+
):
744+
"""
745+
Export Redis instance data into a Redis RDB format file in GCS.
746+
747+
Redis will continue serving during this operation.
748+
749+
The returned operation is automatically deleted after a few hours, so
750+
there is no need to call DeleteOperation.
751+
752+
Example:
753+
>>> from google.cloud import redis_v1
754+
>>>
755+
>>> client = redis_v1.CloudRedisClient()
756+
>>>
757+
>>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]')
758+
>>>
759+
>>> # TODO: Initialize `output_config`:
760+
>>> output_config = {}
761+
>>>
762+
>>> response = client.export_instance(name, output_config)
763+
>>>
764+
>>> def callback(operation_future):
765+
... # Handle result.
766+
... result = operation_future.result()
767+
>>>
768+
>>> response.add_done_callback(callback)
769+
>>>
770+
>>> # Handle metadata.
771+
>>> metadata = response.metadata()
772+
773+
Args:
774+
name (str): Required. Redis instance resource name using the form:
775+
``projects/{project_id}/locations/{location_id}/instances/{instance_id}``
776+
where ``location_id`` refers to a GCP region
777+
output_config (Union[dict, ~google.cloud.redis_v1.types.OutputConfig]): Required. Specify data to be exported.
778+
779+
If a dict is provided, it must be of the same form as the protobuf
780+
message :class:`~google.cloud.redis_v1.types.OutputConfig`
781+
retry (Optional[google.api_core.retry.Retry]): A retry object used
782+
to retry requests. If ``None`` is specified, requests will not
783+
be retried.
784+
timeout (Optional[float]): The amount of time, in seconds, to wait
785+
for the request to complete. Note that if ``retry`` is
786+
specified, the timeout applies to each individual attempt.
787+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
788+
that is provided to the method.
789+
790+
Returns:
791+
A :class:`~google.cloud.redis_v1.types._OperationFuture` instance.
792+
793+
Raises:
794+
google.api_core.exceptions.GoogleAPICallError: If the request
795+
failed for any reason.
796+
google.api_core.exceptions.RetryError: If the request failed due
797+
to a retryable error and retry attempts failed.
798+
ValueError: If the parameters are invalid.
799+
"""
800+
# Wrap the transport method to add retry and timeout logic.
801+
if "export_instance" not in self._inner_api_calls:
802+
self._inner_api_calls[
803+
"export_instance"
804+
] = google.api_core.gapic_v1.method.wrap_method(
805+
self.transport.export_instance,
806+
default_retry=self._method_configs["ExportInstance"].retry,
807+
default_timeout=self._method_configs["ExportInstance"].timeout,
808+
client_info=self._client_info,
809+
)
810+
811+
request = cloud_redis_pb2.ExportInstanceRequest(
812+
name=name, output_config=output_config
813+
)
814+
operation = self._inner_api_calls["export_instance"](
815+
request, retry=retry, timeout=timeout, metadata=metadata
816+
)
817+
return google.api_core.operation.from_gapic(
818+
operation,
819+
self.transport._operations_client,
820+
cloud_redis_pb2.Instance,
821+
metadata_type=cloud_redis_pb2.OperationMetadata,
822+
)
823+
824+
def failover_instance(
825+
self,
826+
name,
827+
data_protection_mode,
828+
retry=google.api_core.gapic_v1.method.DEFAULT,
829+
timeout=google.api_core.gapic_v1.method.DEFAULT,
830+
metadata=None,
831+
):
832+
"""
833+
Failover the master role to current replica node against a specific
834+
STANDARD tier redis instance.
835+
836+
Example:
837+
>>> from google.cloud import redis_v1
838+
>>> from google.cloud.redis_v1 import enums
839+
>>>
840+
>>> client = redis_v1.CloudRedisClient()
841+
>>>
842+
>>> name = client.instance_path('[PROJECT]', '[LOCATION]', '[INSTANCE]')
843+
>>>
844+
>>> # TODO: Initialize `data_protection_mode`:
845+
>>> data_protection_mode = enums.FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED
846+
>>>
847+
>>> response = client.failover_instance(name, data_protection_mode)
848+
>>>
849+
>>> def callback(operation_future):
850+
... # Handle result.
851+
... result = operation_future.result()
852+
>>>
853+
>>> response.add_done_callback(callback)
854+
>>>
855+
>>> # Handle metadata.
856+
>>> metadata = response.metadata()
857+
858+
Args:
859+
name (str): Required. Redis instance resource name using the form:
860+
``projects/{project_id}/locations/{location_id}/instances/{instance_id}``
861+
where ``location_id`` refers to a GCP region
862+
data_protection_mode (~google.cloud.redis_v1.types.DataProtectionMode): Optional. Available data protection modes that the user can choose. If
863+
it's unspecified, data protection mode will be LIMITED\_DATA\_LOSS by
864+
default.
865+
retry (Optional[google.api_core.retry.Retry]): A retry object used
866+
to retry requests. If ``None`` is specified, requests will not
867+
be retried.
868+
timeout (Optional[float]): The amount of time, in seconds, to wait
869+
for the request to complete. Note that if ``retry`` is
870+
specified, the timeout applies to each individual attempt.
871+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
872+
that is provided to the method.
873+
874+
Returns:
875+
A :class:`~google.cloud.redis_v1.types._OperationFuture` instance.
876+
877+
Raises:
878+
google.api_core.exceptions.GoogleAPICallError: If the request
879+
failed for any reason.
880+
google.api_core.exceptions.RetryError: If the request failed due
881+
to a retryable error and retry attempts failed.
882+
ValueError: If the parameters are invalid.
883+
"""
884+
# Wrap the transport method to add retry and timeout logic.
885+
if "failover_instance" not in self._inner_api_calls:
886+
self._inner_api_calls[
887+
"failover_instance"
888+
] = google.api_core.gapic_v1.method.wrap_method(
889+
self.transport.failover_instance,
890+
default_retry=self._method_configs["FailoverInstance"].retry,
891+
default_timeout=self._method_configs["FailoverInstance"].timeout,
892+
client_info=self._client_info,
893+
)
894+
895+
request = cloud_redis_pb2.FailoverInstanceRequest(
896+
name=name, data_protection_mode=data_protection_mode
897+
)
898+
operation = self._inner_api_calls["failover_instance"](
899+
request, retry=retry, timeout=timeout, metadata=metadata
900+
)
901+
return google.api_core.operation.from_gapic(
902+
operation,
903+
self.transport._operations_client,
904+
cloud_redis_pb2.Instance,
905+
metadata_type=cloud_redis_pb2.OperationMetadata,
906+
)

redis/google/cloud/redis_v1/gapic/cloud_redis_client_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@
4242
"retry_codes_name": "non_idempotent",
4343
"retry_params_name": "default",
4444
},
45+
"ImportInstance": {
46+
"timeout_millis": 60000,
47+
"retry_codes_name": "non_idempotent",
48+
"retry_params_name": "default",
49+
},
50+
"ExportInstance": {
51+
"timeout_millis": 60000,
52+
"retry_codes_name": "non_idempotent",
53+
"retry_params_name": "default",
54+
},
55+
"FailoverInstance": {
56+
"timeout_millis": 60000,
57+
"retry_codes_name": "non_idempotent",
58+
"retry_params_name": "default",
59+
},
4560
},
4661
}
4762
}

redis/google/cloud/redis_v1/gapic/enums.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
import enum
1919

2020

21+
class FailoverInstanceRequest(object):
22+
class DataProtectionMode(enum.IntEnum):
23+
"""
24+
Attributes:
25+
DATA_PROTECTION_MODE_UNSPECIFIED (int)
26+
LIMITED_DATA_LOSS (int): Instance failover will be protected with data loss control. More
27+
specifically, the failover will only be performed if the current
28+
replication offset diff between master and replica is under a certain
29+
threshold.
30+
FORCE_DATA_LOSS (int): Instance failover will be performed without data loss control.
31+
"""
32+
33+
DATA_PROTECTION_MODE_UNSPECIFIED = 0
34+
LIMITED_DATA_LOSS = 1
35+
FORCE_DATA_LOSS = 2
36+
37+
2138
class Instance(object):
2239
class State(enum.IntEnum):
2340
"""
@@ -31,9 +48,10 @@ class State(enum.IntEnum):
3148
may cause the instance to become unusable while the update is in
3249
progress.
3350
DELETING (int): Redis instance is being deleted.
34-
REPAIRING (int): Redis instance is being repaired and may be unusable. Details can be
35-
found in the ``status_message`` field.
51+
REPAIRING (int): Redis instance is being repaired and may be unusable.
3652
MAINTENANCE (int): Maintenance is being performed on this Redis instance.
53+
IMPORTING (int): Redis instance is importing data (availability may be affected).
54+
FAILING_OVER (int): Redis instance is failing over (availability may be affected).
3755
"""
3856

3957
STATE_UNSPECIFIED = 0
@@ -43,6 +61,8 @@ class State(enum.IntEnum):
4361
DELETING = 4
4462
REPAIRING = 5
4563
MAINTENANCE = 6
64+
IMPORTING = 8
65+
FAILING_OVER = 9
4666

4767
class Tier(enum.IntEnum):
4868
"""

redis/google/cloud/redis_v1/gapic/transports/cloud_redis_grpc_transport.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,55 @@ def delete_instance(self):
189189
deserialized response object.
190190
"""
191191
return self._stubs["cloud_redis_stub"].DeleteInstance
192+
193+
@property
194+
def import_instance(self):
195+
"""Return the gRPC stub for :meth:`CloudRedisClient.import_instance`.
196+
197+
Import a Redis RDB snapshot file from GCS into a Redis instance.
198+
199+
Redis may stop serving during this operation. Instance state will be
200+
IMPORTING for entire operation. When complete, the instance will contain
201+
only data from the imported file.
202+
203+
The returned operation is automatically deleted after a few hours, so
204+
there is no need to call DeleteOperation.
205+
206+
Returns:
207+
Callable: A callable which accepts the appropriate
208+
deserialized request object and returns a
209+
deserialized response object.
210+
"""
211+
return self._stubs["cloud_redis_stub"].ImportInstance
212+
213+
@property
214+
def export_instance(self):
215+
"""Return the gRPC stub for :meth:`CloudRedisClient.export_instance`.
216+
217+
Export Redis instance data into a Redis RDB format file in GCS.
218+
219+
Redis will continue serving during this operation.
220+
221+
The returned operation is automatically deleted after a few hours, so
222+
there is no need to call DeleteOperation.
223+
224+
Returns:
225+
Callable: A callable which accepts the appropriate
226+
deserialized request object and returns a
227+
deserialized response object.
228+
"""
229+
return self._stubs["cloud_redis_stub"].ExportInstance
230+
231+
@property
232+
def failover_instance(self):
233+
"""Return the gRPC stub for :meth:`CloudRedisClient.failover_instance`.
234+
235+
Failover the master role to current replica node against a specific
236+
STANDARD tier redis instance.
237+
238+
Returns:
239+
Callable: A callable which accepts the appropriate
240+
deserialized request object and returns a
241+
deserialized response object.
242+
"""
243+
return self._stubs["cloud_redis_stub"].FailoverInstance

0 commit comments

Comments
 (0)