Dummy 适配器

概述

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

注册信息

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

支持模型

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

支持平台

操作系统架构
linuxamd64
linuxarm
linuxarm64

使用方式

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

国内用户,可以使用以下方法加速安装:

kubectl apply -f http://rancher-mirror.cnrancher.com/octopus/master/adaptors/dummy/deploy/e2e/all_in_one.yaml

权限

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

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

YAML 示例

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

```YAML
apiVersion: edge.cattle.io/v1alpha1
kind: DeviceLink
metadata:
name: living-room-fan
spec:
adaptor:
node: edge-worker
name: adaptors.edge.cattle.io/dummy
model:
apiVersion: "devices.edge.cattle.io/v1alpha1"
kind: "DummySpecialDevice"
# uses Secret resources
references:
- name: "ca"
secret:
name: "living-room-fan-mqtt-ca"
- name: "tls"
secret:
name: "living-room-fan-mqtt-tls"
template:
metadata:
labels:
device: living-room-fan
spec:
# integrates with MQTT
extension:
mqtt:
client:
server: tcps://test.mosquitto.org:8884
tlsConfig:
caFilePEMRef:
name: ca
item: ca.crt
certFilePEMRef:
name: tls
item: tls.crt
keyFilePEMRef:
name: tls
item: tls.key
serverName: test.mosquitto.org
insecureSkipVerify: true
message:
# uses dynamic topic with namespaced name
topic: "cattle.io/octopus/:namespace/:name"
protocol:
location: "living_room"
gear: slow
"on": true
```

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

```YAML
apiVersion: edge.cattle.io/v1alpha1
kind: DeviceLink
metadata:
name: localhost-robot
spec:
adaptor:
node: edge-worker
name: adaptors.edge.cattle.io/dummy
model:
apiVersion: "devices.edge.cattle.io/v1alpha1"
kind: "DummyProtocolDevice"
template:
metadata:
labels:
device: localhost-robot
spec:
protocol:
ip: "127.0.0.1"
properties:
name:
type: string
description: "The name (unique identifier) of the robot."
readOnly: true
gender:
type: object
description: "The gender of the robot."
objectProperties:
name:
type: string
description: "The name of the gender."
code:
type: int
description: "The code of the gender."
friends:
type: array
description: "The name list of the robot's friends."
arrayProperties:
type: string
description: "The name of the friend."
power:
type: float
description: "The power of the robot."
```

更多的 "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](#dummyprotocoldevicestatusprops)

DummyProtocolDeviceProtocol

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

DummyProtocolDeviceSpecProps

说明:

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

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,该设备模拟客厅的风扇。

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

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

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

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

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

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

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

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

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

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