edgex: 调度(Scheduling)

[复制链接]
925|2
 楼主| keer_zu 发表于 2020-12-18 10:19 | 显示全部楼层 |阅读模式
本帖最后由 keer_zu 于 2020-12-18 10:22 编辑

参考
概述:
调度微服务包括清除事件的Scrubber微服务和读取已经导出到网关的数据(用于核心数据)。可选地,还可以配置Scrubber微服务来删除未导出的过期事件/读取数据。删除过期事件/读取数据使网关继续运营与静态存储,而系统继续收集新的数据从设备和传感器在不操作的情况下,出口设施或操作不够快跟上数据收集。


导出记录和陈旧记录的删除都按照可配置的时间表进行。默认情况下,Scrubber每30分钟清理一次数据。


Scrubber微服务并不直接从EdgeX Foundry的持久存储本身删除数据,而是调用Core data删除记录。Core Data充当持久化事件/读取数据的单一访问点。Scrubber微服务是一个独立的服务,没有任何客户端。也就是说,没有调用Scrubber的API。洗涤器按时间触发器工作。


调度器使用一个数据存储来持久保存时间间隔和间隔动作。持久性是通过位于EdgeX当前配置数据库中的调度器DB来实现的。






Data Dictionary

Class Name                   Description
Interval              An object defining a specific “period” in time.
IntervalAction     The action taken by a Service when the Interval occurs.

 楼主| keer_zu 发表于 2020-12-18 10:38 | 显示全部楼层
本帖最后由 keer_zu 于 2020-12-18 10:45 编辑

EDGEX FOUNDRY配置参数 --- support-scheduler

support-scheduler是主要是EDGEX系统中的提醒服务,support-scheduler使用介绍如下,他有2个启动参数可以配置:

  • registry是一个bool量,True表示support-scheduler的配置参数是从consul拉取,False表示从本地配置文件载入。
  • profile本地配置文件的路径, 即便registry=True, 该参数也必须要指明一个配置文件,因为连接consul服务所需的host,port等参数必须从本地的配置文件中获取
  1. Usage: %s [options]
  2. Server Options:
  3.     -r, --registry                  Indicates service should use Registry
  4.     -p, --profile <name>            Indicate configuration profile other than default
  5. Common Options:
  6.     -h, --help                      Show this message




Table of Contents


support-scheduler的配置文件

Writable

Clients

Databases

Logging

Registry

Service

Intervals

IntervalActions





support-scheduler的配置文件
  1. [Writable]
  2. ScheduleIntervalTime = 500
  3. LogLevel = 'INFO'

  4. [Service]
  5. BootTimeout = 30000
  6. ClientMonitor = 15000
  7. CheckInterval = '10s'
  8. Host = 'localhost'
  9. Port = 48085
  10. Protocol = 'http'
  11. ReadMaxLimit = 100
  12. StartupMsg = 'This is the Support Scheduler Microservice'
  13. Timeout = 5000

  14. [Registry]
  15. Host = 'localhost'
  16. Port = 8500
  17. Type = 'consul'

  18. [Logging]
  19. EnableRemote = false
  20. File = './logs/edgex-support-scheduler.log'

  21. [Clients]
  22.   [Clients.Logging]
  23.   Protocol = 'http'
  24.   Host = 'localhost'
  25.   Port = 48061

  26. [Databases]
  27.   [Databases.Primary]
  28.   Host = 'localhost'
  29.   Name = 'scheduler'
  30.   Password = ''
  31.   Port = 27017
  32.   Username = ''
  33.   Timeout = 5000
  34.   Type = 'mongodb'

  35. [Intervals]
  36.     [Intervals.Midnight]
  37.     Name = 'midnight'
  38.     Start = '20180101T000000'
  39.     Frequency = 'P1D'

  40. [IntervalActions]
  41.     [IntervalActions.ScrubPushed]
  42.     Name = 'scrub-pushed-events'
  43.     Host = 'localhost'
  44.     Port = 48080
  45.     Protocol = 'http'
  46.     Method = 'DELETE'
  47.     Target = 'core-data'
  48.     Path = '/api/v1/event/scrub'
  49.     Interval = 'midnight'

  50.     [IntervalActions.ScrubAged]
  51.     Name = 'scrub-aged-events'
  52.     Host = 'localhost'
  53.     Port = 48080
  54.     Protocol = 'http'
  55.     Method = 'DELETE'
  56.     Target = 'core-data'
  57.     Path = '/api/v1/event/removeold/age/604800000'
  58.     Interval = 'midnight'


如上是项目自带的support-scheduler的配置文件 ,主要分8部分,support-scheduler启动后会将配置文件的信息导入如下结构中,若registry=True则根据Registry中的信息连接consul并拉取相应的配置信息覆盖之前从本地配置文件中读取到的信息。

  1. // Configuration V2 for the Support Scheduler Service
  2. type ConfigurationStruct struct {
  3.         Writable        WritableInfo
  4.         Clients         map[string]config.ClientInfo
  5.         Databases       map[string]config.DatabaseInfo
  6.         Logging         config.LoggingInfo
  7.         Registry        config.RegistryInfo
  8.         Service         config.ServiceInfo
  9.         Intervals       map[string]config.IntervalInfo
  10.         IntervalActions map[string]config.IntervalActionInfo
  11. }

Writable
  1. type WritableInfo struct {
  2.         ScheduleIntervalTime    int
  3.         LogLevel                string
  4. }



support-scheduler有2个参数可以在运行时被修改


  1. ScheduleIntervalTime    内部定时器间隔触发时间,单位:毫秒
  2. LogLevel                日志等级



Clients  

  1. // ClientInfo provides the host and port of another service in the eco-system.
  2. type ClientInfo struct {
  3.         // Host is the hostname or IP address of a service.
  4.         Host string
  5.         // Port defines the port on which to access a given service
  6.         Port int
  7.         // Protocol indicates the protocol to use when accessing a given service
  8.         Protocol string
  9. }
  1. Host 微服务的地址
  2. Port 微服务的端口
  3. Protocol 微服务所使用的协议,目前仅支持http

support-scheduler运行时需要使用其他微服务提供的功能,Client便是连接其他微服务所必须的参数,这是一个map参数,key值便是其他微服务的名字,value便是client的具体参数信息, support-scheduler正常运行一般需要使用logging微服务。

Databases
  1. type DatabaseInfo struct {
  2.         Type     string
  3.         Timeout  int
  4.         Host     string
  5.         Port     int
  6.         Username string
  7.         Password string
  8.         Name     string
  9. }

  1. Type     数据库类型,目前仅支持 mongodb
  2. Timeout  数据库连接超时,单位:s
  3. Host     数据库地址
  4. Port     数据库端口
  5. Username 数据库登录用户名
  6. Password 数据库登录密码
  7. Name     数据库名字




support-scheduler当前支持两种Primary数据库mongodb和redisdb。


Logging  


  1. // LoggingInfo provides basic parameters related to where logs should be written.
  2. type LoggingInfo struct {
  3.         EnableRemote bool
  4.         File         string
  5. }

  1.    EnableRemote True: log于support-logging微服务持久化(support-logging的连接参数由Clients字段提供), False:log于本地文件持久化
  2.    File         log本地持久化时日志文件的路径


Registry
  1. // RegistryInfo defines the type and location (via host/port) of the desired service registry (e.g. Consul, Eureka)
  2. type RegistryInfo struct {
  3.         Host string
  4.         Port int
  5.         Type string
  6. }


consul连接参数


Service  

同support-logging

Intervals
  1. type IntervalInfo struct {
  2.         // Name of the schedule must be unique?
  3.         Name string
  4.         // Start time in ISO 8601 format YYYYMMDD'T'HHmmss
  5.         Start string
  6.         // End time in ISO 8601 format YYYYMMDD'T'HHmmss
  7.         End string
  8.         // Periodicity of the schedule
  9.         Frequency string
  10.         // Cron style regular expression indicating how often the action under schedule should occur.  Use either runOnce, frequency or cron and not all.
  11.         Cron string
  12.         // Boolean indicating that this schedules runs one time - at the time indicated by the start
  13.         RunOnce bool
  14. }

  1. Interval是触发的描述结构,support-scheduler会周期性的检查Interval数组并将满足触发条件的Interval过滤出来,执行下挂在其下的所有触发动作。Interval的来源主要有三处:
  2. 1,support-scheduler使用的数据库,support-scheduler启动时会从数据库load已经存在的Interval
  3. 2,配置文件,support-scheduler会载入配置文件中的Interval并将其写入数据库持久化,值得注意的是support-scheduler不支持重名的    Interval,因此当配置文件的Interval的Name与数据库中的相应Interval的Name相同时会优先使用数据库中的Interval而放弃配置文件中的Interval
  4. 3,support-scheduler提供的restful API接口支持动态更新Interval信息

  5. Name 触发 名字
  6. Start 触发开始时间 ISO 8601 format YYYYMMDD'T'HHmmss
  7. End 触发结束时间 ISO 8601 format YYYYMMDD'T'HHmmss
  8. Frequency 周期性触发时的触发频率
  9. Cron Cron 风格的触发表达式
  10. RunOnce 是否仅仅触发一次


IntervalActions
  1. type IntervalActionInfo struct {
  2.         // Host is the hostname or IP address of a service.
  3.         Host string
  4.         // Port defines the port on which to access a given service
  5.         Port int
  6.         // Protocol indicates the protocol to use when accessing a given service
  7.         Protocol string
  8.         // Action name
  9.         Name string
  10.         // Action http method *const prob*
  11.         Method string
  12.         // Acton target name
  13.         Target string
  14.         // Action target parameters
  15.         Parameters string
  16.         // Action target API path
  17.         Path string
  18.         // Associated Schedule for the Event
  19.         Interval string
  20. }


触发动作的执行最终都表现为访问一个外部服务(外部指的是support-scheduler微服务的外部),可以是core-data等其他微服务,也可以是其他接口兼容的服务。
  1. Host 外部服务主机名
  2. Port 外部服务端口
  3. Protocol 外部服务协议,目前仅支持http
  4. Name 触发动作的名字
  5. Method http方法,GET,POST等等
  6. Target 外部服务的名字
  7. Parameters http参数,目前源码不支持该字段
  8. Path 外部服务path 如/api/v1/event/removeold/age/604800000
  9. Interval 绑定的Interval名字,非常关键,如果该字段在support-scheduler中没有对应的Interval也就意味着该触发动作永远不会被执行

出处:原文



 楼主| keer_zu 发表于 2020-12-18 14:53 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1488

主题

12949

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部