-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure.go
144 lines (113 loc) · 3.79 KB
/
configure.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"bufio"
"fmt"
"github.com/CPSSD/MDFS/config"
"github.com/CPSSD/MDFS/utils"
"os"
"strings"
)
func main() {
fmt.Println("This is the installation program for the MDFS")
fmt.Println("----------------------------------------------------------")
fmt.Println("Please select which software you would like to install")
fmt.Println("1) Storage node software")
fmt.Println("2) Metadata service")
// get user selection
reader := bufio.NewReader(os.Stdin)
fmt.Print("\nEnter selection: ")
selection, _ := reader.ReadString('\n')
fmt.Println("----------------------------------------------------------")
selection = strings.TrimSpace(selection)
home := utils.GetUserHome()
switch selection {
case "1": // configure storage node
path := home + "/.mdfs/stnode/"
port := getPort(reader)
host := getHost(reader)
mdhost := getMdHost(reader)
mdport := getMdPort(reader)
err := setup(path, port, host, mdport, mdhost, "./storagenode/config/", "stnode_conf.json")
if err != nil {
panic(err)
}
// create a subdirectory called files
err = os.MkdirAll(path+"./files", 0700)
if err != nil {
panic(err)
}
fmt.Println("Storage node has been initialised.")
fmt.Printf("The configuration file can be found at %s.stnode_conf.json.\n", path)
case "2": // configure metadata service
path := home + "/.mdfs/mdservice/"
port := getPort(reader)
host := getHost(reader)
err := setup(path, port, host, "", "", "./mdservice/config/", "mdservice_conf.json")
if err != nil {
panic(err)
}
// create a subdirectory called files
err = os.MkdirAll(path+"./files", 0700)
if err != nil {
panic(err)
}
fmt.Println("Metadata service has been initialised.")
fmt.Printf("The configuration file can be found at %s/.mdservice_conf.json.\n", path)
default:
fmt.Println("Invalid Selection.")
}
}
func getPort(reader *bufio.Reader) string {
// listen on this port
fmt.Println("Please enter the port you want the service to listen on.\n")
fmt.Print("Port: ")
port, _ := reader.ReadString('\n')
fmt.Println("----------------------------------------------------------")
port = strings.TrimSpace(port)
return port
}
func getHost(reader *bufio.Reader) string {
// listen on this port
fmt.Println("Please enter the IP address you want the service to listen at.\n")
fmt.Print("Address: ")
host, _ := reader.ReadString('\n')
fmt.Println("----------------------------------------------------------")
host = strings.TrimSpace(host)
return host
}
func getMdPort(reader *bufio.Reader) string {
// listen on this port
fmt.Println("Please enter the port of the metadata service you wish to register with.\n")
fmt.Print("Port: ")
port, _ := reader.ReadString('\n')
fmt.Println("----------------------------------------------------------")
port = strings.TrimSpace(port)
return port
}
func getMdHost(reader *bufio.Reader) string {
// metadata service is at this address
fmt.Println("Please enter the IP address of the metadata service you wish to register with (e.g. \"192.168.1.1\")")
fmt.Println("Enter \"localhost\" if metadata service is running on this host.\n")
fmt.Print("Address: ")
host, _ := reader.ReadString('\n')
fmt.Println("----------------------------------------------------------")
host = strings.TrimSpace(host)
return host
}
func setup(path, port, host, mdport, mdhost, sample, fname string) error {
// create the supplied file path
err := os.MkdirAll(path, 0700)
if err != nil {
return err
}
// get the sample configuration file from the repo
conf := config.ParseConfiguration(sample + fname)
conf.Path = path // change the path variable
conf.Port = port // change the port variable
conf.Host = host
conf.MdHost = mdhost
conf.MdPort = mdport
// encode the new object to a json file
err = config.SetConfiguration(conf, path+"."+fname)
return err
}