Esempio n. 1
0
func (h *HeartBeater) beat(fn func(url.Values) string) {
	values := make(url.Values)
	beatToPath := fn(values)
	values.Add("servicePort", strconv.Itoa(h.ServicePort))
	for _, leader := range h.Leaders {
		_, err := util.Post("http://"+leader+beatToPath, values)
		// println("heart beat to", leader, beatToPath)
		if err != nil {
			println("Failed to heart beat to", leader, beatToPath)
		}
	}
}
Esempio n. 2
0
func Assign(leader string, request *resource.AllocationRequest) (*resource.AllocationResult, error) {
	values := make(url.Values)
	requestBlob, _ := json.Marshal(request)
	values.Add("request", string(requestBlob))
	jsonBlob, err := util.Post(util.SchemePrefix+leader+"/agent/assign", values)
	if err != nil {
		return nil, err
	}
	var ret resource.AllocationResult
	err = json.Unmarshal(jsonBlob, &ret)
	if err != nil {
		return nil, fmt.Errorf("/agent/assign result JSON unmarshal error:%v, json:%s", err, string(jsonBlob))
	}
	if ret.Error != "" {
		return nil, fmt.Errorf("/agent/assign error:%v", ret.Error)
	}
	return &ret, nil
}