forked from ligfx/golang-distributed-filesystem
/
main.go
69 lines (56 loc) · 1.81 KB
/
main.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
62
63
64
65
66
67
68
69
package main
import (
"log"
"math/rand"
"time"
"golang-distributed-filesystem/utils/command"
"golang-distributed-filesystem/datanode"
"golang-distributed-filesystem/metadatanode"
"golang-distributed-filesystem/upload"
)
func main() {
rand.Seed(time.Now().UnixNano())
var debug bool
cli := command.App()
cli.Global(func(flag command.Flags) {
flag.BoolVar(&debug, "debug", false, "Show debug messages")
})
cli.Command("datanode", "Run storage node", func(flag command.Flags) {
listener := command.ListenerFlag(flag, "port", 0, "")
dataDir := flag.String("dataDir", "_data", "")
leaderAddress := flag.String("leaderAddress", "[::1]:5051", "")
heartbeatInterval := flag.Duration("heartbeatInterval", 3*time.Second, "")
flag.Parse()
conf := datanode.Config{
DataDir: *dataDir,
Debug: debug,
Listener: listener.Get(),
HeartbeatInterval: *heartbeatInterval,
LeaderAddress: *leaderAddress}
datanode.Create(conf)
// Wait on goroutines
<-make(chan bool)
})
cli.Command("metadatanode", "Run leader", func(flag command.Flags) {
clientListener := command.ListenerFlag(flag, "clientPort", 5050, "")
clusterListener := command.ListenerFlag(flag, "clusterPort", 5051, "")
replicationFactor := flag.Int("replicationFactor", 2, "")
flag.Parse()
log.Println("Replication factor of", *replicationFactor)
conf := metadatanode.Config{
clientListener.Get(),
clusterListener.Get(),
*replicationFactor,
"metadata.db"}
metadatanode.Create(conf)
// Wait on goroutines
<-make(chan bool)
})
cli.Command("upload", "Upload a file", func(flag command.Flags) {
file := command.FileFlag(flag, "file", "")
leaderAddress := flag.String("leaderAddress", "[::1]:5050", "")
flag.Parse()
upload.Upload(file.Get(), debug, *leaderAddress)
})
cli.Run()
}