From ba84e617ffb200f44fd94bbca757a89c5a6af286 Mon Sep 17 00:00:00 2001 From: Ybjjwwang Date: Fri, 6 Aug 2021 06:16:20 +0000 Subject: [PATCH] fix transfer --- .../cube-transfer/src/transfer/transfer.go | 86 ++++++++----------- .../cube-transfer/src/transfer/trigger.go | 38 ++++---- core/cube/cube-transfer/src/transfer/util.go | 5 +- 3 files changed, 61 insertions(+), 68 deletions(-) diff --git a/core/cube/cube-transfer/src/transfer/transfer.go b/core/cube/cube-transfer/src/transfer/transfer.go index 84ab7427..d29c29a4 100644 --- a/core/cube/cube-transfer/src/transfer/transfer.go +++ b/core/cube/cube-transfer/src/transfer/transfer.go @@ -17,68 +17,56 @@ package transfer import ( "fmt" "github.com/Badangel/logex" - "os" - "time" "transfer/dict" ) func Start() { - go BackupTransfer() - logex.Notice(">>> starting server...") - addr := ":" + Port - err := startHttp(addr) - if err != nil { - logex.Fatalf("start http(addr=%v) failed: %v", addr, err) - os.Exit(255) - } - - logex.Notice(">>> start server succ") + BackupTransfer() } func BackupTransfer() { - for { - //trigger - version, err := TriggerStart(Dict.DonefileAddress) - if err != nil { - logex.Fatalf("[trigger err]trigger err:%v ", err) - fmt.Printf("[error]trigger err:%v \n", err) - break - } - logex.Noticef("[trigger] get version:%v \n", version) - if version.Id == 0 { - logex.Noticef("[sleep]no new version, sleep 5 min") - fmt.Printf("[sleep]no new version, wait 5 min\n") - time.Sleep(5 * time.Minute) - continue - } + //trigger + version, err := TriggerStart(Dict.DonefileAddress) + if err != nil { + logex.Fatalf("[trigger err]trigger err:%v ", err) + fmt.Printf("[error]trigger err:%v \n", err) + fmt.Print("transfer over!") + logex.Noticef("[transfer]status machine exit!") + return + } + logex.Noticef("[trigger] get version:%v \n", version) Dict.WaitVersionInfo = version - logex.Noticef("[trigger finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo) - WriteWaitVersionInfoToFile() + logex.Noticef("[trigger finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo) + WriteWaitVersionInfoToFile() - //builder - Dict.WaitVersionInfo.Status = dict.Dict_Status_Building - Dict.WaitVersionInfo.MetaInfos = make(map[int]string) - WriteWaitVersionInfoToFile() - if err = BuilderStart(Dict.WaitVersionInfo); err != nil { - logex.Fatalf("builder err:%v \n", err) - } + //builder + Dict.WaitVersionInfo.Status = dict.Dict_Status_Building + Dict.WaitVersionInfo.MetaInfos = make(map[int]string) + WriteWaitVersionInfoToFile() + if err = BuilderStart(Dict.WaitVersionInfo); err != nil { + logex.Fatalf("builder err:%v \n", err) + } - if Dict.WaitVersionInfo.Mode == dict.BASE { - var newCurrentVersion []dict.DictVersionInfo - Dict.CurrentVersionInfo = newCurrentVersion - WriteCurrentVersionInfoToFile() - } - logex.Noticef("[builder finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo) + if Dict.WaitVersionInfo.Mode == dict.BASE { + var newCurrentVersion []dict.DictVersionInfo + Dict.CurrentVersionInfo = newCurrentVersion + WriteCurrentVersionInfoToFile() + } + if Dict.WaitVersionInfo.Mode == dict.DELTA { + var newCurrentVersion []dict.DictVersionInfo + Dict.CurrentVersionInfo = newCurrentVersion + WriteCurrentVersionInfoToFile() + } + logex.Noticef("[builder finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo) - //deployer - Dict.WaitVersionInfo.Status = dict.Dict_Status_Deploying - WriteWaitVersionInfoToFile() - if err = DeployStart(Dict.WaitVersionInfo); err != nil { - logex.Fatalf("deploy err:%v \n", err) - } - logex.Noticef("[deploy finish]current version: %v\n",Dict.CurrentVersionInfo) + //deployer + Dict.WaitVersionInfo.Status = dict.Dict_Status_Deploying + WriteWaitVersionInfoToFile() + if err = DeployStart(Dict.WaitVersionInfo); err != nil { + logex.Fatalf("deploy err:%v \n", err) } + logex.Noticef("[deploy finish]current version: %v\n",Dict.CurrentVersionInfo) fmt.Print("transfer over!") logex.Noticef("[transfer]status machine exit!") } diff --git a/core/cube/cube-transfer/src/transfer/trigger.go b/core/cube/cube-transfer/src/transfer/trigger.go index b3696dc5..768f7218 100644 --- a/core/cube/cube-transfer/src/transfer/trigger.go +++ b/core/cube/cube-transfer/src/transfer/trigger.go @@ -38,18 +38,19 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) { Wget(addr, donefileAddr) addr = donefileAddr } - - baseDonefile := addr + "/base.txt" - fmt.Printf("[trigrer]donefile path:%v \n", baseDonefile) - logex.Noticef("[trigrer]base donefile path:%v", baseDonefile) - contents, err := ioutil.ReadFile(baseDonefile) VersionLen := len(Dict.CurrentVersionInfo) version.DictName = Dict.DictName - if err != nil { - fmt.Printf("[trigrer]read files err:%v \n", err) - logex.Fatalf("[trigrer]read files err:%v ", err) + fmt.Printf("get into mode check here\n") + if Dict.DictMode == dict.BASE_ONLY { + baseDonefile := addr + "/base.txt" + fmt.Printf("[trigrer]donefile path:%v \n", baseDonefile) + logex.Noticef("[trigrer]base donefile path:%v", baseDonefile) + contents, err_0 := ioutil.ReadFile(baseDonefile) + if err_0 != nil { + fmt.Printf("[trigrer]read files err:%v \n", err_0) + logex.Fatalf("[trigrer]read files err:%v ", err_0) return - } else { + } else { contentss := string(contents) lines := strings.Split(contentss, "\n") index := len(lines) - 1 @@ -80,19 +81,21 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) { version.Mode = dict.BASE return } - } - if Dict.DictMode == dict.BASR_DELTA && VersionLen > 0 { + } + } + if Dict.DictMode == dict.BASR_DELTA { patchDonefile := addr + "/patch.txt" fmt.Printf("[trigrer]patchDonefile path:%v \n", patchDonefile) logex.Noticef("[trigrer]patch donefile path:%v", patchDonefile) - contents, err = ioutil.ReadFile(patchDonefile) - if err != nil { - fmt.Printf("read files err:%v \n", err) + contents, err_0 := ioutil.ReadFile(patchDonefile) + if err_0 != nil { + fmt.Printf("[trigrer]read files err:%v \n", err_0) + logex.Fatalf("[trigrer]read files err:%v ", err_0) return } else { contentss := string(contents) lines := strings.Split(contentss, "\n") - + fmt.Printf("[trigger]get patch lines here\n") for index := 0; index < len(lines)-1; index++ { if len(lines[index]) < 3 { logex.Noticef("[trigrer]get patch donfile info error") @@ -106,14 +109,15 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) { logex.Noticef("[trigrer]donfile info:%v", donefileInfo) newId, _ := strconv.Atoi(donefileInfo.Id) newKey, _ := strconv.Atoi(donefileInfo.Key) - if newId > Dict.CurrentVersionInfo[VersionLen-1].Id && newKey == Dict.CurrentVersionInfo[VersionLen-1].Key { + fmt.Printf("[trigger]read patch id: %d, key: %d\n", newId, newKey) + if VersionLen == 0 || newId > Dict.CurrentVersionInfo[VersionLen-1].Id { version.Id = newId version.Key, _ = strconv.Atoi(donefileInfo.Key) version.Input = donefileInfo.Input deployVersion := int(time.Now().Unix()) version.CreateTime = deployVersion version.Version = deployVersion - version.Depend = Dict.CurrentVersionInfo[VersionLen-1].Depend + version.Depend = deployVersion version.Mode = dict.DELTA return } diff --git a/core/cube/cube-transfer/src/transfer/util.go b/core/cube/cube-transfer/src/transfer/util.go index f3c18343..8f9e5c54 100644 --- a/core/cube/cube-transfer/src/transfer/util.go +++ b/core/cube/cube-transfer/src/transfer/util.go @@ -96,7 +96,8 @@ func ExeCommad(files string, params []string) (err error) { func Wget(ftpPath string, downPath string) { var params []string - params = append(params, "-P") + params = append(params, "--limit-rate=100m") + params = append(params, "-P") params = append(params, downPath) params = append(params, "-r") params = append(params, "-N") @@ -110,4 +111,4 @@ func Wget(ftpPath string, downPath string) { if err != nil { fmt.Printf("wget exe: %v\n", err) } -} \ No newline at end of file +} -- GitLab