|
@@ -21,39 +21,45 @@ func InitTriggerConfig() {
|
|
defer config.OssMutex.Unlock()
|
|
defer config.OssMutex.Unlock()
|
|
triggerLocalPathsMapTriggerId := make(map[string]string)
|
|
triggerLocalPathsMapTriggerId := make(map[string]string)
|
|
c_log.GlobalLogger.Info("主节点加载触发器插件 - 开始。")
|
|
c_log.GlobalLogger.Info("主节点加载触发器插件 - 开始。")
|
|
- // 1 获取数采任务的触发器列表
|
|
|
|
- cloudTriggers := &config.PlatformConfig.TaskTriggers
|
|
|
|
- // 2 获取本地触发器列表(触发器目录的一级子目录为【触发器ID_触发器Label】)
|
|
|
|
- localTriggerIds := util.GetFirstLevelSubdirectories(config.CloudConfig.TriggersDir)
|
|
|
|
- // 3 对比触发器列表,本地没有的则下载
|
|
|
|
- for _, trigger := range *cloudTriggers {
|
|
|
|
- id := util.ToString(trigger.TriggerId)
|
|
|
|
- hasIdDir := slices.Contains(localTriggerIds, id) // 改成了 slices 工具库
|
|
|
|
- triggerLocalDir := config.CloudConfig.TriggersDir + id + "/"
|
|
|
|
- hasLabelSo, soPaths := util.CheckSoFilesInDirectory(triggerLocalDir)
|
|
|
|
- var triggerLocalPath string
|
|
|
|
- if hasIdDir && hasLabelSo { // 已存在的触发器需要判断是否大小一致
|
|
|
|
- triggerLocalPath = soPaths[0]
|
|
|
|
- ossSize, _ := util.GetOSSFileSize(config.OssBucket, trigger.TriggerScriptPath)
|
|
|
|
- localSize, _ := util.GetFileSize(triggerLocalPath)
|
|
|
|
- if ossSize == localSize {
|
|
|
|
- c_log.GlobalLogger.Info("触发器插件 ", triggerLocalPath, " 存在且与云端触发器大小一致。")
|
|
|
|
- triggerLocalPathsMapTriggerId[triggerLocalPath] = id
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- label := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
|
|
|
|
- triggerLocalPath = config.CloudConfig.TriggersDir + id + "/" + label + ".so"
|
|
|
|
- c_log.GlobalLogger.Info("开始下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
|
|
|
|
- _ = util.CreateParentDir(triggerLocalPath)
|
|
|
|
- for {
|
|
|
|
- if err := config.OssBucket.GetObjectToFile(trigger.TriggerScriptPath, triggerLocalPath); err != nil {
|
|
|
|
- c_log.GlobalLogger.Error("下载触发器插件失败,再次尝试:", err)
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- break
|
|
|
|
|
|
+ if config.LocalConfig.Internet {
|
|
|
|
+ // 1 获取数采任务的触发器列表
|
|
|
|
+ cloudTriggers := &config.PlatformConfig.TaskTriggers
|
|
|
|
+ // 2 获取本地触发器列表(触发器目录的一级子目录为【触发器ID_触发器Label】)
|
|
|
|
+ localTriggerIds := util.GetFirstLevelSubdirectories(config.CloudConfig.TriggersDir)
|
|
|
|
+ // 3 对比触发器列表,本地没有的则下载
|
|
|
|
+ for _, trigger := range *cloudTriggers {
|
|
|
|
+ id := util.ToString(trigger.TriggerId)
|
|
|
|
+ hasIdDir := slices.Contains(localTriggerIds, id) // 改成了 slices 工具库
|
|
|
|
+ triggerLocalDir := config.CloudConfig.TriggersDir + id + "/"
|
|
|
|
+ hasLabelSo, soPaths := util.CheckSoFilesInDirectory(triggerLocalDir)
|
|
|
|
+ var triggerLocalPath string
|
|
|
|
+ if hasIdDir && hasLabelSo { // 已存在的触发器需要判断是否大小一致
|
|
|
|
+ triggerLocalPath = soPaths[0]
|
|
|
|
+ ossSize, _ := util.GetOSSFileSize(config.OssBucket, trigger.TriggerScriptPath)
|
|
|
|
+ localSize, _ := util.GetFileSize(triggerLocalPath)
|
|
|
|
+ if ossSize == localSize {
|
|
|
|
+ c_log.GlobalLogger.Info("触发器插件 ", triggerLocalPath, " 存在且与云端触发器大小一致。")
|
|
|
|
+ triggerLocalPathsMapTriggerId[triggerLocalPath] = id
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ label := util.GetFileNameWithoutExtension(config.CloudConfig.TriggersDir + trigger.TriggerScriptPath)
|
|
|
|
+ triggerLocalPath = config.CloudConfig.TriggersDir + id + "/" + label + ".so"
|
|
|
|
+ c_log.GlobalLogger.Info("开始下载触发器插件从 ", trigger.TriggerScriptPath, " 到 ", triggerLocalPath)
|
|
|
|
+ _ = util.CreateParentDir(triggerLocalPath)
|
|
|
|
+ for {
|
|
|
|
+ if err := config.OssBucket.GetObjectToFile(trigger.TriggerScriptPath, triggerLocalPath); err != nil {
|
|
|
|
+ c_log.GlobalLogger.Error("下载触发器插件失败,再次尝试:", err)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ triggerLocalPathsMapTriggerId[triggerLocalPath] = id
|
|
}
|
|
}
|
|
- triggerLocalPathsMapTriggerId[triggerLocalPath] = id
|
|
|
|
|
|
+ } else {
|
|
|
|
+ errorCodeSoPath := "/mnt/media/sda1/cicv-data-closedloop/ErrorCode.so"
|
|
|
|
+ c_log.GlobalLogger.Error("无法连接互联网,提前准备触发器插件文件:", errorCodeSoPath)
|
|
|
|
+ triggerLocalPathsMapTriggerId[errorCodeSoPath] = "ErrorCodeId"
|
|
}
|
|
}
|
|
|
|
|
|
success := 0
|
|
success := 0
|