@@ -22,6 +22,21 @@ func (s *ShimServer) HealthcheckHandler(w http.ResponseWriter, r *http.Request)
2222 }, nil
2323}
2424
25+ func (s * ShimServer ) ShutdownHandler (w http.ResponseWriter , r * http.Request ) (interface {}, error ) {
26+ var req ShutdownRequest
27+ if err := api .DecodeJSONBody (w , r , & req , true ); err != nil {
28+ return nil , err
29+ }
30+
31+ go func () {
32+ if err := s .Shutdown (s .ctx , req .Force ); err != nil {
33+ log .Error (s .ctx , "Shutdown" , "err" , err )
34+ }
35+ }()
36+
37+ return nil , nil
38+ }
39+
2540func (s * ShimServer ) InstanceHealthHandler (w http.ResponseWriter , r * http.Request ) (interface {}, error ) {
2641 ctx := r .Context ()
2742 response := InstanceHealthResponse {}
@@ -159,9 +174,11 @@ func (s *ShimServer) TaskMetricsHandler(w http.ResponseWriter, r *http.Request)
159174}
160175
161176func (s * ShimServer ) ComponentListHandler (w http.ResponseWriter , r * http.Request ) (interface {}, error ) {
162- runnerStatus := s .runnerManager .GetInfo (r .Context ())
163177 response := & ComponentListResponse {
164- Components : []components.ComponentInfo {runnerStatus },
178+ Components : []components.ComponentInfo {
179+ s .runnerManager .GetInfo (r .Context ()),
180+ s .shimManager .GetInfo (r .Context ()),
181+ },
165182 }
166183 return response , nil
167184}
@@ -176,27 +193,31 @@ func (s *ShimServer) ComponentInstallHandler(w http.ResponseWriter, r *http.Requ
176193 return nil , & api.Error {Status : http .StatusBadRequest , Msg : "empty name" }
177194 }
178195
196+ var componentManager components.ComponentManager
179197 switch components .ComponentName (req .Name ) {
180198 case components .ComponentNameRunner :
181- if req .URL == "" {
182- return nil , & api.Error {Status : http .StatusBadRequest , Msg : "empty url" }
183- }
184-
185- // There is still a small chance of time-of-check race condition, but we ignore it.
186- runnerInfo := s .runnerManager .GetInfo (r .Context ())
187- if runnerInfo .Status == components .ComponentStatusInstalling {
188- return nil , & api.Error {Status : http .StatusConflict , Msg : "already installing" }
189- }
190-
191- s .bgJobsGroup .Go (func () {
192- if err := s .runnerManager .Install (s .bgJobsCtx , req .URL , true ); err != nil {
193- log .Error (s .bgJobsCtx , "runner background install" , "err" , err )
194- }
195- })
196-
199+ componentManager = s .runnerManager
200+ case components .ComponentNameShim :
201+ componentManager = s .shimManager
197202 default :
198203 return nil , & api.Error {Status : http .StatusBadRequest , Msg : "unknown component" }
199204 }
200205
206+ if req .URL == "" {
207+ return nil , & api.Error {Status : http .StatusBadRequest , Msg : "empty url" }
208+ }
209+
210+ // There is still a small chance of time-of-check race condition, but we ignore it.
211+ componentInfo := componentManager .GetInfo (r .Context ())
212+ if componentInfo .Status == components .ComponentStatusInstalling {
213+ return nil , & api.Error {Status : http .StatusConflict , Msg : "already installing" }
214+ }
215+
216+ s .bgJobsGroup .Go (func () {
217+ if err := componentManager .Install (s .bgJobsCtx , req .URL , true ); err != nil {
218+ log .Error (s .bgJobsCtx , "component background install" , "name" , componentInfo .Name , "err" , err )
219+ }
220+ })
221+
201222 return nil , nil
202223}
0 commit comments