summaryrefslogtreecommitdiff
path: root/staging
diff options
context:
space:
mode:
authorwbc6080 <wangbincheng4@huawei.com>2024-01-12 15:32:57 +0800
committerwbc6080 <wangbincheng4@huawei.com>2024-01-18 11:13:55 +0800
commitbd5595bda9021cdd750c9f50a27dd8a5246c8ade (patch)
treec8166b6ba8d551e1c826b2fad0c53b7fd2176f10 /staging
parentMerge pull request #5292 from cl2017/add_lint_check (diff)
downloadkubeedge-bd5595bda9021cdd750c9f50a27dd8a5246c8ade.tar.gz
fix some bug in framework
Signed-off-by: wbc6080 <wangbincheng4@huawei.com>
Diffstat (limited to 'staging')
-rw-r--r--staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go81
1 files changed, 30 insertions, 51 deletions
diff --git a/staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go b/staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go
index 087465d1c..142ea1ee4 100644
--- a/staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go
+++ b/staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go
@@ -2,8 +2,6 @@ package parse
import (
"encoding/json"
- "errors"
-
"k8s.io/klog/v2"
dmiapi "github.com/kubeedge/kubeedge/pkg/apis/dmi/v1beta1"
@@ -19,27 +17,6 @@ func getProtocolNameFromGrpc(device *dmiapi.Device) (string, error) {
return device.Spec.Protocol.ProtocolName, nil
}
-func getPushMethodFromGrpc(visitor *dmiapi.DeviceProperty) (string, error) {
- if visitor.PushMethod != nil && visitor.PushMethod.Http != nil {
- return common.PushMethodHTTP, nil
- }
- if visitor.PushMethod != nil && visitor.PushMethod.Mqtt != nil {
- return common.PushMethodMQTT, nil
- }
- return "", errors.New("can not parse publish method")
-}
-
-func getDBMethodFromGrpc(visitor *dmiapi.DeviceProperty) (string, error) {
- if visitor.PushMethod.DBMethod.Influxdb2 != nil {
- return "influx", nil
- } else if visitor.PushMethod.DBMethod.Redis != nil {
- return "redis", nil
- } else if visitor.PushMethod.DBMethod.Tdengine != nil {
- return "tdengine", nil
- }
- return "", errors.New("can not parse dbMethod")
-}
-
func BuildProtocolFromGrpc(device *dmiapi.Device) (common.ProtocolConfig, error) {
protocolName, err := getProtocolNameFromGrpc(device)
if err != nil {
@@ -123,19 +100,16 @@ func buildPropertiesFromGrpc(device *dmiapi.Device) []common.DeviceProperty {
return nil
}
- // get dbMethod filed by grpc device instance
+ // get the whole pushmethod filed by grpc device instance
var dbMethodName string
var dbconfig common.DBConfig
var pushMethod []byte
var pushMethodName string
if pptv.PushMethod != nil && pptv.PushMethod.DBMethod != nil {
- dbMethodName, err = getDBMethodFromGrpc(pptv)
- if err != nil {
- klog.Errorf("get DBMethod err: %+v", err)
- return nil
- }
- switch dbMethodName {
- case "influx":
+ //parse dbmethod filed
+ switch {
+ case pptv.PushMethod.DBMethod.Influxdb2 != nil:
+ dbMethodName = "influx"
clientconfig, err := json.Marshal(pptv.PushMethod.DBMethod.Influxdb2.Influxdb2ClientConfig)
if err != nil {
klog.Errorf("influx client config err: %+v", err)
@@ -150,7 +124,8 @@ func buildPropertiesFromGrpc(device *dmiapi.Device) []common.DeviceProperty {
Influxdb2ClientConfig: clientconfig,
Influxdb2DataConfig: dataconfig,
}
- case "redis":
+ case pptv.PushMethod.DBMethod.Redis != nil:
+ dbMethodName = "redis"
clientConfig, err := json.Marshal(pptv.PushMethod.DBMethod.Redis.RedisClientConfig)
if err != nil {
klog.Errorf("redis config err: %+v", err)
@@ -159,7 +134,8 @@ func buildPropertiesFromGrpc(device *dmiapi.Device) []common.DeviceProperty {
dbconfig = common.DBConfig{
RedisClientConfig: clientConfig,
}
- case "tdengine":
+ case pptv.PushMethod.DBMethod.Tdengine != nil:
+ dbMethodName = "tdengine"
clientConfig, err := json.Marshal(pptv.PushMethod.DBMethod.Tdengine.TdEngineClientConfig)
if err != nil {
klog.Errorf("tdengine config err: %+v", err)
@@ -168,27 +144,30 @@ func buildPropertiesFromGrpc(device *dmiapi.Device) []common.DeviceProperty {
dbconfig = common.DBConfig{
TDEngineClientConfig: clientConfig,
}
+ default:
+ klog.Errorf("get DBMethod err: Unsupported database type")
}
- }
- // get pushMethod filed by grpc device instance
- pushMethodName, err = getPushMethodFromGrpc(pptv)
- if err != nil {
- klog.Errorf("err: %+v", err)
- return nil
}
- switch pushMethodName {
- case common.PushMethodHTTP:
- pushMethod, err = json.Marshal(pptv.PushMethod.Http)
- if err != nil {
- klog.Errorf("err: %+v", err)
- return nil
- }
- case common.PushMethodMQTT:
- pushMethod, err = json.Marshal(pptv.PushMethod.Mqtt)
- if err != nil {
- klog.Errorf("err: %+v", err)
- return nil
+ if pptv.PushMethod != nil {
+ //parse pushmethod filed
+ switch {
+ case pptv.PushMethod.Http != nil:
+ pushMethodName = common.PushMethodHTTP
+ pushMethod, err = json.Marshal(pptv.PushMethod.Http)
+ if err != nil {
+ klog.Errorf("err: %+v", err)
+ return nil
+ }
+ case pptv.PushMethod.Mqtt != nil:
+ pushMethodName = common.PushMethodMQTT
+ pushMethod, err = json.Marshal(pptv.PushMethod.Mqtt)
+ if err != nil {
+ klog.Errorf("err: %+v", err)
+ return nil
+ }
+ default:
+ klog.Errorf("get PushMethod err: Unsupported pushmethod type")
}
}