Commit 37629af9 authored by YPJ's avatar YPJ

新增Env字段和VersionTestUrl

parent 625c5df0
...@@ -87,3 +87,5 @@ RaspberryServer=112.124.4.47 ...@@ -87,3 +87,5 @@ RaspberryServer=112.124.4.47
StopPai=/home/pi/chain33-pai/stop-pai.sh StopPai=/home/pi/chain33-pai/stop-pai.sh
UploadVersionUrl=https://raspserver.biqianbao.net/pai/uploadinfo UploadVersionUrl=https://raspserver.biqianbao.net/pai/uploadinfo
UploadTestUrl=https://raspserver.biqianbao.net/pai/uploadtest UploadTestUrl=https://raspserver.biqianbao.net/pai/uploadtest
VersionTestUrl=https://raspserver.biqianbao.net/pai/versiontest
Env
\ No newline at end of file
...@@ -3,6 +3,7 @@ package app ...@@ -3,6 +3,7 @@ package app
import ( import (
"bytes" "bytes"
"chain33-pai/pkg/chain33" "chain33-pai/pkg/chain33"
"chain33-pai/pkg/file"
"chain33-pai/pkg/pai" "chain33-pai/pkg/pai"
"chain33-pai/pkg/setting" "chain33-pai/pkg/setting"
"chain33-pai/pkg/util" "chain33-pai/pkg/util"
...@@ -23,7 +24,6 @@ import ( ...@@ -23,7 +24,6 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"chain33-pai/pkg/file"
) )
var tlog = log.New("pkg", "app") var tlog = log.New("pkg", "app")
...@@ -141,7 +141,7 @@ func BityuanJob(ticker *time.Ticker) { ...@@ -141,7 +141,7 @@ func BityuanJob(ticker *time.Ticker) {
select { select {
case <-ticker.C: case <-ticker.C:
BityuanFlag.Lock.Lock() BityuanFlag.Lock.Lock()
if !BityuanFlag.Flag && file.CheckNotExist("/home/pi/chain33-pai/Lock.file"){ //有更新,重置等节点重启操作时 禁止运行,防止冲突 if !BityuanFlag.Flag && file.CheckNotExist("/home/pi/chain33-pai/Lock.file") { //有更新,重置等节点重启操作时 禁止运行,防止冲突
//节点未启动 会调用auto启动 //节点未启动 会调用auto启动
NodeError = getWalletInfo() NodeError = getWalletInfo()
//解锁钱包 //解锁钱包
...@@ -540,7 +540,6 @@ func AutoUpdate() { ...@@ -540,7 +540,6 @@ func AutoUpdate() {
} }
tlog.Info("autoupdatepai", "err", GetVersion()) tlog.Info("autoupdatepai", "err", GetVersion())
DPercent.Flag = false DPercent.Flag = false
} }
} }
......
...@@ -93,6 +93,8 @@ type Chain33_pai struct { ...@@ -93,6 +93,8 @@ type Chain33_pai struct {
StopPai string StopPai string
UploadVersionUrl string UploadVersionUrl string
UploadTestUrl string UploadTestUrl string
VersionTestUrl string
Env string
} }
var Chain33Pai = &Chain33_pai{} var Chain33Pai = &Chain33_pai{}
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"chain33-pai/pkg/chain33" "chain33-pai/pkg/chain33"
"chain33-pai/pkg/e" "chain33-pai/pkg/e"
"chain33-pai/pkg/setting" "chain33-pai/pkg/setting"
"chain33-pai/pkg/util"
"chain33-pai/service/pai_service" "chain33-pai/service/pai_service"
"encoding/json" "encoding/json"
"fmt" "fmt"
...@@ -19,10 +20,8 @@ import ( ...@@ -19,10 +20,8 @@ import (
"reflect" "reflect"
"strings" "strings"
"time" "time"
"chain33-pai/pkg/util"
) )
// @Summary 重置节点钱包 // @Summary 重置节点钱包
// @Description 重置节点钱包 无参 // @Description 重置节点钱包 无参
// @Accept json // @Accept json
...@@ -31,8 +30,8 @@ import ( ...@@ -31,8 +30,8 @@ import (
// @Router /pai/resetwallet [post] // @Router /pai/resetwallet [post]
func ResetWallet(c *gin.Context) { func ResetWallet(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RESETWALLET",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "RESETWALLET", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
} }
...@@ -170,8 +169,8 @@ func UpdateNodeNew(c *gin.Context) { ...@@ -170,8 +169,8 @@ func UpdateNodeNew(c *gin.Context) {
// @Router /pai/reset [post] // @Router /pai/reset [post]
func ResetNode(c *gin.Context) { func ResetNode(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RESET",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "RESET", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
} }
...@@ -232,8 +231,8 @@ func NodeInfo(c *gin.Context) { ...@@ -232,8 +231,8 @@ func NodeInfo(c *gin.Context) {
// @Router /pai/restartnode [post] // @Router /pai/restartnode [post]
func RestartNode(c *gin.Context) { func RestartNode(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RESTART",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "RESTART", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
} }
...@@ -245,8 +244,8 @@ func RestartNode(c *gin.Context) { ...@@ -245,8 +244,8 @@ func RestartNode(c *gin.Context) {
// @Router /pai/closenode [post] // @Router /pai/closenode [post]
func CloseNode(c *gin.Context) { func CloseNode(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "CLOSE",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "CLOSE", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
} }
...@@ -527,15 +526,15 @@ func Test(c *gin.Context) { ...@@ -527,15 +526,15 @@ func Test(c *gin.Context) {
func Rollback(c *gin.Context) { func Rollback(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "ROLLBACK",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "ROLLBACK", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
} }
func NodeBackup(c *gin.Context) { func NodeBackup(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "BACKUP",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "BACKUP", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
//appG := app.Gin{C: c} //appG := app.Gin{C: c}
//var pai pai_service.Pai //var pai pai_service.Pai
...@@ -580,8 +579,8 @@ func CheckBackup(c *gin.Context) { ...@@ -580,8 +579,8 @@ func CheckBackup(c *gin.Context) {
func NodeRecover(c *gin.Context) { func NodeRecover(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RECOVER",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "RECOVER", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
//appG := app.Gin{C: c} //appG := app.Gin{C: c}
//var pai pai_service.Pai //var pai pai_service.Pai
...@@ -610,8 +609,8 @@ func NodeRecover(c *gin.Context) { ...@@ -610,8 +609,8 @@ func NodeRecover(c *gin.Context) {
func DelBackup(c *gin.Context) { func DelBackup(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "DELETEBACKUP",JobID:app.JobID} app.JobChan <- app.MsgType{Name: "DELETEBACKUP", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
//appG := app.Gin{C: c} //appG := app.Gin{C: c}
//var pai pai_service.Pai //var pai pai_service.Pai
...@@ -643,7 +642,7 @@ func JobStatus(c *gin.Context) { ...@@ -643,7 +642,7 @@ func JobStatus(c *gin.Context) {
tlog.Info("invalid params") tlog.Info("invalid params")
return return
} }
if _,exists := app.JobDoneMap[req.JobID];exists { if _, exists := app.JobDoneMap[req.JobID]; exists {
if app.JobDoneMap[req.JobID] != "" { if app.JobDoneMap[req.JobID] != "" {
appG.Response(http.StatusOK, e.ERROR, app.JobDoneMap[req.JobID]) appG.Response(http.StatusOK, e.ERROR, app.JobDoneMap[req.JobID])
return return
...@@ -654,7 +653,7 @@ func JobStatus(c *gin.Context) { ...@@ -654,7 +653,7 @@ func JobStatus(c *gin.Context) {
appG.Response(http.StatusOK, e.JOB_NOT_DONE, nil) appG.Response(http.StatusOK, e.JOB_NOT_DONE, nil)
} }
func BityuanJob (c *gin.Context) { func BityuanJob(c *gin.Context) {
type JReq struct { type JReq struct {
JobMsg string `json:"job_msg" binding:"required"` JobMsg string `json:"job_msg" binding:"required"`
} }
...@@ -666,7 +665,7 @@ func BityuanJob (c *gin.Context) { ...@@ -666,7 +665,7 @@ func BityuanJob (c *gin.Context) {
tlog.Info("invalid params") tlog.Info("invalid params")
return return
} }
util.AddValue(&app.JobID,1) util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: req.JobMsg,JobID:app.JobID} app.JobChan <- app.MsgType{Name: req.JobMsg, JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID) appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
} }
...@@ -42,16 +42,22 @@ func GetDevstatus(c *gin.Context) { ...@@ -42,16 +42,22 @@ func GetDevstatus(c *gin.Context) {
func GetPaiVersion(c *gin.Context) { func GetPaiVersion(c *gin.Context) {
appG := app.Gin{C: c} appG := app.Gin{C: c}
version := app.GetVersion() version := app.GetVersion()
var pai pai_service.Pai
var pai pai_service.Pai
latest, err := pai.GetPaiLatestVersion(int32(2)) latest, err := pai.GetPaiLatestVersion(int32(2))
if err != nil { if err != nil {
appG.Response(http.StatusOK, e.NETWORK_ERROR, nil) appG.Response(http.StatusOK, e.NETWORK_ERROR, nil)
return return
} }
test, err := pai.GetPaiVersionTest(int32(1))
if err != nil {
appG.Response(http.StatusOK, e.NETWORK_ERROR, nil)
return
}
appG.Response(http.StatusOK, e.SUCCESS, gin.H{ appG.Response(http.StatusOK, e.SUCCESS, gin.H{
"current": version, "current": version,
"latest": latest, "latest": latest,
"test": test,
}) })
} }
......
...@@ -225,6 +225,33 @@ func (p *Pai) GetPaiLatestVersion(t int32) (string, error) { ...@@ -225,6 +225,33 @@ func (p *Pai) GetPaiLatestVersion(t int32) (string, error) {
return r.Data, nil return r.Data, nil
} }
func (p *Pai) GetPaiVersionTest(t int32) (string, error) {
data := make(map[string]interface{})
data["type"] = t
bytesData, _ := json.Marshal(data)
resp, err := http.Post(setting.Chain33Pai.VersionTestUrl, "application/json", bytes.NewReader(bytesData))
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
type res struct {
Code int64
Msg string
Data string
}
var r res
err = json.Unmarshal(body, &r)
if err != nil {
return "", err
}
return r.Data, nil
}
func (p *Pai) GetDiskUseage() error { func (p *Pai) GetDiskUseage() error {
disks, err := pai.MonitorServer() disks, err := pai.MonitorServer()
if err != nil { if err != nil {
......
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