func ShowError(rend render.Render) { if master.Error { rend.JSON(200, helper.Success(master.ErrorLog)) } else { rend.JSON(200, helper.Error()) } }
func Edit(rend render.Render, req *http.Request, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithNoBusyOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } body := JSON.FormRequest(req.Body) c := &model.WebServer{} if err := JSON.ParseToStruct(JSON.Stringify(body), c); err != nil { rend.JSON(200, helper.Error(helper.ParamsError)) return } keys := JSON.GetKeys(body) c.Id = id if err := client.Edit(c, keys...); err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(c)) }
func Refresh(rend render.Render) { _, err := client.Fetch() if err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(fillClientList())) }
func init() { webSocket.OnAppend(func(clientLength int) { client.StartTask() }) webSocket.OnOut(func(clientLength int) { if clientLength == 0 { client.StopTask() } }) webSocket.OnEmit("heartbeat", func() JSON.Type { list := client.List() result := JSON.Type{} for _, c := range list { result[helper.Itoa64(c.Id)] = JSON.Type{ "status": c.Status, "message": c.Message, "error": c.Error, } } return helper.Success(result) }) webSocket.OnEmit("procstat", func() JSON.Type { list := client.GetAliveList() result := JSON.Type{} for _, c := range list { result[helper.Itoa64(c.Id)] = JSON.Parse(c.Proc) } return helper.Success(result) }) webSocket.OnEmit("master", func() JSON.Type { return helper.Success(JSON.Type{ "message": master.Message, "error": master.Error, "status": master.Status, }) }) }
func GetLastVersion(rend render.Render) { version, err := master.GetLastVersion() if err != nil { rend.JSON(200, helper.Error(err)) return } result := JSON.Parse(version) result["list"] = JSON.Parse(version.List) rend.JSON(200, helper.Success(result)) }
func Add(rend render.Render, req *http.Request) { params, _ := jason.NewObjectFromReader(req.Body) name, _ := params.GetString("name") result, err := group.Add(name) if err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(result)) }
func Update(rend render.Render, req *http.Request, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithNoBusyOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } //未部署列表 unDeployFileList, err := host.GetUnDeployFiles() if err != nil || unDeployFileList == nil { rend.JSON(200, helper.Error(err)) return } //选择要上传的文件 body := JSON.FormRequest(req.Body) files := body["files"] upFile := rpc.UploadFileList{} JSON.ParseToStruct(JSON.Stringify(files), &upFile) uploadFiles := &rpc.UpdateArgs{ Id: host.Id, ResPath: config.ResServer(), FileList: upFile, DeployPath: host.DeployPath, } //上传 completeUploadList, err := host.CallRpc("Update", uploadFiles) if err != nil { rend.JSON(200, helper.Error(err)) return } //上传ok就删除对应路径记录 helper.Map(completeUploadList, func(key, value interface{}) bool { p := key.(string) v := reflect.ValueOf(value) if v.Kind() == reflect.Bool { delete(unDeployFileList, p) } return false }) //更新记录 host.WebServer.UnDeployList = JSON.Stringify(unDeployFileList) err = client.Edit(host.WebServer, "UnDeployList") if err != nil { fmt.Println(err) } rend.JSON(200, helper.Success(completeUploadList)) }
func Move(rend render.Render, params martini.Params) { id := helper.Int64(params["id"]) gid := helper.Int64(params["gid"]) c := model.WebServer{Id: id, Group: gid} if err := client.Edit(&c, "Group"); err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success()) }
func Compile(rend render.Render, req *http.Request) { if master.IsLock() { rend.JSON(200, helper.Error(helper.BusyError)) return } master.Lock() master.SetBusy() master.SetMessage("ready to compile") task.Trigger("master.Compile") rend.JSON(200, helper.Success()) }
func Update(rend render.Render, req *http.Request) { if master.IsLock() { rend.JSON(200, helper.Error(helper.BusyError)) return } result, err := update() if err != nil { rend.JSON(200, helper.Error(err, result)) return } rend.JSON(200, helper.Success(result)) }
func Check(rend render.Render, req *http.Request) { body, _ := jason.NewObjectFromReader(req.Body) clientsId, _ := body.GetInt64Array("clientsId") clientList := client.List(clientsId) results := JSON.Type{} for _, c := range clientList { result, err := c.CallRpc("CheckDeployPath", rpc.CheckDeployPathArgs{c.Id, c.DeployPath}) if err != nil { results[helper.Itoa64(c.Id)] = helper.Error(err) } else { results[helper.Itoa64(c.Id)] = result } } rend.JSON(200, helper.Success(results)) }
func GetUnDeployFiles(rend render.Render, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithNoBusyOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } result, err := host.GetUnDeployFiles() if err != nil || result == nil || helper.Cap(result) == 0 { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(result)) }
func Del(rend render.Render, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithNoBusyOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } c := model.WebServer{Id: id} if err := client.Del(&c); err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success()) }
func Add(rend render.Render, req *http.Request) { c := &model.WebServer{} body := JSON.FormRequest(req.Body) if err := JSON.ParseToStruct(JSON.Stringify(body), c); err != nil { rend.JSON(200, helper.Error(helper.ParamsError, err)) return } if _, err := client.Add(c); err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(c)) }
func GetBackupList(rend render.Render, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithNoBusyOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } result, err := host.CallRpc("GetBackupList") if err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(result)) }
func ShowLog(rend render.Render, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } result, err := host.CallRpc("ShowLog", &rpc.SimpleArgs{Id: host.Id}) if err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(result)) }
func RemoveBackup(rend render.Render, req *http.Request, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithAliveOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } body, _ := jason.NewObjectFromReader(req.Body) path, _ := body.GetString("path") _, err := host.RemoveBackup(path) if err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success()) }
func Deploy(rend render.Render, req *http.Request, params martini.Params) { id := helper.Int64(params["id"]) host, errResponse := getClientWithAliveOrJSONError(id) if host == nil { rend.JSON(200, errResponse) return } host.SetBusy() result, err := host.Deploy() if err != nil { rend.JSON(200, helper.Error(err)) return } rend.JSON(200, helper.Success(result)) }
func Add(rend render.Render, req *http.Request) { cfg := model.Config{ Name: "hahaha", Content: JSON.Stringify(JSON.Type{ "Name": "languid", "XX": "jeremy", "isTest": true, "clients": []int{1, 2, 3, 4, 5}, }), } if _, err := db.Orm().Insert(&cfg); err != nil { rend.JSON(200, helper.Error(err)) return } result := JSON.Parse(cfg) result["Content"] = JSON.Parse(result["Content"]) rend.JSON(200, helper.Success(result)) }
func update() (model.Version, error) { now := time.Now() version := model.Version{} num, list, err := svnUp() if err != nil { return version, err } if master.IsChanged(num) == false { return version, helper.NewError("no change") } master.Version = num version = model.Version{ Version: num, Time: now, List: JSON.Stringify(list), } if err := master.UpdateVersion(&version); err != nil { return version, err } master.SetUnDeployFile(list) task.Trigger("client.UpdateHostUnDeployList") webSocket.BroadCastAll(&webSocket.Message{ "svnup", helper.Success(version), }) return version, nil }
func List(rend render.Render) { rend.JSON(200, helper.Success(fillClientList())) }