Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
normalize requests at API level before validation (#4136)
Today we only normalize and validate requests at the client side, but only validate on the server side without normalizing first. This causes inconsistencies and issues around optional fields, such as publishers. ## Example before the fix: ``` # hello.json { "Job": { "Type": "batch", "Count": 1, "Tasks": [ { "Name": "main", "Engine": { "Type": "docker", "Params": { "Image": "ubuntu", "Parameters": ["echo", "hello"] } } } ] } } ``` ``` curl -X PUT localhost:1234/api/v1/orchestrator/jobs -H "Content-Type: application/json" -d @hello.json { "error": "code=400, message=task main validation failed: publisher validation failed: nil spec config", "message": "task main validation failed: publisher validation failed: nil spec config" } ``` ## Example after the fix ``` → curl -X PUT localhost:1234/api/v1/orchestrator/jobs -H "Content-Type: application/json" -d @hello.json { "JobID": "j-26b215f9-582c-4374-80cb-fd079e73fc37", "EvaluationID": "36fd6f65-64fd-421b-a9ba-aaf86d876704", "Warnings": null } ``` ``` → bacalhau job describe j-26b215f9-582c-4374-80cb-fd079e73fc37 ID = j-26b215f9-582c-4374-80cb-fd079e73fc37 Name = j-26b215f9-582c-4374-80cb-fd079e73fc37 Namespace = default Type = batch State = Completed Count = 1 Created Time = 2024-06-25 09:14:40 Modified Time = 2024-06-25 09:14:43 Version = 0 Summary Completed = 1 Job History TIME REV. STATE TOPIC EVENT 2024-06-25 11:14:40 1 Pending Submission Job submitted 2024-06-25 11:14:40 2 Running 2024-06-25 11:14:43 3 Completed Executions ID NODE ID STATE DESIRED REV. CREATED MODIFIED COMMENT e-ad7cc59d n-6e8998ad Completed Stopped 6 14s ago 12s ago Accepted job Execution e-ad7cc59d History TIME REV. STATE TOPIC EVENT 2024-06-25 11:14:40 1 New 2024-06-25 11:14:40 2 AskForBid 2024-06-25 11:14:40 3 AskForBidAccepted Requesting Node Accepted job 2024-06-25 11:14:40 4 AskForBidAccepted 2024-06-25 11:14:40 5 BidAccepted 2024-06-25 11:14:43 6 Completed Standard Output hello ``` ``` → bacalhau job describe j-26b215f9-582c-4374-80cb-fd079e73fc37 --output json --pretty | jq ".Job" { "ID": "j-26b215f9-582c-4374-80cb-fd079e73fc37", "Name": "j-26b215f9-582c-4374-80cb-fd079e73fc37", "Namespace": "default", "Type": "batch", "Priority": 0, "Count": 1, "Constraints": [], "Meta": { "bacalhau.org/requester.id": "n-6e8998ad-e0b9-43e6-9ccb-47f05a780f4a" }, "Labels": {}, "Tasks": [ { "Name": "main", "Engine": { "Type": "docker", "Params": { "Image": "ubuntu", "Parameters": [ "echo", "hello" ] } }, "Publisher": { "Type": "" }, "Resources": {}, "Network": { "Type": "None" }, "Timeouts": { "TotalTimeout": 1800 } } ], "State": { "StateType": "Completed" }, "Version": 0, "Revision": 3, "CreateTime": 1719306880611865000, "ModifyTime": 1719306883073224000 } ``` Closes #3950
- Loading branch information