diff --git a/internal/manager/api_impl/worker_mgt.go b/internal/manager/api_impl/worker_mgt.go index 6b305317..c1f8ab30 100644 --- a/internal/manager/api_impl/worker_mgt.go +++ b/internal/manager/api_impl/worker_mgt.go @@ -352,8 +352,15 @@ func (f *Flamenco) CreateWorkerCluster(e echo.Context) error { } // Convert to persistence layer model. + var clusterUUID string + if apiCluster.Id != nil && *apiCluster.Id != "" { + clusterUUID = *apiCluster.Id + } else { + clusterUUID = uuid.New() + } + dbCluster := persistence.WorkerCluster{ - UUID: apiCluster.Id, + UUID: clusterUUID, Name: apiCluster.Name, } if apiCluster.Description != nil { @@ -368,7 +375,7 @@ func (f *Flamenco) CreateWorkerCluster(e echo.Context) error { // TODO: SocketIO broadcast of cluster creation. - return e.NoContent(http.StatusNoContent) + return e.JSON(http.StatusOK, workerClusterDBtoAPI(dbCluster)) } func workerSummary(w persistence.Worker) api.WorkerSummary { @@ -412,8 +419,10 @@ func workerDBtoAPI(w persistence.Worker) api.Worker { } func workerClusterDBtoAPI(wc persistence.WorkerCluster) api.WorkerCluster { + uuid := wc.UUID // Take a copy for safety. + apiCluster := api.WorkerCluster{ - Id: wc.UUID, + Id: &uuid, Name: wc.Name, } if len(wc.Description) > 0 { diff --git a/internal/manager/api_impl/worker_mgt_test.go b/internal/manager/api_impl/worker_mgt_test.go index 60c1521c..f914121d 100644 --- a/internal/manager/api_impl/worker_mgt_test.go +++ b/internal/manager/api_impl/worker_mgt_test.go @@ -271,7 +271,7 @@ func TestWorkerClusterCRUDHappyFlow(t *testing.T) { // Create a cluster. UUID := "18d9234e-5135-458f-a1ba-a350c3d4e837" apiCluster := api.WorkerCluster{ - Id: UUID, + Id: &UUID, Name: "ʻO nā manu ʻino", Description: ptr("Ke aloha"), } @@ -284,7 +284,7 @@ func TestWorkerClusterCRUDHappyFlow(t *testing.T) { // TODO: expect SocketIO broadcast of the cluster creation. echo := mf.prepareMockedJSONRequest(apiCluster) require.NoError(t, mf.flamenco.CreateWorkerCluster(echo)) - assertResponseNoContent(t, echo) + assertResponseJSON(t, echo, http.StatusOK, &apiCluster) // Fetch the cluster mf.persistence.EXPECT().FetchWorkerCluster(gomock.Any(), UUID).Return(&expectDBCluster, nil) @@ -295,7 +295,7 @@ func TestWorkerClusterCRUDHappyFlow(t *testing.T) { // Update & save. newUUID := "60442762-83d3-4fc3-bf75-6ab5799cdbaa" newAPICluster := api.WorkerCluster{ - Id: newUUID, // Intentionally change the UUID. This should just be ignored. + Id: &newUUID, // Intentionally change the UUID. This should just be ignored. Name: "updated name", } expectNewDBCluster := persistence.WorkerCluster{