概述

Dummy 适配器是 Octopus 一种用于测试和 Demo 的模拟适配器。

注册信息

版本注册名称端点 Socket是否可用
v1alpha1adaptors.edge.cattle.io/dummydummy.sock*

支持模型

类型设备组版本是否可用
DummySpecialDevicedevices.edge.cattle.iov1alpha1
DummyProtocolDevicedevices.edge.cattle.iov1alpha1

支持平台

操作系统架构
linuxamd64
linuxarm
linuxarm64

使用方式

  1. kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/dummy/deploy/e2e/all_in_one.yaml

权限

对 Octopus 授予权限,如下所示:

  1. Resources Non-Resource URLs Resource Names Verbs
  2. --------- ----------------- -------------- -----
  3. dummyprotocoldevices.devices.edge.cattle.io [] [] [create delete get list patch update watch]
  4. dummyspecialdevices.devices.edge.cattle.io [] [] [create delete get list patch update watch]
  5. dummyprotocoldevices.devices.edge.cattle.io/status [] [] [get patch update]
  6. dummyspecialdevices.devices.edge.cattle.io/status [] [] [get patch update]

YAML 示例

指定DummySpecialDevice设备,以下示例假定客厅中有一个名为living-room-fan的风扇待连接。

  1. ```YAML
  2. apiVersion: edge.cattle.io/v1alpha1
  3. kind: DeviceLink
  4. metadata:
  5. name: living-room-fan
  6. spec:
  7. adaptor:
  8. node: edge-worker
  9. name: adaptors.edge.cattle.io/dummy
  10. model:
  11. apiVersion: "devices.edge.cattle.io/v1alpha1"
  12. kind: "DummySpecialDevice"
  13. # uses Secret resources
  14. references:
  15. - name: "ca"
  16. secret:
  17. name: "living-room-fan-mqtt-ca"
  18. - name: "tls"
  19. secret:
  20. name: "living-room-fan-mqtt-tls"
  21. template:
  22. metadata:
  23. labels:
  24. device: living-room-fan
  25. spec:
  26. # integrates with MQTT
  27. extension:
  28. mqtt:
  29. client:
  30. server: tcps://test.mosquitto.org:8884
  31. tlsConfig:
  32. caFilePEMRef:
  33. name: ca
  34. item: ca.crt
  35. certFilePEMRef:
  36. name: tls
  37. item: tls.crt
  38. keyFilePEMRef:
  39. name: tls
  40. item: tls.key
  41. serverName: test.mosquitto.org
  42. insecureSkipVerify: true
  43. message:
  44. # uses dynamic topic with namespaced name
  45. topic: "cattle.io/octopus/:namespace/:name"
  46. protocol:
  47. location: "living_room"
  48. gear: slow
  49. "on": true
  50. ```

指定一个 “DummyProtocolDevice “设备链接来连接 localhost 的 chaos robot。

  1. ```YAML
  2. apiVersion: edge.cattle.io/v1alpha1
  3. kind: DeviceLink
  4. metadata:
  5. name: localhost-robot
  6. spec:
  7. adaptor:
  8. node: edge-worker
  9. name: adaptors.edge.cattle.io/dummy
  10. model:
  11. apiVersion: "devices.edge.cattle.io/v1alpha1"
  12. kind: "DummyProtocolDevice"
  13. template:
  14. metadata:
  15. labels:
  16. device: localhost-robot
  17. spec:
  18. protocol:
  19. ip: "127.0.0.1"
  20. properties:
  21. name:
  22. type: string
  23. description: "The name (unique identifier) of the robot."
  24. readOnly: true
  25. gender:
  26. type: object
  27. description: "The gender of the robot."
  28. objectProperties:
  29. name:
  30. type: string
  31. description: "The name of the gender."
  32. code:
  33. type: int
  34. description: "The code of the gender."
  35. friends:
  36. type: array
  37. description: "The name list of the robot's friends."
  38. arrayProperties:
  39. type: string
  40. description: "The name of the friend."
  41. power:
  42. type: float
  43. description: "The power of the robot."
  44. ```

更多的 “DummyDevice”设备链接实例,请参考deploy/e2e目录。

DummySpecialDevice

DummySpecialDevice可被视为模拟风扇。

参数描述类型是否必填
metadata元数据详情请参考metav1.ObjectMeta
spec设备的期望状态DummySpecialDeviceSpec
status设备的实际状态DummySpecialDeviceStatus

DummySpecialDeviceSpec

参数描述类型是否必填
extension设备是否有与 MQTT 插件基础DeviceExtensionSpec
protocol访问设备时使用的传输协议DummySpecialDeviceProtocol
on设备是否已经启动bool
gear如果设备已启动,上报设备运转的频率DummySpecialDeviceGear

DummySpecialDeviceStatus

参数描述类型是否必填
extension集群使用的 MQTT 插件的配置DeviceExtensionStatus
gear如果设备已启动,上报设备运转的频率DummySpecialDeviceGear
rotatingSpeed设备的转速int32

DummySpecialDeviceProtocol

参数描述类型是否必填
location设备所处的位置string

DummySpecialDeviceGear

DummySpecialDeviceGear 定义了设备运行的速度。

参数描述类型是否必填
slow从 0 开始,每 3 秒增加一次,直至达到 100string
middle从 100 开始,每 2 秒增加一次,直至达到 200string
fast从 200 开始,每 1 秒增加一次,直至达到 300string

DummyProtocolDevice

您可以将DummyProtocolDevice 看成一个 chaos protocol robot,它的值每两秒会变化一次。

参数描述类型是否必填
metadata元数据metav1.ObjectMeta
spec设备的期望状态DummyProtocolDeviceSpec
status设备的实际状态DummyProtocolDeviceStatus

DummyProtocolDeviceSpec

参数描述类型是否必填
extension集群使用的 MQTT 插件的配置DeviceExtensionSpec
protocol访问设备时使用的传输协议DummyProtocolDeviceProtocol
props设备属性的期望值DummyProtocolDeviceSpecProps

DummyProtocolDeviceStatus

参数描述类型是否必填
extension集群使用的 MQTT 插件的配置DeviceExtensionStatus
props设备属性的实际值map[string]dummyprotocoldevicestatusprops

DummyProtocolDeviceProtocol

参数描述类型是否必填
ip连接设备时用到的 ip 地址string

DummyProtocolDeviceSpecProps

说明:

  • DummyProtocolDeviceSpecObjectOrArrayPropsDummyProtocolDeviceSpecProps相同
  • 使用DummyProtocolDeviceSpecObjectOrArrayProps 的目的是避免对象循环引用
参数描述类型是否必填
type设备属性的类型,可选值包括:string、int、float、boolean、object 和 arrayDummyProtocolDevicePropertyType
description属性描述string
readOnly是否只读bool
arrayProps数组类型的属性DummyProtocolDeviceSpecObjectOrArrayProps
objectProps对象类型的属性[string]dummyprotocoldevicespecobjectorarrayprops

DummyProtocolDeviceStatusProperty

说明:

  • DummyProtocolDeviceStatusObjectOrArrayPropertyDummyProtocolDeviceStatusProperty相同
  • 使用DummyProtocolDeviceStatusObjectOrArrayProperty的目的是避免对象循环引用
参数描述类型是否必填
type设备属性的类型DummyProtocolDevicePropertyType
intValue如果设备属性的类型是 int,上报 int 的值 Rint
stringValue如果设备属性的类型是 string,上报 string 的值string
floatValue如果设备属性的类型是 float,上报 float 的值resource.Quantity kubernetes-sigs/controller-tools/issues#245
booleanValue如果设备属性的类型是 boolean,上报 boolean 的值boolean
arrayValue如果设备属性的类型是 boolean,上报 array 的值DummyProtocolDeviceStatusObjectOrArrayProps
objectValue如果设备属性的类型是 object,上报 object 的值DummyProtocolDeviceStatusObjectOrArrayProps

DummyProtocolDevicePropertyType

DummyProtocolDevicePropertyType 描述了设备属性的类型。

参数描述类型是否必填
stringint 类型属性的值string
intint 类型属性的值string
floatfloat 类型属性的值string
booleanboolean 类型属性的值string
arrayarray 类型属性的值string
objectobject 类型属性的值string

DummyDeviceExtension

参数描述类型是否必填
mqtt说明 MQTT 插件的配置*v1alpha1.MQTTOptionsSpec

Demo 演示

  1. 创建一个DeviceLink以连接 DummySpecialDevice,该设备模拟客厅的风扇。

    1. kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/dummy/deploy/e2e/dl_specialdevice.yaml

    将上面创建的风扇状态同步到远程 MQTT 代理服务器。

    1. # create a Generic Secret to store the CA for connecting test.mosquitto.org.
    2. kubectl create secret generic living-room-fan-mqtt-ca --from-file=ca.crt=./test/integration/physical/testdata/mosquitto.org.crt
    3. # create a TLS Secret to store the TLS/SSL keypair for connecting test.mosquitto.org.
    4. kubectl create secret tls living-room-fan-mqtt-tls --key ./test/integration/physical/testdata/client-key.pem --cert ./test/integration/physical/testdata/client.crt
    5. # publish status to test.mosquitto.org
    6. kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/dummy/deploy/e2e/dl_specialdevice_with_mqtt.yaml

    使用mosquitto_sub工具观看同步状态。

    1. # get mqtt broker server
    2. kubectl get dummyspecialdevices.devices.edge.cattle.io living-room-fan -o jsonpath="{.status.extension.mqtt.client.server}"
    3. # get topic name
    4. kubectl get dummyspecialdevices.devices.edge.cattle.io living-room-fan -o jsonpath="{.status.extension.mqtt.message.topicName}"
    5. # use mosquitto_sub
    6. mosquitto_sub -h {the host of mqtt broker server} -p {the port of mqtt broker server} -t {the topic name}
    7. # mosquitto_sub -h test.mosquitto.org -p 1883 -t cattle.io/octopus/default/living-room-fan
  2. 创建一个DeviceLink以连接 DummyProtocolDevice,该设备模拟一个智能机器人,它可以在 2 秒内随机填充所需的属性。

    1. kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/dummy/deploy/e2e/dl_protocoldevice.yaml

    将以上创建的机械的答案同步到远程 MQTT 代理服务器。

    1. # publish status to test.mosquitto.org
    2. kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/dummy/deploy/e2e/dl_protocoldevice_with_mqtt.yaml

    使用mosquitto_sub工具观看同步的结果。

    1. # get mqtt broker server
    2. kubectl get dummyprotocoldevices.devices.edge.cattle.io localhost-robot -o jsonpath="{.status.extension.mqtt.client.server}"
    3. # get topic name
    4. kubectl get dummyprotocoldevices.devices.edge.cattle.io localhost-robot -o jsonpath="{.status.extension.mqtt.message.topicName}"
    5. # use mosquitto_sub
    6. mosquitto_sub -h {the host of mqtt broker server} -p {the port of mqtt broker server} -t {the topic name}
    7. # mosquitto_sub -h test.mosquitto.org -p 1883 -t cattle.io/octopus/835aea2e-5f80-4d14-88f5-40c4bda41aa3