title | summary |
---|---|
Maintain DM Clusters Using OpenAPI |
Learn about how to use OpenAPI interface to manage the cluster status and data replication. |
Warning:
DM OpenAPI is still an experimental feature and disabled by default. It is not recommended to use it in a production environment.
DM provides the OpenAPI feature for querying and operating the DM cluster, which is similar to the feature of dmctl tools. If you need to enable this feature, add the following configuration in the DM-master configuration file:
[experimental]
openapi = true
Note:
DM provides the specification document that meets the OpenAPI 3.0.0 standard. This document contains all the request parameters and returned values. You can copy the document yaml and preview it in Swagger Editor.
After you deploy the DM-master nodes, you can access
http://{master-addr}/api/v1/docs
to preview the documentation online.
You can use the APIs to perform the following maintenance operations on the DM cluster:
- Get the information of a DM-master node
- Stop a DM-master node
- Get the information of a DM-worker node
- Stop a DM-worker node
- Create a data source
- Get the data source list
- Delete the data source
- Get the information of a data source
- Start the relay-log feature for data sources
- Stop the relay-log feature for data sources
- Pause the relay-log feature for data sources
- Resume the relay-log feature for data sources
- Change the bindings between the data source and DM-workers
- Get the list of schema names of a data source
- Get the list of table names of a specified schema in a data source
- Create a replication task
- Get the replication task list
- Stop a replication task
- Get the information of a replication task
- Pause a replication task
- Resume a replication task
- Get the list of schema names of the data source that is associated with a replication task
- Get the list of table names of a specified schema in the data source that is associated with a replication task
- Get the CREATE statement for schemas of the data source that is associated with a replication task
- Update the CREATE statement for schemas of the data source that is associated with a replication task
- Delete a schema of the data source that is associated with a replication task
The following sections describe the specific usage of the APIs.
After sending an API request, if an error occurs, the returned error message is in the following format:
{
"error_msg": "",
"error_code": ""
}
From the above JSON output, error_msg
describes the error message and error_code
is the corresponding error code.
This API is a synchronous interface. If the request is successful, the information of the corresponding node is returned.
GET /api/v1/cluster/masters
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/cluster/masters' \
-H 'accept: application/json'
{
"total": 1,
"data": [
{
"name": "master1",
"alive": true,
"leader": true,
"addr": "127.0.0.1:8261"
}
]
}
This API is a synchronous interface. If the request is successful, the status code of the returned body is 204.
DELETE /api/v1/cluster/masters/{master-name}
{{< copyable "shell-regular" >}}
curl -X 'DELETE' \
'http://127.0.0.1:8261/api/v1/cluster/masters/master1' \
-H 'accept: */*'
This API is a synchronous interface. If the request is successful, the information of the corresponding node is returned.
GET /api/v1/cluster/workers
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/cluster/workers' \
-H 'accept: application/json'
{
"total": 1,
"data": [
{
"name": "worker1",
"addr": "127.0.0.1:8261",
"bound_stage": "bound",
"bound_source_name": "mysql-01"
}
]
}
This API is a synchronous interface. If the request is successful, the status code of the returned body is 204.
DELETE /api/v1/cluster/workers/{worker-name}
{{< copyable "shell-regular" >}}
curl -X 'DELETE' \
'http://127.0.0.1:8261/api/v1/cluster/workers/worker1' \
-H 'accept: */*'
This API is a synchronous interface. If the request is successful, the information of the corresponding data source is returned.
POST /api/v1/sources
{{< copyable "shell-regular" >}}
curl -X 'POST' \
'http://127.0.0.1:8261/api/v1/sources' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"source_name": "mysql-01",
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"enable_gtid": false,
"security": {
"ssl_ca_content": "",
"ssl_cert_content": "",
"ssl_key_content": "",
"cert_allowed_cn": [
"string"
]
},
"purge": {
"interval": 3600,
"expires": 0,
"remain_space": 15
}
}'
{
"source_name": "mysql-01",
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"enable_gtid": false,
"security": {
"ssl_ca_content": "",
"ssl_cert_content": "",
"ssl_key_content": "",
"cert_allowed_cn": [
"string"
]
},
"purge": {
"interval": 3600,
"expires": 0,
"remain_space": 15
},
"status_list": [
{
"source_name": "mysql-replica-01",
"worker_name": "worker-1",
"relay_status": {
"master_binlog": "(mysql-bin.000001, 1979)",
"master_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849",
"relay_dir": "./sub_dir",
"relay_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849",
"relay_catch_up_master": true,
"stage": "Running"
},
"error_msg": "string"
}
]
}
This API is a synchronous interface. If the request is successful, the data source list is returned.
GET /api/v1/sources
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/sources?with_status=true' \
-H 'accept: application/json'
{
"data": [
{
"enable_gtid": false,
"host": "127.0.0.1",
"password": "******",
"port": 3306,
"purge": {
"expires": 0,
"interval": 3600,
"remain_space": 15
},
"security": null,
"source_name": "mysql-01",
"user": "root"
},
{
"enable_gtid": false,
"host": "127.0.0.1",
"password": "******",
"port": 3307,
"purge": {
"expires": 0,
"interval": 3600,
"remain_space": 15
},
"security": null,
"source_name": "mysql-02",
"user": "root"
}
],
"total": 2
}
This API is a synchronous interface. If the request is successful, the status code of the returned body is 204.
DELETE /api/v1/sources/{source-name}
{{< copyable "shell-regular" >}}
curl -X 'DELETE' \
'http://127.0.0.1:8261/api/v1/sources/mysql-01?force=true' \
-H 'accept: application/json'
This API is a synchronous interface. If the request is successful, the information of the corresponding node is returned.
GET /api/v1/sources/{source-name}/status
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/sources/mysql-replica-01/status' \
-H 'accept: application/json'
{
"total": 1,
"data": [
{
"source_name": "mysql-replica-01",
"worker_name": "worker-1",
"relay_status": {
"master_binlog": "(mysql-bin.000001, 1979)",
"master_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849",
"relay_dir": "./sub_dir",
"relay_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849",
"relay_catch_up_master": true,
"stage": "Running"
},
"error_msg": "string"
}
]
}
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a data source.
PATCH /api/v1/sources/{source-name}/start-relay
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/sources/mysql-01/start-relay' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"worker_name_list": [
"worker-1"
],
"relay_binlog_name": "mysql-bin.000002",
"relay_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849",
"relay_dir": "./relay_log"
}'
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a data source.
PATCH /api/v1/sources/{source-name}/stop-relay
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/sources/mysql-01/stop-relay' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"worker_name_list": [
"worker-1"
]
}'
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a data source.
PATCH /api/v1/sources/{source-name}/pause-relay
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/sources/mysql-01/pause-relay' \
-H 'accept: */*'
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a data source.
PATCH /api/v1/sources/{source-name}/resume-relay
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/sources/mysql-01/resume-relay' \
-H 'accept: */*'
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a DM-worker node.
PATCH /api/v1/sources/{source-name}/transfer
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/sources/mysql-01/transfer' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"worker_name": "worker-1"
}'
This API is a synchronous interface. If the request is successful, the corresponding list is returned.
GET /api/v1/sources/{source-name}/schemas
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/sources/source-1/schemas' \
-H 'accept: application/json'
[
"db1"
]
This API is a synchronous interface. If the request is successful, the corresponding list is returned.
GET /api/v1/sources/{source-name}/schemas/{schema-name}
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/sources/source-1/schemas/db1' \
-H 'accept: application/json'
[
"table1"
]
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a replication task.
POST /api/v1/tasks
{{< copyable "shell-regular" >}}
curl -X 'POST' \
'http://127.0.0.1:8261/api/v1/tasks' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"remove_meta": false,
"task": {
"name": "task-1",
"task_mode": "all",
"shard_mode": "pessimistic",
"meta_schema": "dm-meta",
"enhance_online_schema_change": true,
"on_duplicate": "overwrite",
"target_config": {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"security": {
"ssl_ca_content": "",
"ssl_cert_content": "",
"ssl_key_content": "",
"cert_allowed_cn": [
"string"
]
}
},
"binlog_filter_rule": {
"rule-1": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
},
"rule-2": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
},
"rule-3": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
}
},
"table_migrate_rule": [
{
"source": {
"source_name": "source-name",
"schema": "db-*",
"table": "tb-*"
},
"target": {
"schema": "db1",
"table": "tb1"
},
"binlog_filter_rule": [
"rule-1",
"rule-2",
"rule-3",
]
}
],
"source_config": {
"full_migrate_conf": {
"export_threads": 4,
"import_threads": 16,
"data_dir": "./exported_data",
"consistency": "auto"
},
"incr_migrate_conf": {
"repl_threads": 16,
"repl_batch": 100
},
"source_conf": [
{
"source_name": "mysql-replica-01",
"binlog_name": "binlog.000001",
"binlog_pos": 4,
"binlog_gtid": "03fc0263-28c7-11e7-a653-6c0b84d59f30:1-7041423,05474d3c-28c7-11e7-8352-203db246dd3d:1-170"
}
]
}
},
"source_name_list": [
"source-1"
]
}'
{
"name": "task-1",
"task_mode": "all",
"shard_mode": "pessimistic",
"meta_schema": "dm-meta",
"enhance_online_schema_change": true,
"on_duplicate": "overwrite",
"target_config": {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"security": {
"ssl_ca_content": "",
"ssl_cert_content": "",
"ssl_key_content": "",
"cert_allowed_cn": [
"string"
]
}
},
"binlog_filter_rule": {
"rule-1": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
},
"rule-2": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
},
"rule-3": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
}
},
"table_migrate_rule": [
{
"source": {
"source_name": "source-name",
"schema": "db-*",
"table": "tb-*"
},
"target": {
"schema": "db1",
"table": "tb1"
},
"binlog_filter_rule": [
"rule-1",
"rule-2",
"rule-3",
]
}
],
"source_config": {
"full_migrate_conf": {
"export_threads": 4,
"import_threads": 16,
"data_dir": "./exported_data",
"consistency": "auto"
},
"incr_migrate_conf": {
"repl_threads": 16,
"repl_batch": 100
},
"source_conf": [
{
"source_name": "mysql-replica-01",
"binlog_name": "binlog.000001",
"binlog_pos": 4,
"binlog_gtid": "03fc0263-28c7-11e7-a653-6c0b84d59f30:1-7041423,05474d3c-28c7-11e7-8352-203db246dd3d:1-170"
}
]
}
}
This API is a synchronous interface. If the request is successful, the information of the corresponding replication task is returned.
GET /api/v1/tasks
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/tasks' \
-H 'accept: application/json'
{
"total": 2,
"data": [
{
"name": "task-1",
"task_mode": "all",
"shard_mode": "pessimistic",
"meta_schema": "dm-meta",
"enhance_online_schema_change": true,
"on_duplicate": "overwrite",
"target_config": {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"security": {
"ssl_ca_content": "",
"ssl_cert_content": "",
"ssl_key_content": "",
"cert_allowed_cn": [
"string"
]
}
},
"binlog_filter_rule": {
"rule-1": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
},
"rule-2": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
},
"rule-3": {
"ignore_event": [
"all dml"
],
"ignore_sql": [
"^Drop"
]
}
},
"table_migrate_rule": [
{
"source": {
"source_name": "source-name",
"schema": "db-*",
"table": "tb-*"
},
"target": {
"schema": "db1",
"table": "tb1"
},
"binlog_filter_rule": [
"rule-1",
"rule-2",
"rule-3",
]
}
],
"source_config": {
"full_migrate_conf": {
"export_threads": 4,
"import_threads": 16,
"data_dir": "./exported_data",
"consistency": "auto"
},
"incr_migrate_conf": {
"repl_threads": 16,
"repl_batch": 100
},
"source_conf": [
{
"source_name": "mysql-replica-01",
"binlog_name": "binlog.000001",
"binlog_pos": 4,
"binlog_gtid": "03fc0263-28c7-11e7-a653-6c0b84d59f30:1-7041423,05474d3c-28c7-11e7-8352-203db246dd3d:1-170"
}
]
}
}
]
}
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 204. To learn about its latest status, You can get the information of a replication task.
DELETE /api/v1/tasks/{task-name}
{{< copyable "shell-regular" >}}
curl -X 'DELETE' \
'http://127.0.0.1:8261/api/v1/tasks/task-1' \
-H 'accept: */*'
This API is a synchronous interface. If the request is successful, the information of the corresponding node is returned.
GET /api/v1/tasks/task-1/status
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/status?stage=running' \
-H 'accept: application/json'
{
"total": 1,
"data": [
{
"name": "string",
"source_name": "string",
"worker_name": "string",
"stage": "runing",
"unit": "sync",
"unresolved_ddl_lock_id": "string",
"load_status": {
"finished_bytes": 0,
"total_bytes": 0,
"progress": "string",
"meta_binlog": "string",
"meta_binlog_gtid": "string"
},
"sync_status": {
"total_events": 0,
"total_tps": 0,
"recent_tps": 0,
"master_binlog": "string",
"master_binlog_gtid": "string",
"syncer_binlog": "string",
"syncer_binlog_gtid": "string",
"blocking_ddls": [
"string"
],
"unresolved_groups": [
{
"target": "string",
"ddl_list": [
"string"
],
"first_location": "string",
"synced": [
"string"
],
"unsynced": [
"string"
]
}
],
"synced": true,
"binlog_type": "string",
"seconds_behind_master": 0
}
}
]
}
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a replication task.
PATCH /api/v1/tasks/task-1/pause
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/pause' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '[
"source-1"
]'
This API is an asynchronous interface. If the request is successful, the status code of the returned body is 200. To learn about its latest status, You can get the information of a replication task.
PATCH /api/v1/tasks/task-1/resume
{{< copyable "shell-regular" >}}
curl -X 'PATCH' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/resume' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '[
"source-1"
]'
This API is a synchronous interface. If the request is successful, the corresponding list is returned.
GET /api/v1/tasks/{task-name}/sources/{source-name}/schemas
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas' \
-H 'accept: application/json'
[
"db1"
]
Get the list of table names of a specified schema in the data source that is associated with a replication task
This API is a synchronous interface. If the request is successful, the corresponding list is returned.
GET /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas/db1' \
-H 'accept: application/json'
[
"table1"
]
This API is a synchronous interface. If the request is successful, the corresponding CREATE statement is returned.
GET /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}/{table-name}
{{< copyable "shell-regular" >}}
curl -X 'GET' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas/db1/table1' \
-H 'accept: application/json'
{
"schema_name": "db1",
"table_name": "table1",
"schema_create_sql": "CREATE TABLE `t1` (`id` int(11) NOT NULL AUTO_INCREMENT,PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
}
Update the CREATE statement for schemas of the data source that is associated with a replication task
This API is a synchronous interface. If the request is successful, the status code of the returned body is 200.
PATCH /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}/{table-name}
{{< copyable "shell-regular" >}}
curl -X 'PUT' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/task-1/schemas/db1/table1' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"sql_content": "CREATE TABLE `t1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL, `c3` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;",
"flush": true,
"sync": true
}'
This API is a synchronous interface. If the request is successful, the status code of the returned body is 200.
DELETE /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}/{table-name}
{{< copyable "shell-regular" >}}
curl -X 'DELETE' \
'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas/db1/table1' \
-H 'accept: */*'