Commit 37629af9 authored by YPJ's avatar YPJ

新增Env字段和VersionTestUrl

parent 625c5df0
......@@ -86,4 +86,6 @@ IsCompleteNosshUrl=https://raspserver.biqianbao.net/pai/iscompletenew
RaspberryServer=112.124.4.47
StopPai=/home/pi/chain33-pai/stop-pai.sh
UploadVersionUrl=https://raspserver.biqianbao.net/pai/uploadinfo
UploadTestUrl=https://raspserver.biqianbao.net/pai/uploadtest
\ No newline at end of file
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
import (
"bytes"
"chain33-pai/pkg/chain33"
"chain33-pai/pkg/file"
"chain33-pai/pkg/pai"
"chain33-pai/pkg/setting"
"chain33-pai/pkg/util"
......@@ -23,7 +24,6 @@ import (
"strings"
"sync"
"time"
"chain33-pai/pkg/file"
)
var tlog = log.New("pkg", "app")
......@@ -42,9 +42,9 @@ type updateInfo struct {
}
type Server struct {
Disks []*pai.Disk `json:"disks"` //硬盘信息
Disks []*pai.Disk `json:"disks"` //硬盘信息
NodeProcessInfo ProcessInfo `json:"node_process_info"` //节点信息
Error string `json:"error"` //错误信息
Error string `json:"error"` //错误信息
}
type BTYDownloadInfo struct {
......@@ -141,7 +141,7 @@ func BityuanJob(ticker *time.Ticker) {
select {
case <-ticker.C:
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启动
NodeError = getWalletInfo()
//解锁钱包
......@@ -540,7 +540,6 @@ func AutoUpdate() {
}
tlog.Info("autoupdatepai", "err", GetVersion())
DPercent.Flag = false
}
}
......
......@@ -93,6 +93,8 @@ type Chain33_pai struct {
StopPai string
UploadVersionUrl string
UploadTestUrl string
VersionTestUrl string
Env string
}
var Chain33Pai = &Chain33_pai{}
......
......@@ -6,6 +6,7 @@ import (
"chain33-pai/pkg/chain33"
"chain33-pai/pkg/e"
"chain33-pai/pkg/setting"
"chain33-pai/pkg/util"
"chain33-pai/service/pai_service"
"encoding/json"
"fmt"
......@@ -19,10 +20,8 @@ import (
"reflect"
"strings"
"time"
"chain33-pai/pkg/util"
)
// @Summary 重置节点钱包
// @Description 重置节点钱包 无参
// @Accept json
......@@ -31,8 +30,8 @@ import (
// @Router /pai/resetwallet [post]
func ResetWallet(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "RESETWALLET",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RESETWALLET", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
}
......@@ -170,8 +169,8 @@ func UpdateNodeNew(c *gin.Context) {
// @Router /pai/reset [post]
func ResetNode(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "RESET",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RESET", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
}
......@@ -194,7 +193,7 @@ func Version(c *gin.Context) {
setting.FreshVersion()
//latestVersion:=app.GetLatestVersion()
var pai pai_service.Pai
//1 bityuan 2 chain33-pai
//1 bityuan 2 chain33-pai
latestVersion, err := pai.GetPaiLatestVersion(int32(1))
if latestVersion == "" || err != nil {
......@@ -232,8 +231,8 @@ func NodeInfo(c *gin.Context) {
// @Router /pai/restartnode [post]
func RestartNode(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "RESTART",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RESTART", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
}
......@@ -245,8 +244,8 @@ func RestartNode(c *gin.Context) {
// @Router /pai/closenode [post]
func CloseNode(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "CLOSE",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "CLOSE", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
}
......@@ -527,15 +526,15 @@ func Test(c *gin.Context) {
func Rollback(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "ROLLBACK",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "ROLLBACK", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
}
func NodeBackup(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "BACKUP",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "BACKUP", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
//appG := app.Gin{C: c}
//var pai pai_service.Pai
......@@ -580,8 +579,8 @@ func CheckBackup(c *gin.Context) {
func NodeRecover(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "RECOVER",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "RECOVER", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
//appG := app.Gin{C: c}
//var pai pai_service.Pai
......@@ -610,8 +609,8 @@ func NodeRecover(c *gin.Context) {
func DelBackup(c *gin.Context) {
appG := app.Gin{C: c}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: "DELETEBACKUP",JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: "DELETEBACKUP", JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
//appG := app.Gin{C: c}
//var pai pai_service.Pai
......@@ -643,7 +642,7 @@ func JobStatus(c *gin.Context) {
tlog.Info("invalid params")
return
}
if _,exists := app.JobDoneMap[req.JobID];exists {
if _, exists := app.JobDoneMap[req.JobID]; exists {
if app.JobDoneMap[req.JobID] != "" {
appG.Response(http.StatusOK, e.ERROR, app.JobDoneMap[req.JobID])
return
......@@ -654,7 +653,7 @@ func JobStatus(c *gin.Context) {
appG.Response(http.StatusOK, e.JOB_NOT_DONE, nil)
}
func BityuanJob (c *gin.Context) {
func BityuanJob(c *gin.Context) {
type JReq struct {
JobMsg string `json:"job_msg" binding:"required"`
}
......@@ -666,7 +665,7 @@ func BityuanJob (c *gin.Context) {
tlog.Info("invalid params")
return
}
util.AddValue(&app.JobID,1)
app.JobChan <- app.MsgType{Name: req.JobMsg,JobID:app.JobID}
util.AddValue(&app.JobID, 1)
app.JobChan <- app.MsgType{Name: req.JobMsg, JobID: app.JobID}
appG.Response(http.StatusOK, e.SUCCESS, app.JobID)
}
\ No newline at end of file
}
......@@ -42,16 +42,22 @@ func GetDevstatus(c *gin.Context) {
func GetPaiVersion(c *gin.Context) {
appG := app.Gin{C: c}
version := app.GetVersion()
var pai pai_service.Pai
var pai pai_service.Pai
latest, err := pai.GetPaiLatestVersion(int32(2))
if err != nil {
appG.Response(http.StatusOK, e.NETWORK_ERROR, nil)
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{
"current": version,
"latest": latest,
"test": test,
})
}
......
......@@ -225,6 +225,33 @@ func (p *Pai) GetPaiLatestVersion(t int32) (string, error) {
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 {
disks, err := pai.MonitorServer()
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