Manager: allow creation of worker clusters without UUID
This commit is contained in:
parent
f5ab2bb4c2
commit
10d7e7e203
@ -352,8 +352,15 @@ func (f *Flamenco) CreateWorkerCluster(e echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert to persistence layer model.
|
// Convert to persistence layer model.
|
||||||
|
var clusterUUID string
|
||||||
|
if apiCluster.Id != nil && *apiCluster.Id != "" {
|
||||||
|
clusterUUID = *apiCluster.Id
|
||||||
|
} else {
|
||||||
|
clusterUUID = uuid.New()
|
||||||
|
}
|
||||||
|
|
||||||
dbCluster := persistence.WorkerCluster{
|
dbCluster := persistence.WorkerCluster{
|
||||||
UUID: apiCluster.Id,
|
UUID: clusterUUID,
|
||||||
Name: apiCluster.Name,
|
Name: apiCluster.Name,
|
||||||
}
|
}
|
||||||
if apiCluster.Description != nil {
|
if apiCluster.Description != nil {
|
||||||
@ -368,7 +375,7 @@ func (f *Flamenco) CreateWorkerCluster(e echo.Context) error {
|
|||||||
|
|
||||||
// TODO: SocketIO broadcast of cluster creation.
|
// 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 {
|
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 {
|
func workerClusterDBtoAPI(wc persistence.WorkerCluster) api.WorkerCluster {
|
||||||
|
uuid := wc.UUID // Take a copy for safety.
|
||||||
|
|
||||||
apiCluster := api.WorkerCluster{
|
apiCluster := api.WorkerCluster{
|
||||||
Id: wc.UUID,
|
Id: &uuid,
|
||||||
Name: wc.Name,
|
Name: wc.Name,
|
||||||
}
|
}
|
||||||
if len(wc.Description) > 0 {
|
if len(wc.Description) > 0 {
|
||||||
|
@ -271,7 +271,7 @@ func TestWorkerClusterCRUDHappyFlow(t *testing.T) {
|
|||||||
// Create a cluster.
|
// Create a cluster.
|
||||||
UUID := "18d9234e-5135-458f-a1ba-a350c3d4e837"
|
UUID := "18d9234e-5135-458f-a1ba-a350c3d4e837"
|
||||||
apiCluster := api.WorkerCluster{
|
apiCluster := api.WorkerCluster{
|
||||||
Id: UUID,
|
Id: &UUID,
|
||||||
Name: "ʻO nā manu ʻino",
|
Name: "ʻO nā manu ʻino",
|
||||||
Description: ptr("Ke aloha"),
|
Description: ptr("Ke aloha"),
|
||||||
}
|
}
|
||||||
@ -284,7 +284,7 @@ func TestWorkerClusterCRUDHappyFlow(t *testing.T) {
|
|||||||
// TODO: expect SocketIO broadcast of the cluster creation.
|
// TODO: expect SocketIO broadcast of the cluster creation.
|
||||||
echo := mf.prepareMockedJSONRequest(apiCluster)
|
echo := mf.prepareMockedJSONRequest(apiCluster)
|
||||||
require.NoError(t, mf.flamenco.CreateWorkerCluster(echo))
|
require.NoError(t, mf.flamenco.CreateWorkerCluster(echo))
|
||||||
assertResponseNoContent(t, echo)
|
assertResponseJSON(t, echo, http.StatusOK, &apiCluster)
|
||||||
|
|
||||||
// Fetch the cluster
|
// Fetch the cluster
|
||||||
mf.persistence.EXPECT().FetchWorkerCluster(gomock.Any(), UUID).Return(&expectDBCluster, nil)
|
mf.persistence.EXPECT().FetchWorkerCluster(gomock.Any(), UUID).Return(&expectDBCluster, nil)
|
||||||
@ -295,7 +295,7 @@ func TestWorkerClusterCRUDHappyFlow(t *testing.T) {
|
|||||||
// Update & save.
|
// Update & save.
|
||||||
newUUID := "60442762-83d3-4fc3-bf75-6ab5799cdbaa"
|
newUUID := "60442762-83d3-4fc3-bf75-6ab5799cdbaa"
|
||||||
newAPICluster := api.WorkerCluster{
|
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",
|
Name: "updated name",
|
||||||
}
|
}
|
||||||
expectNewDBCluster := persistence.WorkerCluster{
|
expectNewDBCluster := persistence.WorkerCluster{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user