liuxiaolong
2020-05-30 c84d13cdcab4472a9e8b7a18e275050d296ad100
fix SdkInstall
2个文件已修改
79 ■■■■■ 已修改文件
extend/util/zip.go 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/SdkInstall.go 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extend/util/zip.go
@@ -10,6 +10,7 @@
    "io/ioutil"
    "log"
    "os"
    "os/exec"
    "path"
    "path/filepath"
    "strings"
@@ -316,6 +317,11 @@
    return (err == nil || os.IsExist(err)) && fi.IsDir()
}
func CopyDirByCmd(src ,dest string) (string,error) {
    cmd := exec.Command("cp","-r", src, dest)
    outPut, err := cmd.Output()
    return string(outPut), err
}
//文件夹复制
func CopyDir(src string, dest string) {
service/SdkInstall.go
@@ -31,8 +31,8 @@
            return false,errors.New("获取安装包md5失败")
        }
        if strMd5 == identifier {
            if !installSdk(identifier, ext) {
                return false,errors.New("执行安装过程异常,请确定上传的安装包是tar.gz格式")
            if _,insE := installSdk(identifier, ext); insE != nil {
                return false, insE
            }
            return true,nil
@@ -46,7 +46,7 @@
}
//安装sdk
func installSdk(identifier string, ext string) bool {
func installSdk(identifier string, ext string) (bool, error) {
    configPatchPath := ""
    if config.Server.PatchPath != "" {
        configPatchPath = config.Server.PatchPath
@@ -59,23 +59,22 @@
        //此版本已经更新过
        rmErr := os.RemoveAll(unPackPath)
        if rmErr !=nil {
            return false
            return false,rmErr
        }
    }
    if !util.CreateDirectory(unPackPath) {
        return false
        return false, errors.New("创建压缩文件夹失败")
    }
    unPackFilePath := configPatchPath+"/"+identifier+ext
    err := util.UnTarGz(unPackFilePath, unPackPath)
    if err !=nil {
        logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
        return false
        return false, err
    }
    //解压完成,获取安装包中的文件,开始安装
    //1.解析安装说明ins.inc
    incPath := unPackPath+"ins.inc"
    ret := false
    if util.Exists(incPath) {
        if incB, err := ioutil.ReadFile(incPath);err == nil {
            var ins InsInc
@@ -90,6 +89,34 @@
                        soM := make(map[string]SdkDef)
                        var skDefArr []SdkDef
                        if err = json.Unmarshal(defB, &skDefArr);err == nil {
                            zconfPath := "/opt/vasystem/bin/zconf/"
                            libPath := "/opt/vasystem/libs/"
                            if !util.DirExists(zconfPath) {
                                os.MkdirAll(zconfPath, 0777)
                            }
                            if !util.DirExists(libPath) {
                                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)
                                    }
                                    if util.DirExists(unPackPath+sdkType+"/"+sdkType) {
                                        if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/"+sdkType, libPath);cE != nil {
                                            return false, cE
                                        }
                                    }
                                    if util.DirExists(unPackPath+sdkType+"/models") {
                                        if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/models", "/opt/vasystem/bin/"); cE != nil {
                                            return false, cE
                                        }
                                    }
                                }
                            }
                            //注册算法信息和算法参数到dbserver
                            var sdkApi dbapi.SdkApi
                            for _,skd := range skDefArr {
                                if _,ok := soM[skd.Def.SdkType];!ok {
@@ -123,32 +150,26 @@
                                paramBody := util.Struct2Map(srv)
                                sdkApi.Register(paramBody) //将算法注册到数据库中
                            }
                            zconfPath := "/opt/vasystem/bin/zconf/"
                            libPath := "/opt/vasystem/libs/"
                            if !util.DirExists(zconfPath) {
                                os.MkdirAll(zconfPath, 0777)
                            }
                            if !util.DirExists(libPath) {
                                os.MkdirAll(libPath, 0777)
                            }
                            for sdkType,_ := range soM {
                                //复制json启动文件
                                util.CopyFile(unPackPath+sdkType+"/zconf/"+sdkType+".json", zconfPath)
                                util.CopyDir(unPackPath+sdkType+"/"+sdkType, libPath)
                                if util.DirExists(unPackPath+sdkType+"/models") {
                                    util.CopyDir(unPackPath+sdkType+"/models", "/opt/vasystem/bin/")
                                }
                            }
                            ret = true
                        } else {
                            return false, errors.New("反序列化算法定义信息失败")
                        }
                    } else {
                        return false, errors.New("读取算法定义信息失败")
                    }
                } else {
                    return false, errors.New("算法定义信息丢失")
                }
            } else {
                return false, errors.New("反序列化授权信息失败")
            }
        } else {
            return false, errors.New("读取授权文件失败")
        }
    } else {
        return false, errors.New("授权文件不存在")
    }
    return ret
    return true, nil
}