|
@@ -5,21 +5,22 @@ package main
|
|
|
*/
|
|
|
|
|
|
import (
|
|
|
- "cicv-data-closedloop/amd64/dispatch_server/package/entity"
|
|
|
"cicv-data-closedloop/amd64/dispatch_server/package/handler"
|
|
|
- "cicv-data-closedloop/common/config/c_log"
|
|
|
- "cicv-data-closedloop/common/config/c_oss"
|
|
|
+ "cicv-data-closedloop/amd64/dispatch_server/package/infra"
|
|
|
commonHandler "cicv-data-closedloop/common/gin/handler"
|
|
|
"cicv-data-closedloop/common/util"
|
|
|
_ "embed"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "gopkg.in/yaml.v3"
|
|
|
"os"
|
|
|
)
|
|
|
|
|
|
type ApplicationYamlStruct struct {
|
|
|
- ApplicationName string `yaml:"application"`
|
|
|
- Web WebStruct `yaml:"web"`
|
|
|
- GpuNodeList []GpuNode `yaml:"gpu_node_list"`
|
|
|
+ ApplicationName string `yaml:"application"`
|
|
|
+ Web WebStruct `yaml:"web"`
|
|
|
+ Redis RedisStruct `yaml:"redis"`
|
|
|
+ Oss OssStruct `yaml:"oss"`
|
|
|
+ GpuNodeList []GpuNode `yaml:"gpu_node_list"`
|
|
|
}
|
|
|
|
|
|
type WebStruct struct {
|
|
@@ -29,36 +30,60 @@ type WebStruct struct {
|
|
|
WhiteList []string `yaml:"white-list"`
|
|
|
}
|
|
|
|
|
|
+type RedisStruct struct {
|
|
|
+ Addr string `yaml:"addr"`
|
|
|
+ Password string `yaml:"password"`
|
|
|
+ Db int `yaml:"db"`
|
|
|
+}
|
|
|
+type OssStruct struct {
|
|
|
+ IsUseCname bool `json:"is-use-cname"`
|
|
|
+ Endpoint string `json:"endpoint"`
|
|
|
+ AccessKeyId string `json:"accessKeyId"`
|
|
|
+ AccessKeySecret string `json:"accessKeySecret"`
|
|
|
+ BucketName string `json:"bucketName"`
|
|
|
+}
|
|
|
+
|
|
|
type GpuNode struct {
|
|
|
Hostname string `yaml:"hostname"`
|
|
|
Ip string `yaml:"ip"`
|
|
|
Parallelism string `yaml:"parallelism"`
|
|
|
}
|
|
|
|
|
|
-type RedisStruct struct {
|
|
|
-}
|
|
|
-
|
|
|
var (
|
|
|
//go:embed application.yaml
|
|
|
- applicationYamlBytes []byte
|
|
|
- ApplicationYaml ApplicationYamlStruct
|
|
|
- KubernetesSchedulerConfig = new(entity.KubernetesSchedulerConfigStruct)
|
|
|
+ applicationYamlBytes []byte
|
|
|
+ ApplicationYaml ApplicationYamlStruct
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
- c_log.InitLog("./log/", KubernetesSchedulerConfig.Service.Name)
|
|
|
- c_oss.InitOss(false)
|
|
|
-
|
|
|
+ // 1 解析YAML内容
|
|
|
+ _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
|
|
|
+ // 2 初始化 日志
|
|
|
+ infra.InitLog("./log/", ApplicationYaml.ApplicationName)
|
|
|
+ // 3 初始化 阿里云oss 客户端
|
|
|
+ infra.InitOss(
|
|
|
+ ApplicationYaml.Oss.IsUseCname,
|
|
|
+ ApplicationYaml.Oss.Endpoint,
|
|
|
+ ApplicationYaml.Oss.AccessKeyId,
|
|
|
+ ApplicationYaml.Oss.AccessKeySecret,
|
|
|
+ ApplicationYaml.Oss.BucketName,
|
|
|
+ )
|
|
|
+ // 4 初始化 Redis 客户端
|
|
|
+ infra.InitRedisClient(
|
|
|
+ ApplicationYaml.Redis.Addr,
|
|
|
+ ApplicationYaml.Redis.Password,
|
|
|
+ ApplicationYaml.Redis.Db,
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
router := gin.Default()
|
|
|
router.Use(commonHandler.ValidateHeaders())
|
|
|
- api := router.Group(KubernetesSchedulerConfig.Service.RouterPrefix)
|
|
|
+ api := router.Group(ApplicationYaml.Web.RoutePrefix)
|
|
|
api.POST("/start-project", handler.StartProject)
|
|
|
- err := router.Run(":12345")
|
|
|
+ err := router.Run(":" + ApplicationYaml.Web.Port)
|
|
|
if err != nil {
|
|
|
- c_log.GlobalLogger.Error("程序崩溃,监听端口 " + util.ToString(KubernetesSchedulerConfig.Service.Port) + " 失败。")
|
|
|
+ infra.GlobalLogger.Error("程序崩溃,监听端口 " + util.ToString(ApplicationYaml.Web.Port) + " 失败。")
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
}
|