Jelajahi Sumber

doc(rule): ruleset import/export

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
Jiyong Huang 2 tahun lalu
induk
melakukan
120522d4f7

+ 28 - 6
docs/directory.json

@@ -491,12 +491,18 @@
 						{
 						{
 							"title": "外部函数管理",
 							"title": "外部函数管理",
 							"path": "operation/restapi/services"
 							"path": "operation/restapi/services"
-						},{
+						},
+						{
 							"title": "模式管理",
 							"title": "模式管理",
 							"path": "operation/restapi/schemas"
 							"path": "operation/restapi/schemas"
-						},{
+						},
+						{
 							"title": "上传文件管理",
 							"title": "上传文件管理",
 							"path": "operation/restapi/uploads"
 							"path": "operation/restapi/uploads"
+						},
+						{
+							"title": "规则集管理",
+							"path": "operation/restapi/ruleset"
 						}
 						}
 					]
 					]
 				},
 				},
@@ -522,9 +528,14 @@
 						{
 						{
 							"title": "插件管理",
 							"title": "插件管理",
 							"path": "operation/cli/plugins"
 							"path": "operation/cli/plugins"
-						},{
+						},
+						{
 							"title": "模式管理",
 							"title": "模式管理",
 							"path": "operation/cli/schemas"
 							"path": "operation/cli/schemas"
+						},
+						{
+							"title": "规则集管理",
+							"path": "operation/cli/ruleset"
 						}
 						}
 					]
 					]
 				},
 				},
@@ -1057,12 +1068,18 @@
 						{
 						{
 							"title": "External Services",
 							"title": "External Services",
 							"path": "operation/restapi/services"
 							"path": "operation/restapi/services"
-						},{
+						},
+						{
 							"title": "Schemas",
 							"title": "Schemas",
 							"path": "operation/restapi/schemas"
 							"path": "operation/restapi/schemas"
-						},{
+						},
+						{
 							"title": "Upload files",
 							"title": "Upload files",
 							"path": "operation/restapi/uploads"
 							"path": "operation/restapi/uploads"
+						},
+						{
+							"title": "Ruleset",
+							"path": "operation/restapi/ruleset"
 						}
 						}
 					]
 					]
 				},
 				},
@@ -1088,9 +1105,14 @@
 						{
 						{
 							"title": "Plugins",
 							"title": "Plugins",
 							"path": "operation/cli/plugins"
 							"path": "operation/cli/plugins"
-						},{
+						},
+						{
 							"title": "Schemas",
 							"title": "Schemas",
 							"path": "operation/cli/schemas"
 							"path": "operation/cli/schemas"
+						},
+						{
+							"title": "Ruleset",
+							"path": "operation/cli/ruleset"
 						}
 						}
 					]
 					]
 				},
 				},

+ 37 - 0
docs/en_US/operation/cli/ruleset.md

@@ -0,0 +1,37 @@
+# Ruleset Management
+
+The eKuiper rule command line tools allows to import and export all the stream and rule configurations.
+
+## Ruleset Format
+
+The file format for importing and exporting ruleset is JSON, which can contain three parts: `streams`, `tables` and `rules`. Each type holds the the key-value pair of the name and the creation statement. In the following example file, we define a stream and two rules.
+
+```json
+{
+    "streams": {
+        "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+    },
+    "tables": {},
+    "rules": {
+        "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+        "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+    }
+}
+```
+
+## Import Ruleset
+
+This command accepts the ruleset and imports it into the system. If a stream or rule in the ruleset already exists, it is not created. The imported rules are started immediately. The command returns text about the number of streams and rules created
+
+
+```shell
+# bin/kuiper import ruleset -f myrules.json
+```
+
+## Export Ruleset
+
+This command exports the ruleset to the specified file. The command returns text about the number of streams and rules exported.
+
+```shell
+# bin/kuiper export ruleset myrules.json
+```

+ 54 - 0
docs/en_US/operation/restapi/ruleset.md

@@ -0,0 +1,54 @@
+# Ruleset Management
+
+eKuiper REST api allows to import or export the stream and rule configurations.
+
+## Ruleset Format
+
+The file format for importing and exporting ruleset is JSON, which can contain three parts: `streams`, `tables` and `rules`. Each type holds the the key-value pair of the name and the creation statement. In the following example file, we define a stream and two rules.
+
+```json
+{
+  "streams": {
+    "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+  },
+  "tables": {},
+  "rules": {
+    "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+    "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+  }
+}
+```
+
+## Import Ruleset
+
+The API accepts rulesets and imports them into the system. If a stream or rule in the ruleset already exists, it is not created. The API returns text informing the number of streams and rules created. The API supports specifying rulesets by means of text content or file URIs.
+
+Example 1: Import by text content
+
+```shell
+POST http://{{host}}/ruleset/import
+Content-Type: application/json
+
+{
+  "content": "$规则集 json 内容"
+}
+```
+
+Example 2: Import by file URI
+
+```shell
+POST http://{{host}}/ruleset/import
+Content-Type: application/json
+
+{
+  "file": "file:///tmp/a.json"
+}
+```
+
+## Export Ruleset
+
+The export API returns a file to download. 
+
+```shell
+POST http://{{host}}/ruleset/export
+```

+ 37 - 0
docs/zh_CN/operation/cli/ruleset.md

@@ -0,0 +1,37 @@
+# 规则集管理
+
+eKuiper 命令行工具允许您导入导出当前的所有流和规则配置。
+
+## 规则集格式
+
+导入导出规则集的文件格式为 JSON,其中可包含三个部分:流 `streams`,表 `tables` 和规则 `rules`。每种类型保存名字和创建语句的键值对。在以下示例文件中,我们定义了一个流和两条规则。
+
+```json
+{
+    "streams": {
+        "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+    },
+    "tables": {},
+    "rules": {
+        "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+        "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+    }
+}
+```
+
+## 导入规则集
+
+该指令接受规则集并将其导入系统中。若规则集中的流或规则已存在,则不再创建。导入的规则将立刻启动。指令返回文本告知创建的流和规则的数目。
+
+
+```shell
+# bin/kuiper import ruleset -f myrules.json
+```
+
+## 导出规则集
+
+该指令导出规则集到指定的文件中。指令返回文本告知导出的流和规则的数目。
+
+```shell
+# bin/kuiper export ruleset myrules.json
+```

+ 55 - 0
docs/zh_CN/operation/restapi/ruleset.md

@@ -0,0 +1,55 @@
+# 规则集管理
+
+eKuiper REST api 允许您导入导出当前的所有流和规则配置。
+
+## 规则集格式
+
+导入导出规则集的文件格式为 JSON,其中可包含三个部分:流 `streams`,表 `tables` 和规则 `rules`。每种类型保存名字和创建语句的键值对。在以下示例文件中,我们定义了一个流和两条规则。
+
+```json
+{
+    "streams": {
+        "demo": "CREATE STREAM demo () WITH (DATASOURCE=\"users\", FORMAT=\"JSON\")"
+    },
+    "tables": {},
+    "rules": {
+        "rule1": "{\"id\": \"rule1\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{\"log\": {}}]}",
+        "rule2": "{\"id\": \"rule2\",\"sql\": \"SELECT * FROM demo\",\"actions\": [{  \"log\": {}}]}"
+    }
+}
+```
+
+## 导入规则集
+
+该 API 接受规则集并将其导入系统中。若规则集中的流或规则已存在,则不再创建。导入的规则将立刻启动。API 返回文本告知创建的流和规则的数目。 API 支持通过文本内容或者文件 URI 的方式指定规则集。
+
+示例1:通过文本内容导入
+
+
+```shell
+POST http://{{host}}/ruleset/import
+Content-Type: application/json
+
+{
+  "content": "$规则集 json 内容"
+}
+```
+
+示例2:通过文件 URI 导入
+
+```shell
+POST http://{{host}}/ruleset/import
+Content-Type: application/json
+
+{
+  "file": "file:///tmp/a.json"
+}
+```
+
+## 导出规则集
+
+导出 API 返回二进制流,在浏览器使用时,可选择下载保存的文件路径。
+
+```shell
+POST http://{{host}}/ruleset/export
+```