Ejemplo n.º 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)

}
Ejemplo n.º 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)
}
Ejemplo n.º 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)

}
Ejemplo n.º 4
0
func (rs *RsyncServer) listHandler(w http.ResponseWriter, r *http.Request) {
	util.Json(w, r, http.StatusAccepted, ListFileResult{rs.fileHashes})
}
Ejemplo n.º 5
0
func (tl *TeamMaster) listAgentsHandler(w http.ResponseWriter, r *http.Request) {
	util.Json(w, r, http.StatusAccepted, tl.MasterResource.Topology)
}
Ejemplo n.º 6
0
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)
}