Dummy Adaptor

Introduction

Dummy is used to quickly experience Octopus. The Dummy adaptor can simulate the interaction of limb and adaptor.

Registration Information

VersionsRegister NameEndpoint SocketAvailable
v1alpha1adaptors.edge.cattle.io/dummydummy.sock*

Support Model

KindGroupVersionAvailable
DummySpecialDevicedevices.edge.cattle.iov1alpha1*
DummyProtocolDevicedevices.edge.cattle.iov1alpha1*

Support Platform

OSArch
linuxamd64
linuxarm
linuxarm64

Usage

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

Authority

Grant permissions to Octopus as below:

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]

Example

  • Specifies a DummySpecialDevice device link to connect a fake fan in living room.

    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
  • Specifies a DummyProtocolDevice device link to connect the chaos robot of localhost.

    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."

For more Dummy*Device device link examples, please refer to the deploy/e2e directory.

DummySpecialDevice

The DummySpecialDevice can be considered as a fake fan.

ParameterDescriptionSchemaRequired
metadatametav1.ObjectMetafalse
specDefines the desired state of DummySpecialDevice.DummySpecialDeviceSpectrue
statusDefines the observed state of DummySpecialDevice.DummySpecialDeviceStatusfalse

DummySpecialDeviceSpec

ParameterDescriptionSchemaRequired
extensionSpecifies the extension of device.DummyDeviceExtensionfalse
protocolSpecifies the protocol for accessing the device.DummySpecialDeviceProtocoltrue
onSpecifies if turn on the device.booltrue
gearSpecifies how fast the device should be, default to slow.DummySpecialDeviceGearfalse

DummySpecialDeviceStatus

ParameterDescriptionSchemaRequired
gearReports the current gear of device.DummySpecialDeviceGearfalse
rotatingSpeedReports the detail number of speed.int32false

DummySpecialDeviceProtocol

ParameterDescriptionSchemaRequired
locationSpecifies the location of device.stringtrue

DummySpecialDeviceGear

DummySpecialDeviceGear defines how fast the dummy special device should be.

ParameterDescriptionSchema
slowStarts from 0 and increases every three seconds until 100.string
middleStarts from 100 and increases every two seconds until 200.string
fastStarts from 200 and increases every one second until 300.string

DummyProtocolDevice

The DummyProtocolDevice can be considered as a chaos protocol robot, it will change its attribute values every two seconds.

ParameterDescriptionSchemaRequired
metadatametav1.ObjectMetafalse
specDefines the desired state of DummyProtocolDevice.DummyProtocolDeviceSpectrue
statusDefines the observed state of DummyProtocolDevice.DummyProtocolDeviceStatusfalse

DummyProtocolDeviceSpec

ParameterDescriptionSchemaRequired
extensionSpecifies the extension of device.DummyDeviceExtensionfalse
protocolSpecifies the protocol for accessing the device.DummyProtocolDeviceProtocoltrue
propertiesSpecifies the properties of device.map[string]DummyProtocolDevicePropertyfalse

DummyProtocolDeviceStatus

ParameterDescriptionSchemaRequired
extensionReports the extension of device.DeviceExtensionStatusfalse
propertiesReports the observed value of the desired properties.map[string]DummyProtocolDeviceStatusPropertyfalse

DummyProtocolDeviceProtocol

ParameterDescriptionSchemaRequired
ipSpecifies where to connect the dummy protocol device.stringtrue

DummyProtocolDeviceProperty

DummyProtocolDeviceObjectOrArrayProperty is the same as DummyProtocolDeviceProperty. The existence of DummyProtocolDeviceObjectOrArrayProperty is to combat the object circular reference.

ParameterDescriptionSchemaRequired
typeDescribes the type of property.DummyProtocolDevicePropertyTypetrue
descriptionOutlines the property.stringfalse
readOnlyConfigures the property is readOnly or not.boolfalse
arrayPropertiesDescribes item properties of the array type.*DummyProtocolDeviceObjectOrArrayPropertyfalse
objectPropertiesDescribes properties of the object type.map[string]DummyProtocolDeviceObjectOrArrayPropertyfalse

DummyProtocolDeviceStatusProperty

DummyProtocolDeviceStatusObjectOrArrayProperty is the same as DummyProtocolDeviceStatusProperty. The existence of DummyProtocolDeviceStatusObjectOrArrayProperty is to combat the object circular reference.

ParameterDescriptionSchemaRequired
typeReports the type of property.DummyProtocolDevicePropertyTypetrue
intValueReports the value of int type.*intfalse
stringValueReports the value of string type.*stringfalse
floatValueReports the value of float type.*resource.Quantity, kubernetes-sigs/controller-tools/issues#245false
booleanValueReports the value of bool type.*boolfalse
arrayValueReports the value of array type.[]DummyProtocolDeviceStatusObjectOrArrayPropertyfalse
objectValueReports the value of object type.map[string]DummyProtocolDeviceStatusObjectOrArrayPropertyfalse

DummyProtocolDevicePropertyType

DummyProtocolDevicePropertyType describes the type of property.

ParameterDescriptionSchema
stringProperty data type is string.string
intProperty data type is int.string
floatProperty data type is float.string
booleanProperty data type is boolean.string
arrayProperty data type is array.string
objectProperty data type is object.string

DummyDeviceExtension

ParameterDescriptionSchemaRequired
mqttSpecifies the MQTT settings.*v1alpha1.MQTTOptionsSpecfalse

Walkthrough

  1. Create a DeviceLink to connect the DummySpecialDevice, which simulates a fan of living room.

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

    Synchronize the above-created fan's status to the remote MQTT broker server.

    # 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

    Use mosquitto_sub tool to watch the synchronized status.

    # get mqtt broker server
    kubectl get dl living-room-fan -o jsonpath="{.spec.template.spec.extension.mqtt.client.server}"
    # get topic name
    kubectl get dl living-room-fan -o jsonpath="{.spec.template.spec.extension.mqtt.message.topic}"
    # 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. Create a DeviceLink to connect the DummyProtocolDevice, which simulates an intelligent property-filled robot, it can fill the desired properties randomly in 2 seconds.

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

    Synchronize the above-created robot's answers to the remote MQTT broker server.

    # 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

    Use mosquitto_sub tool to watch the synchronized answers.

    # get mqtt broker server
    kubectl get dl localhost-robot -o jsonpath="{.spec.template.spec.extension.mqtt.client.server}"
    # get topic name
    kubectl get dl localhost-robot -o jsonpath="{.spec.template.spec.extension.mqtt.message.topic}"
    # get dl uid
    kubectl get dl localhost-robot -o jsonpath="{.metadata.uid}"
    # 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