Ejemplo n.º 1
0
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))
}
Ejemplo n.º 2
0
func fillClientList() map[string]JSON.Type {
	result := map[string]JSON.Type{}
	//组map
	clientsDict := map[string]JSON.Type{}

	//获取组
	groups := group.List()
	//获取主机
	clients := client.List()

	//创建组map
	for id, g := range groups {
		result[helper.Itoa64(id)] = JSON.Parse(g)
		clientsDict[helper.Itoa64(id)] = JSON.Type{}
	}

	for id, c := range clients {
		//添加到对应组map里
		if list, found := clientsDict[helper.Itoa64(c.Group)]; found {
			list[helper.Itoa64(id)] = c
		}
	}

	for id, g := range result {
		g["clients"] = clientsDict[id]
	}

	return result
}
Ejemplo n.º 3
0
func (r *HostClient) GetUnDeployFiles() (JSON.Type, error) {
	c := model.WebServer{Id: r.Id}
	err := db.Orm().Read(&c)
	if err != nil {
		return nil, err
	}
	return JSON.Parse(c.UnDeployList), nil
}
Ejemplo n.º 4
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))
}
Ejemplo n.º 5
0
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,
		})
	})
}
Ejemplo n.º 6
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
}