LingxinMeng hai 1 ano
pai
achega
a95deab79b

+ 5 - 4
aarch64/pjisuv/master/service/for_competition.go

@@ -15,10 +15,11 @@ import (
 )
 
 var (
-	dir                    = "/userdata/competition/"
-	dirBak                 = "/userdata/competition-bak/"
-	ossPrefix              = "competition/"
-	commandArgs            = []string{"record", "--split", "--duration=1", "/pji_gps", "/data_read"}
+	dir       = "/userdata/competition/"
+	dirBak    = "/userdata/competition-bak/"
+	ossPrefix = "competition/"
+	// v20240604 添加 /pj_vehicle_fdb_pub 判断人工接管场景
+	commandArgs            = []string{"record", "--split", "--duration=1", "/pji_gps", "/data_read", "/pj_vehicle_fdb_pub"}
 	topic                  = "/team_name"
 	urlExamTick            = "http://36.110.106.142:12341/web_server/exam/tick"
 	urlExamBegin           = "http://36.110.106.142:12341/web_server/exam/begin"

+ 2 - 0
aarch64/plugin-compile/main/main.go

@@ -17,6 +17,7 @@ const serviceName = "plugin-compile"
 func init() {
 	c_log.InitLog("./log/", serviceName)
 	c_oss.InitOss(false)
+	c_oss.InitOss2(false)
 	c_nacos.InitService(true, serviceName, servicePort, map[string]string{
 		"开发者":  "孟令鑫",
 		"内网IP": "10.14.85.228",
@@ -27,6 +28,7 @@ func init() {
 func main() {
 	mux := http.NewServeMux()
 	mux.Handle("/compile", h_validate_request_header.HeaderValidationMiddleware(&handler.CompileHandler{}))
+	mux.Handle("/pji_compile", h_validate_request_header.HeaderValidationMiddleware(&handler.CompileHandler{}))
 	err := http.ListenAndServe(":"+util.ToString(servicePort), mux)
 	if err != nil {
 		c_log.GlobalLogger.Error("程序崩溃监听端口 " + util.ToString(servicePort) + " 失败。")

+ 28 - 2
aarch64/plugin-compile/package/config/oss_config.go

@@ -15,13 +15,21 @@ type OssConnectInfoStruct struct {
 }
 
 var (
-	cname           = "http://pji-bucket1.oss.icvdc.com"
+	cname           = "http://open-bucket.oss.icvdc.com"
 	endpoint        = "oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com"
 	accessKeyId     = "n8glvFGS25MrLY7j"
 	accessKeySecret = "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
-	bucketName      = "pji-bucket1"
+	bucketName      = "open-bucket"
 	OssClient       *oss.Client
 	OssBucket       *oss.Bucket
+
+	cname2           = "http://pji-bucket1.oss.icvdc.com"
+	endpoint2        = "oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com"
+	accessKeyId2     = "n8glvFGS25MrLY7j"
+	accessKeySecret2 = "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
+	bucketName2      = "pji-bucket1"
+	OssClient2       *oss.Client
+	OssBucket2       *oss.Bucket
 )
 
 func InitOss(isUseCname bool) {
@@ -41,3 +49,21 @@ func InitOss(isUseCname bool) {
 		os.Exit(-1)
 	}
 }
+
+func InitOss2(isUseCname bool) {
+	var err error
+	if isUseCname {
+		OssClient2, err = oss.New(cname2, accessKeyId2, accessKeySecret2, oss.UseCname(true)) // 公网
+	} else {
+		OssClient2, err = oss.New(endpoint2, accessKeyId2, accessKeySecret2, oss.UseCname(false)) // 内网
+	}
+	if err != nil {
+		fmt.Println("无法创建阿里云client:", err)
+		os.Exit(-1)
+	}
+	OssBucket2, err = OssClient2.Bucket(bucketName2)
+	if err != nil {
+		fmt.Println("无法创建阿里云bucket:", err)
+		os.Exit(-1)
+	}
+}

+ 83 - 0
aarch64/plugin-compile/package/handler/compile_plugin.go

@@ -108,3 +108,86 @@ func (h *CompileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	result, _ := json.Marshal(entity.HttpResult{Status: true, Code: "2000", Message: "编译插件" + goObjectKey + "成功。"})
 	_, _ = fmt.Fprintf(w, string(result))
 }
+
+// PjiCompileHandler implements http.Handler
+type PjiCompileHandler struct{}
+
+func (h *PjiCompileHandler) ServeHTTP2(w http.ResponseWriter, r *http.Request) {
+
+	// 1 校验参数
+	queryParams := r.URL.Query()
+	goObjectKey := queryParams.Get("goObjectKey")
+	if goObjectKey == "" {
+		c_log.GlobalLogger.Error("参数 goObjectKey 不能为空。")
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1003", Message: "参数 goObjectKey 不能为空。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+	soObjectKey := queryParams.Get("soObjectKey")
+	if soObjectKey == "" {
+		c_log.GlobalLogger.Error("参数 soObjectKey 不能为空。")
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1003", Message: "参数 soObjectKey 不能为空。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+	//c_log.GlobalLogger.Infof("接收到参数【deviceType】=%v,【goObjectKey】=%v,【soObjectKey】=%v", deviceType, goObjectKey, soObjectKey)
+	c_log.GlobalLogger.Infof("接收到参数【goObjectKey】=%v,【soObjectKey】=%v", goObjectKey, soObjectKey)
+
+	// 2 从 oss 上下载 go 文件
+	tempMiddlePath := uuid.New().String()[:8]
+	goLocalPath := codeDir + tempMiddlePath + "/main/" + tempMiddlePath + ".go"
+	c_log.GlobalLogger.Infof("下载源代码 %v --> %v", goObjectKey, goLocalPath)
+	if err := util2.LimitDownload(c_oss.OssBucket2, 41943040, goObjectKey, goLocalPath); err != nil {
+		c_log.GlobalLogger.Error("下载源代码 ", goObjectKey, " 出错:", err)
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1004", Message: "下载源代码 " + goObjectKey + " 出错。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+	// 修改文件权限为 777
+	if err := os.Chmod(goLocalPath, 0777); err != nil {
+		c_log.GlobalLogger.Error("修改文件权限 "+goLocalPath+" 出错:", err)
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1005", Message: "修改文件权限 " + goLocalPath + " 出错。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+
+	// 3 编译 go 文件
+	soLocalPath := codeDir + tempMiddlePath + "/main/" + tempMiddlePath + ".so"
+	copiedCompileCmdArgs := make([]string, len(compileCmdArgs))
+	copy(copiedCompileCmdArgs, compileCmdArgs)
+	copiedCompileCmdArgs = append(copiedCompileCmdArgs, "-o", soLocalPath, goLocalPath)
+	if _, output, err := util2.ExecuteWithEnvAndDir(os.Environ(), codeDir, compileCmd, copiedCompileCmdArgs...); err != nil {
+		c_log.GlobalLogger.Error("编译插件 ", goLocalPath, " 出错:【命令】=", compileCmd, " ", copiedCompileCmdArgs, "【output】=", output, ",【err】=", err)
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1006", Message: "编译插件 " + goObjectKey + " 出错。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+
+	// 4 校验插件是否能用
+	if _, output, err := util2.Execute(vaildateCmd, soLocalPath); err != nil || output != "0" {
+		c_log.GlobalLogger.Error("插件 ", goLocalPath, " 校验失败:【命令】=", vaildateCmd, " ", soLocalPath, "【output】=", output)
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1007", Message: "插件 " + soObjectKey + " 校验失败。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+	c_log.GlobalLogger.Error("插件 ", soLocalPath, " 校验成功。")
+	// 5 如果插件能用,将插件上传到 oss
+	if err := util2.LimitUpload(c_oss.OssBucket2, 41943040, soObjectKey, soLocalPath); err != nil {
+		c_log.GlobalLogger.Error("上传插件 ", soObjectKey, " 出错:", err)
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1008", Message: "上传插件 " + soObjectKey + " 出错。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+	// 6 删除本地缓存的源代码和插件
+	if err := util2.RemoveDir(codeDir + tempMiddlePath + "/"); err != nil {
+		c_log.GlobalLogger.Error("删除本地缓存目录 ", codeDir+tempMiddlePath+"/", " 出错:", err)
+		result, _ := json.Marshal(entity.HttpResult{Status: false, Code: "1009", Message: "删除本地缓存出错。"})
+		_, _ = fmt.Fprintf(w, string(result))
+		return
+	}
+
+	// 7 返回成功数据
+	c_log.GlobalLogger.Error("编译插件 ", goLocalPath, " 成功。")
+	result, _ := json.Marshal(entity.HttpResult{Status: true, Code: "2000", Message: "编译插件" + goObjectKey + "成功。"})
+	_, _ = fmt.Fprintf(w, string(result))
+}