Esempio n. 1
0
func initChunkserverHandler(resp http.ResponseWriter, req *http.Request) {
	reqData, err := ioutil.ReadAll(req.Body)
	defer req.Body.Close()
	if err != nil {
		util.HandleError(resp, "", err, http.StatusBadRequest)
		return
	}
	log.Infof("[initserverHandler] read reqData %v", string(reqData))

	var jsonMap map[string]interface{}
	err = json.Unmarshal(reqData, &jsonMap)
	if err != nil {
		util.HandleError(resp, "", err, http.StatusBadRequest)
		return
	}
	log.Infof("[initserverHandler] change json to map %v", jsonMap)

	groupId := uint16((jsonMap["GroupId"]).(float64))
	ip := jsonMap["Ip"].(string)
	port := int((jsonMap["Port"]).(float64))
	chunkserver := new(metadata.Chunkserver)
	chunkserver.GroupId = groupId
	chunkserver.Ip = ip
	chunkserver.Port = port
	chunkserver.Status = INIT_STATUS
	chunkserver.TotalFreeSpace = 0
	chunkserver.MaxFreeSpace = 0
	chunkserver.PendingWrites = 0
	chunkserver.WritingCount = 0
	chunkserver.DataDir = ""
	chunkserver.ReadingCount = 0
	chunkserver.TotalChunks = 0
	chunkserver.ConnectionsCount = 0

	err = AddChunkserver(chunkserver)
	if err != nil {
		util.HandleError(resp, "", err, http.StatusInternalServerError)
		return
	}

	util.Response(nil, http.StatusOK, resp)
}
Esempio n. 2
0
func TestAddChunkserver(t *testing.T) {
	conn, err := getConn()

	chunkserver := new(metadata.Chunkserver)
	chunkserver.GroupId = uint16(65535)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(45465465)
	chunkserver.MaxFreeSpace = int64(123123123123123)
	chunkserver.PendingWrites = 1
	chunkserver.WritingCount = 1
	chunkserver.DataDir = "/export/"
	chunkserver.ReadingCount = 1
	chunkserver.TotalChunks = 1
	chunkserver.ConnectionsCount = 1

	err = conn.AddChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
}
Esempio n. 3
0
func AddChunkserver(chunkserver *metadata.Chunkserver) error {
	chunkserver.Status = INIT_STATUS
	chunkserver.TotalFreeSpace = 0
	chunkserver.MaxFreeSpace = 0
	chunkserver.PendingWrites = 0
	chunkserver.WritingCount = 0
	chunkserver.DataDir = ""
	chunkserver.ReadingCount = 0
	chunkserver.TotalChunks = 0
	chunkserver.ConnectionsCount = 0

	err := mdDriver.AddChunkserver(chunkserver)
	if err != nil {
		return err
	}
	lock.Lock()
	defer lock.Unlock()

	key := fmt.Sprintf("%d:%s:%d", chunkserver.GroupId, chunkserver.Ip, chunkserver.Port)
	chunkserver.UpdateTime = time.Now()
	serverInfo[key] = chunkserver
	return nil
}