Manager: adjust code for WorkerStatusChangeRequest
extraction
See preceeding OpenAPI change.
This commit is contained in:
parent
9ca14cd471
commit
9ed6b6d931
@ -84,12 +84,12 @@ func (f *Flamenco) RequestWorkerStatusChange(e echo.Context, workerUUID string)
|
|||||||
// Store the status change.
|
// Store the status change.
|
||||||
logger = logger.With().
|
logger = logger.With().
|
||||||
Str("status", string(dbWorker.Status)).
|
Str("status", string(dbWorker.Status)).
|
||||||
Str("requested", string(change.StatusRequested)).
|
Str("requested", string(change.Status)).
|
||||||
Bool("lazy", change.IsLazy).
|
Bool("lazy", change.IsLazy).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
logger.Info().Msg("worker status change requested")
|
logger.Info().Msg("worker status change requested")
|
||||||
dbWorker.StatusRequested = change.StatusRequested
|
dbWorker.StatusRequested = change.Status
|
||||||
dbWorker.LazyStatusRequest = change.IsLazy
|
dbWorker.LazyStatusRequest = change.IsLazy
|
||||||
if err := f.persist.SaveWorker(e.Request().Context(), dbWorker); err != nil {
|
if err := f.persist.SaveWorker(e.Request().Context(), dbWorker); err != nil {
|
||||||
logger.Error().Err(err).Msg("error saving worker after status change request")
|
logger.Error().Err(err).Msg("error saving worker after status change request")
|
||||||
@ -111,8 +111,10 @@ func workerSummary(w persistence.Worker) api.WorkerSummary {
|
|||||||
Version: w.Software,
|
Version: w.Software,
|
||||||
}
|
}
|
||||||
if w.StatusRequested != "" {
|
if w.StatusRequested != "" {
|
||||||
summary.StatusRequested = &w.StatusRequested
|
summary.StatusChange = &api.WorkerStatusChangeRequest{
|
||||||
summary.LazyStatusRequest = &w.LazyStatusRequest
|
Status: w.StatusRequested,
|
||||||
|
IsLazy: w.LazyStatusRequest,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
@ -38,18 +38,20 @@ func TestFetchWorkers(t *testing.T) {
|
|||||||
workers := api.WorkerList{
|
workers := api.WorkerList{
|
||||||
Workers: []api.WorkerSummary{
|
Workers: []api.WorkerSummary{
|
||||||
{
|
{
|
||||||
Id: worker1.UUID,
|
Id: worker1.UUID,
|
||||||
Nickname: worker1.Name,
|
Nickname: worker1.Name,
|
||||||
Status: worker1.Status,
|
Status: worker1.Status,
|
||||||
StatusRequested: nil,
|
Version: worker1.Software,
|
||||||
Version: worker1.Software,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: worker2.UUID,
|
Id: worker2.UUID,
|
||||||
Nickname: worker2.Name,
|
Nickname: worker2.Name,
|
||||||
Status: worker2.Status,
|
Status: worker2.Status,
|
||||||
StatusRequested: &worker2.StatusRequested,
|
Version: worker2.Software,
|
||||||
Version: worker2.Software,
|
StatusChange: &api.WorkerStatusChangeRequest{
|
||||||
|
Status: worker2.StatusRequested,
|
||||||
|
IsLazy: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -110,11 +112,11 @@ func TestFetchWorker(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assertResponseJSON(t, echo, http.StatusOK, api.Worker{
|
assertResponseJSON(t, echo, http.StatusOK, api.Worker{
|
||||||
WorkerSummary: api.WorkerSummary{
|
WorkerSummary: api.WorkerSummary{
|
||||||
Id: workerUUID,
|
Id: workerUUID,
|
||||||
Nickname: "дрон",
|
Nickname: "дрон",
|
||||||
Version: "3.0",
|
Version: "3.0",
|
||||||
Status: api.WorkerStatusAwake,
|
Status: api.WorkerStatusAwake,
|
||||||
StatusRequested: &requestedStatus,
|
StatusChange: &api.WorkerStatusChangeRequest{Status: requestedStatus},
|
||||||
},
|
},
|
||||||
IpAddress: "fe80::5054:ff:fede:2ad7",
|
IpAddress: "fe80::5054:ff:fede:2ad7",
|
||||||
Platform: "linux",
|
Platform: "linux",
|
||||||
@ -141,18 +143,20 @@ func TestRequestWorkerStatusChange(t *testing.T) {
|
|||||||
|
|
||||||
// Expect a broadcast of the change
|
// Expect a broadcast of the change
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Nickname: worker.Name,
|
||||||
Status: prevStatus,
|
Status: prevStatus,
|
||||||
StatusRequested: &requestStatus,
|
Updated: worker.UpdatedAt,
|
||||||
LazyStatusRequest: ptr(true),
|
Version: worker.Software,
|
||||||
Updated: worker.UpdatedAt,
|
StatusChange: &api.WorkerStatusChangeRequest{
|
||||||
Version: worker.Software,
|
Status: requestStatus,
|
||||||
|
IsLazy: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
echo := mf.prepareMockedJSONRequest(api.WorkerStatusChangeRequest{
|
echo := mf.prepareMockedJSONRequest(api.WorkerStatusChangeRequest{
|
||||||
StatusRequested: requestStatus,
|
Status: requestStatus,
|
||||||
IsLazy: true,
|
IsLazy: true,
|
||||||
})
|
})
|
||||||
err := mf.flamenco.RequestWorkerStatusChange(echo, workerUUID)
|
err := mf.flamenco.RequestWorkerStatusChange(echo, workerUUID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -94,9 +94,6 @@ func (f *Flamenco) SignOn(e echo.Context) error {
|
|||||||
if prevStatus != "" {
|
if prevStatus != "" {
|
||||||
update.PreviousStatus = &prevStatus
|
update.PreviousStatus = &prevStatus
|
||||||
}
|
}
|
||||||
if w.StatusRequested != "" {
|
|
||||||
update.StatusRequested = &w.StatusRequested
|
|
||||||
}
|
|
||||||
f.broadcaster.BroadcastWorkerUpdate(update)
|
f.broadcaster.BroadcastWorkerUpdate(update)
|
||||||
|
|
||||||
resp := api.WorkerStateChange{}
|
resp := api.WorkerStateChange{}
|
||||||
|
@ -99,13 +99,12 @@ func TestWorkerSignOn(t *testing.T) {
|
|||||||
prevStatus := worker.Status
|
prevStatus := worker.Status
|
||||||
|
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: "Lazy Boi",
|
Nickname: "Lazy Boi",
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusStarting,
|
Status: api.WorkerStatusStarting,
|
||||||
StatusRequested: nil,
|
Updated: worker.UpdatedAt,
|
||||||
Updated: worker.UpdatedAt,
|
Version: "3.0-testing",
|
||||||
Version: "3.0-testing",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mf.persistence.EXPECT().SaveWorker(gomock.Any(), &worker).Return(nil)
|
mf.persistence.EXPECT().SaveWorker(gomock.Any(), &worker).Return(nil)
|
||||||
@ -206,13 +205,12 @@ func TestWorkerStateChanged(t *testing.T) {
|
|||||||
|
|
||||||
// Expect a broadcast of the change
|
// Expect a broadcast of the change
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Nickname: worker.Name,
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusAwake,
|
Status: api.WorkerStatusAwake,
|
||||||
StatusRequested: nil,
|
Updated: worker.UpdatedAt,
|
||||||
Updated: worker.UpdatedAt,
|
Version: worker.Software,
|
||||||
Version: worker.Software,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Expect the Worker to be saved with the new status
|
// Expect the Worker to be saved with the new status
|
||||||
|
@ -22,8 +22,10 @@ func NewWorkerUpdate(worker *persistence.Worker) api.SocketIOWorkerUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if worker.StatusRequested != "" {
|
if worker.StatusRequested != "" {
|
||||||
workerUpdate.StatusRequested = &worker.StatusRequested
|
workerUpdate.StatusChange = &api.WorkerStatusChangeRequest{
|
||||||
workerUpdate.LazyStatusRequest = &worker.LazyStatusRequest
|
Status: worker.StatusRequested,
|
||||||
|
IsLazy: worker.LazyStatusRequest,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return workerUpdate
|
return workerUpdate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user