Repository: lf-edge/ekuiper
Pull request #1510 (2022-11-18 06:35:12)

refactor(meta): add data source property for source nodes


Patch:
diff --git a/etc/mqtt_source.json b/etc/mqtt_source.json
index 0f48597c..e359db21 100644
--- a/etc/mqtt_source.json
+++ b/etc/mqtt_source.json
@@ -17,6 +17,17 @@
 		}
 	},
 	"libs": [],
+	"dataSource": {
+		"default": "topic1",
+		"hint": {
+			"en_US": "The MQTT topic to subscribe to, e.g. topic1",
+			"zh_CN": "将要订阅的 MQTT 主题， 例如 topic1"
+		},
+		"label": {
+			"en_US": "Data Source (MQTT Topic)",
+			"zh_CN": "数据源（MQTT 主题）"
+		}
+	},
 	"properties": {
 		"default": [{
 			"name": "connectionSelector",
diff --git a/etc/sources/file.json b/etc/sources/file.json
index aa85df86..087fd206 100644
--- a/etc/sources/file.json
+++ b/etc/sources/file.json
@@ -17,6 +17,17 @@
     }
   },
   "libs": [],
+  "dataSource": {
+    "default": "test.json",
+    "hint": {
+      "en_US": "The file name without directory, e.g. test.json",
+      "zh_CN": "不含路径的文件名，例如 test.json"
+    },
+    "label": {
+      "en_US": "Data Source (File Name)",
+      "zh_CN": "数据源（文件名）"
+    }
+  },
   "properties": {
     "default": [
       {
diff --git a/etc/sources/httppull.json b/etc/sources/httppull.json
index 82ea1d49..c57a3a45 100644
--- a/etc/sources/httppull.json
+++ b/etc/sources/httppull.json
@@ -17,6 +17,16 @@
 			"zh_CN": "eKuiper 为提取 HTTP 源流提供了内置支持，该支持可从 HTTP 服务器代理提取消息并输入 eKuiper 处理管道。"
 		}
 	},
+	"dataSource": {
+		"hint": {
+			"en_US": "The URL endpoint to concatenate with the URL property to form the complete URL, e.g. /api/data",
+			"zh_CN": "URL 的路径部分，与 URL 属性拼接成最终 URL， 例如 /api/data"
+		},
+		"label": {
+			"en_US": "Data Source (URL Endpoint)",
+			"zh_CN": "数据源（URL拼接路径）"
+		}
+	},
 	"properties": {
 		"default": [{
 			"name": "url",
diff --git a/etc/sources/httppush.json b/etc/sources/httppush.json
index a10b7064..a12c924e 100644
--- a/etc/sources/httppush.json
+++ b/etc/sources/httppush.json
@@ -17,6 +17,17 @@
 			"zh_CN": "eKuiper 提供了内置的 HTTP 服务支持，用于接收 HTTP 协议推送的流数据。"
 		}
 	},
+	"dataSource": {
+		"default": "/api/data",
+		"hint": {
+			"en_US": "The URL endpoint to append to the http server URL, e.g. /api/data",
+			"zh_CN": "URL 的路径部分，与配置的 HTTP 服务器地址拼接成最终 URL， 例如 /api/data"
+		},
+		"label": {
+			"en_US": "Data Source (URL Endpoint)",
+			"zh_CN": "数据源（URL拼接路径）"
+		}
+	},
 	"properties": {
 		"default": [{
 			"name": "method",
diff --git a/etc/sources/memory.json b/etc/sources/memory.json
index 16811aaa..869112e2 100644
--- a/etc/sources/memory.json
+++ b/etc/sources/memory.json
@@ -17,6 +17,17 @@
     }
   },
   "libs": [],
+  "dataSource": {
+    "default": "topic1",
+    "hint": {
+      "en_US": "The memory topic to subscribe to, e.g. topic1. It is similar to MQTT topic.",
+      "zh_CN": "将要订阅的内存主题， 例如 topic1。类似 MQTT 主题"
+    },
+    "label": {
+      "en_US": "Data Source (Topic)",
+      "zh_CN": "数据源（主题）"
+    }
+  },
   "properties": {
   },
   "outputs": [
diff --git a/etc/sources/redis.json b/etc/sources/redis.json
index b8181abe..0b43c875 100644
--- a/etc/sources/redis.json
+++ b/etc/sources/redis.json
@@ -17,6 +17,17 @@
     }
   },
   "libs": [],
+  "dataSource": {
+    "default": "0",
+    "hint": {
+      "en_US": "The Redis database to connect to, e.g. 0",
+      "zh_CN": "将要连接的 Redis 数据库号，例如 0"
+    },
+    "label": {
+      "en_US": "Data Source (Database Number)",
+      "zh_CN": "数据源（数据库号）"
+    }
+  },
   "properties": {
     "default": [
       {
diff --git a/extensions/sources/sql/sql.json b/extensions/sources/sql/sql.json
index d26f8bea..1fbaccd9 100644
--- a/extensions/sources/sql/sql.json
+++ b/extensions/sources/sql/sql.json
@@ -16,6 +16,17 @@
       "zh_CN": "从数据库中读取消息"
     }
   },
+  "dataSource": {
+    "default": "table1",
+    "hint": {
+      "en_US": "The SQL database to connect to, e.g. table1",
+      "zh_CN": "将要连接的关系数据库表，例如 table1"
+    },
+    "label": {
+      "en_US": "Data Source (Table)",
+      "zh_CN": "数据源（表名）"
+    }
+  },
   "libs": [],
   "properties": {
     "default": [
diff --git a/extensions/sources/zmq/zmq.json b/extensions/sources/zmq/zmq.json
index ec976c96..cf0096f3 100644
--- a/extensions/sources/zmq/zmq.json
+++ b/extensions/sources/zmq/zmq.json
@@ -19,6 +19,17 @@
   "libs": [
     "github.com/pebbe/zmq4@v1.0.0"
   ],
+  "dataSource": {
+    "default": "topic1",
+    "hint": {
+      "en_US": "The topic to subscribe to, e.g. topic1",
+      "zh_CN": "将要订阅的主题， 例如 topic1"
+    },
+    "label": {
+      "en_US": "Data Source (Topic)",
+      "zh_CN": "数据源（主题）"
+    }
+  },
   "properties": {
     "default": [
       {
diff --git a/internal/meta/sourceMeta.go b/internal/meta/sourceMeta.go
index bfd9161a..a6cf7e83 100644
--- a/internal/meta/sourceMeta.go
+++ b/internal/meta/sourceMeta.go
@@ -28,18 +28,20 @@ import (
 
 type (
 	fileSource struct {
-		About    *fileAbout              `json:"about"`
-		Libs     []string                `json:"libs"`
-		ConfKeys map[string][]*fileField `json:"properties"`
-		Node     interface{}             `json:"node"`
+		About      *fileAbout              `json:"about"`
+		Libs       []string                `json:"libs"`
+		DataSource interface{}             `json:"dataSource,omitempty"`
+		ConfKeys   map[string][]*fileField `json:"properties"`
+		Node       interface{}             `json:"node"`
 	}
 	uiSource struct {
-		About    *about             `json:"about"`
-		Libs     []string           `json:"libs"`
-		ConfKeys map[string][]field `json:"properties"`
-		Node     interface{}        `json:"node"`
-		isScan   bool
-		isLookup bool
+		About      *about             `json:"about"`
+		Libs       []string           `json:"libs"`
+		DataSource interface{}        `json:"dataSource,omitempty"`
+		ConfKeys   map[string][]field `json:"properties"`
+		Node       interface{}        `json:"node"`
+		isScan     bool
+		isLookup   bool
 	}
 )
 
@@ -52,6 +54,9 @@ func newUiSource(fi *fileSource, isScan bool, isLookup bool) (*uiSource, error)
 	ui.Libs = fi.Libs
 	ui.About = newAbout(fi.About)
 	ui.Node = fi.Node
+	if fi.DataSource != nil {
+		ui.DataSource = fi.DataSource
+	}
 	ui.ConfKeys = make(map[string][]field)
 	for k, fields := range fi.ConfKeys {
 		if ui.ConfKeys[k], err = newField(fields); nil != err {


Test patch:
diff --git a/internal/meta/sourceMeta_test.go b/internal/meta/sourceMeta_test.go
index 1835197a..bac5e6a7 100644
--- a/internal/meta/sourceMeta_test.go
+++ b/internal/meta/sourceMeta_test.go
@@ -37,6 +37,10 @@ func TestGetMqttSourceMeta(t *testing.T) {
 		t.Error(err)
 	}
 
+	if showMeta.DataSource == nil {
+		t.Errorf("mqtt source meta data source is null")
+	}
+
 	fields := showMeta.ConfKeys["default"]
 
 	if len(fields) == 0 {