Adjust Go code for Nickname -> Name change
This fixes a bug where 'Worker undefined changed status' was logged in the web interface, as that was (back then incorrectly) `workerupdate.name`. Now that code is correct.
This commit is contained in:
parent
61aad21e99
commit
9ab41984ac
@ -111,10 +111,10 @@ func (f *Flamenco) RequestWorkerStatusChange(e echo.Context, workerUUID string)
|
|||||||
|
|
||||||
func workerSummary(w persistence.Worker) api.WorkerSummary {
|
func workerSummary(w persistence.Worker) api.WorkerSummary {
|
||||||
summary := api.WorkerSummary{
|
summary := api.WorkerSummary{
|
||||||
Id: w.UUID,
|
Id: w.UUID,
|
||||||
Nickname: w.Name,
|
Name: w.Name,
|
||||||
Status: w.Status,
|
Status: w.Status,
|
||||||
Version: w.Software,
|
Version: w.Software,
|
||||||
}
|
}
|
||||||
if w.StatusRequested != "" {
|
if w.StatusRequested != "" {
|
||||||
summary.StatusChange = &api.WorkerStatusChangeRequest{
|
summary.StatusChange = &api.WorkerStatusChangeRequest{
|
||||||
|
@ -38,16 +38,16 @@ 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,
|
Name: worker1.Name,
|
||||||
Status: worker1.Status,
|
Status: worker1.Status,
|
||||||
Version: worker1.Software,
|
Version: worker1.Software,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Id: worker2.UUID,
|
Id: worker2.UUID,
|
||||||
Nickname: worker2.Name,
|
Name: worker2.Name,
|
||||||
Status: worker2.Status,
|
Status: worker2.Status,
|
||||||
Version: worker2.Software,
|
Version: worker2.Software,
|
||||||
StatusChange: &api.WorkerStatusChangeRequest{
|
StatusChange: &api.WorkerStatusChangeRequest{
|
||||||
Status: worker2.StatusRequested,
|
Status: worker2.StatusRequested,
|
||||||
IsLazy: false,
|
IsLazy: false,
|
||||||
@ -92,10 +92,10 @@ 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: "дрон",
|
Name: "дрон",
|
||||||
Version: "3.0",
|
Version: "3.0",
|
||||||
Status: api.WorkerStatusAwake,
|
Status: api.WorkerStatusAwake,
|
||||||
},
|
},
|
||||||
IpAddress: "fe80::5054:ff:fede:2ad7",
|
IpAddress: "fe80::5054:ff:fede:2ad7",
|
||||||
Platform: "linux",
|
Platform: "linux",
|
||||||
@ -113,7 +113,7 @@ func TestFetchWorker(t *testing.T) {
|
|||||||
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: "дрон",
|
Name: "дрон",
|
||||||
Version: "3.0",
|
Version: "3.0",
|
||||||
Status: api.WorkerStatusAwake,
|
Status: api.WorkerStatusAwake,
|
||||||
StatusChange: &api.WorkerStatusChangeRequest{Status: requestedStatus},
|
StatusChange: &api.WorkerStatusChangeRequest{Status: requestedStatus},
|
||||||
@ -142,11 +142,11 @@ 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,
|
Name: worker.Name,
|
||||||
Status: prevStatus,
|
Status: prevStatus,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
Version: worker.Software,
|
Version: worker.Software,
|
||||||
StatusChange: &api.WorkerStatusChangeRequest{
|
StatusChange: &api.WorkerStatusChangeRequest{
|
||||||
Status: requestStatus,
|
Status: requestStatus,
|
||||||
IsLazy: true,
|
IsLazy: true,
|
||||||
@ -187,7 +187,7 @@ func TestRequestWorkerStatusChangeRevert(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,
|
Name: worker.Name,
|
||||||
Status: currentStatus,
|
Status: currentStatus,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
Version: worker.Software,
|
Version: worker.Software,
|
||||||
|
@ -39,7 +39,7 @@ func (f *Flamenco) RegisterWorker(e echo.Context) error {
|
|||||||
|
|
||||||
// TODO: validate the request, should at least have non-empty name, secret, and platform.
|
// TODO: validate the request, should at least have non-empty name, secret, and platform.
|
||||||
|
|
||||||
logger.Info().Str("nickname", req.Nickname).Msg("registering new worker")
|
logger.Info().Str("name", req.Name).Msg("registering new worker")
|
||||||
|
|
||||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.Secret), bcryptCost)
|
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.Secret), bcryptCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,7 +49,7 @@ func (f *Flamenco) RegisterWorker(e echo.Context) error {
|
|||||||
|
|
||||||
dbWorker := persistence.Worker{
|
dbWorker := persistence.Worker{
|
||||||
UUID: uuid.New(),
|
UUID: uuid.New(),
|
||||||
Name: req.Nickname,
|
Name: req.Name,
|
||||||
Secret: string(hashedPassword),
|
Secret: string(hashedPassword),
|
||||||
Platform: req.Platform,
|
Platform: req.Platform,
|
||||||
Address: e.RealIP(),
|
Address: e.RealIP(),
|
||||||
@ -65,7 +65,7 @@ func (f *Flamenco) RegisterWorker(e echo.Context) error {
|
|||||||
|
|
||||||
return e.JSON(http.StatusOK, &api.RegisteredWorker{
|
return e.JSON(http.StatusOK, &api.RegisteredWorker{
|
||||||
Uuid: dbWorker.UUID,
|
Uuid: dbWorker.UUID,
|
||||||
Nickname: dbWorker.Name,
|
Name: dbWorker.Name,
|
||||||
Address: dbWorker.Address,
|
Address: dbWorker.Address,
|
||||||
Platform: dbWorker.Platform,
|
Platform: dbWorker.Platform,
|
||||||
Software: dbWorker.Software,
|
Software: dbWorker.Software,
|
||||||
@ -116,7 +116,7 @@ func (f *Flamenco) workerUpdateAfterSignOn(e echo.Context, update api.SignOnJSON
|
|||||||
prevStatus := w.Status
|
prevStatus := w.Status
|
||||||
w.Status = api.WorkerStatusStarting
|
w.Status = api.WorkerStatusStarting
|
||||||
w.Address = e.RealIP()
|
w.Address = e.RealIP()
|
||||||
w.Name = update.Nickname
|
w.Name = update.Name
|
||||||
w.Software = update.SoftwareVersion
|
w.Software = update.SoftwareVersion
|
||||||
|
|
||||||
// Remove trailing spaces from task types, and convert to lower case.
|
// Remove trailing spaces from task types, and convert to lower case.
|
||||||
|
@ -161,7 +161,7 @@ func TestWorkerSignOn(t *testing.T) {
|
|||||||
|
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: "Lazy Boi",
|
Name: "Lazy Boi",
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusStarting,
|
Status: api.WorkerStatusStarting,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
@ -172,7 +172,7 @@ func TestWorkerSignOn(t *testing.T) {
|
|||||||
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
|
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
|
||||||
|
|
||||||
echo := mf.prepareMockedJSONRequest(api.WorkerSignOn{
|
echo := mf.prepareMockedJSONRequest(api.WorkerSignOn{
|
||||||
Nickname: "Lazy Boi",
|
Name: "Lazy Boi",
|
||||||
SoftwareVersion: "3.0-testing",
|
SoftwareVersion: "3.0-testing",
|
||||||
SupportedTaskTypes: []string{"testing", "sleeping", "snoozing"},
|
SupportedTaskTypes: []string{"testing", "sleeping", "snoozing"},
|
||||||
})
|
})
|
||||||
@ -213,7 +213,7 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) {
|
|||||||
prevStatus := api.WorkerStatusAwake
|
prevStatus := api.WorkerStatusAwake
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusOffline,
|
Status: api.WorkerStatusOffline,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
@ -238,7 +238,7 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
|
|||||||
|
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
PreviousStatus: ptr(api.WorkerStatusAwake),
|
PreviousStatus: ptr(api.WorkerStatusAwake),
|
||||||
Status: api.WorkerStatusOffline,
|
Status: api.WorkerStatusOffline,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
@ -274,7 +274,7 @@ 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,
|
Name: worker.Name,
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusAwake,
|
Status: api.WorkerStatusAwake,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
@ -312,7 +312,7 @@ func TestWorkerStateChangedAfterChangeRequest(t *testing.T) {
|
|||||||
// asleep but would do so via `offline → starting → asleep`.
|
// asleep but would do so via `offline → starting → asleep`.
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
PreviousStatus: ptr(api.WorkerStatusOffline),
|
PreviousStatus: ptr(api.WorkerStatusOffline),
|
||||||
Status: api.WorkerStatusStarting,
|
Status: api.WorkerStatusStarting,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
@ -345,7 +345,7 @@ func TestWorkerStateChangedAfterChangeRequest(t *testing.T) {
|
|||||||
// Expect a broadcast.
|
// Expect a broadcast.
|
||||||
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
PreviousStatus: ptr(api.WorkerStatusStarting),
|
PreviousStatus: ptr(api.WorkerStatusStarting),
|
||||||
Status: api.WorkerStatusAsleep,
|
Status: api.WorkerStatusAsleep,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
|
@ -62,7 +62,7 @@ func (ttc *TimeoutChecker) timeoutWorker(ctx context.Context, worker *persistenc
|
|||||||
// Broadcast worker change via SocketIO
|
// Broadcast worker change via SocketIO
|
||||||
ttc.broadcaster.BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
ttc.broadcaster.BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusError,
|
Status: api.WorkerStatusError,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
|
@ -55,7 +55,7 @@ func TestWorkerTimeout(t *testing.T) {
|
|||||||
prevStatus := worker.Status
|
prevStatus := worker.Status
|
||||||
mocks.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
mocks.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
PreviousStatus: &prevStatus,
|
PreviousStatus: &prevStatus,
|
||||||
Status: api.WorkerStatusError,
|
Status: api.WorkerStatusError,
|
||||||
Updated: persistedWorker.UpdatedAt,
|
Updated: persistedWorker.UpdatedAt,
|
||||||
|
@ -14,11 +14,11 @@ import (
|
|||||||
// the caller.
|
// the caller.
|
||||||
func NewWorkerUpdate(worker *persistence.Worker) api.SocketIOWorkerUpdate {
|
func NewWorkerUpdate(worker *persistence.Worker) api.SocketIOWorkerUpdate {
|
||||||
workerUpdate := api.SocketIOWorkerUpdate{
|
workerUpdate := api.SocketIOWorkerUpdate{
|
||||||
Id: worker.UUID,
|
Id: worker.UUID,
|
||||||
Nickname: worker.Name,
|
Name: worker.Name,
|
||||||
Status: worker.Status,
|
Status: worker.Status,
|
||||||
Version: worker.Software,
|
Version: worker.Software,
|
||||||
Updated: worker.UpdatedAt,
|
Updated: worker.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
if worker.StatusRequested != "" {
|
if worker.StatusRequested != "" {
|
||||||
|
@ -83,7 +83,7 @@ func register(ctx context.Context, cfg WorkerConfig, client FlamencoClient) Work
|
|||||||
secretKey := hex.EncodeToString(secret)
|
secretKey := hex.EncodeToString(secret)
|
||||||
|
|
||||||
req := api.RegisterWorkerJSONRequestBody{
|
req := api.RegisterWorkerJSONRequestBody{
|
||||||
Nickname: mustHostname(),
|
Name: mustHostname(),
|
||||||
Platform: runtime.GOOS,
|
Platform: runtime.GOOS,
|
||||||
Secret: secretKey,
|
Secret: secretKey,
|
||||||
SupportedTaskTypes: cfg.TaskTypes,
|
SupportedTaskTypes: cfg.TaskTypes,
|
||||||
@ -142,13 +142,13 @@ func signOn(ctx context.Context, cfg WorkerConfig, client FlamencoClient) (api.W
|
|||||||
logger := log.With().Str("manager", cfg.ManagerURL).Logger()
|
logger := log.With().Str("manager", cfg.ManagerURL).Logger()
|
||||||
|
|
||||||
req := api.SignOnJSONRequestBody{
|
req := api.SignOnJSONRequestBody{
|
||||||
Nickname: mustHostname(),
|
Name: mustHostname(),
|
||||||
SupportedTaskTypes: cfg.TaskTypes,
|
SupportedTaskTypes: cfg.TaskTypes,
|
||||||
SoftwareVersion: appinfo.ApplicationVersion,
|
SoftwareVersion: appinfo.ApplicationVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info().
|
logger.Info().
|
||||||
Str("nickname", req.Nickname).
|
Str("name", req.Name).
|
||||||
Str("softwareVersion", req.SoftwareVersion).
|
Str("softwareVersion", req.SoftwareVersion).
|
||||||
Interface("taskTypes", req.SupportedTaskTypes).
|
Interface("taskTypes", req.SupportedTaskTypes).
|
||||||
Msg("signing on at Manager")
|
Msg("signing on at Manager")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user