-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
66 lines (55 loc) · 2.35 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
package main
import (
"flag"
"github.com/rounakdatta/GoDFS/daemon/client"
"github.com/rounakdatta/GoDFS/daemon/datanode"
"github.com/rounakdatta/GoDFS/daemon/namenode"
"log"
"os"
"strings"
)
func main() {
dataNodeCommand := flag.NewFlagSet("datanode", flag.ExitOnError)
nameNodeCommand := flag.NewFlagSet("namenode", flag.ExitOnError)
clientCommand := flag.NewFlagSet("client", flag.ExitOnError)
dataNodePortPtr := dataNodeCommand.Int("port", 7000, "DataNode communication port")
dataNodeDataLocationPtr := dataNodeCommand.String("data-location", ".", "DataNode data storage location")
nameNodePortPtr := nameNodeCommand.Int("port", 9000, "NameNode communication port")
nameNodeListPtr := nameNodeCommand.String("datanodes", "", "Comma-separated list of DataNodes to connect to")
nameNodeBlockSizePtr := nameNodeCommand.Int("block-size", 32, "Block size to store")
nameNodeReplicationFactorPtr := nameNodeCommand.Int("replication-factor", 1, "Replication factor of the system")
clientNameNodePortPtr := clientCommand.String("namenode", "localhost:9000", "NameNode communication port")
clientOperationPtr := clientCommand.String("operation", "", "Operation to perform")
clientSourcePathPtr := clientCommand.String("source-path", "", "Source path of the file")
clientFilenamePtr := clientCommand.String("filename", "", "File name")
if len(os.Args) < 2 {
log.Println("sub-command is required")
os.Exit(1)
}
switch os.Args[1] {
case "datanode":
_ = dataNodeCommand.Parse(os.Args[2:])
datanode.InitializeDataNodeUtil(*dataNodePortPtr, *dataNodeDataLocationPtr)
case "namenode":
_ = nameNodeCommand.Parse(os.Args[2:])
var listOfDataNodes []string
if len(*nameNodeListPtr) > 1 {
listOfDataNodes = strings.Split(*nameNodeListPtr, ",")
} else {
listOfDataNodes = []string{}
}
namenode.InitializeNameNodeUtil(*nameNodePortPtr, *nameNodeBlockSizePtr, *nameNodeReplicationFactorPtr, listOfDataNodes)
case "client":
_ = clientCommand.Parse(os.Args[2:])
if *clientOperationPtr == "put" {
status := client.PutHandler(*clientNameNodePortPtr, *clientSourcePathPtr, *clientFilenamePtr)
log.Printf("Put status: %t\n", status)
} else if *clientOperationPtr == "get" {
contents, status := client.GetHandler(*clientNameNodePortPtr, *clientFilenamePtr)
log.Printf("Get status: %t\n", status)
if status {
log.Println(contents)
}
}
}
}