liuxiaolong
2020-06-02 d05ee5c2f75d791f3e717b639d2e0343746dee91
service/SdkInstall.go
@@ -2,12 +2,14 @@
import (
   "basic.com/dbapi.git"
   //"basic.com/dbapi.git"
   "basic.com/valib/logger.git"
   "encoding/json"
   "errors"
   "io/ioutil"
   "os"
   "path"
   "path/filepath"
   "webserver/extend/config"
   "webserver/extend/util"
)
@@ -67,11 +69,26 @@
   }
   unPackFilePath := configPatchPath+"/"+identifier+ext
   err := util.UnTarGz(unPackFilePath, unPackPath)
   logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackPath)
   _,err := util.UnTarGzByCmd(unPackFilePath, unPackPath)
   if err !=nil {
      logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath)
      return false, err
   }
   targetFileName := ""
   err = filepath.Walk(unPackPath, func(path string, f os.FileInfo, err error) error {
      if f == nil {
         return err
      }
      if f.IsDir() {
         targetFileName = f.Name()
      }
      return nil
   })
   if err != nil {
      return false, err
   }
   unPackPath = unPackPath + targetFileName +"/"
   //解压完成,获取安装包中的文件,开始安装
   //1.解析安装说明ins.inc
   incPath := unPackPath+"ins.inc"
@@ -80,7 +97,10 @@
         var ins InsInc
         if err = json.Unmarshal(incB, &ins); err == nil {
            //处理授权信息
            curMc := ""
            if ins.MachineCode != curMc {
            }
            //2.解析sdk.def,将so和zconf复制到/opt/vasystem/libs/文件夹下
            defPath := unPackPath + "sdk.def"
            if util.Exists(defPath) {
@@ -89,33 +109,6 @@
                  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 {
@@ -148,8 +141,39 @@
                           srv.Args = append(srv.Args,  sra)
                        }
                        paramBody := util.Struct2Map(srv)
                        logger.Debug("sdkApi.Register paramBody:", paramBody)
                        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 {
                        //先解压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 util.DirExists(unPackPath+sdkType+"/models") {
                              if _,cE := util.CopyDirByCmd(unPackPath+sdkType+"/models", "/opt/vasystem/bin/zconf"); cE != nil {
                                 return false, cE
                              }
                           }
                        } else {
                           logger.Debug("unTarGzE sdkType.tar.gz err:", unTarGzE)
                        }
                     }
                  } else {
                     return false, errors.New("反序列化算法定义信息失败")
                  }