当前位置: 首页 > news >正文

「连载」边缘计算(二十)02-23:边缘部分源码(源码分析篇)

(接上篇)

EdgeCoredevicetwin

前面对EdgeCore组件的edged功能模块进行了分析,本节对EdgeCore组件的另一个功能模块devicetwin进行剖析,包括devicetwin的struct调用剖析、devicetwin的具体逻辑剖析、devicetwin的缓存机制剖析。

1.devicetwin的struct调用剖析

EdgeCore模块注册函数入手,具体如下所示。

KubeEdge/edge/cmd/EdgeCore/app/server.go

// registerModules register all the modules started in EdgeCore

func registerModules() {

devicetwin.Register()

...

}

进入registerModules()函数中的devicetwin.Register()函数定义,具体如下所示。

KubeEdge/edge/pkg/devicetwin/devicetwin.go

// Register register devicetwin

func Register() {

dtclient.InitDBTable()

dt := DeviceTwin{}

core.Register(&dt)

}

Register()函数主要做了如下3件事。

1)初始化devicetwin需要的数据库表(dtclient.InitDBTable());

2)实例化DeviceTwin struct(dt := DeviceTwin{});

3)注册将已经实例化的DeviceTwin struct(core.Register(&dt))。

下面深入剖析初始化devicetwin需要的数据库表具体做了哪些事情以及DeviceTwin struct具体由哪些属性组成。

(1)devicetwin数据库相关struct剖析

这部分剖析初始化devicetwin需要的数据库及数据库表相关的struct,具体如下所示。

KubeEdge/edge/pkg/devicetwin/dtclient/sql.go

//InitDBTable create table

func InitDBTable() {

klog.Info("Begin to register twin model")

dbm.RegisterModel("twin", new(Device))

dbm.RegisterModel("twin", new(DeviceAttr))

dbm.RegisterModel("twin", new(DeviceTwin))

}

InitDBTable()函数中,通过封装的beegoorm(https://GitHub.com/astaxie/beego/tree/develop/orm)创建数据库twin,并初始化device、device_attr和device_twin三张表。与上述三张表对应的结构体如下所示。

KubeEdge/edge/pkg/devicetwin/dtclient/device_db.go

//Device the struct of device

type Device struct {

ID          string `orm:"column(id); size(64); pk"`

Name        string `orm:"column(name); null; type(text)"`

Description string `orm:"column(description); null; type(text)"`

State       string `orm:"column(state); null; type(text)"`

LastOnline  string `orm:"column(last_online); null; type(text)"`

}

KubeEdge/edge/pkg/devicetwin/dtclient/deviceattr_db.go

//DeviceAttr the struct of device attributes

type DeviceAttr struct {

ID          int64  `orm:"column(id);size(64);auto;pk"`

DeviceID    string `orm:"column(deviceid); null; type(text)"`

Name        string `orm:"column(name);null;type(text)"`

Description string `orm:"column(description);null;type(text)"`

Value       string `orm:"column(value);null;type(text)"`

Optional    bool   `orm:"column(optional);null;type(integer)"`

AttrType    string `orm:"column(attr_type);null;type(text)"`

Meta Data    string `orm:"column(metadata);null;type(text)"`

}

KubeEdge/edge/pkg/devicetwin/dtclient/devicetwin_db.go

//DeviceTwin the struct of device twin

type DeviceTwin struct {

ID              int64  `orm:"column(id);size(64);auto;pk"`

DeviceID        string `orm:"column(deviceid); null; type(text)"`

Name            string `orm:"column(name);null;type(text)"`

Description     string `orm:"column(description);null;type(text)"`

Expected        string `orm:"column(expected);null;type(text)"`

Actual          string `orm:"column(actual);null;type(text)"`

ExpectedMeta    string `orm:"column(expected_meta);null;type(text)"`

ActualMeta      string `orm:"column(actual_meta);null;type(text)"`

ExpectedVersion string `orm:"column(expected_version);null;type(text)"`

ActualVersion   string `orm:"column(actual_version);null;type(text)"`

Optional        bool   `orm:"column(optional);null;type(integer)"`

AttrType        string `orm:"column(attr_type);null;type(text)"`

Meta Data        string `orm:"column(metadata);null;type(text)"`

}

以上3个文件中除了包含与device、device_attr和device_twin三张表对应的结构体定义外,还有针对这三张表的增、删、改、查方法的定义。

未完待续…… 

http://www.lryc.cn/news/307825.html

相关文章:

  • Swagger接口文档管理工具
  • 关于HTML5表单验证的方法教程
  • .NET生成MongoDB中的主键ObjectId
  • BeautifulSoup+xpath+re+css简单复习+新的scrapy的学习
  • Python爬虫实战:从API获取数据
  • 音频转换器哪个好?3款电脑软件+3款手机应用
  • 惯性导航 | 运动学---运动模型
  • Java Web(十一)--JSON Ajax
  • GL/gl.h: No such file or directory(CentOS8 QT5.12.12)
  • 【外设篇】-显示器
  • 可视化图文报表
  • CW023A-H035 CW023A-R230铜合金硬度材质书
  • Ribbon负载均衡:提升应用性能与可靠性的秘密武器(一)
  • python递归算法
  • azure devops工具实践分析
  • 2024年2月19日-2月25日(全面进行+收集免费虚幻商城资源,20小时,合计2561小时,剩余7439小时)
  • Ubuntu制作本地安装源
  • java springmvc/springboot 项目通过HttpServletRequest对象获取请求体body工具类
  • 新手怎么使用github?
  • CSS_实现三角形和聊天气泡框
  • VPX基于全国产飞腾FT-2000+/64核+复旦微FPGA的计算刀片
  • ifcplusplus 示例 函数中英文 对照分析
  • 天一个数据分析题(一百七十三)
  • 尚硅谷(SpringCloudAlibaba微服务分布式)学习代码Eureka部分
  • arm服务器上部署kibana
  • Redis之二:Redis 常用命令
  • npm 镜像源切换与设置
  • 【HDFS】Decommision(退役) EC数据节点剩最后几个块卡住的问题
  • MySQL知识点归纳总结(一)
  • SocketWeb实现小小聊天室