Commit e4b023a4 authored by szh's avatar szh

add rollback interface

parent 7852b80e
......@@ -550,4 +550,45 @@ func Test(c *gin.Context) {
body, _ := ioutil.ReadAll(resp.Body)
tlog.Info("uploadtest","report",string(body))
appG.Response(http.StatusOK,e.SUCCESS,"")
}
func Rollback(c *gin.Context) {
appG:=app.Gin{C:c}
app.BityuanFlag = true
_,err := app.SafeCloseNode()
if err != nil {
appG.Response(http.StatusOK,e.NODE_ERROR,err)
app.BityuanFlag = false
return
}
var pai pai_service.Pai
err = pai.SetPai()
if err != nil {
tlog.Error("SetPai","err",err)
appG.Response(http.StatusOK,e.NODE_ERROR,err)
app.BityuanFlag = false
return
}
rollheight := pai.LocalLastHeight
if pai.LocalLastHeight == 0 {
tlog.Error("LocalLastHeight","height",pai.LocalLastHeight)
appG.Response(http.StatusOK,e.NODE_ERROR,err)
app.BityuanFlag = false
}
if (pai.LocalLastHeight - 1000) <= 0 {
rollheight = 1
}
tlog.Info("rollback start","height",pai.LocalLastHeight,"rollbackheight",rollheight)
var buf bytes.Buffer
cmd := exec.Command("v7-bityuan", "-rollback",fmt.Sprintf("%d",rollheight))
cmd.Stdout = &buf
err = cmd.Run()
if err != nil {
appG.Response(http.StatusOK,e.NODE_ERROR,err)
app.BityuanFlag = false
return
}
tlog.Info("rollback end","height",pai.LocalLastHeight,"rollbackheight",rollheight)
app.BityuanFlag = false
appG.Response(http.StatusOK,e.SUCCESS,"bityuan rollback")
}
\ No newline at end of file
......@@ -57,6 +57,7 @@ func InitRouter() *gin.Engine {
apiv1.POST("/poweroff",v1.PoweroffPai)
//test
apiv1.POST("/test",v1.Test)
apiv1.POST("/rollback",v1.Rollback)
return r
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment