예제 #1
0
// put agent information list under a path
func (tl *TeamMaster) updateChannelHandler(w http.ResponseWriter, r *http.Request) {
	servicePort := r.FormValue("servicePort")
	host := r.Host
	if strings.Contains(host, ":") {
		host = host[0:strings.Index(host, ":")]
	}
	location := host + ":" + servicePort
	path := r.URL.Path[len("/channel/"):]
	// println(path, ":", location)

	rps, ok := tl.channels[path]
	if !ok {
		rps = make([]*ChannelInformation, 0)
	}
	found := false
	for _, rp := range rps {
		if rp.Location == location {
			rp.LastHeartBeat = time.Now()
			found = true
			break
		}
	}
	if !found {
		rps = append(rps, &ChannelInformation{
			Location:      location,
			LastHeartBeat: time.Now(),
		})
	}
	tl.channelsLock.Lock()
	tl.channels[path] = rps
	tl.channelsLock.Unlock()

	util.Json(w, r, http.StatusAccepted, tl.channels)

}
예제 #2
0
func (tl *TeamMaster) listChannelsHandler(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Path[len("/channel/"):]

	freshChannels := make([]*ChannelInformation, 0)
	rps, ok := tl.channels.GetChannels(path)
	if !ok {
		util.Json(w, r, http.StatusOK, freshChannels)
		return
	}
	for _, rp := range rps {
		if rp.LastHeartBeat.Add(TimeOutLimit * time.Second).After(time.Now()) {
			freshChannels = append(freshChannels, rp)
		}
	}
	for i, j := 0, len(freshChannels)-1; i < j; i, j = i+1, j-1 {
		freshChannels[i], freshChannels[j] = freshChannels[j], freshChannels[i]
	}
	tl.channels.SetChannels(path, freshChannels)
	util.Json(w, r, http.StatusOK, freshChannels)
}
예제 #3
0
func (tl *TeamMaster) requestAgentHandler(w http.ResponseWriter, r *http.Request) {
	requestBlob := []byte(r.FormValue("request"))
	var request resource.AllocationRequest
	err := json.Unmarshal(requestBlob, &request)
	if err != nil {
		util.Error(w, r, http.StatusBadRequest, fmt.Sprintf("request JSON unmarshal error:%v, json:%s", err, string(requestBlob)))
		return
	}

	// fmt.Printf("request:\n%+v\n", request)

	result := tl.allocate(&request)
	// fmt.Printf("result: %v\n%+v\n", result.Error, result.Allocations)
	if result.Error != "" {
		util.Json(w, r, http.StatusNotFound, result)
		return
	}

	util.Json(w, r, http.StatusAccepted, result)

}
예제 #4
0
파일: http_server.go 프로젝트: gao8954/glow
func (rs *RsyncServer) listHandler(w http.ResponseWriter, r *http.Request) {
	util.Json(w, r, http.StatusAccepted, ListFileResult{rs.fileHashes})
}
예제 #5
0
func (tl *TeamMaster) listAgentsHandler(w http.ResponseWriter, r *http.Request) {
	util.Json(w, r, http.StatusAccepted, tl.MasterResource.Topology)
}
예제 #6
0
파일: master.go 프로젝트: wxdublin/glow
func (tl *TeamMaster) statusHandler(w http.ResponseWriter, r *http.Request) {
	infos := make(map[string]interface{})
	infos["Version"] = "0.001"
	util.Json(w, r, http.StatusOK, infos)
}