@@ -41,12 +41,16 @@ const (
4141)
4242
4343type (
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+
119157func 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
0 commit comments