LingxinMeng 7 kuukautta sitten
vanhempi
commit
fa551ec58c

+ 2 - 1
README.md

@@ -1,4 +1,5 @@
 # 开发
 1. 在 go.mod 查看 golang sdk 版本
 # 依赖
-1. Redis
+1. Redis
+# 部署

+ 10 - 8
src/package/domain/comm_with_redis.go

@@ -45,11 +45,12 @@ func CanRunCluster() (bool, infra.GpuNode, error) {
 	return can, maxNode, nil
 }
 
-func AddWaitingUser(userId string, userParallelism int64, algorithmObjectKey string, task entity.Task) error {
+func AddWaitingUser(project *entity.Project, task entity.Task) error {
 	taskCacheTemp := entity.TaskCache{
-		UserId:             userId,
-		AlgorithmObjectKey: algorithmObjectKey,
-		UserParallelism:    userParallelism,
+		UserId:             project.UserId,
+		AlgorithmObjectKey: project.AlgorithmObjectKey,
+		UserParallelism:    project.Parallelism,
+		EquipmentType:      project.EquipmentType,
 		Task:               task,
 	}
 	// 转 json
@@ -78,11 +79,12 @@ func DeleteWaitingUser(taskCacheJson string) error {
 	return nil
 }
 
-func AddWaitingCluster(userId string, userParallelism int64, algorithmObjectKey string, task entity.Task) error {
+func AddWaitingCluster(project *entity.Project, task entity.Task) error {
 	taskCacheTemp := entity.TaskCache{
-		UserId:             userId,
-		AlgorithmObjectKey: algorithmObjectKey,
-		UserParallelism:    userParallelism,
+		UserId:             project.UserId,
+		AlgorithmObjectKey: project.AlgorithmObjectKey,
+		UserParallelism:    project.Parallelism,
+		EquipmentType:      project.EquipmentType,
 		Task:               task,
 	}
 	// 转 json

+ 1 - 0
src/package/entity/project.go

@@ -3,6 +3,7 @@ package entity
 type Project struct {
 	ProjectId          string `json:"projectId"`
 	AlgorithmObjectKey string `json:"algorithmObjectKey"`
+	EquipmentType      string `json:"equipmentType"`
 	UserId             string `json:"userId"`
 	Parallelism        int64  `json:"parallelism"`
 	Tasks              []Task `json:"tasks"`

+ 1 - 0
src/package/entity/task_cache.go

@@ -4,5 +4,6 @@ type TaskCache struct {
 	UserId             string `json:"userId"`
 	UserParallelism    int64  `json:"userParallelism"`
 	AlgorithmObjectKey string `json:"algorithmObjectKey"`
+	EquipmentType      string `json:"equipmentType"`
 	Task               Task   `json:"task"`
 }

+ 33 - 3
src/package/handler/start_project.go

@@ -133,25 +133,27 @@ func StartProject(c *gin.Context) {
 		c.JSON(http.StatusBadRequest, entity.HttpResult{Status: false, Code: "1003", Message: "请求参数格式错误。"})
 		return
 	}
+	if !checkEquipmentType(projectStartParam.EquipmentType) {
+		c.JSON(http.StatusOK, entity.HttpResult{Status: true, Code: "400", Message: "设备类型错误。"})
+	}
 	// ------------ 维护一个运行任务队列,绑定用户id和节点名称,供下面两个判断同时使用(使用redis的队列)
 	userId := projectStartParam.UserId               // 用户ID
 	taskReceived := projectStartParam.Tasks          // 接收到的所有任务
 	userParallelism := projectStartParam.Parallelism // 用户的并行度上限
-	algorithmObjectKey := projectStartParam.AlgorithmObjectKey
 
 	// 1 判断用户并行度
 	for _, task := range taskReceived {
 		global.RunTaskMutex.Lock()
 		// 1 判断用户并行度是否有剩余,有剩余则加入集群等待队列,并从用户等待队列中拿出,没有剩余则不需要改动
 		if domain.CanRunUser(userId, userParallelism) { // 可以运行
-			err := domain.AddWaitingCluster(userId, userParallelism, algorithmObjectKey, task)
+			err := domain.AddWaitingCluster(projectStartParam, task)
 			if err != nil {
 				infra.GlobalLogger.Errorf("将任务 %v 添加到【集群等待队列】失败,错误信息为:%v", task, err)
 				continue
 			}
 			infra.GlobalLogger.Infof("将任务 %v 添加到【集群等待队列】成功。", task.Info.TaskId)
 		} else { // 不能运行
-			err := domain.AddWaitingUser(userId, userParallelism, algorithmObjectKey, task)
+			err := domain.AddWaitingUser(projectStartParam, task)
 			if err != nil {
 				infra.GlobalLogger.Errorf("将任务 %v 添加到【用户等待队列】失败,错误信息为:%v", task, err)
 				continue
@@ -164,3 +166,31 @@ func StartProject(c *gin.Context) {
 	// 4 返回
 	c.JSON(http.StatusOK, entity.HttpResult{Status: true, Code: "2000", Message: "项目启动请求已被成功接收,等待调度处理。"})
 }
+
+func checkEquipmentType(equipmentType string) bool {
+	/*
+		JIN_LONG_BA_SHI // "金龙中巴"
+		    PEI_SONG_JI_QI_REN // "智能配送机器人",
+		    SAO_DI_JI_QI_REN // "室内清洁机器人",
+		    YI_DAO_JI_QI_REN // "引导服务机器人",
+		    PU_JIN_DUO_GONG_NENG_CHE // " "朴津多功能车",
+		    AN_FANG_JI_QI_REN // " "安防巡检机器人";
+	*/
+	if equipmentType == "JIN_LONG_BA_SHI" {
+		infra.GlobalLogger.Infof("接收到【金龙中巴】的仿真测试项目。")
+	} else if equipmentType == "PEI_SONG_JI_QI_REN" {
+		infra.GlobalLogger.Infof("接收到【智能配送机器人】的仿真测试项目。")
+	} else if equipmentType == "SAO_DI_JI_QI_REN" {
+		infra.GlobalLogger.Infof("接收到【室内清洁机器人】的仿真测试项目。")
+	} else if equipmentType == "YI_DAO_JI_QI_REN" {
+		infra.GlobalLogger.Infof("接收到【引导服务机器人】的仿真测试项目。")
+	} else if equipmentType == "PU_JIN_DUO_GONG_NENG_CHE" {
+		infra.GlobalLogger.Infof("接收到【朴津多功能车】的仿真测试项目。")
+	} else if equipmentType == "AN_FANG_JI_QI_REN" {
+		infra.GlobalLogger.Infof("接收到【安防巡检机器人】的仿真测试项目。")
+	} else {
+		infra.GlobalLogger.Infof("接收到未知的设备类型【%v】", equipmentType)
+		return false
+	}
+	return true
+}

+ 2 - 1
src/package/infra/application.yaml

@@ -45,7 +45,8 @@ k8s:
   namespace-name: cicvdcl
   vtd-image: 10.14.85.237:5000/vtd.run.perception.release:latest
 #  vtd-command: /Controller/config/docker_cloud_algContest.ini
-  vtd-command: /Controller/config/docker_cloud.ini
+  vtd-command-pjisuv: /Controller/config/docker_cloud.ini
+  vtd-command-pjibot: /Controller/config/docker_cloud.ini
   callback-uri: http://10.14.86.127:9081/project/task/callback
   platform-type: 2
 

+ 2 - 1
src/package/infra/i_application.go

@@ -65,7 +65,8 @@ type K8sStruct struct {
 	RegistryUri         string `yaml:"registry-uri"`
 	NamespaceName       string `yaml:"namespace-name"`
 	VtdImage            string `yaml:"vtd-image"`
-	VtdCommand          string `yaml:"vtd-command"`
+	VtdCommandPjisuv    string `yaml:"vtd-command-pjisuv"`
+	VtdCommandPjibot    string `yaml:"vtd-command-pjibot"`
 	CallbackUri         string `yaml:"callback-uri"`
 	PlatformType        string `yaml:"platform-type"`
 }

+ 12 - 2
src/package/service/run_task.go

@@ -43,10 +43,16 @@ func RunWaitingUser() {
 			userId := taskCache.UserId
 			userParallelism := taskCache.UserParallelism
 			algorithmObjectKey := taskCache.AlgorithmObjectKey
+			equipmentType := taskCache.EquipmentType
 			task := taskCache.Task
 			// 1 判断用户并行度是否有剩余,有剩余则加入集群等待队列,并从用户等待队列中拿出,没有剩余则不需要改动
 			if domain.CanRunUser(userId, userParallelism) { // 可以运行
-				err = domain.AddWaitingCluster(userId, userParallelism, algorithmObjectKey, task)
+				err = domain.AddWaitingCluster(&entity.Project{
+					UserId:             userId,
+					Parallelism:        userParallelism,
+					AlgorithmObjectKey: algorithmObjectKey,
+					EquipmentType:      equipmentType,
+				}, task)
 				if err != nil {
 					infra.GlobalLogger.Error(err)
 					continue
@@ -251,7 +257,11 @@ func RunWaitingCluster() {
 		podString = strings.Replace(podString, "algorithm-image", algorithmImageName, -1)
 		podString = strings.Replace(podString, "vtd-container", vtdContainer, -1)
 		podString = strings.Replace(podString, "vtd-image", vtdImage, -1)
-		podString = strings.Replace(podString, "vtd-command", infra.ApplicationYaml.K8s.VtdCommand, -1)
+		if firstTaskCache.EquipmentType == "PU_JIN_DUO_GONG_NENG_CHE" { // 多功能车仿真
+			podString = strings.Replace(podString, "vtd-command", infra.ApplicationYaml.K8s.VtdCommandPjisuv, -1)
+		} else {
+			podString = strings.Replace(podString, "vtd-command", infra.ApplicationYaml.K8s.VtdCommandPjibot, -1)
+		}
 		podString = strings.Replace(podString, "platform-ip", infra.ApplicationYaml.Web.IpPrivate+":"+infra.ApplicationYaml.Web.Port, -1)
 		podString = strings.Replace(podString, "simulation-cloud-ip", infra.ApplicationYaml.Web.IpPrivate+":"+infra.ApplicationYaml.Web.Port, -1)
 		podString = strings.Replace(podString, "platform-type", "\""+infra.ApplicationYaml.K8s.PlatformType+"\"", -1)