From 1a3c4110dec5741538394d5317c9b3c2fcdd68d7 Mon Sep 17 00:00:00 2001 From: Dorota Wojcik Date: Wed, 11 Dec 2024 15:29:07 +0100 Subject: [PATCH] api calls for CRDR management --- .../crdr/crdr-failover-to-recovery.md | 62 +++++++++- .../postgresql/crdr/crdr-revert-to-primary.md | 117 +++++++++++++++++- docs/products/postgresql/crdr/enable-crdr.md | 83 ++++++++++++- 3 files changed, 256 insertions(+), 6 deletions(-) diff --git a/docs/products/postgresql/crdr/crdr-failover-to-recovery.md b/docs/products/postgresql/crdr/crdr-failover-to-recovery.md index aa739be12..4f98e3446 100644 --- a/docs/products/postgresql/crdr/crdr-failover-to-recovery.md +++ b/docs/products/postgresql/crdr/crdr-failover-to-recovery.md @@ -17,8 +17,10 @@ infrastructure, you can also perform a manual failover. ## Prerequisites - [CRDR setup](/docs/products/postgresql/crdr/enable-crdr) up and running -- Access to the [Aiven Console](https://console.aiven.io/) or - the [Aiven CLI client installed](/docs/tools/cli) +- One of the following tools for operating CRDR: + - [Aiven Console](https://console.aiven.io/) + - [Aiven CLI](/docs/tools/cli) + - [Aiven API](/docs/tools/api) ## Automatic failover @@ -56,6 +58,62 @@ avn service update PRIMARY_SERVICE_NAME \ Replace `PRIMARY_SERVICE_NAME` with the name of the primary service, for example, `pg-demo`. + + + +Call the [ServiceUpdte endpoint](https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate) +to change `disaster_recovery_role` of the primary service to `failed`: + +```bash {5} +curl --request PUT \ + --url https://api.aiven.io/v1/project/PROJECT_NAME/service/PRIMARY_SERVICE_NAME \ + -H 'Authorization: Bearer BEARER_TOKEN' \ + -H 'content-type: application/json' \ + --data '{"disaster_recovery_role": "failed"}' +``` + +Replace the following placeholders with meaningful data: + +- `PROJECT_NAME`, for example `crdr-test` +- `PRIMARY_SERVICE_NAME`, for example `pg-primary-test` +- `BEARER_TOKEN` + +After sending the request, you can check the CRDR status on each of the CRDR peer services: + +- Primary service status + + ```bash + avn service get pg-primary + --project $PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "POWEROFF", + "disaster_recovery_role": "failed" + } + ``` + +- Recovery service status + + ```bash + avn service get pg-primary-dr + --project $PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "RUNNING", + "disaster_recovery_role": "active" + } + ``` + diff --git a/docs/products/postgresql/crdr/crdr-revert-to-primary.md b/docs/products/postgresql/crdr/crdr-revert-to-primary.md index 213961716..65dd2d51d 100644 --- a/docs/products/postgresql/crdr/crdr-revert-to-primary.md +++ b/docs/products/postgresql/crdr/crdr-revert-to-primary.md @@ -14,8 +14,10 @@ Shift your workloads back to the primary region, where your service was hosted o ## Prerequisites - [CRDR failover](/docs/products/postgresql/crdr/crdr-failover-to-recovery) completed -- Access to the [Aiven Console](https://console.aiven.io/) or - the [Aiven CLI client installed](/docs/tools/cli) +- One of the following tools for operating CRDR: + - [Aiven Console](https://console.aiven.io/) + - [Aiven CLI](/docs/tools/cli) + - [Aiven API](/docs/tools/api) ## Revert to the primary region @@ -70,6 +72,117 @@ using a tool of your choice: Replace `PRIMARY_SERVICE_NAME` with the name of the primary service, for example, `pg-demo`. + + + +1. Trigger the recreation of the primary service by calling the + [ServiceUpdte endpoint](https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate) + to change `disaster_recovery_role` of the primary service to `passive`: + + ```bash {5} + curl --request PUT \ + --url https://api.aiven.io/v1/project/PROJECT_NAME/service/PRIMARY_SERVICE_NAME \ + -H 'Authorization: Bearer BEARER_TOKEN' \ + -H 'content-type: application/json' \ + --data '{"disaster_recovery_role": "passive"}' + ``` + + Replace the following placeholders with meaningful data: + + - `PROJECT_NAME`, for example `crdr-test` + - `PRIMARY_SERVICE_NAME`, for example `pg-primary-test` + - `BEARER_TOKEN` + + After sending the request, you can check the CRDR status on each of the CRDR peer services: + + - Primary service status + + ```bash + avn service get pg-primary + --project $PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "REBUILDING", + "disaster_recovery_role": "passive" + } + ``` + + - Recovery service status + + ```bash + avn service get pg-primary-dr + --project $PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "RUNNING", + "disaster_recovery_role": "active" + } + ``` + +1. Promote the primary service as active by calling the + [ServiceUpdte endpoint](https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate) + to change `disaster_recovery_role` of the primary service to `active`: + + ```bash {5} + curl --request PUT \ + --url https://api.aiven.io/v1/project/PROJECT_NAME/service/PRIMARY_SERVICE_NAME \ + -H 'Authorization: Bearer BEARER_TOKEN' \ + -H 'content-type: application/json' \ + --data '{"disaster_recovery_role": "active"}' + ``` + + Replace the following placeholders with meaningful data: + + - `PROJECT_NAME`, for example `crdr-test` + - `PRIMARY_SERVICE_NAME`, for example `pg-primary-test` + - `BEARER_TOKEN` + + After sending the request, you can check the CRDR status on each of the CRDR peer services: + + - Primary service status + + ```bash + avn service get pg-primary + --project $PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "RUNNING", + "disaster_recovery_role": "active" + } + ``` + + - Recovery service status + + ```bash + avn service get pg-primary-dr + --project $PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "RUNNING", + "disaster_recovery_role": "passive" + } + ``` + diff --git a/docs/products/postgresql/crdr/enable-crdr.md b/docs/products/postgresql/crdr/enable-crdr.md index 1476e5c77..981c52722 100644 --- a/docs/products/postgresql/crdr/enable-crdr.md +++ b/docs/products/postgresql/crdr/enable-crdr.md @@ -22,8 +22,10 @@ Enable the [cross-region disaster recovery (CRDR)](/docs/products/postgresql/crd plan. ::: -- Access to the [Aiven Console](https://console.aiven.io/) or - the [Aiven CLI client installed](/docs/tools/cli) +- One of the following tools for operating CRDR: + - [Aiven Console](https://console.aiven.io/) + - [Aiven CLI](/docs/tools/cli) + - [Aiven API](/docs/tools/api) ## Set up a recovery service @@ -66,6 +68,83 @@ Replace the following: `google-europe-west-4` - `PRIMARY_SERVICE_NAME` with the name of the primary service, for example, `pg-demo` + + + +Call the +[ServiceCreate endpoint](https://api.aiven.io/doc/#tag/Service/operation/ServiceCreate) to +create a recovery service and enable the `disaster_recovery` service integration between +the recovery service and the primary service, for example: + +```bash {14} +curl --request POST \ + --url https://api.aiven.io/v1/project/PROJECT_NAME/service \ + -H 'accept: application/json, text/plain, */*' \ + -H 'Authorization: Bearer BEARER_TOKEN' \ + -H 'content-type: application/json' \ + --data-raw '{ + "service_name": "RECOVERY_SERCICE_NAME", + "cloud": "CLOUD_PROVIDER_REGION", + "plan": "SERVICE_PLAN", + "service_type": "SERVICE_TYPE", + "disk_space_mb": DISK_SIZE, + "service_integrations": [ + { + "integration_type": "disaster_recovery", + "source_service": "PRIMARY_SERVICE_NAME", + "user_config": {} + } + ] + }' +``` + +Replace the following placeholders with meaningful data: + +- `PROJECT_NAME`, for example `crdr-test` +- `BEARER_TOKEN` +- `RECOVERY_SERCICE_NAME`, for example `pg-dr-test` +- `CLOUD_PROVIDER_REGION`, for example `google-europe-west10` +- `SERVICE_PLAN`, for example `startup-4` +- `SERVICE_TYPE`, for example `pg` +- `DISK_SIZE` in MiB, for example `81920` +- `PRIMARY_SERVICE_NAME`, for example `pg-primary-test` + +After sending the request, you can check the CRDR status on each of the CRDR peer services: + +- Primary service status + + ```bash + avn service get PRIMARY_SERVICE_NAME + --project PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "RUNNING", + "disaster_recovery_role": "active" + } + ``` + +- Recovery service status + + ```bash + avn service get RECOVERY_SERVICE_NAME + --project PROJECT_NAME + --json | jq '{state: .state, disaster_recovery_role: .disaster_recovery_role}' + ``` + + Expect the following output: + + ```json + { + "state": "REBUILDING", + "disaster_recovery_role": "passive" + } + ``` +