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:
Sybren A. Stüvel 2022-06-16 11:02:59 +02:00
parent 61aad21e99
commit 9ab41984ac
8 changed files with 44 additions and 44 deletions

View File

@ -111,10 +111,10 @@ func (f *Flamenco) RequestWorkerStatusChange(e echo.Context, workerUUID string)
func workerSummary(w persistence.Worker) api.WorkerSummary {
summary := api.WorkerSummary{
Id: w.UUID,
Nickname: w.Name,
Status: w.Status,
Version: w.Software,
Id: w.UUID,
Name: w.Name,
Status: w.Status,
Version: w.Software,
}
if w.StatusRequested != "" {
summary.StatusChange = &api.WorkerStatusChangeRequest{

View File

@ -38,16 +38,16 @@ func TestFetchWorkers(t *testing.T) {
workers := api.WorkerList{
Workers: []api.WorkerSummary{
{
Id: worker1.UUID,
Nickname: worker1.Name,
Status: worker1.Status,
Version: worker1.Software,
Id: worker1.UUID,
Name: worker1.Name,
Status: worker1.Status,
Version: worker1.Software,
},
{
Id: worker2.UUID,
Nickname: worker2.Name,
Status: worker2.Status,
Version: worker2.Software,
Id: worker2.UUID,
Name: worker2.Name,
Status: worker2.Status,
Version: worker2.Software,
StatusChange: &api.WorkerStatusChangeRequest{
Status: worker2.StatusRequested,
IsLazy: false,
@ -92,10 +92,10 @@ func TestFetchWorker(t *testing.T) {
assert.NoError(t, err)
assertResponseJSON(t, echo, http.StatusOK, api.Worker{
WorkerSummary: api.WorkerSummary{
Id: workerUUID,
Nickname: "дрон",
Version: "3.0",
Status: api.WorkerStatusAwake,
Id: workerUUID,
Name: "дрон",
Version: "3.0",
Status: api.WorkerStatusAwake,
},
IpAddress: "fe80::5054:ff:fede:2ad7",
Platform: "linux",
@ -113,7 +113,7 @@ func TestFetchWorker(t *testing.T) {
assertResponseJSON(t, echo, http.StatusOK, api.Worker{
WorkerSummary: api.WorkerSummary{
Id: workerUUID,
Nickname: "дрон",
Name: "дрон",
Version: "3.0",
Status: api.WorkerStatusAwake,
StatusChange: &api.WorkerStatusChangeRequest{Status: requestedStatus},
@ -142,11 +142,11 @@ func TestRequestWorkerStatusChange(t *testing.T) {
// Expect a broadcast of the change
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Status: prevStatus,
Updated: worker.UpdatedAt,
Version: worker.Software,
Id: worker.UUID,
Name: worker.Name,
Status: prevStatus,
Updated: worker.UpdatedAt,
Version: worker.Software,
StatusChange: &api.WorkerStatusChangeRequest{
Status: requestStatus,
IsLazy: true,
@ -187,7 +187,7 @@ func TestRequestWorkerStatusChangeRevert(t *testing.T) {
// Expect a broadcast of the change
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
Status: currentStatus,
Updated: worker.UpdatedAt,
Version: worker.Software,

View File

@ -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.
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)
if err != nil {
@ -49,7 +49,7 @@ func (f *Flamenco) RegisterWorker(e echo.Context) error {
dbWorker := persistence.Worker{
UUID: uuid.New(),
Name: req.Nickname,
Name: req.Name,
Secret: string(hashedPassword),
Platform: req.Platform,
Address: e.RealIP(),
@ -65,7 +65,7 @@ func (f *Flamenco) RegisterWorker(e echo.Context) error {
return e.JSON(http.StatusOK, &api.RegisteredWorker{
Uuid: dbWorker.UUID,
Nickname: dbWorker.Name,
Name: dbWorker.Name,
Address: dbWorker.Address,
Platform: dbWorker.Platform,
Software: dbWorker.Software,
@ -116,7 +116,7 @@ func (f *Flamenco) workerUpdateAfterSignOn(e echo.Context, update api.SignOnJSON
prevStatus := w.Status
w.Status = api.WorkerStatusStarting
w.Address = e.RealIP()
w.Name = update.Nickname
w.Name = update.Name
w.Software = update.SoftwareVersion
// Remove trailing spaces from task types, and convert to lower case.

View File

@ -161,7 +161,7 @@ func TestWorkerSignOn(t *testing.T) {
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: "Lazy Boi",
Name: "Lazy Boi",
PreviousStatus: &prevStatus,
Status: api.WorkerStatusStarting,
Updated: worker.UpdatedAt,
@ -172,7 +172,7 @@ func TestWorkerSignOn(t *testing.T) {
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
echo := mf.prepareMockedJSONRequest(api.WorkerSignOn{
Nickname: "Lazy Boi",
Name: "Lazy Boi",
SoftwareVersion: "3.0-testing",
SupportedTaskTypes: []string{"testing", "sleeping", "snoozing"},
})
@ -213,7 +213,7 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) {
prevStatus := api.WorkerStatusAwake
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: &prevStatus,
Status: api.WorkerStatusOffline,
Updated: worker.UpdatedAt,
@ -238,7 +238,7 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: ptr(api.WorkerStatusAwake),
Status: api.WorkerStatusOffline,
Updated: worker.UpdatedAt,
@ -274,7 +274,7 @@ func TestWorkerStateChanged(t *testing.T) {
// Expect a broadcast of the change
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: &prevStatus,
Status: api.WorkerStatusAwake,
Updated: worker.UpdatedAt,
@ -312,7 +312,7 @@ func TestWorkerStateChangedAfterChangeRequest(t *testing.T) {
// asleep but would do so via `offline → starting → asleep`.
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: ptr(api.WorkerStatusOffline),
Status: api.WorkerStatusStarting,
Updated: worker.UpdatedAt,
@ -345,7 +345,7 @@ func TestWorkerStateChangedAfterChangeRequest(t *testing.T) {
// Expect a broadcast.
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: ptr(api.WorkerStatusStarting),
Status: api.WorkerStatusAsleep,
Updated: worker.UpdatedAt,

View File

@ -62,7 +62,7 @@ func (ttc *TimeoutChecker) timeoutWorker(ctx context.Context, worker *persistenc
// Broadcast worker change via SocketIO
ttc.broadcaster.BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: &prevStatus,
Status: api.WorkerStatusError,
Updated: worker.UpdatedAt,

View File

@ -55,7 +55,7 @@ func TestWorkerTimeout(t *testing.T) {
prevStatus := worker.Status
mocks.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Name: worker.Name,
PreviousStatus: &prevStatus,
Status: api.WorkerStatusError,
Updated: persistedWorker.UpdatedAt,

View File

@ -14,11 +14,11 @@ import (
// the caller.
func NewWorkerUpdate(worker *persistence.Worker) api.SocketIOWorkerUpdate {
workerUpdate := api.SocketIOWorkerUpdate{
Id: worker.UUID,
Nickname: worker.Name,
Status: worker.Status,
Version: worker.Software,
Updated: worker.UpdatedAt,
Id: worker.UUID,
Name: worker.Name,
Status: worker.Status,
Version: worker.Software,
Updated: worker.UpdatedAt,
}
if worker.StatusRequested != "" {

View File

@ -83,7 +83,7 @@ func register(ctx context.Context, cfg WorkerConfig, client FlamencoClient) Work
secretKey := hex.EncodeToString(secret)
req := api.RegisterWorkerJSONRequestBody{
Nickname: mustHostname(),
Name: mustHostname(),
Platform: runtime.GOOS,
Secret: secretKey,
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()
req := api.SignOnJSONRequestBody{
Nickname: mustHostname(),
Name: mustHostname(),
SupportedTaskTypes: cfg.TaskTypes,
SoftwareVersion: appinfo.ApplicationVersion,
}
logger.Info().
Str("nickname", req.Nickname).
Str("name", req.Name).
Str("softwareVersion", req.SoftwareVersion).
Interface("taskTypes", req.SupportedTaskTypes).
Msg("signing on at Manager")