|
@@ -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
|
|
|
+}
|