-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
97 lines (83 loc) · 2.26 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
var NODE_ID = ""
var LOCAL_IP = ""
var RING_POSITION = -1
var isLeader = false
func main() {
// Synchronizes start of client and server.
clientServerChan := make(chan int, 5)
// Listener is started even before introduction so that the
// introducer can make a connection to this node.
go startServer(clientServerChan)
LOCAL_IP, err := GetLocalIP()
if err != nil {
log.Fatalf("Unable to get local IP")
}
if LOCAL_IP == LEADER_SERVER_HOST {
isLeader = true
}
JoinRing()
clientServerChan <- 1
// Dial connection.
go startClient(clientServerChan)
for {
var demoInstruction string
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
demoInstruction = scanner.Text()
}
demoArgs := strings.Split(demoInstruction, " ")
switch {
case demoArgs[0] == "RainStorm":
if len(demoArgs) < 6 {
log.Println("Expected usage: \"Rainstorm <op1 _exe> <op2 _exe> " +
"<hydfs_src_file> <hydfs_dest_filename> <num_tasks>\"")
continue
}
case demoArgs[0] == "list_mem":
PrintMembershipInfo()
case demoArgs[0] == "list_self":
fmt.Printf("ID: %s POINT: %d \n", NODE_ID, RING_POSITION)
case demoArgs[0] == "piggybacks":
PrintPiggybackMessages()
case demoArgs[0] == "leave":
ExitGroup()
case demoArgs[0] == "meta_info":
fmt.Printf("ID: %s\n", NODE_ID)
case demoArgs[0] == "create":
err = CreateHDFSFile(demoArgs[1], demoArgs[2])
if err == nil {
fmt.Println("Creation completed")
} else {
fmt.Println("Error while creating file: ", err.Error())
}
case demoArgs[0] == "print_succ":
ringSuccessors := GetRingSuccessors(RING_POSITION)
fmt.Print(ringSuccessors)
case demoArgs[0] == "list_ring":
PrintRing()
case demoArgs[0] == "store":
PrintStoredFiles()
case demoArgs[0] == "append":
AppendToHDFSFile(demoArgs[1], demoArgs[2])
case demoArgs[0] == "get":
GetHDFSToLocal(demoArgs[1], demoArgs[2], "")
case demoArgs[0] == "get_from_replica":
GetHDFSToLocal(demoArgs[2], demoArgs[3], demoArgs[1])
case demoArgs[0] == "list_files":
filenames := GetFilesNamesOnNode()
fmt.Print(filenames)
case demoArgs[0] == "merge":
MergeHDFSFile(demoArgs[1])
case demoArgs[0] == "ls":
PrintMachinesWithFile(demoArgs[1])
}
}
}