|
@@ -5,93 +5,72 @@ package main
|
|
|
*/
|
|
|
|
|
|
import (
|
|
|
+ "cicv-data-closedloop/amd64/dispatch_server/package/global"
|
|
|
"cicv-data-closedloop/amd64/dispatch_server/package/handler"
|
|
|
"cicv-data-closedloop/amd64/dispatch_server/package/infra"
|
|
|
+ "cicv-data-closedloop/amd64/dispatch_server/package/service"
|
|
|
commonHandler "cicv-data-closedloop/common/gin/handler"
|
|
|
"cicv-data-closedloop/common/util"
|
|
|
_ "embed"
|
|
|
- "fmt"
|
|
|
+ "encoding/json"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
- "gopkg.in/yaml.v3"
|
|
|
"os"
|
|
|
)
|
|
|
|
|
|
-type ApplicationYamlStruct struct {
|
|
|
- ApplicationName string `yaml:"application-name"`
|
|
|
- Web WebStruct `yaml:"web"`
|
|
|
- Log LogStruct `yaml:"log"`
|
|
|
- Redis RedisStruct `yaml:"redis"`
|
|
|
- Oss OssStruct `yaml:"oss"`
|
|
|
- GpuNodeList []GpuNode `yaml:"gpu_node_list"`
|
|
|
-}
|
|
|
-
|
|
|
-type WebStruct struct {
|
|
|
- Port string `yaml:"port"`
|
|
|
- RoutePrefix string `yaml:"route-prefix"`
|
|
|
- Token string `yaml:"token"`
|
|
|
- WhiteList []string `yaml:"white-list"`
|
|
|
-}
|
|
|
-
|
|
|
-type LogStruct struct {
|
|
|
- Dir string `yaml:"dir"`
|
|
|
- Prefix string `yaml:"prefix"`
|
|
|
-}
|
|
|
-
|
|
|
-type RedisStruct struct {
|
|
|
- Addr string `yaml:"addr"`
|
|
|
- Password string `yaml:"password"`
|
|
|
- Db int `yaml:"db"`
|
|
|
-}
|
|
|
-type OssStruct struct {
|
|
|
- IsUseCname bool `yaml:"is-use-cname"`
|
|
|
- Endpoint string `yaml:"endpoint"`
|
|
|
- AccessKeyId string `yaml:"access-key-id"`
|
|
|
- AccessKeySecret string `yaml:"access-key-secret"`
|
|
|
- BucketName string `yaml:"bucket-name"`
|
|
|
-}
|
|
|
-
|
|
|
-type GpuNode struct {
|
|
|
- Hostname string `yaml:"hostname"`
|
|
|
- Ip string `yaml:"ip"`
|
|
|
- Parallelism string `yaml:"parallelism"`
|
|
|
-}
|
|
|
-
|
|
|
-var (
|
|
|
- //go:embed application.yaml
|
|
|
- applicationYamlBytes []byte
|
|
|
- ApplicationYaml ApplicationYamlStruct
|
|
|
-)
|
|
|
-
|
|
|
func init() {
|
|
|
// 1 解析YAML内容
|
|
|
- _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
|
|
|
- fmt.Println("加载配置文件内容为:", ApplicationYaml)
|
|
|
+ infra.InitApplication()
|
|
|
// 2 初始化 日志
|
|
|
- infra.InitLog(ApplicationYaml.Log.Dir, ApplicationYaml.Log.Prefix)
|
|
|
+ infra.InitLog(infra.ApplicationYaml.Log.Dir, infra.ApplicationYaml.Log.Prefix)
|
|
|
// 3 初始化 阿里云oss 客户端
|
|
|
infra.InitOss(
|
|
|
- ApplicationYaml.Oss.IsUseCname,
|
|
|
- ApplicationYaml.Oss.Endpoint,
|
|
|
- ApplicationYaml.Oss.AccessKeyId,
|
|
|
- ApplicationYaml.Oss.AccessKeySecret,
|
|
|
- ApplicationYaml.Oss.BucketName,
|
|
|
+ infra.ApplicationYaml.Oss.IsUseCname,
|
|
|
+ infra.ApplicationYaml.Oss.Endpoint,
|
|
|
+ infra.ApplicationYaml.Oss.AccessKeyId,
|
|
|
+ infra.ApplicationYaml.Oss.AccessKeySecret,
|
|
|
+ infra.ApplicationYaml.Oss.BucketName,
|
|
|
)
|
|
|
// 4 初始化 Redis 客户端
|
|
|
infra.InitRedisClient(
|
|
|
- ApplicationYaml.Redis.Addr,
|
|
|
- ApplicationYaml.Redis.Password,
|
|
|
- ApplicationYaml.Redis.Db,
|
|
|
+ infra.ApplicationYaml.Redis.Addr,
|
|
|
+ infra.ApplicationYaml.Redis.Password,
|
|
|
+ infra.ApplicationYaml.Redis.Db,
|
|
|
)
|
|
|
+ // 5 将 gpu-node-list 写入redis
|
|
|
+ err := infra.GlobalRedisClient.Del(global.KeyGpuNodeList).Err()
|
|
|
+ if err != nil {
|
|
|
+ infra.GlobalLogger.Error("程序崩溃。gpu-node-list 初始化失败1:", err)
|
|
|
+ os.Exit(-1)
|
|
|
+ }
|
|
|
+ for _, gpuNode := range infra.ApplicationYaml.GpuNodeList {
|
|
|
+ gpuNodeJson, err := json.MarshalIndent(gpuNode, "", " ")
|
|
|
+ if err != nil {
|
|
|
+ infra.GlobalLogger.Error("程序崩溃。gpu-node-list 初始化失败2:", err)
|
|
|
+ os.Exit(-1)
|
|
|
+ }
|
|
|
+ _, err = infra.GlobalRedisClient.RPush("gpu-node-list", gpuNodeJson).Result()
|
|
|
+ if err != nil {
|
|
|
+ infra.GlobalLogger.Error("程序崩溃。gpu-node-list 初始化失败3:", err)
|
|
|
+ os.Exit(-1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
+
|
|
|
+ // 启动任务处理进程
|
|
|
+ go service.RunWaitingUser()
|
|
|
+ go service.RunWaitingCluster()
|
|
|
+
|
|
|
+ // 启动 web 服务器
|
|
|
router := gin.Default()
|
|
|
router.Use(commonHandler.ValidateHeaders())
|
|
|
- api := router.Group(ApplicationYaml.Web.RoutePrefix)
|
|
|
+ api := router.Group(infra.ApplicationYaml.Web.RoutePrefix)
|
|
|
api.POST("/start-project", handler.StartProject)
|
|
|
- err := router.Run(":" + ApplicationYaml.Web.Port)
|
|
|
+ err := router.Run(":" + infra.ApplicationYaml.Web.Port)
|
|
|
if err != nil {
|
|
|
- infra.GlobalLogger.Error("程序崩溃,监听端口 " + util.ToString(ApplicationYaml.Web.Port) + " 失败。")
|
|
|
+ infra.GlobalLogger.Error("程序崩溃,监听端口 " + util.ToString(infra.ApplicationYaml.Web.Port) + " 失败。")
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
}
|