예제 #1
0
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())
}
예제 #2
0
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))
}
예제 #3
0
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))
}
예제 #4
0
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))
}
예제 #5
0
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())
}
예제 #6
0
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))
}
예제 #7
0
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))
}
예제 #8
0
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())
}
예제 #9
0
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))
}