Esempio n. 1
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))
}
Esempio n. 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))
}
Esempio n. 3
0
func (r *HostClient) UpdateUnDeployList(list *JSON.Type) error {
	db.Orm().Read(r.WebServer)
	newList := JSON.Extend(r.WebServer.UnDeployList, list)
	r.WebServer.UnDeployList = JSON.Stringify(newList)
	_, err := db.Orm().Update(r.WebServer, "UnDeployList")
	if err != nil {
		return err
	}
	return nil
}
Esempio n. 4
0
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))
}
Esempio n. 5
0
func Send(url string, method string, params interface{}) (interface{}, error) {
	contentString := `{"method": "` + method + `", "params":[` + JSON.Stringify(params) + `], "id":"` + helper.RandString(10) + `"}`
	contentBody := []byte(contentString)

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(contentBody))
	defer req.Body.Close()

	if err != nil {
		return nil, helper.NewError("create request error:", err)
	}

	req.Header.Set("Content-Type", "application/json")

	transport := http.Transport{
		Dial: dial,
	}

	client := &http.Client{
		Transport: &transport,
	}

	resp, err := client.Do(req)
	if err != nil {
		return nil, helper.NewError("rpc request error", err)
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	result := JSON.Parse(string(body))

	if result == nil {
		return nil, nil
	}

	if result["error"] != nil {
		return nil, helper.NewError(method + ":" + result["error"].(string))
	}
	//无返回内容
	if result["result"] == nil {
		return nil, nil
	}
	return result["result"].(map[string]interface{})["Response"], nil
}
Esempio n. 6
0
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))
}
Esempio n. 7
0
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
}
Esempio n. 8
0
func (r report) String() string {
	return JSON.Stringify(r.Data())
}