Skip to content

Commit 2e54749

Browse files
committed
fix code, init create root path.
1 parent c787ac3 commit 2e54749

2 files changed

Lines changed: 36 additions & 30 deletions

File tree

ServerConfig.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"zookeeper": {
3-
"hosts": "192.168.2.80:2181,192.168.2.81:2181,192.168.2.82:2181",
4-
"root": "/cloudtask"
5-
},
6-
"serverconfig":{
7-
"websitehost": "192.168.2.80:8901",
8-
"centerhost": "192.168.2.80:8985",
9-
"storage": {
10-
"mongo": {
11-
"hosts": "192.168.2.80:27017,192.168.2.81:27017,192.168.2.82:27017",
12-
"database": "cloudtask",
13-
"auth": {
14-
"user": "datastoreAdmin",
15-
"password": "ds4dev"
16-
},
17-
"options": [
18-
"maxPoolSize=20",
19-
"replicaSet=mgoCluster",
20-
"authSource=admin"
21-
]
22-
}
23-
}
24-
}
25-
}
2+
"zookeeper": {
3+
"hosts": "192.168.2.80:2181,192.168.2.81:2181,192.168.2.82:2181",
4+
"root": "/cloudtask"
5+
},
6+
"serverconfig": {
7+
"websitehost": "192.168.2.80:8091",
8+
"centerhost": "192.168.2.80:8985",
9+
"storagedriver": {
10+
"mongo": {
11+
"hosts": "192.168.2.80:27017,192.168.2.81:27017,192.168.2.82:27017",
12+
"database": "cloudtask",
13+
"auth": {
14+
"user": "datastoreAdmin",
15+
"password": "ds4dev"
16+
},
17+
"options": [
18+
"maxPoolSize=20",
19+
"replicaSet=mgoCluster",
20+
"authSource=admin"
21+
]
22+
}
23+
}
24+
}
25+
}

main.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Configuration struct {
2121
ServerConfig struct {
2222
WebsiteHost string `json:"websitehost"`
2323
CenterHost string `json:"centerhost"`
24-
Storage map[string]interface{} `json:"storage"`
24+
StorageDriver map[string]interface{} `json:"storagedriver"`
2525
} `json:"serverconfig"`
2626
}
2727

@@ -39,8 +39,14 @@ func initServerConfigData(conf *Configuration) (string, []byte, error) {
3939
return "", nil, err
4040
}
4141

42-
<-event
4342
defer conn.Close()
43+
<-event
44+
if ret, _, _ := conn.Exists(conf.Zookeeper.Root); !ret {
45+
if _, err := conn.Create(conf.Zookeeper.Root, []byte{}, zkFlags, zkACL); err != nil {
46+
return "", nil, fmt.Errorf("zookeeper root: %s failure", conf.Zookeeper.Root)
47+
}
48+
}
49+
4450
serverConfigPath := conf.Zookeeper.Root + "/ServerConfig"
4551
ret, _, err := conn.Exists(serverConfigPath)
4652
if err != nil {
@@ -84,7 +90,7 @@ func main() {
8490

8591
conf, err := readConfiguration()
8692
if err != nil {
87-
fmt.Errorf("ServerConfig.json invalid, %s", err)
93+
fmt.Printf("ServerConfig.json invalid, %s", err)
8894
return
8995
}
9096

@@ -98,10 +104,10 @@ func main() {
98104

99105
path, data, err := initServerConfigData(conf)
100106
if err != nil {
101-
fmt.Errorf("init server config failure, %s", err)
107+
fmt.Printf("init server config failure, %s", err)
102108
return
103109
}
104110
fmt.Printf("zookeeper path: %s\n", path)
105-
fmt.Printf("data: %s\n", string(data))
106-
fmt.Printf("init to zookeeper successed!\n")
111+
fmt.Printf("serverconfig: %s\n", string(data))
112+
fmt.Printf("initconfig to zookeeper successed!\n")
107113
}

0 commit comments

Comments
 (0)