Skip to content

Commit f3c320b

Browse files
committed
fixed amin man bugs
1 parent c575063 commit f3c320b

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

utils/admin/admin.go

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func (m *Manager) SetConfig(admin *config.Admin) {
3131
m.lock.Unlock()
3232
}
3333

34+
// GetConfig returns the adming config
35+
func (m *Manager) GetConfig() *config.Admin {
36+
m.lock.RLock()
37+
defer m.lock.RUnlock()
38+
return m.admin
39+
}
40+
3441
// SetOperationMode sets the operation mode
3542
func (m *Manager) SetOperationMode(op *config.OperationConfig) error {
3643
m.lock.Lock()

utils/admin/validate.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ func newValidator(cb func()) *validator {
2626
// Start starts the validation process
2727
func (v *validator) startValidation(id, account, key string, mode int) error {
2828
// Set validation status to active
29-
v.lock.Lock()
30-
v.active = true
31-
v.lock.Unlock()
29+
v.setActive(true)
3230

3331
if err := v.registerSpaceCloud(id, account, key, mode); err != nil {
3432
return err
@@ -51,8 +49,8 @@ func (v *validator) startValidation(id, account, key string, mode int) error {
5149
// Check if 15 days are lapsed without authorization
5250
if time.Since(timer).Hours() > 24*15 {
5351

54-
// Reduce op mode to open source
55-
v.reduceMode()
52+
// Stop the validation process
53+
v.stopValidation()
5654
return
5755
}
5856

@@ -68,16 +66,20 @@ func (v *validator) startValidation(id, account, key string, mode int) error {
6866
}
6967

7068
func (v *validator) stopValidation() {
71-
v.lock.Lock()
72-
v.active = false
69+
v.setActive(false)
70+
v.reduceMode()
7371
if v.socket != nil {
7472
v.socket.Close()
7573
}
76-
v.lock.Unlock()
7774
}
7875

7976
func (v *validator) isActive() bool {
8077
v.lock.Lock()
8178
defer v.lock.Unlock()
8279
return v.active
8380
}
81+
func (v *validator) setActive(active bool) {
82+
v.lock.Lock()
83+
v.active = active
84+
v.lock.Unlock()
85+
}

utils/admin/websocket.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package admin
33
import (
44
"errors"
55
"log"
6-
"os"
76
"time"
87

98
"github.com/gorilla/websocket"
@@ -63,7 +62,8 @@ func (v *validator) routineRead() error {
6362

6463
if !data.Ack {
6564
log.Println("Validate Error -", data.Error)
66-
os.Exit(-1)
65+
// Reduce op mode to open source
66+
v.stopValidation()
6767
}
6868
}
6969
}

utils/handlers/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ func HandleLoadOperationModeConfig(adminMan *admin.Manager, syncMan *syncman.Syn
258258
return
259259
}
260260

261-
c := syncMan.GetGlobalConfig()
261+
c := adminMan.GetConfig()
262262

263263
w.WriteHeader(http.StatusOK)
264-
json.NewEncoder(w).Encode(map[string]interface{}{"operation": &c.Admin.Operation})
264+
json.NewEncoder(w).Encode(map[string]interface{}{"operation": &c.Operation})
265265
}
266266
}
267267

0 commit comments

Comments
 (0)