Пример #1
0
/*
	call by server
	send task to client to retask
*/
func Retask(task string) {
	tempMap := make(map[string]string)
	tempMap["task"] = task
	command := &gocommand.Command{"retask", "retask", tempMap}
	temp := gocommand.EnCode(command.GetCommandString())
	gonet.ServerSend(temp)
}
Пример #2
0
/*
	call by server
	to send the res to client
*/
func reduceToClient() {
	tempMap := make(map[string]string)
	tempMap["result"] = ReduceMap
	command := &gocommand.Command{"reduce", "reduce", tempMap}
	temp := gocommand.EnCode(command.GetCommandString())
	gonet.ServerSend(temp)
	ReduceMap = ""
}
Пример #3
0
/*
	call by client
	to send the reduce command to client
*/
func CollectReduceToClient() {
	for _, config := range NodeConfig {
		tempMap := make(map[string]string)
		tempMap["result"] = ReduceMap
		command := &gocommand.Command{"reduce", "reduce", tempMap}
		temp := gocommand.EnCode(command.GetCommandString())
		msg := gonet.Message{config.Config["NodeAddr"], temp}
		gonet.Send(msg, func(msg string) {})
	}
}
Пример #4
0
/*
	allocate data task with node performance
	//define the user collect data
*/
func AllocateData(method string, commandType string, data map[string]string, userCollect func(msg string)) {
	loadNodeChan()
	switch commandType {
	case gocommand.TypeSequence:
		//TO-DO performance
		count := 0
		avg := len(data) / len(NodeConfig)
		tempMap := make(map[string]string)
		for key, value := range data {
			tempMap[key] = value
			count++
			// log.Printf("datalength: %s \n", len(tempMap))
			if len(tempMap) >= avg {
				command := &gocommand.Command{method, commandType, tempMap}
				commandString := command.GetCommandString()
				content := gocommand.EnCode(commandString)
				sendNode(content, userCollect)
				// log.Printf("datalength1: %s \n", len(tempMapOther))
				tempMap = make(map[string]string)
				// log.Printf("datalength2: %s \n", len(tempMap))
			} else {
				if count >= len(data) {
					//at the end
					command := &gocommand.Command{method, commandType, tempMap}
					commandString := command.GetCommandString()
					content := gocommand.EnCode(commandString)
					sendNode(content, userCollect)
				}
			}
		}

	case gocommand.TypeStartEnd:
		//TO-DO performance

		start, err := strconv.ParseInt(data["start"], 10, 64)
		if err != nil {
			log.Printf("scheduler, execute start end at start type wrong: %v\n", err)
		}
		end, err1 := strconv.ParseInt(data["end"], 10, 64)
		if err1 != nil {
			log.Printf("scheduler, execute start end at end type wrong: %v\n", err)
		}

		avg := (end - start) / int64(len(NodeConfig))
		tempMap := make(map[string]string)

		for current := int64(start); current <= end; current = current + int64(avg) + 1 {
			tempMap["start"] = strconv.FormatInt(current, 10)
			tempEnd := current + int64(avg)
			if tempEnd > end {
				tempEnd = end
			}
			tempMap["end"] = strconv.FormatInt(tempEnd, 10)
			command := &gocommand.Command{method, commandType, tempMap}
			commandString := command.GetCommandString()
			content := gocommand.EnCode(commandString)
			sendNode(content, userCollect)
			tempMap = make(map[string]string)
		}
	case gocommand.TypeCurrentNext:
		command := &gocommand.Command{method, commandType, data}
		commandString := command.GetCommandString()
		content := gocommand.EnCode(commandString)
		sendNode(content, userCollect)
	}

}