| | |
| | | "os" |
| | | "path" |
| | | "path/filepath" |
| | | "strconv" |
| | | "strings" |
| | | "webserver/extend/config" |
| | | "webserver/extend/util" |
| | | ) |
| | |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | | } else { |
| | | configPatchPath = "/opt/vasystem/patch" |
| | | configPatchPath = "../patch" |
| | | } |
| | | |
| | | filenameWithSuffix := path.Base(filename) |
| | | ext := path.Ext(filenameWithSuffix) |
| | | |
| | | zipFilePath := configPatchPath + "/"+identifier+ext |
| | | unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" |
| | | if util.Exists(zipFilePath) { |
| | | strMd5, e := util.FileMd5(zipFilePath) |
| | | if e !=nil || strMd5 == "" { |
| | | go os.Remove(zipFilePath) |
| | | if util.DirExists(unPackTargetPath) { |
| | | go os.RemoveAll(unPackTargetPath) |
| | | } |
| | | return false,errors.New("获取安装包md5失败") |
| | | } |
| | | if strMd5 == identifier { |
| | |
| | | |
| | | } else { |
| | | go os.Remove(zipFilePath) |
| | | if util.DirExists(unPackTargetPath) { |
| | | go os.RemoveAll(unPackTargetPath) |
| | | } |
| | | logger.Debug("strMd5 is", strMd5,"identifier is",identifier,"not equal") |
| | | return false,errors.New("校验安装文件失败") |
| | | } |
| | |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | | } else { |
| | | configPatchPath = "/opt/vasystem/patch" |
| | | configPatchPath = "../patch" |
| | | } |
| | | //1.解压缩更新包 |
| | | unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" |
| | |
| | | //3.将算法so、依赖文件、zconf、 |
| | | soM := make(map[string]SdkDef) |
| | | var skDefArr []SdkDef |
| | | nInsM := make(map[string]string) |
| | | aInsM := make(map[string]string) |
| | | if err = json.Unmarshal(defB, &skDefArr);err == nil { |
| | | //注册算法信息和算法参数到dbserver |
| | | var sdkApi dbapi.SdkApi |
| | | for _,skd := range skDefArr { |
| | | //注册算法信息和算法参数到dbserver |
| | | //先看此算法有没有注册,如果已安装,比对版本号 |
| | | bf, curDbSdk := sdkApi.GetById(skd.Def.Id) |
| | | if bf { |
| | | bytes, _ := json.Marshal(curDbSdk) |
| | | var sm map[string]interface{} |
| | | unE := json.Unmarshal(bytes, &sm) |
| | | if unE != nil { |
| | | continue |
| | | } |
| | | sdkVersion, ok := sm["version"] |
| | | if ok { //有版本号 |
| | | vStr := sdkVersion.(string) |
| | | if shouldVersionBeUpgrade(vStr, skd.Def.Version) { |
| | | nInsM[skd.Def.SdkType] = skd.Def.SdkType |
| | | aInsM[skd.Def.Id] = skd.Def.Id |
| | | } |
| | | } else { |
| | | nInsM[skd.Def.SdkType] = skd.Def.SdkType |
| | | aInsM[skd.Def.Id] = skd.Def.Id |
| | | } |
| | | } else { |
| | | nInsM[skd.Def.SdkType] = skd.Def.SdkType |
| | | aInsM[skd.Def.Id] = skd.Def.Id |
| | | } |
| | | |
| | | |
| | | if _,ok := soM[skd.Def.SdkType];!ok { |
| | | soM[skd.Def.SdkType] = skd |
| | | } |
| | | srv := SdkRegisterVo{ |
| | | Id: skd.Def.Id, |
| | | SdkType: skd.Def.SdkType, |
| | | SdkName: skd.Def.SdkName, |
| | | Icon: skd.Def.Icon, |
| | | Url: skd.Def.Url, |
| | | } |
| | | for _,ag := range skd.Args { |
| | | sra := SdkRegisterArgVo{ |
| | | Scope: ag.Scope, |
| | | if _,ok := aInsM[skd.Def.Id]; ok { |
| | | srv := SdkRegisterVo{ |
| | | Id: skd.Def.Id, |
| | | SdkType: skd.Def.SdkType, |
| | | SdkName: skd.Def.SdkName, |
| | | Icon: skd.Def.Icon, |
| | | Url: skd.Def.Url, |
| | | IconBlob: skd.Def.IconBlob, |
| | | Version: skd.Def.Version, |
| | | } |
| | | sra.SdkArg = SdkArg{ |
| | | Alias: ag.Alias, |
| | | Name: ag.Name, |
| | | Type: ag.Type, |
| | | ArgType: ag.ArgType, |
| | | Must: ag.Must, |
| | | Unit: ag.Unit, |
| | | Range: ag.Range, |
| | | DefaultValue: ag.DefaultValue, |
| | | DefaultOperator: ag.DefaultOperator, |
| | | Sort: ag.Sort, |
| | | for _,ag := range skd.Args { |
| | | sra := SdkRegisterArgVo{ |
| | | Scope: ag.Scope, |
| | | } |
| | | sra.SdkArg = SdkArg{ |
| | | Alias: ag.Alias, |
| | | Name: ag.Name, |
| | | Type: ag.Type, |
| | | ArgType: ag.ArgType, |
| | | Must: ag.Must, |
| | | Unit: ag.Unit, |
| | | Range: ag.Range, |
| | | DefaultValue: ag.DefaultValue, |
| | | DefaultOperator: ag.DefaultOperator, |
| | | Sort: ag.Sort, |
| | | } |
| | | srv.Args = append(srv.Args, sra) |
| | | } |
| | | srv.Args = append(srv.Args, sra) |
| | | paramBody := util.Struct2Map(srv) |
| | | logger.Debug("sdkApi.Register paramBody:", paramBody) |
| | | sdkApi.Register(paramBody) //将算法注册到数据库中 |
| | | } |
| | | paramBody := util.Struct2Map(srv) |
| | | logger.Debug("sdkApi.Register paramBody:", paramBody) |
| | | sdkApi.Register(paramBody) //将算法注册到数据库中 |
| | | } |
| | | zconfPath := "/opt/vasystem/bin/zconf/" |
| | | libPath := "/opt/vasystem/libs/" |
| | | zconfPath := "./zconf/" |
| | | libPath := "../libs/" |
| | | if !util.DirExists(zconfPath) { |
| | | os.MkdirAll(zconfPath, 0777) |
| | | } |
| | |
| | | os.MkdirAll(libPath, 0777) |
| | | } |
| | | for sdkType,_ := range soM { |
| | | //先解压SdkType.tar.gz文件 |
| | | if unTarGzE := util.UnTarGz(unPackPath+sdkType+".tar.gz", unPackPath);unTarGzE == nil { |
| | | //复制json启动文件 |
| | | if util.Exists(unPackPath+sdkType+"/zconf/"+sdkType+".json") { |
| | | util.CopyFile(unPackPath+sdkType+"/zconf/"+sdkType+".json", zconfPath+sdkType+".json") |
| | | } |
| | | if util.DirExists(unPackPath+sdkType) { |
| | | if _,cE := util.CopyDirByCmd(unPackPath+sdkType, libPath);cE != nil { |
| | | return false, cE |
| | | if _,iOk := nInsM[sdkType];iOk { |
| | | //先解压SdkType.tar.gz文件 |
| | | if unTarGzE := util.UnTarGz(unPackPath+sdkType+".tar.gz", unPackPath);unTarGzE == nil { |
| | | //复制json启动文件 |
| | | if util.Exists(unPackPath+sdkType+"/zconf/"+sdkType+".json") { |
| | | util.CopyFile(unPackPath+sdkType+"/zconf/"+sdkType+".json", zconfPath+sdkType+".json") |
| | | } |
| | | } |
| | | if util.DirExists(unPackPath+sdkType+"/models") { |
| | | if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/models", "/opt/vasystem/bin/zconf"); cE != nil { |
| | | return false, cE |
| | | if util.DirExists(unPackPath+sdkType) { |
| | | if _,cE := util.CopyDirByCmd(unPackPath+sdkType, libPath);cE != nil { |
| | | return false, cE |
| | | } |
| | | } |
| | | if util.DirExists(unPackPath+sdkType+"/models") { |
| | | if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/models", "./zconf"); cE != nil { |
| | | return false, cE |
| | | } |
| | | } |
| | | } else { |
| | | logger.Debug("unTarGzE sdkType.tar.gz err:", unTarGzE) |
| | | } |
| | | } else { |
| | | logger.Debug("unTarGzE sdkType.tar.gz err:", unTarGzE) |
| | | logger.Debug("upper version has been installed") |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | return true, nil |
| | | } |
| | | |
| | | func shouldVersionBeUpgrade(curVersion,dstVersion string) bool { |
| | | if curVersion == "" { |
| | | return true |
| | | } |
| | | if dstVersion == "" { |
| | | return false |
| | | } |
| | | curIVArr := strings.Split(curVersion, ".") |
| | | dstIVArr := strings.Split(dstVersion, ".") |
| | | if len(curIVArr) !=3 || len(dstIVArr) != 3{ |
| | | return false |
| | | } |
| | | cH,cEH := strconv.Atoi(curIVArr[0]) |
| | | cM,cEM := strconv.Atoi(curIVArr[1]) |
| | | cL,cEL := strconv.Atoi(curIVArr[2]) |
| | | |
| | | dH,dEH := strconv.Atoi(curIVArr[0]) |
| | | dM,dEM := strconv.Atoi(curIVArr[1]) |
| | | dL,dEL := strconv.Atoi(curIVArr[2]) |
| | | if cEH !=nil || cEM != nil || cEL != nil || dEH != nil ||dEM !=nil || dEL !=nil { |
| | | return false |
| | | } |
| | | if cH > dH { |
| | | return false |
| | | } else if cH == dH { |
| | | if cM > dM { |
| | | return false |
| | | } else if cM == dM { |
| | | if cL > dL { |
| | | return false |
| | | } else if cL == dL { |
| | | return false |
| | | } else { |
| | | return true |
| | | } |
| | | } else { |
| | | return true |
| | | } |
| | | } else { |
| | | return true |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | Enable bool `gorm:"column:enable;default:1" json:"enable"` |
| | | DelFlag int `gorm:"column:del_flag;default:0" json:"del_flag"` |
| | | Env string `gorm:"column:env" json:"env"` //运行环境及结果说明,json格式,包含so_file_path,runtime,param,depends(cuda版本,opencv版本,tensorflow版本等) |
| | | IconBlob string `gorm:"column:iconBlob;type:text;" json:"iconBlob"` //图片 |
| | | Version string `gorm:"column:version;type:varchar(50);default:'1.0';" json:"version"` //版本号 |
| | | } |
| | | |
| | | type SdkInsOrUpgrade struct { |
| | | Sdk |
| | | RemoteVersion string `json:"remoteVersion"` //商城仓库版本号 |
| | | Installed bool `json:"installed"` //是否已安装 |
| | | IsUpgrade bool `json:"isUpgrade"` //是否需要升级 |
| | | } |
| | | |
| | | type SdkArgEntity struct { |
| | |
| | | |
| | | |
| | | type SdkRegisterVo struct { |
| | | Id string `json:"id"` |
| | | SdkType string `json:"sdk_type"`//人脸检测:FaceDetect,人脸提取:FaceExtract,人脸比对:FaceCompare,行为:Yolo |
| | | SdkName string `json:"sdk_name"` //算法名称 |
| | | Args []SdkRegisterArgVo `json:"args"` //算法参数 |
| | | Icon string `json:"icon"` //算法图标 |
| | | Url string `json:"url"` //算法下载地址 |
| | | Id string `json:"id"` |
| | | SdkType string `json:"sdk_type"`//人脸检测:FaceDetect,人脸提取:FaceExtract,人脸比对:FaceCompare,行为:Yolo |
| | | SdkName string `json:"sdk_name"` //算法名称 |
| | | Args []SdkRegisterArgVo `json:"args"` //算法参数 |
| | | Icon string `json:"icon"` //算法图标 |
| | | Url string `json:"url"` //算法下载地址 |
| | | IconBlob string `json:"iconBlob"` //图片 |
| | | Version string `json:"version"` //版本号 |
| | | } |
| | | |
| | | type SdkRegisterArgVo struct { |
| | | Scope string `json:"scope"` |
| | | Scope string `json:"scope"` |
| | | SdkArg |
| | | |
| | | Dics []SdkArgDic `json:"dics"` //如果此算法参数是被选项,需要将参数枚举值写入到字典表中 |
| | | Dics []SdkArgDic `json:"dics"` //如果此算法参数是被选项,需要将参数枚举值写入到字典表中 |
| | | } |
| | | |
| | | type SdkArgDic struct { |
| | | Value string `json:"value"` |
| | | Name string `json:"name"` |
| | | Sort int `json:"sort"` |
| | | Value string `json:"value"` |
| | | Name string `json:"name"` |
| | | Sort int `json:"sort"` |
| | | } |