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.
A full list of all the 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
shell> curl 'GET https://127.0.0.1:8090/api/v8/manager/services/west/datasources/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
shell> curl 'POST https://localhost:8090/api/v8/manager/services/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
shell> curl 'GET https://127.0.0.1:8090/api/v8/manager/tasks/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.