提交 ba84e617 编写于 作者: Y Ybjjwwang

fix transfer

上级 61bc89d0
...@@ -17,68 +17,56 @@ package transfer ...@@ -17,68 +17,56 @@ package transfer
import ( import (
"fmt" "fmt"
"github.com/Badangel/logex" "github.com/Badangel/logex"
"os"
"time"
"transfer/dict" "transfer/dict"
) )
func Start() { func Start() {
go BackupTransfer() 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")
} }
func BackupTransfer() { func BackupTransfer() {
for { //trigger
//trigger version, err := TriggerStart(Dict.DonefileAddress)
version, err := TriggerStart(Dict.DonefileAddress) if err != nil {
if err != nil { logex.Fatalf("[trigger err]trigger err:%v ", err)
logex.Fatalf("[trigger err]trigger err:%v ", err) fmt.Printf("[error]trigger err:%v \n", err)
fmt.Printf("[error]trigger err:%v \n", err) fmt.Print("transfer over!")
break logex.Noticef("[transfer]status machine exit!")
} return
logex.Noticef("[trigger] get version:%v \n", version) }
if version.Id == 0 { logex.Noticef("[trigger] get version:%v \n", version)
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
}
Dict.WaitVersionInfo = version Dict.WaitVersionInfo = version
logex.Noticef("[trigger finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo) logex.Noticef("[trigger finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo)
WriteWaitVersionInfoToFile() WriteWaitVersionInfoToFile()
//builder //builder
Dict.WaitVersionInfo.Status = dict.Dict_Status_Building Dict.WaitVersionInfo.Status = dict.Dict_Status_Building
Dict.WaitVersionInfo.MetaInfos = make(map[int]string) Dict.WaitVersionInfo.MetaInfos = make(map[int]string)
WriteWaitVersionInfoToFile() WriteWaitVersionInfoToFile()
if err = BuilderStart(Dict.WaitVersionInfo); err != nil { if err = BuilderStart(Dict.WaitVersionInfo); err != nil {
logex.Fatalf("builder err:%v \n", err) logex.Fatalf("builder err:%v \n", err)
} }
if Dict.WaitVersionInfo.Mode == dict.BASE { if Dict.WaitVersionInfo.Mode == dict.BASE {
var newCurrentVersion []dict.DictVersionInfo var newCurrentVersion []dict.DictVersionInfo
Dict.CurrentVersionInfo = newCurrentVersion Dict.CurrentVersionInfo = newCurrentVersion
WriteCurrentVersionInfoToFile() WriteCurrentVersionInfoToFile()
} }
logex.Noticef("[builder finish] WaitVersionInfo version:%v \n", Dict.WaitVersionInfo) 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 //deployer
Dict.WaitVersionInfo.Status = dict.Dict_Status_Deploying Dict.WaitVersionInfo.Status = dict.Dict_Status_Deploying
WriteWaitVersionInfoToFile() WriteWaitVersionInfoToFile()
if err = DeployStart(Dict.WaitVersionInfo); err != nil { if err = DeployStart(Dict.WaitVersionInfo); err != nil {
logex.Fatalf("deploy err:%v \n", err) logex.Fatalf("deploy err:%v \n", err)
}
logex.Noticef("[deploy finish]current version: %v\n",Dict.CurrentVersionInfo)
} }
logex.Noticef("[deploy finish]current version: %v\n",Dict.CurrentVersionInfo)
fmt.Print("transfer over!") fmt.Print("transfer over!")
logex.Noticef("[transfer]status machine exit!") logex.Noticef("[transfer]status machine exit!")
} }
...@@ -38,18 +38,19 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) { ...@@ -38,18 +38,19 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) {
Wget(addr, donefileAddr) Wget(addr, donefileAddr)
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) VersionLen := len(Dict.CurrentVersionInfo)
version.DictName = Dict.DictName version.DictName = Dict.DictName
if err != nil { fmt.Printf("get into mode check here\n")
fmt.Printf("[trigrer]read files err:%v \n", err) if Dict.DictMode == dict.BASE_ONLY {
logex.Fatalf("[trigrer]read files err:%v ", err) 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 return
} else { } else {
contentss := string(contents) contentss := string(contents)
lines := strings.Split(contentss, "\n") lines := strings.Split(contentss, "\n")
index := len(lines) - 1 index := len(lines) - 1
...@@ -80,19 +81,21 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) { ...@@ -80,19 +81,21 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) {
version.Mode = dict.BASE version.Mode = dict.BASE
return return
} }
} }
if Dict.DictMode == dict.BASR_DELTA && VersionLen > 0 { }
if Dict.DictMode == dict.BASR_DELTA {
patchDonefile := addr + "/patch.txt" patchDonefile := addr + "/patch.txt"
fmt.Printf("[trigrer]patchDonefile path:%v \n", patchDonefile) fmt.Printf("[trigrer]patchDonefile path:%v \n", patchDonefile)
logex.Noticef("[trigrer]patch donefile path:%v", patchDonefile) logex.Noticef("[trigrer]patch donefile path:%v", patchDonefile)
contents, err = ioutil.ReadFile(patchDonefile) contents, err_0 := ioutil.ReadFile(patchDonefile)
if err != nil { if err_0 != nil {
fmt.Printf("read files err:%v \n", err) fmt.Printf("[trigrer]read files err:%v \n", err_0)
logex.Fatalf("[trigrer]read files err:%v ", err_0)
return return
} else { } else {
contentss := string(contents) contentss := string(contents)
lines := strings.Split(contentss, "\n") lines := strings.Split(contentss, "\n")
fmt.Printf("[trigger]get patch lines here\n")
for index := 0; index < len(lines)-1; index++ { for index := 0; index < len(lines)-1; index++ {
if len(lines[index]) < 3 { if len(lines[index]) < 3 {
logex.Noticef("[trigrer]get patch donfile info error") logex.Noticef("[trigrer]get patch donfile info error")
...@@ -106,14 +109,15 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) { ...@@ -106,14 +109,15 @@ func GetDoneFileInfo(addr string) (version dict.DictVersionInfo, err error) {
logex.Noticef("[trigrer]donfile info:%v", donefileInfo) logex.Noticef("[trigrer]donfile info:%v", donefileInfo)
newId, _ := strconv.Atoi(donefileInfo.Id) newId, _ := strconv.Atoi(donefileInfo.Id)
newKey, _ := strconv.Atoi(donefileInfo.Key) 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.Id = newId
version.Key, _ = strconv.Atoi(donefileInfo.Key) version.Key, _ = strconv.Atoi(donefileInfo.Key)
version.Input = donefileInfo.Input version.Input = donefileInfo.Input
deployVersion := int(time.Now().Unix()) deployVersion := int(time.Now().Unix())
version.CreateTime = deployVersion version.CreateTime = deployVersion
version.Version = deployVersion version.Version = deployVersion
version.Depend = Dict.CurrentVersionInfo[VersionLen-1].Depend version.Depend = deployVersion
version.Mode = dict.DELTA version.Mode = dict.DELTA
return return
} }
......
...@@ -96,7 +96,8 @@ func ExeCommad(files string, params []string) (err error) { ...@@ -96,7 +96,8 @@ func ExeCommad(files string, params []string) (err error) {
func Wget(ftpPath string, downPath string) { func Wget(ftpPath string, downPath string) {
var params []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, downPath)
params = append(params, "-r") params = append(params, "-r")
params = append(params, "-N") params = append(params, "-N")
...@@ -110,4 +111,4 @@ func Wget(ftpPath string, downPath string) { ...@@ -110,4 +111,4 @@ func Wget(ftpPath string, downPath string) {
if err != nil { if err != nil {
fmt.Printf("wget exe: %v\n", err) fmt.Printf("wget exe: %v\n", err)
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册