فهرست منبع

fix(doc): add full data export/import docs

Signed-off-by: Jianxiang Ran <rxan_embedded@163.com>
Jianxiang Ran 2 سال پیش
والد
کامیت
3e7e27127b

+ 16 - 0
docs/directory.json

@@ -511,6 +511,10 @@
 						{
 							"title": "规则集管理",
 							"path": "operation/restapi/ruleset"
+						},
+						{
+							"title": "数据导入导出",
+							"path": "operation/restapi/configuration"
 						}
 					]
 				},
@@ -544,6 +548,10 @@
 						{
 							"title": "规则集管理",
 							"path": "operation/cli/ruleset"
+						},
+						{
+							"title": "数据导入导出",
+							"path": "operation/cli/configuration"
 						}
 					]
 				},
@@ -1204,6 +1212,10 @@
 						{
 							"title": "Ruleset",
 							"path": "api/restapi/ruleset"
+						},
+						{
+							"title": "Data Export/Import",
+							"path": "api/restapi/configuration"
 						}
 					]
 				},
@@ -1237,6 +1249,10 @@
 						{
 							"title": "Ruleset",
 							"path": "api/cli/ruleset"
+						},
+						{
+							"title": "Data Export/Import",
+							"path": "api/cli/configuration"
 						}
 					]
 				}

+ 65 - 0
docs/en_US/api/cli/configuration.md

@@ -0,0 +1,65 @@
+# Data Import/Export Management
+
+The eKuiper rule command line tools allows to import and export all the Data.
+
+## Data Format
+
+The file format for importing and exporting Data is JSON, which can contain : `streams`, `tables`, `rules`, `plugin`, `source yaml` and so on. Each type holds the the key-value pair of the name and the creation statement. In the following example file, we define stream 、rules、table、plugin、source config、sink config
+
+```json
+{
+  "streams": {
+    "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+  },
+  "tables": {
+    "T110":"\n CREATE TABLE T110\n (\n S1 string\n )\n WITH (DATASOURCE=\"test.json\", FORMAT=\"json\", TYPE=\"file\", KIND=\"scan\", );\n "
+  },
+  "rules": {
+    "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+    "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+  },
+  "nativePlugins":{
+    "sinks_file":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: no such file or directory",
+    "sinks_tdengine":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: no such file or directory",
+    "sources_random":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: no such file or directory"
+  },
+  "portablePlugins":{
+  },
+  "sourceConfig":{
+    "mqtt":"{\"td\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://broker.emqx.io:1883\",\"username\":\"admin\"},\"test\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://127.0.0.1:1883\",\"username\":\"admin\"}}"
+  },
+  "sinkConfig":{
+    "edgex":"{\"test\":{\"bufferLength\":1024,\"contentType\":\"application/json\",\"enableCache\":false,\"format\":\"json\",\"messageType\":\"event\",\"omitIfEmpty\":false,\"port\":6379,\"protocol\":\"redis\",\"runAsync\":false,\"sendSingle\":true,\"server\":\"localhost\",\"topic\":\"application\",\"type\":\"redis\"}}"
+  },
+  "connectionConfig":{
+  },
+  "Service":{
+  },
+  "Schema":{
+  }
+}
+```
+
+## Import Data
+
+The API resets all existing data and then imports the new data into the system. 
+
+```shell
+# bin/kuiper import data -f myrules.json -s false
+```
+
+## Import Data Status
+
+This API returns Data import errors. If all returns are empty, it means that the import is completely successful.
+
+```shell
+# bin/kuiper getstatus import
+```
+
+## Data Export
+
+This command exports the Data to the specified file. 
+
+```shell
+# bin/kuiper export data myrules.json
+```

+ 138 - 0
docs/en_US/api/restapi/configuration.md

@@ -0,0 +1,138 @@
+# Data Import/Export Management
+
+eKuiper REST api allows to import or export all data.
+
+## Data Format
+
+The file format for importing and exporting data is JSON, which can contain : `streams`, `tables`, `rules`, `plugin`, `source yaml` and so on. Each type holds the the key-value pair of the name and the creation statement. In the following example file, we define stream 、rules、table、plugin、source config、sink config
+
+```json
+{
+    "streams": {
+        "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+    },
+    "tables": {
+      "T110":"\n CREATE TABLE T110\n (\n S1 string\n )\n WITH (DATASOURCE=\"test.json\", FORMAT=\"json\", TYPE=\"file\", KIND=\"scan\", );\n "
+    },
+    "rules": {
+        "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+        "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+    },
+    "nativePlugins":{
+        "sinks_file":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: no such file or directory",
+        "sinks_tdengine":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: no such file or directory",
+        "sources_random":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: no such file or directory"
+    },
+    "portablePlugins":{
+    },
+    "sourceConfig":{
+      "mqtt":"{\"td\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://broker.emqx.io:1883\",\"username\":\"admin\"},\"test\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://127.0.0.1:1883\",\"username\":\"admin\"}}"
+    },
+    "sinkConfig":{
+      "edgex":"{\"test\":{\"bufferLength\":1024,\"contentType\":\"application/json\",\"enableCache\":false,\"format\":\"json\",\"messageType\":\"event\",\"omitIfEmpty\":false,\"port\":6379,\"protocol\":\"redis\",\"runAsync\":false,\"sendSingle\":true,\"server\":\"localhost\",\"topic\":\"application\",\"type\":\"redis\"}}"
+    },
+    "connectionConfig":{
+    },
+    "Service":{
+    },
+    "Schema":{
+    }
+}
+```
+
+## Import Data
+
+The API resets all existing data and then imports the new data into the system. The API supports specifying data by means of text content or file URIs.
+
+
+Example 1: Import by text content
+
+
+```shell
+POST http://{{host}}/data/import
+Content-Type: application/json
+
+{
+  "content": "$规则集 json 内容"
+}
+```
+
+Example 2: Import by file URI
+
+```shell
+POST http://{{host}}/data/import
+Content-Type: application/json
+
+{
+  "file": "file:///tmp/a.json"
+}
+```
+
+Example 3: Import data via file URI and exit (for plug-ins and static schema updates, users need to ensure that eKuiper can be restarted after exiting)
+
+```shell
+POST http://{{host}}/data/import?stop=1
+Content-Type: application/json
+
+{
+  "file": "file:///tmp/a.json"
+}
+```
+
+## Import data status
+
+
+This API returns data import errors. If all returns are empty, it means that the import is completely successful.
+
+```shell
+GET http://{{host}}/data/import/status
+```
+
+Example 1: The data import is completely successful
+
+```shell
+GET http://{{host}}/data/import/status
+Content-Type: application/json
+
+{
+  "streams":{},
+  "tables":{},
+  "rules":{},
+  "nativePlugins":{},
+  "portablePlugins":{},
+  "sourceConfig":{},
+  "sinkConfig":{},
+  "connectionConfig":{},
+  "Service":{},
+  "Schema":{}}
+```
+
+Example 2: Failed to import plugin
+
+```shell
+GET http://{{host}}/data/import/status
+Content-Type: application/json
+
+{
+  "streams":{},
+  "tables":{},
+  "rules":{},
+  "nativePlugins":{
+    "sinks_file":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: no such file or directory",
+    "sinks_tdengine":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: no such file or directory",
+    "sources_random":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: no such file or directory"},
+  "portablePlugins":{},
+  "sourceConfig":{},
+  "sinkConfig":{},
+  "connectionConfig":{},
+  "Service":{},
+  "Schema":{}}
+```
+
+## Data Export
+
+The export API returns a file to download.
+
+```shell
+GET http://{{host}}/data/export
+```

+ 65 - 0
docs/zh_CN/operation/cli/configuration.md

@@ -0,0 +1,65 @@
+# 数据导入导出管理
+
+eKuiper 命令行工具允许您导入导出当前的所有数据。
+
+## 数据格式
+
+导入导出数据的文件格式为 JSON, 包含流 `stream`,表 `table`, 规则 `rule`,插件 `plugin`,源配置 `source yaml` 等。每种类型保存名字和创建语句的键值对。在以下示例文件中,我们定义了流、规则、表、插件、源配置、目标动作配置。
+
+```json
+{
+  "streams": {
+    "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+  },
+  "tables": {
+    "T110":"\n CREATE TABLE T110\n (\n S1 string\n )\n WITH (DATASOURCE=\"test.json\", FORMAT=\"json\", TYPE=\"file\", KIND=\"scan\", );\n "
+  },
+  "rules": {
+    "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+    "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+  },
+  "nativePlugins":{
+    "sinks_file":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: no such file or directory",
+    "sinks_tdengine":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: no such file or directory",
+    "sources_random":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: no such file or directory"
+  },
+  "portablePlugins":{
+  },
+  "sourceConfig":{
+    "mqtt":"{\"td\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://broker.emqx.io:1883\",\"username\":\"admin\"},\"test\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://127.0.0.1:1883\",\"username\":\"admin\"}}"
+  },
+  "sinkConfig":{
+    "edgex":"{\"test\":{\"bufferLength\":1024,\"contentType\":\"application/json\",\"enableCache\":false,\"format\":\"json\",\"messageType\":\"event\",\"omitIfEmpty\":false,\"port\":6379,\"protocol\":\"redis\",\"runAsync\":false,\"sendSingle\":true,\"server\":\"localhost\",\"topic\":\"application\",\"type\":\"redis\"}}"
+  },
+  "connectionConfig":{
+  },
+  "Service":{
+  },
+  "Schema":{
+  }
+}
+```
+
+## 导入数据
+
+该 API 接受数据并将其导入系统中。若已有历史遗留数据,则首先清除旧有数据,然后导入。
+
+```shell
+# bin/kuiper import data -f myrules.json -s false
+```
+
+## 导入数据状态查询
+
+该 API 返回数据导入出错情况,如所有返回为空,则代表导入完全成功。
+
+```shell
+# bin/kuiper getstatus import
+```
+
+## 导出数据
+
+导出 API 返回二进制流,在浏览器使用时,可选择下载保存的文件路径。
+
+```shell
+# bin/kuiper export data myrules.json
+```

+ 136 - 0
docs/zh_CN/operation/restapi/configuration.md

@@ -0,0 +1,136 @@
+# 数据导入导出管理
+
+eKuiper REST api 允许您导入导出当前的所有数据。
+
+## 数据格式
+
+导入导出数据的文件格式为 JSON, 包含流 `stream`,表 `table`, 规则 `rule`,插件 `plugin`,源配置 `source yaml` 等。每种类型保存名字和创建语句的键值对。在以下示例文件中,我们定义了流、规则、表、插件、源配置、目标动作配置。
+
+```json
+{
+    "streams": {
+        "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+    },
+    "tables": {
+      "T110":"\n CREATE TABLE T110\n (\n S1 string\n )\n WITH (DATASOURCE=\"test.json\", FORMAT=\"json\", TYPE=\"file\", KIND=\"scan\", );\n "
+    },
+    "rules": {
+        "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+        "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+    },
+    "nativePlugins":{
+        "sinks_file":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: no such file or directory",
+        "sinks_tdengine":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: no such file or directory",
+        "sources_random":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: no such file or directory"
+    },
+    "portablePlugins":{
+    },
+    "sourceConfig":{
+      "mqtt":"{\"td\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://broker.emqx.io:1883\",\"username\":\"admin\"},\"test\":{\"insecureSkipVerify\":false,\"password\":\"public\",\"protocolVersion\":\"3.1.1\",\"qos\":1,\"server\":\"tcp://127.0.0.1:1883\",\"username\":\"admin\"}}"
+    },
+    "sinkConfig":{
+      "edgex":"{\"test\":{\"bufferLength\":1024,\"contentType\":\"application/json\",\"enableCache\":false,\"format\":\"json\",\"messageType\":\"event\",\"omitIfEmpty\":false,\"port\":6379,\"protocol\":\"redis\",\"runAsync\":false,\"sendSingle\":true,\"server\":\"localhost\",\"topic\":\"application\",\"type\":\"redis\"}}"
+    },
+    "connectionConfig":{
+    },
+    "Service":{
+    },
+    "Schema":{
+    }
+}
+```
+
+## 导入数据
+
+该 API 接受数据并将其导入系统中。若已有历史遗留数据,则首先清除旧有数据,然后导入。 API 支持通过文本内容或者文件 URI 的方式指定数据。
+
+示例1:通过文本内容导入
+
+
+```shell
+POST http://{{host}}/data/import
+Content-Type: application/json
+
+{
+  "content": "$数据 json 内容"
+}
+```
+
+示例2:通过文件 URI 导入
+
+```shell
+POST http://{{host}}/data/import
+Content-Type: application/json
+
+{
+  "file": "file:///tmp/a.json"
+}
+```
+
+示例3:通过文件 URI 导入数据并退出 (用于插件和静态模式更新,用户需保证 eKuiper 退出后能重新启动)
+
+```shell
+POST http://{{host}}/data/import?stop=1
+Content-Type: application/json
+
+{
+  "file": "file:///tmp/a.json"
+}
+```
+
+## 导入数据状态查询
+
+该 API 返回数据导入出错情况,如所有返回为空,则代表导入完全成功。
+
+```shell
+GET http://{{host}}/data/import/status
+```
+
+示例1:导入数据完全成功
+
+```shell
+GET http://{{host}}/data/import/status
+Content-Type: application/json
+
+{
+  "streams":{},
+  "tables":{},
+  "rules":{},
+  "nativePlugins":{},
+  "portablePlugins":{},
+  "sourceConfig":{},
+  "sinkConfig":{},
+  "connectionConfig":{},
+  "Service":{},
+  "Schema":{}}
+```
+
+示例2:导入插件失败
+
+```shell
+GET http://{{host}}/data/import/status
+Content-Type: application/json
+
+{
+  "streams":{},
+  "tables":{},
+  "rules":{},
+  "nativePlugins":{
+    "sinks_file":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/file_amd64.zip: no such file or directory",
+    "sinks_tdengine":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sinks/tdengine_amd64.zip: no such file or directory",
+    "sources_random":"fail to download file file:///root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: stat /root/ekuiper-jran/_plugins/ubuntu/sources/random_amd64.zip: no such file or directory"},
+  "portablePlugins":{},
+  "sourceConfig":{},
+  "sinkConfig":{},
+  "connectionConfig":{},
+  "Service":{},
+  "Schema":{}}
+```
+
+## 导出数据
+
+导出 API 返回二进制流,在浏览器使用时,可选择下载保存的文件路径。
+
+```shell
+GET http://{{host}}/data/export
+```