百度智能云

All Product Document

          Intelligent Edge

          Typical Configuration

          This article introduces how to configure the module application for the edge core after the edge core is initially connected to the BIE cloud management suite.

          Prerequisite Preparation

          The edge core has been connected to the cloud BIE. For the configuration process, see Getting Started.

          Simulation Scenarios

          1.The edge core collects 3 operating parameters x, y and z 2.Compute the result of result=x+y+z 3.Filter out data with result> 10

          Configuration Process

          1. Module configuration

            • Configure the baetyl-hub module
            • Configure the baetyl-function-manager module
            • Configure the baetyl-function-python27 module
            • Configure the baetyl-function-sql
          2. Release the draft configuration as a version
          3. Distribute an official version configuration
          4. Use MQTTBox to check results

          Module Configuration

          Description of the Module Functions

          • baetyl-hub: MQTT Broker on the edge side, support message subscription and releasing
          • baetyl-function-manager: Realize function runtime scheduling
          • baetyl-function-python27: Realize parameter computing
          • baetyl-function-sql: Realize result filtering
          • MQTT-Clinet: Non-baetyl modules, the tool MQTTBox is used in this case to simulate MQTT Client

          Module Relation Diagram

          image.png

          Module 1: baetyl-hub

          3 storage volumes are required for the hub service, which are used for mapping configuration, mapping log and data persistence, among which log and data persistence are optional configurations.

          Create a configuration storage volume

          image.png

          Select baetyl template configuration for the storage volume template, name it bie-demo-hub-conf, and click “OK”.

          image.png

          You can find that the service.yml file has been generated by default in the storage volume, and it is the default configuration file name in the baetyl module.

          image.png

          Enter the configuration of the hub:

          listen: 
            - tcp://0.0.0.0:1883
          principals: 
            - username: test 
              password: hahaha 
              permissions: 
                - action: 'pub' 
                  permit: ['#'] 
                - action: 'sub' 
                  permit: ['#'] 
          subscriptions: 
            - source: 
                topic: 't' 
              target: 
                topic: 't/topic' 
          logger: 
            path: var/log/baetyl/service.log 
            level: "debug" 

          The definition of configuration is that you have an access identity with a user name of test and a password of hahaha, you have all pub and sub privileges, and the hub will forward the topic t to the topic t/topic. For more configuration resolutions, please see Configuration File Description.

          image.png

          Save and release the new version.

          image.png

          Create a log storage volume

          Select storage volume with empty directory for the storage volume template, name it bie-demo-hub-log, and click “OK”.

          After the storage volume with empty directory is created, a new version will be released. Modified files cannot be added in it, and it only acts as a “folder/directory”.

          image.png

          image.png

          Create a data persistence storage volume

          The process of creating a data persistence storage volume is the same as that of creating a log storage volume, and name it bie-demo-hub-data.

          Create a baetyl-hub service

          Click “Add a service” in the Application configuration details of the core, select the baetyl-hub module, set the service name as local-hub, and configure port mapping 1883:1883, which means mapping the 1883 port in the container to the host.

          image.png

          Mount storage volumes of the hub module:

          image.png

          Mount the storage volumes to the service one by one, and “Save” them, in which the configuration file should be mapped to the directory etc/baetyl in the container.

          With this, the baetyl-hub service is configured.

          Module 2: baetyl-function-manager

          baetyl-function-manager The service requires one storage volume (log file can also be mapped based on demands) to map the configuration file.

          Create a configuration storage volume

          First, create a storage volume, select baetyl template configuration for the template, name it bie-demo-func-conf and click “OK”.

          image.png

          As in baetyl-hub, enter the configuration, save it and release the new version.

          hub: 
            address: tcp://local-hub:1883 # Here, local-hub is the service name defined earlier, not the module name 
            username: test 
            password: hahaha 
          rules: 
            - clientid: localfunc-1 
              subscribe: 
                topic: t 
              function: 
                name: compute 
              publish: 
                topic: t/compute 
            - clientid: localfunc-2 
              subscribe: 
                topic: t/compute 
                qos: 1 
              function: 
                name: filter 
              publish: 
                topic: t/filter 
                qos: 1 
          functions: 
            - name: compute 
              service: function-compute 
            - name: filter 
              service: function-filter 
          logger: 
            path: var/log/baetyl/service.log 
            level: "debug" 

          The definition of configuration is that baetyl-function-manager subscribes t, computes it through compute functions, sends it in the topic t/compute, subscribes the topic t/compute, computes it through filter functions and then sends it in the topic t/filter. Among them, the compute functions are started by the service function-compute, and the filter functions are started by the service function-filter. For more configuration resolutions, please see Configuration File Description.

          Create a baetyl-function-manager service

          Click “Add a service” in the Application configuration details of the core, select the baetyl-function-manager module, and name it local-func.

          image.png

          Mount storage volumes:

          image.png

          Mount the storage volumes to the service and save them, in which the configuration file should be mapped to the directory etc/baetyl in the container.

          With this, the baetyl-function-manager service is configured.

          Module 3: baetyl-function-python27

          2 storage volumes are required for the baetyl-function-python27 service to map configuration file and code.

          Create a cfc function

          Enter the Baidu AI Cloud CFC console, create a compute function, and enter a simple addition code in the current code. The code is as follows:

          def handler(event, context): 
              event["result"] = event["x"] + event["y"] + event["z"] 
              return event 

          Then click Release a new version to generate version 1, as shown in the figure below:

          image.png

          Currently, Baidu IntelliEdge (BIE) supports 3 kinds of function runtime Python27, Python36 and Nodejs85, therefore only these 3 functions created in CFC can be imported to BIE.

          Create a configuration storage volume

          First, create a storage volume, select baetyl module configuration for the template, name it bie-demo-compute-conf and click “OK”.

          As in baetyl-hub, enter the configuration, save it and release the new version.

          functions: 
            - name: 'compute' 
              handler: 'index.handler' 
              codedir: 'var/db/baetyl/compute' 

          The definition of configuration is that by defining the function compute, the code path is var/db/baetyl/compute in the container. For more configuration resolutions, please see Configuration File Description.

          Create a code storage volume

          First, create a storage volume, select CFC function template as the template, name it bie-demo-compute-code and click “OK”.

          image.png

          Select to import a CFC function, and select the function which has been created in advance in Baidu AI Cloud CFC. Currently, it only supports to import Python27, Python36 and Nodejs85 scripts.

          image.png

          Create a baetyl-function-python27 service

          Click “Add a service” in the Application configuration details of the core, select the baetyl-function-python27 module, and name it function-compute. In it, the number of copies of the function runtime module must be 0.

          image.png

          Mount storage volumes:

          image.png

          Mount the storage volumes to the service and save them, in which the configuration file should be mapped to the directory etc/baetyl in the container.

          With this, the baetyl-function-python27 service is configured.

          Module 4: baetyl-function-sql

          The baetyl-function-sql service requires one storage volume to map configuration file.

          Create a configuration storage volume

          First, create a storage volume, select baetyl module configuration for the template, name it bie-demo-filter-conf and click “OK”.

          As in baetyl-hub, enter the configuration, save it and release the new version.

          functions: 
            - name: filter 
              handler: 'select * where result > 10' 

          The definition of configuration is that by defining the function filter, messages with result less than 0 will be filtered out. For more configuration resolutions, please see Configuration File Description.

          Create a baetyl-function-sql service

          Click “Add a service” in the Application configuration details of the core, select the baetyl-function-sql module, and name it function-filter. In it, the number of copies of the function runtime module must be 0.

          image.png

          Mount storage volumes:

          image.png

          Mount the storage volumes to the service and save them, in which the configuration file should be mapped to the directory etc/baetyl in the container.

          With this, the baetyl-function-sql service is configured.

          Release and Distribute a Configuration

          After all configuration operations are completed, you can Release the draft version as the official version, and then click Distribute for the official version. For details, see the documentation: Release and Distribute a Configuration

          Use MQTTBox to Subscribe Data Check Results

          Configuration MQTT Connection

          Start the MQTTBOX client, enter the client creation page, and start to create the MQTT client. Select “mqtt/tcp” as the protocol for connection, and make configuration according to the address and port of starting the baetyl-hub module and combined with connection configuration information of the MQTT client in the configuration item which can be connected to the baetyl-hub module. Enter the user test and password ‘hahaha’, and then click “Save”, so the MQTTBOX connection configuration in the TCP connection mode can be completed, as shown in the figure below:

          getting-started-practice-mqttbox-link-01.png

          Send Simulation data x, y and z

          Start the test. According to the design, send test data in the format of {"x":1,"y":2,"z":3} to the topic t, and it will go through the two computing functions compute and filter, in which:

          • The computing result of compute is output to the topic t/compute to get the result of result=x+y+z
          • The computing result of filter is output to the topic t/ filter to get the filtered data with result>10

          View the Computing Results

          The results are shown below, indicating that the operation is correct.

          getting-started-practice-mqttbox-test.png

          Previous
          Release and Distribute a Configuration
          Next
          Master Program and Module Upgrade