Google Cloud AlloyDB Operators¶
The AlloyDB for PostgreSQL is a fully managed, PostgreSQL-compatible database service that’s designed for your most demanding workloads, including hybrid transactional and analytical processing. AlloyDB pairs a Google-built database engine with a cloud-based, multi-node architecture to deliver enterprise-grade performance, reliability, and availability.
Airflow provides operators to manage AlloyDB clusters.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
Create cluster¶
To create an AlloyDB cluster (primary end secondary) you can use
AlloyDBCreateClusterOperator
.
create_cluster = AlloyDBCreateClusterOperator(
task_id="create_cluster",
cluster_id=CLUSTER_ID,
cluster_configuration=CLUSTER,
is_secondary=False,
location=GCP_LOCATION,
project_id=GCP_PROJECT_ID,
)
Update cluster¶
To update an AlloyDB cluster you can use
AlloyDBUpdateClusterOperator
.
update_cluster = AlloyDBUpdateClusterOperator(
task_id="update_cluster",
cluster_id=CLUSTER_ID,
cluster_configuration=CLUSTER_UPDATE,
update_mask=CLUSTER_UPDATE_MASK,
location=GCP_LOCATION,
project_id=GCP_PROJECT_ID,
)
Delete cluster¶
To delete an AlloyDB cluster you can use
AlloyDBDeleteClusterOperator
.
delete_cluster = AlloyDBDeleteClusterOperator(
task_id="delete_cluster",
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
cluster_id=CLUSTER_ID,
)
Create instance¶
To create an AlloyDB instance (primary end secondary) you can use
AlloyDBCreateInstanceOperator
.
create_instance = AlloyDBCreateInstanceOperator(
task_id="create_instance",
cluster_id=CLUSTER_ID,
instance_id=INSTANCE_ID,
instance_configuration=INSTANCE,
is_secondary=False,
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
)
Update instance¶
To update an AlloyDB instance you can use
AlloyDBUpdateInstanceOperator
.
update_instance = AlloyDBUpdateInstanceOperator(
task_id="update_instance",
cluster_id=CLUSTER_ID,
instance_id=INSTANCE_ID,
instance_configuration=INSTANCE_UPDATE,
update_mask=INSTANCE_UPDATE_MASK,
location=GCP_LOCATION,
project_id=GCP_PROJECT_ID,
)
Delete instance¶
To delete an AlloyDB instance you can use
AlloyDBDeleteInstanceOperator
.
delete_instance = AlloyDBDeleteInstanceOperator(
task_id="delete_instance",
cluster_id=CLUSTER_ID,
instance_id=INSTANCE_ID,
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
)
Create user¶
To create an AlloyDB user you can use
AlloyDBCreateUserOperator
. Note that the primary instance
must be created in the cluster
creat_user = AlloyDBCreateUserOperator(
task_id="create_user",
user_id=USER_ID,
user_configuration=USER,
cluster_id=CLUSTER_ID,
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
)
Update user¶
To update an AlloyDB user you can use
AlloyDBUpdateUserOperator
.
update_user = AlloyDBUpdateUserOperator(
task_id="update_user",
user_id=USER_ID,
user_configuration=USER_UPDATE,
cluster_id=CLUSTER_ID,
update_mask=USER_UPDATE_MASK,
location=GCP_LOCATION,
project_id=GCP_PROJECT_ID,
)
Delete user¶
To delete an AlloyDB user you can use
AlloyDBDeleteUserOperator
.
delete_user = AlloyDBDeleteUserOperator(
task_id="delete_user",
cluster_id=CLUSTER_ID,
user_id=USER_ID,
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
)
Create backup¶
To create an AlloyDB backup you can use
AlloyDBCreateBackupOperator
.
create_backup = AlloyDBCreateBackupOperator(
task_id="create_backup",
backup_id=BACKUP_ID,
backup_configuration=BACKUP,
location=GCP_LOCATION_BACKUP,
project_id=GCP_PROJECT_ID,
)
Update backup¶
To update an AlloyDB backup you can use
AlloyDBUpdateBackupOperator
.
update_backup = AlloyDBUpdateBackupOperator(
task_id="update_backup",
backup_id=BACKUP_ID,
backup_configuration=BACKUP_UPDATE,
update_mask=BACKUP_UPDATE_MASK,
location=GCP_LOCATION_BACKUP,
project_id=GCP_PROJECT_ID,
)
Delete backup¶
To delete an AlloyDB backup you can use
AlloyDBDeleteBackupOperator
.
delete_backup = AlloyDBDeleteBackupOperator(
task_id="delete_backup",
backup_id=BACKUP_ID,
location=GCP_LOCATION_BACKUP,
project_id=GCP_PROJECT_ID,
)