Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load connection props for stream #3266

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/topo/node/conf/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/lf-edge/ekuiper/v2/internal/conf"
"github.com/lf-edge/ekuiper/v2/pkg/ast"
"github.com/lf-edge/ekuiper/v2/pkg/connection"
)

// GetSourceConf unifies all properties set in different locations
Expand Down Expand Up @@ -56,6 +57,21 @@ func GetSourceConf(sourceType string, options *ast.Options) map[string]interface
}
}
}
connectionSelector, ok := props["connectionSelector"]
if ok {
selectorID, ok := connectionSelector.(string)
if ok {
meta, err := connection.GetConnectionDetail(nil, selectorID)
if err != nil {
conf.Log.Warnf("load connection meta %s failed, err:%v", selectorID, err)
} else {
for key, value := range meta.Props {
props[key] = value
}
}
}
}

f := options.FORMAT
if f == "" {
f = "json"
Expand Down
40 changes: 40 additions & 0 deletions internal/topo/node/conf/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/lf-edge/ekuiper/v2/internal/conf"
"github.com/lf-edge/ekuiper/v2/pkg/ast"
"github.com/lf-edge/ekuiper/v2/pkg/connection"
mockContext "github.com/lf-edge/ekuiper/v2/pkg/mock/context"
)

func TestGetSourceConf(t *testing.T) {
connection.InitConnectionManager4Test()
ctx := mockContext.NewMockContext("1", "2")
_, err := connection.CreateNamedConnection(ctx, "test11", "mock", map[string]any{
"a": 1,
})
require.NoError(t, err)
require.NoError(t, conf.WriteCfgIntoKVStorage("sources", "mqtt", "test11", map[string]interface{}{
"connectionSelector": "test11",
}))
type args struct {
sourceType string
options *ast.Options
Expand Down Expand Up @@ -82,6 +95,33 @@ func TestGetSourceConf(t *testing.T) {
"timestampFormat": "",
},
},
{
name: "connTest",
args: args{
sourceType: "mqtt",
options: &ast.Options{
CONF_KEY: "test11",
DATASOURCE: "abc",
},
},
want: map[string]interface{}{
"server": "tcp://127.0.0.1:1883",
"format": "json",
"key": "",
"insecureSkipVerify": false,
"protocolVersion": "3.1.1",
"qos": 1,
"datasource": "abc",
"delimiter": "",
"retainSize": 0,
"schemaId": "",
"strictValidation": false,
"timestamp": "",
"timestampFormat": "",
"connectionSelector": "test11",
"a": 1,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading