summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloud/pkg/common/messagelayer/util.go10
-rw-r--r--cloud/pkg/common/messagelayer/util_test.go8
-rw-r--r--edge/pkg/devicetwin/process.go6
-rw-r--r--edge/pkg/devicetwin/process_test.go2
-rw-r--r--edge/pkg/eventbus/mqtt/client.go4
-rw-r--r--edge/test/integration/utils/helpers/helpers.go2
6 files changed, 18 insertions, 14 deletions
diff --git a/cloud/pkg/common/messagelayer/util.go b/cloud/pkg/common/messagelayer/util.go
index 01e7aa9e0..a8b1f9b97 100644
--- a/cloud/pkg/common/messagelayer/util.go
+++ b/cloud/pkg/common/messagelayer/util.go
@@ -36,8 +36,8 @@ const (
ResourceResourceTypeIndex = 3
ResourceResourceNameIndex = 4
- ResourceDeviceIndex = 2
- ResourceDeviceIDIndex = 3
+ ResourceDeviceIndex = 2
+ ResourceDeviceNamespaceIndex = 3
ResourceDevice = "device"
ResourceTypeTwinEdgeUpdated = "twin/edge_updated"
@@ -128,11 +128,11 @@ func BuildResourceForDevice(nodeID, resourceType, resourceID string) (resource s
return
}
-// GetDeviceID returns the ID of the device
+// GetDeviceID returns the ID of the device,resource's format:$hw/events/device/{namespace}/{deviceName}
func GetDeviceID(resource string) (string, error) {
res := strings.Split(resource, "/")
- if len(res) >= ResourceDeviceIDIndex+1 && res[ResourceDeviceIndex] == ResourceDevice {
- return res[ResourceDeviceIDIndex], nil
+ if len(res) >= ResourceDeviceNamespaceIndex+2 && res[ResourceDeviceIndex] == ResourceDevice {
+ return res[ResourceDeviceNamespaceIndex] + "/" + res[ResourceDeviceNamespaceIndex+1], nil
}
return "", errors.New("failed to get device id")
}
diff --git a/cloud/pkg/common/messagelayer/util_test.go b/cloud/pkg/common/messagelayer/util_test.go
index b82e23182..d1bf278df 100644
--- a/cloud/pkg/common/messagelayer/util_test.go
+++ b/cloud/pkg/common/messagelayer/util_test.go
@@ -91,15 +91,15 @@ func TestGetDeviceID(t *testing.T) {
{
name: "TestGetDeviceID(): Case 1: success",
args: args{
- resource: fmt.Sprintf("node/%s/%s/%s", "nid", ResourceDevice, "did"),
+ resource: fmt.Sprintf("node/%s/%s/%s/%s", "nid", ResourceDevice, "ns", "did"),
},
- want: "did",
+ want: "ns/did",
wantErr: nil,
},
{
- name: "TestGetDeviceID(): Case 2: length less then 4",
+ name: "TestGetDeviceID(): Case 2: length less then 5",
args: args{
- resource: fmt.Sprintf("node/%s/%s", "nid", ResourceDevice),
+ resource: fmt.Sprintf("node/%s/%s/%s", "nid", ResourceDevice, "ns"),
},
want: "",
wantErr: fmt.Errorf("failed to get device id"),
diff --git a/edge/pkg/devicetwin/process.go b/edge/pkg/devicetwin/process.go
index 05178e569..b4f808a7e 100644
--- a/edge/pkg/devicetwin/process.go
+++ b/edge/pkg/devicetwin/process.go
@@ -214,7 +214,11 @@ func classifyMsg(message *dttype.DTMessage) bool {
} else {
identity = splitString[idLoc]
loc := strings.Index(topic, identity)
- nextLoc := loc + len(identity)
+ var nextLoc int
+ if strings.Contains(topic, dtcommon.DeviceETPrefix) {
+ identity = identity + "/" + splitString[idLoc+1]
+ }
+ nextLoc = loc + len(identity)
prefix := topic[0:loc]
suffix := topic[nextLoc:]
klog.Infof("%s %s", prefix, suffix)
diff --git a/edge/pkg/devicetwin/process_test.go b/edge/pkg/devicetwin/process_test.go
index 6d35fde38..50ab9392f 100644
--- a/edge/pkg/devicetwin/process_test.go
+++ b/edge/pkg/devicetwin/process_test.go
@@ -397,7 +397,7 @@ func Test_classifyMsg(t *testing.T) {
otherTopic := "/membership/detail/result"
otherEncodedTopic := base64.URLEncoding.EncodeToString([]byte(otherTopic))
//Encoded eventbus resource
- eventbusTopic := "$hw/events/device/+/state/update"
+ eventbusTopic := "$hw/events/device/+/+/state/update"
eventbusResource := base64.URLEncoding.EncodeToString([]byte(eventbusTopic))
content := testutil.GenerateAddDevicePalyloadMsg(t)
diff --git a/edge/pkg/eventbus/mqtt/client.go b/edge/pkg/eventbus/mqtt/client.go
index 760380076..898b952be 100644
--- a/edge/pkg/eventbus/mqtt/client.go
+++ b/edge/pkg/eventbus/mqtt/client.go
@@ -42,8 +42,8 @@ var (
// SubTopics which edge-client should be sub
SubTopics = []string{
"$hw/events/upload/#",
- "$hw/events/device/+/state/update",
- "$hw/events/device/+/twin/+",
+ "$hw/events/device/+/+/state/update",
+ "$hw/events/device/+/+/twin/+",
"$hw/events/node/+/membership/get",
UploadTopic,
"+/user/#",
diff --git a/edge/test/integration/utils/helpers/helpers.go b/edge/test/integration/utils/helpers/helpers.go
index 48ec24181..fb8e1590e 100644
--- a/edge/test/integration/utils/helpers/helpers.go
+++ b/edge/test/integration/utils/helpers/helpers.go
@@ -82,7 +82,7 @@ type TwinAttribute struct {
}
func GenerateDeviceID(deviceSuffix string) string {
- return deviceSuffix + edge.GetRandomString(10)
+ return "default/" + deviceSuffix + edge.GetRandomString(10)
}
// Function to Generate Device