/
mapTaskInfo.go
61 lines (51 loc) · 1.05 KB
/
mapTaskInfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package master
import (
"github.com/BWbwchen/MapReduce/rpc"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
)
type MapTaskInfo struct {
Files []FileInfo
TaskState int
UUID string
}
type FileInfo struct {
FileName string
From int
To int
}
func (mt *MapTaskInfo) addFile(file string, from int, to int) {
mt.Files = append(mt.Files, FileInfo{
FileName: file,
From: from,
To: to,
})
log.Trace("Add map input file")
}
func newMapTask() MapTaskInfo {
return MapTaskInfo{
UUID: uuid.New().String(),
TaskState: TASK_IDLE,
}
}
func newMapTasks(size int) []MapTaskInfo {
var ret []MapTaskInfo
for i := 0; i < size; i++ {
ret = append(ret, newMapTask())
}
return ret
}
func (mt *MapTaskInfo) toRPC() *rpc.MapInfo {
ret := &rpc.MapInfo{}
for _, finfo := range mt.Files {
ret.Files = append(ret.Files, &rpc.MapFileInfo{
FileName: finfo.FileName,
From: int64(finfo.From),
To: int64(finfo.To),
})
}
return ret
}
func (mt *MapTaskInfo) setState(state int) {
mt.TaskState = state
}