Using the API, it is possible to do a backup, switch, shun or welcome the node, put replicator online/offline, ping a datasource and all other commands that can be achieved from the cctrl command line utility. Here we present the ping and the switch command. All commands are listed in the Manager API Developer documentation.
To ping a datasource, the following command can be used, resulting in a BooleanPayload return as shown in the following example
GET https://127.0.0.1:8090/api/v2/manager/service/west/datasource/db1/ping { "payloadType": "BooleanPayload", "payloadVersion": "1", "payload": { "value": true } }
To initiate a switch within a cluster, you can issue the following commands, resulting in a TaskPayload
GET https://localhost:8090/api/v2/manager/control/service/west/switch { "payloadType": "TaskPayload", "payloadVersion": "1", "payload": { "taskId": "84ad5757-0a6c-44d9-a631-686a740150a3", "state": "in_progress" } }
A cluster switch is deemed a long lasting command, and therefore you can then use the taskId returned from above, to view the status of the switch, as follows
GET https://127.0.0.1:8090/api/v2/manager/task/84ad5757-0a6c-44d9-a631-686a740150a3 { "payloadType": "TaskPayload", "payloadVersion": "1", "payload": { "taskId": "84ad5757-0a6c-44d9-a631-686a740150a3", "state": "complete", "taskResult": { "newPrimary": "db3" } } }
From the output, you can see the switch completed and the new Primary node is db3.