Skip to content

Commit 4b65b90

Browse files
committed
Improve(client/status): display statuses even if get status failed for some clients.
Signed-off-by: Wine93 <[email protected]>
1 parent 1098a7f commit 4b65b90

File tree

5 files changed

+66
-28
lines changed

5 files changed

+66
-28
lines changed

cli/command/client/status.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636

3737
var (
3838
GET_STATUS_PLAYBOOK_STEPS = []int{
39+
playbook.INIT_CLIENT_STATUS,
3940
playbook.GET_CLIENT_STATUS,
4041
}
4142
)
@@ -81,7 +82,9 @@ func genStatusPlaybook(curveadm *cli.CurveAdm,
8182
comm.KEY_CLIENT_STATUS_VERBOSE: options.verbose,
8283
},
8384
ExecOptions: playbook.ExecOptions{
84-
SilentSubBar: true,
85+
SilentSubBar: true,
86+
SilentMainBar: step == playbook.INIT_CLIENT_STATUS,
87+
SkipError: true,
8588
},
8689
})
8790
}
@@ -119,11 +122,9 @@ func runStatus(curveadm *cli.CurveAdm, options statusOptions) error {
119122
}
120123

121124
// 3) run playground
122-
if err = pb.Run(); err != nil {
123-
return err
124-
}
125+
err = pb.Run()
125126

126127
// 4) display service status
127128
displayStatus(curveadm, clients, options)
128-
return nil
129+
return err
129130
}

internal/common/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const (
8484
KEY_MAP_OPTIONS = "MAP_OPTIONS"
8585
KEY_MOUNT_OPTIONS = "MOUNT_OPTIONS"
8686
CLIENT_STATUS_LOSED = "Losed"
87+
CLIENT_STATUS_UNKNOWN = "Unknown"
8788
KERNERL_MODULE_NBD = "nbd"
8889
KERNERL_MODULE_FUSE = "fuse"
8990

internal/playbook/factory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const (
7777
COLLECT_CLIENT
7878
BACKUP_ETCD_DATA
7979
CHECK_MDS_ADDRESS
80+
INIT_CLIENT_STATUS
8081
GET_CLIENT_STATUS
8182
INSTALL_CLIENT
8283
UNINSTALL_CLIENT
@@ -224,6 +225,8 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
224225
t, err = comm.NewCollectClientTask(curveadm, config.GetAny(i))
225226
case BACKUP_ETCD_DATA:
226227
t, err = comm.NewBackupEtcdDataTask(curveadm, config.GetDC(i))
228+
case INIT_CLIENT_STATUS:
229+
t, err = comm.NewInitClientStatusTask(curveadm, config.GetAny(i))
227230
case GET_CLIENT_STATUS:
228231
t, err = comm.NewGetClientStatusTask(curveadm, config.GetAny(i))
229232
case INSTALL_CLIENT:

internal/task/task/common/client_status.go

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ const (
4141
)
4242

4343
type (
44+
step2InitClientStatus struct {
45+
client storage.Client
46+
cfgPath *string
47+
memStorage *utils.SafeMap
48+
}
49+
4450
step2FormatClientStatus struct {
45-
client storage.Client
46-
containerId string
47-
status *string
48-
cfgPath *string
49-
memStorage *utils.SafeMap
51+
client storage.Client
52+
status *string
53+
memStorage *utils.SafeMap
5054
}
5155

5256
ClientStatus struct {
@@ -96,26 +100,60 @@ func setClientStatus(memStorage *utils.SafeMap, id string, status ClientStatus)
96100
})
97101
}
98102

99-
func (s *step2FormatClientStatus) Execute(ctx *context.Context) error {
100-
status := *s.status
101-
if len(status) == 0 { // container losed
102-
status = comm.CLIENT_STATUS_LOSED
103-
}
104-
103+
func (s *step2InitClientStatus) Execute(ctx *context.Context) error {
105104
client := s.client
106105
id := client.Id
107106
setClientStatus(s.memStorage, id, ClientStatus{
108107
Id: client.Id,
109108
Host: client.Host,
110109
Kind: client.Kind,
111-
ContainerId: s.containerId,
112-
Status: status,
110+
ContainerId: client.ContainerId,
111+
Status: comm.CLIENT_STATUS_UNKNOWN,
113112
AuxInfo: client.AuxInfo,
114113
CfgPath: *s.cfgPath,
115114
})
116115
return nil
117116
}
118117

118+
func (s *step2FormatClientStatus) Execute(ctx *context.Context) error {
119+
status := *s.status
120+
if len(status) == 0 { // container losed
121+
status = comm.CLIENT_STATUS_LOSED
122+
}
123+
124+
id := s.client.Id
125+
s.memStorage.TX(func(kv *utils.SafeMap) error {
126+
v := kv.Get(comm.KEY_ALL_CLIENT_STATUS)
127+
m := v.(map[string]ClientStatus)
128+
129+
// update the status
130+
s := m[id]
131+
s.Status = status
132+
m[id] = s
133+
kv.Set(comm.KEY_ALL_CLIENT_STATUS, m)
134+
return nil
135+
})
136+
return nil
137+
}
138+
139+
func NewInitClientStatusTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, error) {
140+
client := v.(storage.Client)
141+
142+
t := task.NewTask("Init Client Status", "", nil)
143+
144+
var cfgPath string
145+
t.AddStep(&step.Lambda{
146+
Lambda: dumpCfg(curveadm, client.Id, &cfgPath),
147+
})
148+
t.AddStep(&step2InitClientStatus{
149+
client: client,
150+
cfgPath: &cfgPath,
151+
memStorage: curveadm.MemStorage(),
152+
})
153+
154+
return t, nil
155+
}
156+
119157
func NewGetClientStatusTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, error) {
120158
client := v.(storage.Client)
121159
hc, err := curveadm.GetHost(client.Host)
@@ -129,23 +167,18 @@ func NewGetClientStatusTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task,
129167
t := task.NewTask("Get Client Status", subname, hc.GetSSHConfig())
130168

131169
// add step
132-
var status, cfgPath string
170+
var status string
133171
t.AddStep(&step.ListContainers{
134172
ShowAll: true,
135173
Format: `"{{.Status}}"`,
136174
Filter: fmt.Sprintf("id=%s", containerId),
137175
Out: &status,
138176
ExecOptions: curveadm.ExecOptions(),
139177
})
140-
t.AddStep(&step.Lambda{
141-
Lambda: dumpCfg(curveadm, client.Id, &cfgPath),
142-
})
143178
t.AddStep(&step2FormatClientStatus{
144-
client: client,
145-
containerId: containerId,
146-
status: &status,
147-
cfgPath: &cfgPath,
148-
memStorage: curveadm.MemStorage(),
179+
client: client,
180+
status: &status,
181+
memStorage: curveadm.MemStorage(),
149182
})
150183

151184
return t, nil

internal/tui/client/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
func statusDecorate(status string) string {
3535
switch status {
36-
case comm.CLIENT_STATUS_LOSED:
36+
case comm.CLIENT_STATUS_LOSED, comm.CLIENT_STATUS_UNKNOWN:
3737
return color.RedString(status)
3838
}
3939
return status

0 commit comments

Comments
 (0)