From dc23e0b5c1c28ae93f20406cc6fa676f55a3a5e5 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:54:02 -0700 Subject: [PATCH] feat(spanner): Add support for Cloud Spanner Scheduled Backups (#7503) PiperOrigin-RevId: 649277844 Source-Link: https://github.com/googleapis/googleapis/commit/fd7efa2da3860e813485e63661d3bdd21fc9ba82 Source-Link: https://github.com/googleapis/googleapis-gen/commit/50be251329d8db5b555626ebd4886721f547d3cc Copy-Tag: eyJwIjoiU3Bhbm5lci8uT3dsQm90LnlhbWwiLCJoIjoiNTBiZTI1MTMyOWQ4ZGI1YjU1NTYyNmViZDQ4ODY3MjFmNTQ3ZDNjYyJ9 --- Spanner/metadata/Admin/Database/V1/Backup.php | Bin 5331 -> 5380 bytes .../Admin/Database/V1/BackupSchedule.php | Bin 0 -> 3113 bytes .../Database/V1/SpannerDatabaseAdmin.php | Bin 11945 -> 13533 bytes Spanner/src/Admin/Database/V1/Backup.php | 62 ++++ .../src/Admin/Database/V1/BackupSchedule.php | 347 +++++++++++++++++ .../Admin/Database/V1/BackupScheduleSpec.php | 75 ++++ .../V1/Client/DatabaseAdminClient.php | 161 ++++++++ .../V1/CreateBackupScheduleRequest.php | 174 +++++++++ Spanner/src/Admin/Database/V1/CrontabSpec.php | 214 +++++++++++ .../V1/DeleteBackupScheduleRequest.php | 92 +++++ .../src/Admin/Database/V1/FullBackupSpec.php | 35 ++ .../V1/Gapic/DatabaseAdminGapicClient.php | 346 +++++++++++++++++ .../Database/V1/GetBackupScheduleRequest.php | 92 +++++ .../V1/ListBackupSchedulesRequest.php | 180 +++++++++ .../V1/ListBackupSchedulesResponse.php | 110 ++++++ .../V1/UpdateBackupScheduleRequest.php | 167 +++++++++ .../database_admin_client_config.json | 25 ++ .../database_admin_descriptor_config.php | 70 ++++ .../database_admin_rest_client_config.php | 79 ++++ .../V1/Client/DatabaseAdminClientTest.php | 350 ++++++++++++++++++ .../Database/V1/DatabaseAdminClientTest.php | 319 ++++++++++++++++ 21 files changed, 2898 insertions(+) create mode 100644 Spanner/metadata/Admin/Database/V1/BackupSchedule.php create mode 100644 Spanner/src/Admin/Database/V1/BackupSchedule.php create mode 100644 Spanner/src/Admin/Database/V1/BackupScheduleSpec.php create mode 100644 Spanner/src/Admin/Database/V1/CreateBackupScheduleRequest.php create mode 100644 Spanner/src/Admin/Database/V1/CrontabSpec.php create mode 100644 Spanner/src/Admin/Database/V1/DeleteBackupScheduleRequest.php create mode 100644 Spanner/src/Admin/Database/V1/FullBackupSpec.php create mode 100644 Spanner/src/Admin/Database/V1/GetBackupScheduleRequest.php create mode 100644 Spanner/src/Admin/Database/V1/ListBackupSchedulesRequest.php create mode 100644 Spanner/src/Admin/Database/V1/ListBackupSchedulesResponse.php create mode 100644 Spanner/src/Admin/Database/V1/UpdateBackupScheduleRequest.php diff --git a/Spanner/metadata/Admin/Database/V1/Backup.php b/Spanner/metadata/Admin/Database/V1/Backup.php index b610f628c7710a42b0e686c9a703228810f5ff09..442563283e244ee86233d87cb370c62d3305d2af 100644 GIT binary patch delta 82 zcmcbt*`l=}ikbPE64zuy7NyDc%nuoNZcb!jWtI|>d+z$2t2z{TfQnv>%MRuf#1n!LGDIEWDd4e%J6 delta 49 zcmZqCx~#b&ikW$-64zuy7NyDc%nuo7ZBAriW!~J%F3rQ?^p}xKB{@HLaw41J=G(%W Fi~xq>4=4Zt diff --git a/Spanner/metadata/Admin/Database/V1/BackupSchedule.php b/Spanner/metadata/Admin/Database/V1/BackupSchedule.php new file mode 100644 index 0000000000000000000000000000000000000000..aa7db7cd3d4736aceb94cdf0605b9a003edca60b GIT binary patch literal 3113 zcmcImQEwYX5XN>0WFwmNkf@tVWNQL(ft+!uK)R43J8n!-+eA%BrRv1#e7AO%ocFGG zdnsw<7bN%}2=T%n0r4yP+*jUsVs>x$Y&W**Mj|gc@9umv`^`7A^VQeUafCj=ZNfj3<_6Zny1h@B__Xu}|jop@L z_CbbbHw2p9QfT&3eG4HkaFYZ#CF+3!Mb8k1zbNel)WZpPIs99ri9;FX)D7rUxZ*bM zx@NxF>?dEMG`Nj5f9^i zIBHov!gFrLO7(_vE8u7sSF;!`>s*lAn8zs@^^S2&cp9@U8Mgo!cGZ~_sWh}C^E(i_8=mj z(L@Vg95N??ALRlrR2Mfl%nW$?#myZsf$ky@zImg$gx=AeMdDQcnnRbyeHoY0oai>v z#X__6yz#ctMsw2Zy!3kW)n3OTg>wN^Ff3$1brL3I?`WROB?)^~!)l^UT_Bn5_vkWV zUVIiwV=rV~+AGgV(_7kfssMlo0-ZaH>vj&aBT+K^yJ)$a27%L29azx(mW2Q8)$qGu zsV*&-WNo#;*nRp}t3!UJz|!!rM|)9#k7Q z9s1n8PiB%t zsq$w5T^miT4)_6ioI;NS;Q7dnL2fDvd;NK%_;2GnTAf0$emjj-WT*>jRvhXNV=fx^ zks>L7s#VN0h^0C98jH*qD-Th*P5AhZzQ)#AMQ+GD*y}T@r1A(|Ymoq|?*9P)rGQrM z(&VMU6CL@*698I?+#W~^h7rm8n^~1!K}fFi@Psf~{!&DR%1@w$iIF5x$P!|Fn@d(_ zGyzqVpo_kC#*8ayiGjAAkw~PRE5AVy-^sF{O!frTWS#uAW00yD=`!Luk~}SLp6@dG zxFD^XKNry&v=iNobS<2FHJk5_-(p`3a{GlxyIv5czBU()sTWQgX`y$)RI9sA)Y%$- z{!#p>EeBY0N8%l1W2`C1SW}mxc~t*fAGB?G(#|JdHS!K;UKn~`6hFyeElZxZECp;? n64|mev}GODJM*#^f4-hiBcEm?<;Vm&b^4Sivl(%K1_=EJyU`SW literal 0 HcmV?d00001 diff --git a/Spanner/metadata/Admin/Database/V1/SpannerDatabaseAdmin.php b/Spanner/metadata/Admin/Database/V1/SpannerDatabaseAdmin.php index b1a561e387ec9a285c3c543c4c4ee0b374e62c2a..adb707cc73e33a74227d9d6fadf7d02eaaeb481b 100644 GIT binary patch delta 1000 zcmZ1(dpC2#1QtH0#N_PKg5czg)RfYk)XDtJT9b8Hq$W>b@n*UfxA`v1az;k8$@f_l z`IEp38-u9Qlh45EOw0`cJIabtOXv#oWMQQ&#ut<8 zlw?^>F)6vg9ayR?I{BHB7jv{y7|e~lC?-zMQ z=B9#eb`-Lod{A8x7?a$3=r#j`S!e<T- zxq`OTe8yXj{6(q7`K3k4sX7JuIho0oO_!fcW@?+Pqu9G$ z>E!uJLCiwmnI?NHXDM|v-EtIxsnID&Ey~R-F3!x)D+a57%c$fsSzpm;GN(%X=A$YB LoSU~8X)*x-EM`Jr diff --git a/Spanner/src/Admin/Database/V1/Backup.php b/Spanner/src/Admin/Database/V1/Backup.php index d1826bc0e8a..2c91b4aa824 100644 --- a/Spanner/src/Admin/Database/V1/Backup.php +++ b/Spanner/src/Admin/Database/V1/Backup.php @@ -143,6 +143,19 @@ class Backup extends \Google\Protobuf\Internal\Message * Generated from protobuf field .google.protobuf.Timestamp max_expire_time = 12 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ private $max_expire_time = null; + /** + * Output only. List of backup schedule URIs that are associated with + * creating this backup. This is only applicable for scheduled backups, and + * is empty for on-demand backups. + * To optimize for storage, whenever possible, multiple schedules are + * collapsed together to create one backup. In such cases, this field captures + * the list of all backup schedule URIs that are associated with creating + * this backup. If collapsing is not done, then this field captures the + * single backup schedule URI associated with creating this backup. + * + * Generated from protobuf field repeated string backup_schedules = 14 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $backup_schedules; /** * Constructor. @@ -226,6 +239,15 @@ class Backup extends \Google\Protobuf\Internal\Message * multiple APIs: CreateBackup, UpdateBackup, CopyBackup. When updating or * copying an existing backup, the expiration time specified must be * less than `Backup.max_expire_time`. + * @type array|\Google\Protobuf\Internal\RepeatedField $backup_schedules + * Output only. List of backup schedule URIs that are associated with + * creating this backup. This is only applicable for scheduled backups, and + * is empty for on-demand backups. + * To optimize for storage, whenever possible, multiple schedules are + * collapsed together to create one backup. In such cases, this field captures + * the list of all backup schedule URIs that are associated with creating + * this backup. If collapsing is not done, then this field captures the + * single backup schedule URI associated with creating this backup. * } */ public function __construct($data = NULL) { @@ -721,5 +743,45 @@ public function setMaxExpireTime($var) return $this; } + /** + * Output only. List of backup schedule URIs that are associated with + * creating this backup. This is only applicable for scheduled backups, and + * is empty for on-demand backups. + * To optimize for storage, whenever possible, multiple schedules are + * collapsed together to create one backup. In such cases, this field captures + * the list of all backup schedule URIs that are associated with creating + * this backup. If collapsing is not done, then this field captures the + * single backup schedule URI associated with creating this backup. + * + * Generated from protobuf field repeated string backup_schedules = 14 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getBackupSchedules() + { + return $this->backup_schedules; + } + + /** + * Output only. List of backup schedule URIs that are associated with + * creating this backup. This is only applicable for scheduled backups, and + * is empty for on-demand backups. + * To optimize for storage, whenever possible, multiple schedules are + * collapsed together to create one backup. In such cases, this field captures + * the list of all backup schedule URIs that are associated with creating + * this backup. If collapsing is not done, then this field captures the + * single backup schedule URI associated with creating this backup. + * + * Generated from protobuf field repeated string backup_schedules = 14 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setBackupSchedules($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->backup_schedules = $arr; + + return $this; + } + } diff --git a/Spanner/src/Admin/Database/V1/BackupSchedule.php b/Spanner/src/Admin/Database/V1/BackupSchedule.php new file mode 100644 index 00000000000..27c363efda4 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/BackupSchedule.php @@ -0,0 +1,347 @@ +google.spanner.admin.database.v1.BackupSchedule + */ +class BackupSchedule extends \Google\Protobuf\Internal\Message +{ + /** + * Identifier. Output only for the + * [CreateBackupSchedule][DatabaseAdmin.CreateBackupSchededule] operation. + * Required for the + * [UpdateBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackupSchedule] + * operation. A globally unique identifier for the backup schedule which + * cannot be changed. Values are of the form + * `projects//instances//databases//backupSchedules/[a-z][a-z0-9_\-]*[a-z0-9]` + * The final segment of the name must be between 2 and 60 characters in + * length. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; + */ + private $name = ''; + /** + * Optional. The schedule specification based on which the backup creations + * are triggered. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupScheduleSpec spec = 6 [(.google.api.field_behavior) = OPTIONAL]; + */ + private $spec = null; + /** + * Optional. The retention duration of a backup that must be at least 6 hours + * and at most 366 days. The backup is eligible to be automatically deleted + * once the retention period has elapsed. + * + * Generated from protobuf field .google.protobuf.Duration retention_duration = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + private $retention_duration = null; + /** + * Optional. The encryption configuration that will be used to encrypt the + * backup. If this field is not specified, the backup will use the same + * encryption configuration as the database. + * + * Generated from protobuf field .google.spanner.admin.database.v1.CreateBackupEncryptionConfig encryption_config = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + private $encryption_config = null; + /** + * Output only. The timestamp at which the schedule was last updated. + * If the schedule has never been updated, this field contains the timestamp + * when the schedule was first created. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $update_time = null; + protected $backup_type_spec; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Identifier. Output only for the + * [CreateBackupSchedule][DatabaseAdmin.CreateBackupSchededule] operation. + * Required for the + * [UpdateBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackupSchedule] + * operation. A globally unique identifier for the backup schedule which + * cannot be changed. Values are of the form + * `projects//instances//databases//backupSchedules/[a-z][a-z0-9_\-]*[a-z0-9]` + * The final segment of the name must be between 2 and 60 characters in + * length. + * @type \Google\Cloud\Spanner\Admin\Database\V1\BackupScheduleSpec $spec + * Optional. The schedule specification based on which the backup creations + * are triggered. + * @type \Google\Protobuf\Duration $retention_duration + * Optional. The retention duration of a backup that must be at least 6 hours + * and at most 366 days. The backup is eligible to be automatically deleted + * once the retention period has elapsed. + * @type \Google\Cloud\Spanner\Admin\Database\V1\CreateBackupEncryptionConfig $encryption_config + * Optional. The encryption configuration that will be used to encrypt the + * backup. If this field is not specified, the backup will use the same + * encryption configuration as the database. + * @type \Google\Cloud\Spanner\Admin\Database\V1\FullBackupSpec $full_backup_spec + * The schedule creates only full backups. + * @type \Google\Protobuf\Timestamp $update_time + * Output only. The timestamp at which the schedule was last updated. + * If the schedule has never been updated, this field contains the timestamp + * when the schedule was first created. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Identifier. Output only for the + * [CreateBackupSchedule][DatabaseAdmin.CreateBackupSchededule] operation. + * Required for the + * [UpdateBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackupSchedule] + * operation. A globally unique identifier for the backup schedule which + * cannot be changed. Values are of the form + * `projects//instances//databases//backupSchedules/[a-z][a-z0-9_\-]*[a-z0-9]` + * The final segment of the name must be between 2 and 60 characters in + * length. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Identifier. Output only for the + * [CreateBackupSchedule][DatabaseAdmin.CreateBackupSchededule] operation. + * Required for the + * [UpdateBackupSchedule][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackupSchedule] + * operation. A globally unique identifier for the backup schedule which + * cannot be changed. Values are of the form + * `projects//instances//databases//backupSchedules/[a-z][a-z0-9_\-]*[a-z0-9]` + * The final segment of the name must be between 2 and 60 characters in + * length. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Optional. The schedule specification based on which the backup creations + * are triggered. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupScheduleSpec spec = 6 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\Spanner\Admin\Database\V1\BackupScheduleSpec|null + */ + public function getSpec() + { + return $this->spec; + } + + public function hasSpec() + { + return isset($this->spec); + } + + public function clearSpec() + { + unset($this->spec); + } + + /** + * Optional. The schedule specification based on which the backup creations + * are triggered. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupScheduleSpec spec = 6 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\Spanner\Admin\Database\V1\BackupScheduleSpec $var + * @return $this + */ + public function setSpec($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Spanner\Admin\Database\V1\BackupScheduleSpec::class); + $this->spec = $var; + + return $this; + } + + /** + * Optional. The retention duration of a backup that must be at least 6 hours + * and at most 366 days. The backup is eligible to be automatically deleted + * once the retention period has elapsed. + * + * Generated from protobuf field .google.protobuf.Duration retention_duration = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Protobuf\Duration|null + */ + public function getRetentionDuration() + { + return $this->retention_duration; + } + + public function hasRetentionDuration() + { + return isset($this->retention_duration); + } + + public function clearRetentionDuration() + { + unset($this->retention_duration); + } + + /** + * Optional. The retention duration of a backup that must be at least 6 hours + * and at most 366 days. The backup is eligible to be automatically deleted + * once the retention period has elapsed. + * + * Generated from protobuf field .google.protobuf.Duration retention_duration = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Protobuf\Duration $var + * @return $this + */ + public function setRetentionDuration($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Duration::class); + $this->retention_duration = $var; + + return $this; + } + + /** + * Optional. The encryption configuration that will be used to encrypt the + * backup. If this field is not specified, the backup will use the same + * encryption configuration as the database. + * + * Generated from protobuf field .google.spanner.admin.database.v1.CreateBackupEncryptionConfig encryption_config = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\Spanner\Admin\Database\V1\CreateBackupEncryptionConfig|null + */ + public function getEncryptionConfig() + { + return $this->encryption_config; + } + + public function hasEncryptionConfig() + { + return isset($this->encryption_config); + } + + public function clearEncryptionConfig() + { + unset($this->encryption_config); + } + + /** + * Optional. The encryption configuration that will be used to encrypt the + * backup. If this field is not specified, the backup will use the same + * encryption configuration as the database. + * + * Generated from protobuf field .google.spanner.admin.database.v1.CreateBackupEncryptionConfig encryption_config = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\Spanner\Admin\Database\V1\CreateBackupEncryptionConfig $var + * @return $this + */ + public function setEncryptionConfig($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Spanner\Admin\Database\V1\CreateBackupEncryptionConfig::class); + $this->encryption_config = $var; + + return $this; + } + + /** + * The schedule creates only full backups. + * + * Generated from protobuf field .google.spanner.admin.database.v1.FullBackupSpec full_backup_spec = 7; + * @return \Google\Cloud\Spanner\Admin\Database\V1\FullBackupSpec|null + */ + public function getFullBackupSpec() + { + return $this->readOneof(7); + } + + public function hasFullBackupSpec() + { + return $this->hasOneof(7); + } + + /** + * The schedule creates only full backups. + * + * Generated from protobuf field .google.spanner.admin.database.v1.FullBackupSpec full_backup_spec = 7; + * @param \Google\Cloud\Spanner\Admin\Database\V1\FullBackupSpec $var + * @return $this + */ + public function setFullBackupSpec($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Spanner\Admin\Database\V1\FullBackupSpec::class); + $this->writeOneof(7, $var); + + return $this; + } + + /** + * Output only. The timestamp at which the schedule was last updated. + * If the schedule has never been updated, this field contains the timestamp + * when the schedule was first created. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getUpdateTime() + { + return $this->update_time; + } + + public function hasUpdateTime() + { + return isset($this->update_time); + } + + public function clearUpdateTime() + { + unset($this->update_time); + } + + /** + * Output only. The timestamp at which the schedule was last updated. + * If the schedule has never been updated, this field contains the timestamp + * when the schedule was first created. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setUpdateTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->update_time = $var; + + return $this; + } + + /** + * @return string + */ + public function getBackupTypeSpec() + { + return $this->whichOneof("backup_type_spec"); + } + +} + diff --git a/Spanner/src/Admin/Database/V1/BackupScheduleSpec.php b/Spanner/src/Admin/Database/V1/BackupScheduleSpec.php new file mode 100644 index 00000000000..b78eef7af97 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/BackupScheduleSpec.php @@ -0,0 +1,75 @@ +google.spanner.admin.database.v1.BackupScheduleSpec + */ +class BackupScheduleSpec extends \Google\Protobuf\Internal\Message +{ + protected $schedule_spec; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\Spanner\Admin\Database\V1\CrontabSpec $cron_spec + * Cron style schedule specification. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Cron style schedule specification. + * + * Generated from protobuf field .google.spanner.admin.database.v1.CrontabSpec cron_spec = 1; + * @return \Google\Cloud\Spanner\Admin\Database\V1\CrontabSpec|null + */ + public function getCronSpec() + { + return $this->readOneof(1); + } + + public function hasCronSpec() + { + return $this->hasOneof(1); + } + + /** + * Cron style schedule specification. + * + * Generated from protobuf field .google.spanner.admin.database.v1.CrontabSpec cron_spec = 1; + * @param \Google\Cloud\Spanner\Admin\Database\V1\CrontabSpec $var + * @return $this + */ + public function setCronSpec($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Spanner\Admin\Database\V1\CrontabSpec::class); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * @return string + */ + public function getScheduleSpec() + { + return $this->whichOneof("schedule_spec"); + } + +} + diff --git a/Spanner/src/Admin/Database/V1/Client/DatabaseAdminClient.php b/Spanner/src/Admin/Database/V1/Client/DatabaseAdminClient.php index 5d64a5653f5..05ea952d580 100644 --- a/Spanner/src/Admin/Database/V1/Client/DatabaseAdminClient.php +++ b/Spanner/src/Admin/Database/V1/Client/DatabaseAdminClient.php @@ -42,20 +42,25 @@ use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; use Google\Cloud\Spanner\Admin\Database\V1\Backup; +use Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule; use Google\Cloud\Spanner\Admin\Database\V1\CopyBackupMetadata; use Google\Cloud\Spanner\Admin\Database\V1\CopyBackupRequest; use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupMetadata; use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseMetadata; use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\Database; use Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\DropDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\GetBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlResponse; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsRequest; +use Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupsRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseOperationsRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseRolesRequest; @@ -63,6 +68,7 @@ use Google\Cloud\Spanner\Admin\Database\V1\RestoreDatabaseMetadata; use Google\Cloud\Spanner\Admin\Database\V1\RestoreDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlMetadata; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseMetadata; @@ -90,14 +96,18 @@ * * @method PromiseInterface copyBackupAsync(CopyBackupRequest $request, array $optionalArgs = []) * @method PromiseInterface createBackupAsync(CreateBackupRequest $request, array $optionalArgs = []) + * @method PromiseInterface createBackupScheduleAsync(CreateBackupScheduleRequest $request, array $optionalArgs = []) * @method PromiseInterface createDatabaseAsync(CreateDatabaseRequest $request, array $optionalArgs = []) * @method PromiseInterface deleteBackupAsync(DeleteBackupRequest $request, array $optionalArgs = []) + * @method PromiseInterface deleteBackupScheduleAsync(DeleteBackupScheduleRequest $request, array $optionalArgs = []) * @method PromiseInterface dropDatabaseAsync(DropDatabaseRequest $request, array $optionalArgs = []) * @method PromiseInterface getBackupAsync(GetBackupRequest $request, array $optionalArgs = []) + * @method PromiseInterface getBackupScheduleAsync(GetBackupScheduleRequest $request, array $optionalArgs = []) * @method PromiseInterface getDatabaseAsync(GetDatabaseRequest $request, array $optionalArgs = []) * @method PromiseInterface getDatabaseDdlAsync(GetDatabaseDdlRequest $request, array $optionalArgs = []) * @method PromiseInterface getIamPolicyAsync(GetIamPolicyRequest $request, array $optionalArgs = []) * @method PromiseInterface listBackupOperationsAsync(ListBackupOperationsRequest $request, array $optionalArgs = []) + * @method PromiseInterface listBackupSchedulesAsync(ListBackupSchedulesRequest $request, array $optionalArgs = []) * @method PromiseInterface listBackupsAsync(ListBackupsRequest $request, array $optionalArgs = []) * @method PromiseInterface listDatabaseOperationsAsync(ListDatabaseOperationsRequest $request, array $optionalArgs = []) * @method PromiseInterface listDatabaseRolesAsync(ListDatabaseRolesRequest $request, array $optionalArgs = []) @@ -106,6 +116,7 @@ * @method PromiseInterface setIamPolicyAsync(SetIamPolicyRequest $request, array $optionalArgs = []) * @method PromiseInterface testIamPermissionsAsync(TestIamPermissionsRequest $request, array $optionalArgs = []) * @method PromiseInterface updateBackupAsync(UpdateBackupRequest $request, array $optionalArgs = []) + * @method PromiseInterface updateBackupScheduleAsync(UpdateBackupScheduleRequest $request, array $optionalArgs = []) * @method PromiseInterface updateDatabaseAsync(UpdateDatabaseRequest $request, array $optionalArgs = []) * @method PromiseInterface updateDatabaseDdlAsync(UpdateDatabaseDdlRequest $request, array $optionalArgs = []) */ @@ -208,6 +219,27 @@ public static function backupName(string $project, string $instance, string $bac ]); } + /** + * Formats a string containing the fully-qualified path to represent a + * backup_schedule resource. + * + * @param string $project + * @param string $instance + * @param string $database + * @param string $schedule + * + * @return string The formatted backup_schedule resource. + */ + public static function backupScheduleName(string $project, string $instance, string $database, string $schedule): string + { + return self::getPathTemplate('backupSchedule')->render([ + 'project' => $project, + 'instance' => $instance, + 'database' => $database, + 'schedule' => $schedule, + ]); + } + /** * Formats a string containing the fully-qualified path to represent a crypto_key * resource. @@ -293,6 +325,7 @@ public static function instanceName(string $project, string $instance): string * The following name formats are supported: * Template: Pattern * - backup: projects/{project}/instances/{instance}/backups/{backup} + * - backupSchedule: projects/{project}/instances/{instance}/databases/{database}/backupSchedules/{schedule} * - cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key} * - cryptoKeyVersion: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version} * - database: projects/{project}/instances/{instance}/databases/{database} @@ -468,6 +501,32 @@ public function createBackup(CreateBackupRequest $request, array $callOptions = return $this->startApiCall('CreateBackup', $request, $callOptions)->wait(); } + /** + * Creates a new backup schedule. + * + * The async variant is {@see DatabaseAdminClient::createBackupScheduleAsync()} . + * + * @example samples/V1/DatabaseAdminClient/create_backup_schedule.php + * + * @param CreateBackupScheduleRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return BackupSchedule + * + * @throws ApiException Thrown if the API call fails. + */ + public function createBackupSchedule(CreateBackupScheduleRequest $request, array $callOptions = []): BackupSchedule + { + return $this->startApiCall('CreateBackupSchedule', $request, $callOptions)->wait(); + } + /** * Creates a new Cloud Spanner database and starts to prepare it for serving. * The returned [long-running operation][google.longrunning.Operation] will @@ -526,6 +585,30 @@ public function deleteBackup(DeleteBackupRequest $request, array $callOptions = $this->startApiCall('DeleteBackup', $request, $callOptions)->wait(); } + /** + * Deletes a backup schedule. + * + * The async variant is {@see DatabaseAdminClient::deleteBackupScheduleAsync()} . + * + * @example samples/V1/DatabaseAdminClient/delete_backup_schedule.php + * + * @param DeleteBackupScheduleRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteBackupSchedule(DeleteBackupScheduleRequest $request, array $callOptions = []): void + { + $this->startApiCall('DeleteBackupSchedule', $request, $callOptions)->wait(); + } + /** * Drops (aka deletes) a Cloud Spanner database. * Completed backups for the database will be retained according to their @@ -581,6 +664,32 @@ public function getBackup(GetBackupRequest $request, array $callOptions = []): B return $this->startApiCall('GetBackup', $request, $callOptions)->wait(); } + /** + * Gets backup schedule for the input schedule name. + * + * The async variant is {@see DatabaseAdminClient::getBackupScheduleAsync()} . + * + * @example samples/V1/DatabaseAdminClient/get_backup_schedule.php + * + * @param GetBackupScheduleRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return BackupSchedule + * + * @throws ApiException Thrown if the API call fails. + */ + public function getBackupSchedule(GetBackupScheduleRequest $request, array $callOptions = []): BackupSchedule + { + return $this->startApiCall('GetBackupSchedule', $request, $callOptions)->wait(); + } + /** * Gets the state of a Cloud Spanner database. * @@ -703,6 +812,32 @@ public function listBackupOperations(ListBackupOperationsRequest $request, array return $this->startApiCall('ListBackupOperations', $request, $callOptions); } + /** + * Lists all the backup schedules for the database. + * + * The async variant is {@see DatabaseAdminClient::listBackupSchedulesAsync()} . + * + * @example samples/V1/DatabaseAdminClient/list_backup_schedules.php + * + * @param ListBackupSchedulesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listBackupSchedules(ListBackupSchedulesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListBackupSchedules', $request, $callOptions); + } + /** * Lists completed and pending backups. * Backups returned are ordered by `create_time` in descending order, @@ -952,6 +1087,32 @@ public function updateBackup(UpdateBackupRequest $request, array $callOptions = return $this->startApiCall('UpdateBackup', $request, $callOptions)->wait(); } + /** + * Updates a backup schedule. + * + * The async variant is {@see DatabaseAdminClient::updateBackupScheduleAsync()} . + * + * @example samples/V1/DatabaseAdminClient/update_backup_schedule.php + * + * @param UpdateBackupScheduleRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return BackupSchedule + * + * @throws ApiException Thrown if the API call fails. + */ + public function updateBackupSchedule(UpdateBackupScheduleRequest $request, array $callOptions = []): BackupSchedule + { + return $this->startApiCall('UpdateBackupSchedule', $request, $callOptions)->wait(); + } + /** * Updates a Cloud Spanner database. The returned * [long-running operation][google.longrunning.Operation] can be used to track diff --git a/Spanner/src/Admin/Database/V1/CreateBackupScheduleRequest.php b/Spanner/src/Admin/Database/V1/CreateBackupScheduleRequest.php new file mode 100644 index 00000000000..305a447b4b2 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/CreateBackupScheduleRequest.php @@ -0,0 +1,174 @@ +google.spanner.admin.database.v1.CreateBackupScheduleRequest + */ +class CreateBackupScheduleRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the database that this backup schedule applies to. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $parent = ''; + /** + * Required. The Id to use for the backup schedule. The `backup_schedule_id` + * appended to `parent` forms the full backup schedule name of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string backup_schedule_id = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $backup_schedule_id = ''; + /** + * Required. The backup schedule to create. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupSchedule backup_schedule = 3 [(.google.api.field_behavior) = REQUIRED]; + */ + private $backup_schedule = null; + + /** + * @param string $parent Required. The name of the database that this backup schedule applies to. Please see + * {@see DatabaseAdminClient::databaseName()} for help formatting this field. + * @param \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $backupSchedule Required. The backup schedule to create. + * @param string $backupScheduleId Required. The Id to use for the backup schedule. The `backup_schedule_id` + * appended to `parent` forms the full backup schedule name of the form + * `projects//instances//databases//backupSchedules/`. + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\CreateBackupScheduleRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $backupSchedule, string $backupScheduleId): self + { + return (new self()) + ->setParent($parent) + ->setBackupSchedule($backupSchedule) + ->setBackupScheduleId($backupScheduleId); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The name of the database that this backup schedule applies to. + * @type string $backup_schedule_id + * Required. The Id to use for the backup schedule. The `backup_schedule_id` + * appended to `parent` forms the full backup schedule name of the form + * `projects//instances//databases//backupSchedules/`. + * @type \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $backup_schedule + * Required. The backup schedule to create. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the database that this backup schedule applies to. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The name of the database that this backup schedule applies to. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * Required. The Id to use for the backup schedule. The `backup_schedule_id` + * appended to `parent` forms the full backup schedule name of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string backup_schedule_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getBackupScheduleId() + { + return $this->backup_schedule_id; + } + + /** + * Required. The Id to use for the backup schedule. The `backup_schedule_id` + * appended to `parent` forms the full backup schedule name of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string backup_schedule_id = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setBackupScheduleId($var) + { + GPBUtil::checkString($var, True); + $this->backup_schedule_id = $var; + + return $this; + } + + /** + * Required. The backup schedule to create. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupSchedule backup_schedule = 3 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule|null + */ + public function getBackupSchedule() + { + return $this->backup_schedule; + } + + public function hasBackupSchedule() + { + return isset($this->backup_schedule); + } + + public function clearBackupSchedule() + { + unset($this->backup_schedule); + } + + /** + * Required. The backup schedule to create. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupSchedule backup_schedule = 3 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $var + * @return $this + */ + public function setBackupSchedule($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule::class); + $this->backup_schedule = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/CrontabSpec.php b/Spanner/src/Admin/Database/V1/CrontabSpec.php new file mode 100644 index 00000000000..6e5d7ca01b6 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/CrontabSpec.php @@ -0,0 +1,214 @@ +google.spanner.admin.database.v1.CrontabSpec + */ +class CrontabSpec extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Textual representation of the crontab. User can customize the + * backup frequency and the backup version time using the cron + * expression. The version time must be in UTC timzeone. + * The backup will contain an externally consistent copy of the + * database at the version time. Allowed frequencies are 12 hour, 1 day, + * 1 week and 1 month. Examples of valid cron specifications: + * * `0 2/12 * * * ` : every 12 hours at (2, 14) hours past midnight in UTC. + * * `0 2,14 * * * ` : every 12 hours at (2,14) hours past midnight in UTC. + * * `0 2 * * * ` : once a day at 2 past midnight in UTC. + * * `0 2 * * 0 ` : once a week every Sunday at 2 past midnight in UTC. + * * `0 2 8 * * ` : once a month on 8th day at 2 past midnight in UTC. + * + * Generated from protobuf field string text = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $text = ''; + /** + * Output only. The time zone of the times in `CrontabSpec.text`. Currently + * only UTC is supported. + * + * Generated from protobuf field string time_zone = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $time_zone = ''; + /** + * Output only. Schedule backups will contain an externally consistent copy + * of the database at the version time specified in + * `schedule_spec.cron_spec`. However, Spanner may not initiate the creation + * of the scheduled backups at that version time. Spanner will initiate + * the creation of scheduled backups within the time window bounded by the + * version_time specified in `schedule_spec.cron_spec` and version_time + + * `creation_window`. + * + * Generated from protobuf field .google.protobuf.Duration creation_window = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $creation_window = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $text + * Required. Textual representation of the crontab. User can customize the + * backup frequency and the backup version time using the cron + * expression. The version time must be in UTC timzeone. + * The backup will contain an externally consistent copy of the + * database at the version time. Allowed frequencies are 12 hour, 1 day, + * 1 week and 1 month. Examples of valid cron specifications: + * * `0 2/12 * * * ` : every 12 hours at (2, 14) hours past midnight in UTC. + * * `0 2,14 * * * ` : every 12 hours at (2,14) hours past midnight in UTC. + * * `0 2 * * * ` : once a day at 2 past midnight in UTC. + * * `0 2 * * 0 ` : once a week every Sunday at 2 past midnight in UTC. + * * `0 2 8 * * ` : once a month on 8th day at 2 past midnight in UTC. + * @type string $time_zone + * Output only. The time zone of the times in `CrontabSpec.text`. Currently + * only UTC is supported. + * @type \Google\Protobuf\Duration $creation_window + * Output only. Schedule backups will contain an externally consistent copy + * of the database at the version time specified in + * `schedule_spec.cron_spec`. However, Spanner may not initiate the creation + * of the scheduled backups at that version time. Spanner will initiate + * the creation of scheduled backups within the time window bounded by the + * version_time specified in `schedule_spec.cron_spec` and version_time + + * `creation_window`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Required. Textual representation of the crontab. User can customize the + * backup frequency and the backup version time using the cron + * expression. The version time must be in UTC timzeone. + * The backup will contain an externally consistent copy of the + * database at the version time. Allowed frequencies are 12 hour, 1 day, + * 1 week and 1 month. Examples of valid cron specifications: + * * `0 2/12 * * * ` : every 12 hours at (2, 14) hours past midnight in UTC. + * * `0 2,14 * * * ` : every 12 hours at (2,14) hours past midnight in UTC. + * * `0 2 * * * ` : once a day at 2 past midnight in UTC. + * * `0 2 * * 0 ` : once a week every Sunday at 2 past midnight in UTC. + * * `0 2 8 * * ` : once a month on 8th day at 2 past midnight in UTC. + * + * Generated from protobuf field string text = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * Required. Textual representation of the crontab. User can customize the + * backup frequency and the backup version time using the cron + * expression. The version time must be in UTC timzeone. + * The backup will contain an externally consistent copy of the + * database at the version time. Allowed frequencies are 12 hour, 1 day, + * 1 week and 1 month. Examples of valid cron specifications: + * * `0 2/12 * * * ` : every 12 hours at (2, 14) hours past midnight in UTC. + * * `0 2,14 * * * ` : every 12 hours at (2,14) hours past midnight in UTC. + * * `0 2 * * * ` : once a day at 2 past midnight in UTC. + * * `0 2 * * 0 ` : once a week every Sunday at 2 past midnight in UTC. + * * `0 2 8 * * ` : once a month on 8th day at 2 past midnight in UTC. + * + * Generated from protobuf field string text = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setText($var) + { + GPBUtil::checkString($var, True); + $this->text = $var; + + return $this; + } + + /** + * Output only. The time zone of the times in `CrontabSpec.text`. Currently + * only UTC is supported. + * + * Generated from protobuf field string time_zone = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getTimeZone() + { + return $this->time_zone; + } + + /** + * Output only. The time zone of the times in `CrontabSpec.text`. Currently + * only UTC is supported. + * + * Generated from protobuf field string time_zone = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setTimeZone($var) + { + GPBUtil::checkString($var, True); + $this->time_zone = $var; + + return $this; + } + + /** + * Output only. Schedule backups will contain an externally consistent copy + * of the database at the version time specified in + * `schedule_spec.cron_spec`. However, Spanner may not initiate the creation + * of the scheduled backups at that version time. Spanner will initiate + * the creation of scheduled backups within the time window bounded by the + * version_time specified in `schedule_spec.cron_spec` and version_time + + * `creation_window`. + * + * Generated from protobuf field .google.protobuf.Duration creation_window = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Duration|null + */ + public function getCreationWindow() + { + return $this->creation_window; + } + + public function hasCreationWindow() + { + return isset($this->creation_window); + } + + public function clearCreationWindow() + { + unset($this->creation_window); + } + + /** + * Output only. Schedule backups will contain an externally consistent copy + * of the database at the version time specified in + * `schedule_spec.cron_spec`. However, Spanner may not initiate the creation + * of the scheduled backups at that version time. Spanner will initiate + * the creation of scheduled backups within the time window bounded by the + * version_time specified in `schedule_spec.cron_spec` and version_time + + * `creation_window`. + * + * Generated from protobuf field .google.protobuf.Duration creation_window = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Duration $var + * @return $this + */ + public function setCreationWindow($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Duration::class); + $this->creation_window = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/DeleteBackupScheduleRequest.php b/Spanner/src/Admin/Database/V1/DeleteBackupScheduleRequest.php new file mode 100644 index 00000000000..d6820f0d8e9 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/DeleteBackupScheduleRequest.php @@ -0,0 +1,92 @@ +google.spanner.admin.database.v1.DeleteBackupScheduleRequest + */ +class DeleteBackupScheduleRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the schedule to delete. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + + /** + * @param string $name Required. The name of the schedule to delete. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. Please see + * {@see DatabaseAdminClient::backupScheduleName()} for help formatting this field. + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupScheduleRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the schedule to delete. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the schedule to delete. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The name of the schedule to delete. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/FullBackupSpec.php b/Spanner/src/Admin/Database/V1/FullBackupSpec.php new file mode 100644 index 00000000000..3edbb8d4fd2 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/FullBackupSpec.php @@ -0,0 +1,35 @@ +google.spanner.admin.database.v1.FullBackupSpec + */ +class FullBackupSpec extends \Google\Protobuf\Internal\Message +{ + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\Backup::initOnce(); + parent::__construct($data); + } + +} + diff --git a/Spanner/src/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php b/Spanner/src/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php index 228f9323bbb..1d5b0bbae64 100644 --- a/Spanner/src/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php +++ b/Spanner/src/Admin/Database/V1/Gapic/DatabaseAdminGapicClient.php @@ -42,24 +42,30 @@ use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; use Google\Cloud\Spanner\Admin\Database\V1\Backup; +use Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule; use Google\Cloud\Spanner\Admin\Database\V1\CopyBackupEncryptionConfig; use Google\Cloud\Spanner\Admin\Database\V1\CopyBackupMetadata; use Google\Cloud\Spanner\Admin\Database\V1\CopyBackupRequest; use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupEncryptionConfig; use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupMetadata; use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseMetadata; use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\Database; use Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\DropDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\EncryptionConfig; use Google\Cloud\Spanner\Admin\Database\V1\GetBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\GetBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlResponse; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsResponse; +use Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesRequest; +use Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupsRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupsResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseOperationsRequest; @@ -72,6 +78,7 @@ use Google\Cloud\Spanner\Admin\Database\V1\RestoreDatabaseMetadata; use Google\Cloud\Spanner\Admin\Database\V1\RestoreDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlMetadata; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseMetadata; @@ -169,6 +176,8 @@ class DatabaseAdminGapicClient private static $backupNameTemplate; + private static $backupScheduleNameTemplate; + private static $cryptoKeyNameTemplate; private static $cryptoKeyVersionNameTemplate; @@ -217,6 +226,17 @@ private static function getBackupNameTemplate() return self::$backupNameTemplate; } + private static function getBackupScheduleNameTemplate() + { + if (self::$backupScheduleNameTemplate == null) { + self::$backupScheduleNameTemplate = new PathTemplate( + 'projects/{project}/instances/{instance}/databases/{database}/backupSchedules/{schedule}' + ); + } + + return self::$backupScheduleNameTemplate; + } + private static function getCryptoKeyNameTemplate() { if (self::$cryptoKeyNameTemplate == null) { @@ -266,6 +286,7 @@ private static function getPathTemplateMap() if (self::$pathTemplateMap == null) { self::$pathTemplateMap = [ 'backup' => self::getBackupNameTemplate(), + 'backupSchedule' => self::getBackupScheduleNameTemplate(), 'cryptoKey' => self::getCryptoKeyNameTemplate(), 'cryptoKeyVersion' => self::getCryptoKeyVersionNameTemplate(), 'database' => self::getDatabaseNameTemplate(), @@ -295,6 +316,31 @@ public static function backupName($project, $instance, $backup) ]); } + /** + * Formats a string containing the fully-qualified path to represent a + * backup_schedule resource. + * + * @param string $project + * @param string $instance + * @param string $database + * @param string $schedule + * + * @return string The formatted backup_schedule resource. + */ + public static function backupScheduleName( + $project, + $instance, + $database, + $schedule + ) { + return self::getBackupScheduleNameTemplate()->render([ + 'project' => $project, + 'instance' => $instance, + 'database' => $database, + 'schedule' => $schedule, + ]); + } + /** * Formats a string containing the fully-qualified path to represent a crypto_key * resource. @@ -389,6 +435,7 @@ public static function instanceName($project, $instance) * The following name formats are supported: * Template: Pattern * - backup: projects/{project}/instances/{instance}/backups/{backup} + * - backupSchedule: projects/{project}/instances/{instance}/databases/{database}/backupSchedules/{schedule} * - cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key} * - cryptoKeyVersion: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version} * - database: projects/{project}/instances/{instance}/databases/{database} @@ -761,6 +808,66 @@ public function createBackup( )->wait(); } + /** + * Creates a new backup schedule. + * + * Sample code: + * ``` + * $databaseAdminClient = new DatabaseAdminClient(); + * try { + * $formattedParent = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + * $backupScheduleId = 'backup_schedule_id'; + * $backupSchedule = new BackupSchedule(); + * $response = $databaseAdminClient->createBackupSchedule($formattedParent, $backupScheduleId, $backupSchedule); + * } finally { + * $databaseAdminClient->close(); + * } + * ``` + * + * @param string $parent Required. The name of the database that this backup schedule applies to. + * @param string $backupScheduleId Required. The Id to use for the backup schedule. The `backup_schedule_id` + * appended to `parent` forms the full backup schedule name of the form + * `projects//instances//databases//backupSchedules/`. + * @param BackupSchedule $backupSchedule Required. The backup schedule to create. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule + * + * @throws ApiException if the remote call fails + */ + public function createBackupSchedule( + $parent, + $backupScheduleId, + $backupSchedule, + array $optionalArgs = [] + ) { + $request = new CreateBackupScheduleRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $request->setBackupScheduleId($backupScheduleId); + $request->setBackupSchedule($backupSchedule); + $requestParamHeaders['parent'] = $parent; + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'CreateBackupSchedule', + BackupSchedule::class, + $optionalArgs, + $request + )->wait(); + } + /** * Creates a new Cloud Spanner database and starts to prepare it for serving. * The returned [long-running operation][google.longrunning.Operation] will @@ -945,6 +1052,54 @@ public function deleteBackup($name, array $optionalArgs = []) )->wait(); } + /** + * Deletes a backup schedule. + * + * Sample code: + * ``` + * $databaseAdminClient = new DatabaseAdminClient(); + * try { + * $formattedName = $databaseAdminClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + * $databaseAdminClient->deleteBackupSchedule($formattedName); + * } finally { + * $databaseAdminClient->close(); + * } + * ``` + * + * @param string $name Required. The name of the schedule to delete. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @throws ApiException if the remote call fails + */ + public function deleteBackupSchedule($name, array $optionalArgs = []) + { + $request = new DeleteBackupScheduleRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'DeleteBackupSchedule', + GPBEmpty::class, + $optionalArgs, + $request + )->wait(); + } + /** * Drops (aka deletes) a Cloud Spanner database. * Completed backups for the database will be retained according to their @@ -1046,6 +1201,56 @@ public function getBackup($name, array $optionalArgs = []) )->wait(); } + /** + * Gets backup schedule for the input schedule name. + * + * Sample code: + * ``` + * $databaseAdminClient = new DatabaseAdminClient(); + * try { + * $formattedName = $databaseAdminClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + * $response = $databaseAdminClient->getBackupSchedule($formattedName); + * } finally { + * $databaseAdminClient->close(); + * } + * ``` + * + * @param string $name Required. The name of the schedule to retrieve. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule + * + * @throws ApiException if the remote call fails + */ + public function getBackupSchedule($name, array $optionalArgs = []) + { + $request = new GetBackupScheduleRequest(); + $requestParamHeaders = []; + $request->setName($name); + $requestParamHeaders['name'] = $name; + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'GetBackupSchedule', + BackupSchedule::class, + $optionalArgs, + $request + )->wait(); + } + /** * Gets the state of a Cloud Spanner database. * @@ -1372,6 +1577,85 @@ public function listBackupOperations($parent, array $optionalArgs = []) ); } + /** + * Lists all the backup schedules for the database. + * + * Sample code: + * ``` + * $databaseAdminClient = new DatabaseAdminClient(); + * try { + * $formattedParent = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + * // Iterate over pages of elements + * $pagedResponse = $databaseAdminClient->listBackupSchedules($formattedParent); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $databaseAdminClient->listBackupSchedules($formattedParent); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $databaseAdminClient->close(); + * } + * ``` + * + * @param string $parent Required. Database is the parent resource whose backup schedules should be + * listed. Values are of the form + * projects//instances//databases/ + * @param array $optionalArgs { + * Optional. + * + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\ApiCore\PagedListResponse + * + * @throws ApiException if the remote call fails + */ + public function listBackupSchedules($parent, array $optionalArgs = []) + { + $request = new ListBackupSchedulesRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->getPagedListResponse( + 'ListBackupSchedules', + $optionalArgs, + ListBackupSchedulesResponse::class, + $request + ); + } + /** * Lists completed and pending backups. * Backups returned are ordered by `create_time` in descending order, @@ -2103,6 +2387,68 @@ public function updateBackup($backup, $updateMask, array $optionalArgs = []) )->wait(); } + /** + * Updates a backup schedule. + * + * Sample code: + * ``` + * $databaseAdminClient = new DatabaseAdminClient(); + * try { + * $backupSchedule = new BackupSchedule(); + * $updateMask = new FieldMask(); + * $response = $databaseAdminClient->updateBackupSchedule($backupSchedule, $updateMask); + * } finally { + * $databaseAdminClient->close(); + * } + * ``` + * + * @param BackupSchedule $backupSchedule Required. The backup schedule to update. `backup_schedule.name`, and the + * fields to be updated as specified by `update_mask` are required. Other + * fields are ignored. + * @param FieldMask $updateMask Required. A mask specifying which fields in the BackupSchedule resource + * should be updated. This mask is relative to the BackupSchedule resource, + * not to the request message. The field mask must always be + * specified; this prevents any future fields from being erased + * accidentally. + * @param array $optionalArgs { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule + * + * @throws ApiException if the remote call fails + */ + public function updateBackupSchedule( + $backupSchedule, + $updateMask, + array $optionalArgs = [] + ) { + $request = new UpdateBackupScheduleRequest(); + $requestParamHeaders = []; + $request->setBackupSchedule($backupSchedule); + $request->setUpdateMask($updateMask); + $requestParamHeaders[ + 'backup_schedule.name' + ] = $backupSchedule->getName(); + $requestParams = new RequestParamsHeaderDescriptor( + $requestParamHeaders + ); + $optionalArgs['headers'] = isset($optionalArgs['headers']) + ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) + : $requestParams->getHeader(); + return $this->startCall( + 'UpdateBackupSchedule', + BackupSchedule::class, + $optionalArgs, + $request + )->wait(); + } + /** * Updates a Cloud Spanner database. The returned * [long-running operation][google.longrunning.Operation] can be used to track diff --git a/Spanner/src/Admin/Database/V1/GetBackupScheduleRequest.php b/Spanner/src/Admin/Database/V1/GetBackupScheduleRequest.php new file mode 100644 index 00000000000..9de0e5cf662 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/GetBackupScheduleRequest.php @@ -0,0 +1,92 @@ +google.spanner.admin.database.v1.GetBackupScheduleRequest + */ +class GetBackupScheduleRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the schedule to retrieve. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + + /** + * @param string $name Required. The name of the schedule to retrieve. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. Please see + * {@see DatabaseAdminClient::backupScheduleName()} for help formatting this field. + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\GetBackupScheduleRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the schedule to retrieve. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the schedule to retrieve. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The name of the schedule to retrieve. + * Values are of the form + * `projects//instances//databases//backupSchedules/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/ListBackupSchedulesRequest.php b/Spanner/src/Admin/Database/V1/ListBackupSchedulesRequest.php new file mode 100644 index 00000000000..211aaf8833a --- /dev/null +++ b/Spanner/src/Admin/Database/V1/ListBackupSchedulesRequest.php @@ -0,0 +1,180 @@ +google.spanner.admin.database.v1.ListBackupSchedulesRequest + */ +class ListBackupSchedulesRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Database is the parent resource whose backup schedules should be + * listed. Values are of the form + * projects//instances//databases/ + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $parent = ''; + /** + * Optional. Number of backup schedules to be returned in the response. If 0 + * or less, defaults to the server's maximum allowed page size. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + private $page_size = 0; + /** + * Optional. If non-empty, `page_token` should contain a + * [next_page_token][google.spanner.admin.database.v1.ListBackupSchedulesResponse.next_page_token] + * from a previous + * [ListBackupSchedulesResponse][google.spanner.admin.database.v1.ListBackupSchedulesResponse] + * to the same `parent`. + * + * Generated from protobuf field string page_token = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + private $page_token = ''; + + /** + * @param string $parent Required. Database is the parent resource whose backup schedules should be + * listed. Values are of the form + * projects//instances//databases/ + * Please see {@see DatabaseAdminClient::databaseName()} for help formatting this field. + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. Database is the parent resource whose backup schedules should be + * listed. Values are of the form + * projects//instances//databases/ + * @type int $page_size + * Optional. Number of backup schedules to be returned in the response. If 0 + * or less, defaults to the server's maximum allowed page size. + * @type string $page_token + * Optional. If non-empty, `page_token` should contain a + * [next_page_token][google.spanner.admin.database.v1.ListBackupSchedulesResponse.next_page_token] + * from a previous + * [ListBackupSchedulesResponse][google.spanner.admin.database.v1.ListBackupSchedulesResponse] + * to the same `parent`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Required. Database is the parent resource whose backup schedules should be + * listed. Values are of the form + * projects//instances//databases/ + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. Database is the parent resource whose backup schedules should be + * listed. Values are of the form + * projects//instances//databases/ + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * Optional. Number of backup schedules to be returned in the response. If 0 + * or less, defaults to the server's maximum allowed page size. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * Optional. Number of backup schedules to be returned in the response. If 0 + * or less, defaults to the server's maximum allowed page size. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * Optional. If non-empty, `page_token` should contain a + * [next_page_token][google.spanner.admin.database.v1.ListBackupSchedulesResponse.next_page_token] + * from a previous + * [ListBackupSchedulesResponse][google.spanner.admin.database.v1.ListBackupSchedulesResponse] + * to the same `parent`. + * + * Generated from protobuf field string page_token = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * Optional. If non-empty, `page_token` should contain a + * [next_page_token][google.spanner.admin.database.v1.ListBackupSchedulesResponse.next_page_token] + * from a previous + * [ListBackupSchedulesResponse][google.spanner.admin.database.v1.ListBackupSchedulesResponse] + * to the same `parent`. + * + * Generated from protobuf field string page_token = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/ListBackupSchedulesResponse.php b/Spanner/src/Admin/Database/V1/ListBackupSchedulesResponse.php new file mode 100644 index 00000000000..37f24fe471a --- /dev/null +++ b/Spanner/src/Admin/Database/V1/ListBackupSchedulesResponse.php @@ -0,0 +1,110 @@ +google.spanner.admin.database.v1.ListBackupSchedulesResponse + */ +class ListBackupSchedulesResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The list of backup schedules for a database. + * + * Generated from protobuf field repeated .google.spanner.admin.database.v1.BackupSchedule backup_schedules = 1; + */ + private $backup_schedules; + /** + * `next_page_token` can be sent in a subsequent + * [ListBackupSchedules][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupSchedules] + * call to fetch more of the schedules. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule>|\Google\Protobuf\Internal\RepeatedField $backup_schedules + * The list of backup schedules for a database. + * @type string $next_page_token + * `next_page_token` can be sent in a subsequent + * [ListBackupSchedules][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupSchedules] + * call to fetch more of the schedules. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * The list of backup schedules for a database. + * + * Generated from protobuf field repeated .google.spanner.admin.database.v1.BackupSchedule backup_schedules = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getBackupSchedules() + { + return $this->backup_schedules; + } + + /** + * The list of backup schedules for a database. + * + * Generated from protobuf field repeated .google.spanner.admin.database.v1.BackupSchedule backup_schedules = 1; + * @param array<\Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setBackupSchedules($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule::class); + $this->backup_schedules = $arr; + + return $this; + } + + /** + * `next_page_token` can be sent in a subsequent + * [ListBackupSchedules][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupSchedules] + * call to fetch more of the schedules. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * `next_page_token` can be sent in a subsequent + * [ListBackupSchedules][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupSchedules] + * call to fetch more of the schedules. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/UpdateBackupScheduleRequest.php b/Spanner/src/Admin/Database/V1/UpdateBackupScheduleRequest.php new file mode 100644 index 00000000000..fc730bbd549 --- /dev/null +++ b/Spanner/src/Admin/Database/V1/UpdateBackupScheduleRequest.php @@ -0,0 +1,167 @@ +google.spanner.admin.database.v1.UpdateBackupScheduleRequest + */ +class UpdateBackupScheduleRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The backup schedule to update. `backup_schedule.name`, and the + * fields to be updated as specified by `update_mask` are required. Other + * fields are ignored. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + private $backup_schedule = null; + /** + * Required. A mask specifying which fields in the BackupSchedule resource + * should be updated. This mask is relative to the BackupSchedule resource, + * not to the request message. The field mask must always be + * specified; this prevents any future fields from being erased + * accidentally. + * + * Generated from protobuf field .google.protobuf.FieldMask update_mask = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + private $update_mask = null; + + /** + * @param \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $backupSchedule Required. The backup schedule to update. `backup_schedule.name`, and the + * fields to be updated as specified by `update_mask` are required. Other + * fields are ignored. + * @param \Google\Protobuf\FieldMask $updateMask Required. A mask specifying which fields in the BackupSchedule resource + * should be updated. This mask is relative to the BackupSchedule resource, + * not to the request message. The field mask must always be + * specified; this prevents any future fields from being erased + * accidentally. + * + * @return \Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupScheduleRequest + * + * @experimental + */ + public static function build(\Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $backupSchedule, \Google\Protobuf\FieldMask $updateMask): self + { + return (new self()) + ->setBackupSchedule($backupSchedule) + ->setUpdateMask($updateMask); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $backup_schedule + * Required. The backup schedule to update. `backup_schedule.name`, and the + * fields to be updated as specified by `update_mask` are required. Other + * fields are ignored. + * @type \Google\Protobuf\FieldMask $update_mask + * Required. A mask specifying which fields in the BackupSchedule resource + * should be updated. This mask is relative to the BackupSchedule resource, + * not to the request message. The field mask must always be + * specified; this prevents any future fields from being erased + * accidentally. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Spanner\Admin\Database\V1\BackupSchedule::initOnce(); + parent::__construct($data); + } + + /** + * Required. The backup schedule to update. `backup_schedule.name`, and the + * fields to be updated as specified by `update_mask` are required. Other + * fields are ignored. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule|null + */ + public function getBackupSchedule() + { + return $this->backup_schedule; + } + + public function hasBackupSchedule() + { + return isset($this->backup_schedule); + } + + public function clearBackupSchedule() + { + unset($this->backup_schedule); + } + + /** + * Required. The backup schedule to update. `backup_schedule.name`, and the + * fields to be updated as specified by `update_mask` are required. Other + * fields are ignored. + * + * Generated from protobuf field .google.spanner.admin.database.v1.BackupSchedule backup_schedule = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule $var + * @return $this + */ + public function setBackupSchedule($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule::class); + $this->backup_schedule = $var; + + return $this; + } + + /** + * Required. A mask specifying which fields in the BackupSchedule resource + * should be updated. This mask is relative to the BackupSchedule resource, + * not to the request message. The field mask must always be + * specified; this prevents any future fields from being erased + * accidentally. + * + * Generated from protobuf field .google.protobuf.FieldMask update_mask = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Protobuf\FieldMask|null + */ + public function getUpdateMask() + { + return $this->update_mask; + } + + public function hasUpdateMask() + { + return isset($this->update_mask); + } + + public function clearUpdateMask() + { + unset($this->update_mask); + } + + /** + * Required. A mask specifying which fields in the BackupSchedule resource + * should be updated. This mask is relative to the BackupSchedule resource, + * not to the request message. The field mask must always be + * specified; this prevents any future fields from being erased + * accidentally. + * + * Generated from protobuf field .google.protobuf.FieldMask update_mask = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Protobuf\FieldMask $var + * @return $this + */ + public function setUpdateMask($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\FieldMask::class); + $this->update_mask = $var; + + return $this; + } + +} + diff --git a/Spanner/src/Admin/Database/V1/resources/database_admin_client_config.json b/Spanner/src/Admin/Database/V1/resources/database_admin_client_config.json index ca8f1d556f1..c39bb9e64ee 100644 --- a/Spanner/src/Admin/Database/V1/resources/database_admin_client_config.json +++ b/Spanner/src/Admin/Database/V1/resources/database_admin_client_config.json @@ -72,6 +72,11 @@ "retry_codes_name": "no_retry_1_codes", "retry_params_name": "no_retry_1_params" }, + "CreateBackupSchedule": { + "timeout_millis": 3600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, "CreateDatabase": { "timeout_millis": 3600000, "retry_codes_name": "no_retry_1_codes", @@ -82,6 +87,11 @@ "retry_codes_name": "retry_policy_1_codes", "retry_params_name": "retry_policy_1_params" }, + "DeleteBackupSchedule": { + "timeout_millis": 3600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, "DropDatabase": { "timeout_millis": 3600000, "retry_codes_name": "retry_policy_1_codes", @@ -92,6 +102,11 @@ "retry_codes_name": "retry_policy_1_codes", "retry_params_name": "retry_policy_1_params" }, + "GetBackupSchedule": { + "timeout_millis": 3600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, "GetDatabase": { "timeout_millis": 3600000, "retry_codes_name": "retry_policy_1_codes", @@ -112,6 +127,11 @@ "retry_codes_name": "retry_policy_1_codes", "retry_params_name": "retry_policy_1_params" }, + "ListBackupSchedules": { + "timeout_millis": 3600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, "ListBackups": { "timeout_millis": 3600000, "retry_codes_name": "retry_policy_1_codes", @@ -152,6 +172,11 @@ "retry_codes_name": "retry_policy_1_codes", "retry_params_name": "retry_policy_1_params" }, + "UpdateBackupSchedule": { + "timeout_millis": 3600000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, "UpdateDatabase": { "timeout_millis": 3600000, "retry_codes_name": "retry_policy_1_codes", diff --git a/Spanner/src/Admin/Database/V1/resources/database_admin_descriptor_config.php b/Spanner/src/Admin/Database/V1/resources/database_admin_descriptor_config.php index fc499b10c12..8c838a9fed4 100644 --- a/Spanner/src/Admin/Database/V1/resources/database_admin_descriptor_config.php +++ b/Spanner/src/Admin/Database/V1/resources/database_admin_descriptor_config.php @@ -138,6 +138,18 @@ ], ], ], + 'CreateBackupSchedule' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], 'DeleteBackup' => [ 'callType' => \Google\ApiCore\Call::UNARY_CALL, 'responseType' => 'Google\Protobuf\GPBEmpty', @@ -150,6 +162,18 @@ ], ], ], + 'DeleteBackupSchedule' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Protobuf\GPBEmpty', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'DropDatabase' => [ 'callType' => \Google\ApiCore\Call::UNARY_CALL, 'responseType' => 'Google\Protobuf\GPBEmpty', @@ -174,6 +198,18 @@ ], ], ], + 'GetBackupSchedule' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], 'GetDatabase' => [ 'callType' => \Google\ApiCore\Call::UNARY_CALL, 'responseType' => 'Google\Cloud\Spanner\Admin\Database\V1\Database', @@ -230,6 +266,26 @@ ], ], ], + 'ListBackupSchedules' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getBackupSchedules', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesResponse', + 'headerParams' => [ + [ + 'keyName' => 'parent', + 'fieldAccessors' => [ + 'getParent', + ], + ], + ], + ], 'ListBackups' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', @@ -347,8 +403,22 @@ ], ], ], + 'UpdateBackupSchedule' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule', + 'headerParams' => [ + [ + 'keyName' => 'backup_schedule.name', + 'fieldAccessors' => [ + 'getBackupSchedule', + 'getName', + ], + ], + ], + ], 'templateMap' => [ 'backup' => 'projects/{project}/instances/{instance}/backups/{backup}', + 'backupSchedule' => 'projects/{project}/instances/{instance}/databases/{database}/backupSchedules/{schedule}', 'cryptoKey' => 'projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}', 'cryptoKeyVersion' => 'projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}', 'database' => 'projects/{project}/instances/{instance}/databases/{database}', diff --git a/Spanner/src/Admin/Database/V1/resources/database_admin_rest_client_config.php b/Spanner/src/Admin/Database/V1/resources/database_admin_rest_client_config.php index 001f0f77400..1bf0d796614 100644 --- a/Spanner/src/Admin/Database/V1/resources/database_admin_rest_client_config.php +++ b/Spanner/src/Admin/Database/V1/resources/database_admin_rest_client_config.php @@ -152,6 +152,21 @@ 'backup_id', ], ], + 'CreateBackupSchedule' => [ + 'method' => 'post', + 'uriTemplate' => '/v1/{parent=projects/*/instances/*/databases/*}/backupSchedules', + 'body' => 'backup_schedule', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + 'queryParams' => [ + 'backup_schedule_id', + ], + ], 'CreateDatabase' => [ 'method' => 'post', 'uriTemplate' => '/v1/{parent=projects/*/instances/*}/databases', @@ -175,6 +190,17 @@ ], ], ], + 'DeleteBackupSchedule' => [ + 'method' => 'delete', + 'uriTemplate' => '/v1/{name=projects/*/instances/*/databases/*/backupSchedules/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'DropDatabase' => [ 'method' => 'delete', 'uriTemplate' => '/v1/{database=projects/*/instances/*/databases/*}', @@ -197,6 +223,17 @@ ], ], ], + 'GetBackupSchedule' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=projects/*/instances/*/databases/*/backupSchedules/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'GetDatabase' => [ 'method' => 'get', 'uriTemplate' => '/v1/{name=projects/*/instances/*/databases/*}', @@ -229,6 +266,11 @@ 'uriTemplate' => '/v1/{resource=projects/*/instances/*/backups/*}:getIamPolicy', 'body' => '*', ], + [ + 'method' => 'post', + 'uriTemplate' => '/v1/{resource=projects/*/instances/*/databases/*/backupSchedules/*}:getIamPolicy', + 'body' => '*', + ], ], 'placeholders' => [ 'resource' => [ @@ -249,6 +291,17 @@ ], ], ], + 'ListBackupSchedules' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{parent=projects/*/instances/*/databases/*}/backupSchedules', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], 'ListBackups' => [ 'method' => 'get', 'uriTemplate' => '/v1/{parent=projects/*/instances/*}/backups', @@ -315,6 +368,11 @@ 'uriTemplate' => '/v1/{resource=projects/*/instances/*/backups/*}:setIamPolicy', 'body' => '*', ], + [ + 'method' => 'post', + 'uriTemplate' => '/v1/{resource=projects/*/instances/*/databases/*/backupSchedules/*}:setIamPolicy', + 'body' => '*', + ], ], 'placeholders' => [ 'resource' => [ @@ -334,6 +392,11 @@ 'uriTemplate' => '/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions', 'body' => '*', ], + [ + 'method' => 'post', + 'uriTemplate' => '/v1/{resource=projects/*/instances/*/databases/*/backupSchedules/*}:testIamPermissions', + 'body' => '*', + ], [ 'method' => 'post', 'uriTemplate' => '/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions', @@ -364,6 +427,22 @@ 'update_mask', ], ], + 'UpdateBackupSchedule' => [ + 'method' => 'patch', + 'uriTemplate' => '/v1/{backup_schedule.name=projects/*/instances/*/databases/*/backupSchedules/*}', + 'body' => 'backup_schedule', + 'placeholders' => [ + 'backup_schedule.name' => [ + 'getters' => [ + 'getBackupSchedule', + 'getName', + ], + ], + ], + 'queryParams' => [ + 'update_mask', + ], + ], 'UpdateDatabase' => [ 'method' => 'patch', 'uriTemplate' => '/v1/{database.name=projects/*/instances/*/databases/*}', diff --git a/Spanner/tests/Unit/Admin/Database/V1/Client/DatabaseAdminClientTest.php b/Spanner/tests/Unit/Admin/Database/V1/Client/DatabaseAdminClientTest.php index f91d06e8531..47b04732e66 100644 --- a/Spanner/tests/Unit/Admin/Database/V1/Client/DatabaseAdminClientTest.php +++ b/Spanner/tests/Unit/Admin/Database/V1/Client/DatabaseAdminClientTest.php @@ -33,20 +33,26 @@ use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; use Google\Cloud\Spanner\Admin\Database\V1\Backup; +use Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule; use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient; use Google\Cloud\Spanner\Admin\Database\V1\CopyBackupRequest; use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\CreateBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\CreateDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\Database; use Google\Cloud\Spanner\Admin\Database\V1\DatabaseRole; use Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\DeleteBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\DropDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\GetBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlRequest; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlResponse; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsResponse; +use Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesRequest; +use Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupsRequest; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupsResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseOperationsRequest; @@ -57,6 +63,7 @@ use Google\Cloud\Spanner\Admin\Database\V1\ListDatabasesResponse; use Google\Cloud\Spanner\Admin\Database\V1\RestoreDatabaseRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupRequest; +use Google\Cloud\Spanner\Admin\Database\V1\UpdateBackupScheduleRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseDdlRequest; use Google\Cloud\Spanner\Admin\Database\V1\UpdateDatabaseRequest; use Google\LongRunning\GetOperationRequest; @@ -380,6 +387,82 @@ public function createBackupExceptionTest() $this->assertTrue($operationsTransport->isExhausted()); } + /** @test */ + public function createBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $expectedResponse = new BackupSchedule(); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $backupScheduleId = 'backupScheduleId326010054'; + $backupSchedule = new BackupSchedule(); + $request = (new CreateBackupScheduleRequest()) + ->setParent($formattedParent) + ->setBackupScheduleId($backupScheduleId) + ->setBackupSchedule($backupSchedule); + $response = $gapicClient->createBackupSchedule($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/CreateBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getBackupScheduleId(); + $this->assertProtobufEquals($backupScheduleId, $actualValue); + $actualValue = $actualRequestObject->getBackupSchedule(); + $this->assertProtobufEquals($backupSchedule, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $backupScheduleId = 'backupScheduleId326010054'; + $backupSchedule = new BackupSchedule(); + $request = (new CreateBackupScheduleRequest()) + ->setParent($formattedParent) + ->setBackupScheduleId($backupScheduleId) + ->setBackupSchedule($backupSchedule); + try { + $gapicClient->createBackupSchedule($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function createDatabaseTest() { @@ -578,6 +661,67 @@ public function deleteBackupExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function deleteBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + $request = (new DeleteBackupScheduleRequest()) + ->setName($formattedName); + $gapicClient->deleteBackupSchedule($request); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + $request = (new DeleteBackupScheduleRequest()) + ->setName($formattedName); + try { + $gapicClient->deleteBackupSchedule($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function dropDatabaseTest() { @@ -707,6 +851,70 @@ public function getBackupExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function getBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new BackupSchedule(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + $request = (new GetBackupScheduleRequest()) + ->setName($formattedName); + $response = $gapicClient->getBackupSchedule($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/GetBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + $request = (new GetBackupScheduleRequest()) + ->setName($formattedName); + try { + $gapicClient->getBackupSchedule($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function getDatabaseTest() { @@ -981,6 +1189,78 @@ public function listBackupOperationsExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function listBackupSchedulesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $backupSchedulesElement = new BackupSchedule(); + $backupSchedules = [ + $backupSchedulesElement, + ]; + $expectedResponse = new ListBackupSchedulesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setBackupSchedules($backupSchedules); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $request = (new ListBackupSchedulesRequest()) + ->setParent($formattedParent); + $response = $gapicClient->listBackupSchedules($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getBackupSchedules()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/ListBackupSchedules', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listBackupSchedulesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $request = (new ListBackupSchedulesRequest()) + ->setParent($formattedParent); + try { + $gapicClient->listBackupSchedules($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function listBackupsTest() { @@ -1620,6 +1900,76 @@ public function updateBackupExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function updateBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $expectedResponse = new BackupSchedule(); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $backupSchedule = new BackupSchedule(); + $updateMask = new FieldMask(); + $request = (new UpdateBackupScheduleRequest()) + ->setBackupSchedule($backupSchedule) + ->setUpdateMask($updateMask); + $response = $gapicClient->updateBackupSchedule($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getBackupSchedule(); + $this->assertProtobufEquals($backupSchedule, $actualValue); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $backupSchedule = new BackupSchedule(); + $updateMask = new FieldMask(); + $request = (new UpdateBackupScheduleRequest()) + ->setBackupSchedule($backupSchedule) + ->setUpdateMask($updateMask); + try { + $gapicClient->updateBackupSchedule($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function updateDatabaseTest() { diff --git a/Spanner/tests/Unit/Admin/Database/V1/DatabaseAdminClientTest.php b/Spanner/tests/Unit/Admin/Database/V1/DatabaseAdminClientTest.php index 529e0e8cc6f..7803aa01965 100644 --- a/Spanner/tests/Unit/Admin/Database/V1/DatabaseAdminClientTest.php +++ b/Spanner/tests/Unit/Admin/Database/V1/DatabaseAdminClientTest.php @@ -30,11 +30,13 @@ use Google\Cloud\Iam\V1\Policy; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; use Google\Cloud\Spanner\Admin\Database\V1\Backup; +use Google\Cloud\Spanner\Admin\Database\V1\BackupSchedule; use Google\Cloud\Spanner\Admin\Database\V1\Database; use Google\Cloud\Spanner\Admin\Database\V1\DatabaseAdminClient; use Google\Cloud\Spanner\Admin\Database\V1\DatabaseRole; use Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupOperationsResponse; +use Google\Cloud\Spanner\Admin\Database\V1\ListBackupSchedulesResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListBackupsResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseOperationsResponse; use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseRolesResponse; @@ -342,6 +344,74 @@ public function createBackupExceptionTest() $this->assertTrue($operationsTransport->isExhausted()); } + /** @test */ + public function createBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $expectedResponse = new BackupSchedule(); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $backupScheduleId = 'backupScheduleId326010054'; + $backupSchedule = new BackupSchedule(); + $response = $gapicClient->createBackupSchedule($formattedParent, $backupScheduleId, $backupSchedule); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/CreateBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualRequestObject->getBackupScheduleId(); + $this->assertProtobufEquals($backupScheduleId, $actualValue); + $actualValue = $actualRequestObject->getBackupSchedule(); + $this->assertProtobufEquals($backupSchedule, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function createBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $backupScheduleId = 'backupScheduleId326010054'; + $backupSchedule = new BackupSchedule(); + try { + $gapicClient->createBackupSchedule($formattedParent, $backupScheduleId, $backupSchedule); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function createDatabaseTest() { @@ -530,6 +600,63 @@ public function deleteBackupExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function deleteBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new GPBEmpty(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + $gapicClient->deleteBackupSchedule($formattedName); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function deleteBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + try { + $gapicClient->deleteBackupSchedule($formattedName); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function dropDatabaseTest() { @@ -651,6 +778,66 @@ public function getBackupExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function getBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $expectedResponse = new BackupSchedule(); + $expectedResponse->setName($name2); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + $response = $gapicClient->getBackupSchedule($formattedName); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/GetBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->backupScheduleName('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SCHEDULE]'); + try { + $gapicClient->getBackupSchedule($formattedName); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function getDatabaseTest() { @@ -909,6 +1096,74 @@ public function listBackupOperationsExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function listBackupSchedulesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $backupSchedulesElement = new BackupSchedule(); + $backupSchedules = [ + $backupSchedulesElement, + ]; + $expectedResponse = new ListBackupSchedulesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setBackupSchedules($backupSchedules); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + $response = $gapicClient->listBackupSchedules($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getBackupSchedules()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/ListBackupSchedules', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listBackupSchedulesExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $gapicClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]'); + try { + $gapicClient->listBackupSchedules($formattedParent); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function listBackupsTest() { @@ -1508,6 +1763,70 @@ public function updateBackupExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** @test */ + public function updateBackupScheduleTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name = 'name3373707'; + $expectedResponse = new BackupSchedule(); + $expectedResponse->setName($name); + $transport->addResponse($expectedResponse); + // Mock request + $backupSchedule = new BackupSchedule(); + $updateMask = new FieldMask(); + $response = $gapicClient->updateBackupSchedule($backupSchedule, $updateMask); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackupSchedule', $actualFuncCall); + $actualValue = $actualRequestObject->getBackupSchedule(); + $this->assertProtobufEquals($backupSchedule, $actualValue); + $actualValue = $actualRequestObject->getUpdateMask(); + $this->assertProtobufEquals($updateMask, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function updateBackupScheduleExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $backupSchedule = new BackupSchedule(); + $updateMask = new FieldMask(); + try { + $gapicClient->updateBackupSchedule($backupSchedule, $updateMask); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** @test */ public function updateDatabaseTest() {