Beispiel #1
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
}
Beispiel #2
0
//多终端Rpc调用
//TODO
//队列调用,最大同时调用数
func BatchCallRpc(clients HostMap, method string, params ...rpc.RpcInterface) JSON.Type {
	results := JSON.Type{}
	helper.AsyncMap(clients, func(key, value interface{}) bool {
		c := value.(*HostClient)
		result, err := c.CallRpc(method, params...)
		if err != nil {
			results[helper.Itoa64(c.Id)] = helper.Error(err)
		} else {
			results[helper.Itoa64(c.Id)] = result
		}
		return false
	})
	return results
}
Beispiel #3
0
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))
}
Beispiel #4
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,
		})
	})
}