summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKubeEdge Bot <48982446+kubeedge-bot@users.noreply.github.com>2023-11-24 15:49:37 +0800
committerGitHub <noreply@github.com>2023-11-24 15:49:37 +0800
commited4634c64c8d80d2cc9cf95a1b5402751ecf6ce4 (patch)
tree59aac66810e44314781845c1fe5ca4a2c97cdfe2
parentMerge pull request #5201 from Shelley-BaoYue/bump-kubernetes-1.26.10 (diff)
parentpptv.PushMethod != nil (diff)
downloadkubeedge-ed4634c64c8d80d2cc9cf95a1b5402751ecf6ce4.tar.gz
Merge pull request #5204 from Shelley-BaoYue/automated-cherry-pick-of-#5112-upstream-release-1.15
Automated cherry pick of #5112: Fixed a null pointer error when PushMethod is not defined for device properties
-rw-r--r--staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go80
1 files changed, 41 insertions, 39 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 8f6e89254..9fb9621e6 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
@@ -134,63 +134,65 @@ func buildPropertiesFromGrpc(device *dmiapi.Device) []common.DeviceProperty {
// get dbMethod filed by grpc device instance
var dbMethodName string
var dbconfig common.DBConfig
- if pptv.PushMethod.DBMethod != nil {
- dbMethodName, err = getDBMethodFromGrpc(pptv)
+ var pushMethod []byte
+ var pushMethodName string
+ if pptv.PushMethod != nil {
+ if pptv.PushMethod.DBMethod != nil {
+ dbMethodName, err = getDBMethodFromGrpc(pptv)
+ if err != nil {
+ klog.Errorf("err: %+v", err)
+ return nil
+ }
+ switch dbMethodName {
+ case "influx":
+ clientconfig, err := json.Marshal(pptv.PushMethod.DBMethod.Influxdb2.Influxdb2ClientConfig)
+ if err != nil {
+ klog.Errorf("err: %+v", err)
+ return nil
+ }
+ dataconfig, err := json.Marshal(pptv.PushMethod.DBMethod.Influxdb2.Influxdb2DataConfig)
+ if err != nil {
+ klog.Errorf("err: %+v", err)
+ return nil
+ }
+ dbconfig = common.DBConfig{
+ Influxdb2ClientConfig: clientconfig,
+ Influxdb2DataConfig: dataconfig,
+ }
+ }
+ }
+ // get pushMethod filed by grpc device instance
+ pushMethodName, err = getPushMethodFromGrpc(pptv)
if err != nil {
klog.Errorf("err: %+v", err)
return nil
}
- switch dbMethodName {
- case "influx":
- clientconfig, err := json.Marshal(pptv.PushMethod.DBMethod.Influxdb2.Influxdb2ClientConfig)
+ switch pushMethodName {
+ case "http":
+ pushMethod, err = json.Marshal(pptv.PushMethod.Http)
if err != nil {
klog.Errorf("err: %+v", err)
return nil
}
- dataconfig, err := json.Marshal(pptv.PushMethod.DBMethod.Influxdb2.Influxdb2DataConfig)
+ case "mqtt":
+ pushMethod, err = json.Marshal(pptv.PushMethod.Mqtt)
if err != nil {
klog.Errorf("err: %+v", err)
return nil
}
- dbconfig = common.DBConfig{
- Influxdb2ClientConfig: clientconfig,
- Influxdb2DataConfig: dataconfig,
- }
- }
- }
-
- // get pushMethod filed by grpc device instance
- pushMethodName, err := getPushMethodFromGrpc(pptv)
- if err != nil {
- klog.Errorf("err: %+v", err)
- return nil
- }
- var pushMethod []byte
- switch pushMethodName {
- case "http":
- pushMethod, err = json.Marshal(pptv.PushMethod.Http)
- if err != nil {
- klog.Errorf("err: %+v", err)
- return nil
- }
- case "mqtt":
- pushMethod, err = json.Marshal(pptv.PushMethod.Mqtt)
- if err != nil {
- klog.Errorf("err: %+v", err)
- return nil
}
}
// get the final Properties
cur := common.DeviceProperty{
- Name: pptv.GetName(),
- PropertyName: pptv.GetName(),
- ModelName: device.Spec.DeviceModelReference,
- CollectCycle: pptv.GetCollectCycle(),
- ReportCycle: pptv.GetReportCycle(),
+ Name: pptv.GetName(),
+ PropertyName: pptv.GetName(),
+ ModelName: device.Spec.DeviceModelReference,
+ CollectCycle: pptv.GetCollectCycle(),
+ ReportCycle: pptv.GetReportCycle(),
ReportToCloud: pptv.GetReportToCloud(),
- Protocol: protocolName,
- Visitors: visitorConfig,
+ Protocol: protocolName,
+ Visitors: visitorConfig,
PushMethod: common.PushMethodConfig{
MethodName: pushMethodName,
MethodConfig: pushMethod,