diff options
| author | KubeEdge Bot <48982446+kubeedge-bot@users.noreply.github.com> | 2023-11-28 16:42:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-28 16:42:42 +0800 |
| commit | 4ff43c020f9eda36359add23ab399cba59bc1129 (patch) | |
| tree | 4d679765133b6903e3aa29f827e46d1c2db03d3d | |
| parent | Merge pull request #5213 from Onion-of-dreamed/automated-cherry-pick-of-#5107... (diff) | |
| parent | Define Twin based on properties in mapper. (diff) | |
| download | kubeedge-4ff43c020f9eda36359add23ab399cba59bc1129.tar.gz | |
Merge pull request #5217 from wbc6080/automated-cherry-pick-of-#5140-upstream-release-1.15
Automated cherry pick of #5140: Define Twin based on properties in mapper.
| -rw-r--r-- | cloud/pkg/devicecontroller/controller/upstream.go | 30 | ||||
| -rw-r--r-- | staging/src/github.com/kubeedge/mapper-framework/pkg/util/parse/grpc.go | 22 |
2 files changed, 33 insertions, 19 deletions
diff --git a/cloud/pkg/devicecontroller/controller/upstream.go b/cloud/pkg/devicecontroller/controller/upstream.go index 566a393d4..d1bcc3836 100644 --- a/cloud/pkg/devicecontroller/controller/upstream.go +++ b/cloud/pkg/devicecontroller/controller/upstream.go @@ -135,8 +135,9 @@ func (uc *UpstreamController) updateDeviceStatus() { } deviceStatus := &DeviceStatus{Status: cacheDevice.Status} for twinName, twin := range msgTwin.Twin { - for i, cacheTwin := range deviceStatus.Status.Twins { - if twinName == cacheTwin.PropertyName && twin.Actual != nil && twin.Actual.Value != nil { + deviceTwin := findTwinByName(twinName, &deviceStatus.Status.Twins) + if deviceTwin != nil { + if twin.Actual != nil && twin.Actual.Value != nil { reported := v1beta1.TwinProperty{} reported.Value = *twin.Actual.Value reported.Metadata = make(map[string]string) @@ -146,8 +147,20 @@ func (uc *UpstreamController) updateDeviceStatus() { if twin.Metadata != nil { reported.Metadata["type"] = twin.Metadata.Type } - deviceStatus.Status.Twins[i].Reported = reported - break + deviceTwin.Reported = reported + } + + if twin.Expected != nil && twin.Expected.Value != nil { + observedDesired := v1beta1.TwinProperty{} + observedDesired.Value = *twin.Expected.Value + observedDesired.Metadata = make(map[string]string) + if twin.Expected.Metadata != nil { + observedDesired.Metadata["timestamp"] = strconv.FormatInt(twin.Expected.Metadata.Timestamp, 10) + } + if twin.Metadata != nil { + observedDesired.Metadata["type"] = twin.Metadata.Type + } + deviceTwin.ObservedDesired = observedDesired } } } @@ -212,3 +225,12 @@ func NewUpstreamController(dc *DownstreamController) (*UpstreamController, error } return uc, nil } + +func findTwinByName(twinName string, twins *[]v1beta1.Twin) *v1beta1.Twin { + for _, twin := range *twins { + if twinName == twin.PropertyName { + return &twin + } + } + return nil +} 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 9fb9621e6..450e3730b 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 @@ -72,26 +72,18 @@ func BuildProtocolFromGrpc(device *dmiapi.Device) (common.ProtocolConfig, error) } func buildTwinsFromGrpc(device *dmiapi.Device) []common.Twin { - if len(device.Status.Twins) == 0 { + if len(device.Spec.Properties) == 0 { return nil } - res := make([]common.Twin, 0, len(device.Status.Twins)) - for _, twin := range device.Status.Twins { + res := make([]common.Twin, 0, len(device.Spec.Properties)) + for _, property := range device.Spec.Properties { cur := common.Twin{ - PropertyName: twin.PropertyName, - + PropertyName: property.Name, ObservedDesired: common.TwinProperty{ - Value: twin.ObservedDesired.Value, - Metadata: common.Metadata{ - Timestamp: twin.ObservedDesired.Metadata["timestamp"], - Type: twin.ObservedDesired.Metadata["type"], - }, - }, - Reported: common.TwinProperty{ - Value: twin.Reported.Value, + Value: property.Desired.Value, Metadata: common.Metadata{ - Timestamp: twin.ObservedDesired.Metadata["timestamp"], - Type: twin.ObservedDesired.Metadata["type"], + Timestamp: property.Desired.Metadata["timestamp"], + Type: property.Desired.Metadata["type"], }, }, } |
