This is an automated email from the ASF dual-hosted git repository. DImuthuUpe pushed a commit to branch qos-addition in repository https://gitbox.apache.org/repos/asf/airavata.git
commit 0629846590a4b49fd1e043d03bd0cb0c64d2ae48 Author: DImuthuUpe <[email protected]> AuthorDate: Thu Nov 12 19:11:21 2026 -0500 Added support to configure qos for deployment and process --- api/application/dto/application.go | 4 ++++ api/application/model/deployment.go | 3 +++ dashboard/src/components/BatchJobConfigFields.tsx | 1 + dashboard/src/lib/types.ts | 1 + docs/api.md | 1 + docs/application.md | 2 +- docs/openapi.yaml | 2 ++ internal/db/migrations/0018_batch_job_config_qos.sql | 4 ++++ internal/mcp/client/client.gen.go | 2 ++ internal/mcp/estimate/estimate.go | 6 ++++-- internal/mcp/server/server_test.go | 6 +++--- internal/mcp/tools/applications/proposal.go | 2 +- internal/mcp/tools/processes/plan.go | 2 +- internal/orchestration/tasks/batch/slurm.go | 6 +++++- internal/orchestration/tasks/batch/slurm_test.go | 17 ++++++++++++++++- internal/slurmconv/convert.go | 3 +++ internal/slurmconv/render.go | 1 + internal/slurmconv/slurmconv_test.go | 8 ++++---- 18 files changed, 57 insertions(+), 14 deletions(-) diff --git a/api/application/dto/application.go b/api/application/dto/application.go index 3d33a94b07..10a846f47c 100644 --- a/api/application/dto/application.go +++ b/api/application/dto/application.go @@ -213,6 +213,7 @@ type BatchJobConfigRequest struct { CPUsPerGPU *string `json:"cpusPerGpu"` GPUsPerNode *int32 `json:"gpusPerNode"` Constraints *string `json:"constraints"` + QOS *string `json:"qos"` } // Validate implements httpx.Validator. @@ -243,6 +244,7 @@ type BatchJobConfigResponse struct { CPUsPerGPU *string `json:"cpusPerGpu"` GPUsPerNode *int32 `json:"gpusPerNode"` Constraints *string `json:"constraints"` + QOS *string `json:"qos"` } // ApplyBatchJobConfigRequest copies a request onto a config entity, preserving the @@ -265,6 +267,7 @@ func ApplyBatchJobConfigRequest(dst *model.BatchJobConfig, src *BatchJobConfigRe dst.CPUsPerGPU = src.CPUsPerGPU dst.GPUsPerNode = src.GPUsPerNode dst.Constraints = src.Constraints + dst.QOS = src.QOS } // ToBatchJobConfigResponse renders a config entity. @@ -289,6 +292,7 @@ func ToBatchJobConfigResponse(c *model.BatchJobConfig) *BatchJobConfigResponse { CPUsPerGPU: c.CPUsPerGPU, GPUsPerNode: c.GPUsPerNode, Constraints: c.Constraints, + QOS: c.QOS, } } diff --git a/api/application/model/deployment.go b/api/application/model/deployment.go index d493f5b14c..5d806c8357 100644 --- a/api/application/model/deployment.go +++ b/api/application/model/deployment.go @@ -60,6 +60,9 @@ type BatchJobConfig struct { // Constraints is a Slurm feature constraint expression, e.g. "gpu", "highmem". Constraints *string `gorm:"column:constraints;type:varchar(255)" json:"constraints,omitempty"` + // QOS is the Slurm quality of service the job is submitted under, e.g. "normal". + QOS *string `gorm:"column:qos;type:varchar(255)" json:"qos,omitempty"` + Allocation string `gorm:"column:allocation;type:varchar(255);not null" json:"allocation"` } diff --git a/dashboard/src/components/BatchJobConfigFields.tsx b/dashboard/src/components/BatchJobConfigFields.tsx index b4b5c5105d..cab65ade2b 100644 --- a/dashboard/src/components/BatchJobConfigFields.tsx +++ b/dashboard/src/components/BatchJobConfigFields.tsx @@ -27,6 +27,7 @@ const FIELDS: { key: keyof BatchJobConfigDraft; label: string; placeholder?: str { key: "cpusPerGpu", label: "CPUs per GPU" }, { key: "gres", label: "GRES", placeholder: "gpu:a100:1" }, { key: "constraints", label: "Constraints" }, + { key: "qos", label: "QOS", placeholder: "normal" }, ]; export function draftFrom(c: BatchJobConfig | null | undefined): BatchJobConfigDraft { diff --git a/dashboard/src/lib/types.ts b/dashboard/src/lib/types.ts index fb795beb9a..1f0e3c4f7f 100644 --- a/dashboard/src/lib/types.ts +++ b/dashboard/src/lib/types.ts @@ -277,6 +277,7 @@ export interface BatchJobConfig { cpusPerGpu?: string | null; gpusPerNode?: number | null; constraints?: string | null; + qos?: string | null; } export interface BatchDeployment { diff --git a/docs/api.md b/docs/api.md index 63f3e45234..c51eac2ff2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1226,6 +1226,7 @@ DEPLOYMENT_ID=$(curl -s -X POST localhost:9095/api/v1/slurm-deployments \ | `defaultBatchJobConfig.cpusPerGpu` | string \| null | optional | | `defaultBatchJobConfig.gpusPerNode` | integer \| null | optional | | `defaultBatchJobConfig.constraints` | string \| null | optional | +| `defaultBatchJobConfig.qos` | string \| null | optional | | `defaultPartition` | string \| null | optional | ```json diff --git a/docs/application.md b/docs/application.md index 98fabac53c..6c48296127 100644 --- a/docs/application.md +++ b/docs/application.md @@ -117,7 +117,7 @@ A deployment makes a template runnable on one compute resource. For the Slurm ba | `templateId` | The template being deployed. | | `slurmClusterId` | The cluster it runs on. This names only the machine. The account and SSH key a run submits under come from a [cluster config](api.md#slurm-cluster-configs) that the run chooses. | | `slurmRunSection` | The commands that run the application: module loads, the program invocation and any cleanup. It is a Jinja template ([pongo2](https://github.com/flosch/pongo2)). | -| `defaultBatchJobConfig` | The resource request a run starts from: wall time, allocation, nodes, CPUs, memory, GPUs and constraints. A run copies it and may change any of it. | +| `defaultBatchJobConfig` | The resource request a run starts from: wall time, allocation, nodes, CPUs, memory, GPUs, constraints and QOS. A run copies it and may change any of it. | | `defaultPartition` | The Slurm partition to submit to. | ### The run section diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 3639353bb7..75b9354196 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -3906,6 +3906,7 @@ components: cpusPerGpu: { type: [string, "null"] } gpusPerNode: { type: [integer, "null"], format: int32 } constraints: { type: [string, "null"] } + qos: { type: [string, "null"], description: "Slurm quality of service (`--qos`)." } required: [wallTimeMinutes, allocation] BatchJobConfigResponse: @@ -3927,6 +3928,7 @@ components: cpusPerGpu: { type: [string, "null"] } gpusPerNode: { type: [integer, "null"], format: int32 } constraints: { type: [string, "null"] } + qos: { type: [string, "null"], description: "Slurm quality of service (`--qos`)." } required: [batchJobConfigId, wallTimeMinutes, allocation] BatchDeploymentRequest: diff --git a/internal/db/migrations/0018_batch_job_config_qos.sql b/internal/db/migrations/0018_batch_job_config_qos.sql new file mode 100644 index 0000000000..0831d64412 --- /dev/null +++ b/internal/db/migrations/0018_batch_job_config_qos.sql @@ -0,0 +1,4 @@ +-- Let a batch job config carry a Slurm quality of service. The DDL is what AutoMigrate +-- emits for BatchJobConfig.QOS — see TestBaselineMigrationMatchesAutoMigrate. + +ALTER TABLE "batch_job_configs" ADD COLUMN "qos" varchar(255); diff --git a/internal/mcp/client/client.gen.go b/internal/mcp/client/client.gen.go index 9ca90453df..29e268108a 100644 --- a/internal/mcp/client/client.gen.go +++ b/internal/mcp/client/client.gen.go @@ -668,6 +668,7 @@ type BatchJobConfigRequest struct { Nodes *int32 `json:"nodes,omitempty"` Ntasks *int32 `json:"ntasks,omitempty"` NtasksPerNode *int32 `json:"ntasksPerNode,omitempty"` + Qos *string `json:"qos,omitempty"` WallTimeMinutes int64 `json:"wallTimeMinutes"` } @@ -688,6 +689,7 @@ type BatchJobConfigResponse struct { Nodes *int32 `json:"nodes,omitempty"` Ntasks *int32 `json:"ntasks,omitempty"` NtasksPerNode *int32 `json:"ntasksPerNode,omitempty"` + Qos *string `json:"qos,omitempty"` WallTimeMinutes int64 `json:"wallTimeMinutes"` } diff --git a/internal/mcp/estimate/estimate.go b/internal/mcp/estimate/estimate.go index a6fcbd3af0..edb2d5f74c 100644 --- a/internal/mcp/estimate/estimate.go +++ b/internal/mcp/estimate/estimate.go @@ -46,6 +46,7 @@ type Request struct { CpusPerGpu *string `json:"cpus_per_gpu,omitempty"` Gres *string `json:"gres,omitempty"` Constraints *string `json:"constraints,omitempty"` + Qos *string `json:"qos,omitempty"` } // FromResponse copies a stored job config. @@ -56,7 +57,7 @@ func FromResponse(c *client.BatchJobConfigResponse) Request { return Request{WallTimeMinutes: c.WallTimeMinutes, Allocation: c.Allocation, Nodes: c.Nodes, Ntasks: c.Ntasks, NtasksPerNode: c.NtasksPerNode, Cpus: c.Cpus, CpusPerTask: c.CpusPerTask, Mem: c.Mem, MemPerCpu: c.MemPerCpu, Gpus: c.Gpus, GpusPerNode: c.GpusPerNode, MemPerGpu: c.MemPerGpu, CpusPerGpu: c.CpusPerGpu, Gres: c.Gres, - Constraints: c.Constraints} + Constraints: c.Constraints, Qos: c.Qos} } // API converts to the request body airavata-server takes. @@ -64,7 +65,7 @@ func (r Request) API() client.BatchJobConfigRequest { return client.BatchJobConfigRequest{WallTimeMinutes: r.WallTimeMinutes, Allocation: r.Allocation, Nodes: r.Nodes, Ntasks: r.Ntasks, NtasksPerNode: r.NtasksPerNode, Cpus: r.Cpus, CpusPerTask: r.CpusPerTask, Mem: r.Mem, MemPerCpu: r.MemPerCpu, Gpus: r.Gpus, GpusPerNode: r.GpusPerNode, MemPerGpu: r.MemPerGpu, - CpusPerGpu: r.CpusPerGpu, Gres: r.Gres, Constraints: r.Constraints} + CpusPerGpu: r.CpusPerGpu, Gres: r.Gres, Constraints: r.Constraints, Qos: r.Qos} } // Overlay returns r with every field set in o replacing r's. @@ -98,6 +99,7 @@ func (r Request) Overlay(o Request) Request { pickS(&r.CpusPerGpu, o.CpusPerGpu) pickS(&r.Gres, o.Gres) pickS(&r.Constraints, o.Constraints) + pickS(&r.Qos, o.Qos) return r } diff --git a/internal/mcp/server/server_test.go b/internal/mcp/server/server_test.go index f555e1910c..97e794d4e9 100644 --- a/internal/mcp/server/server_test.go +++ b/internal/mcp/server/server_test.go @@ -491,17 +491,17 @@ func TestPolicyConfirmListGatesReadTool(t *testing.T) { func TestConvertScriptPreview(t *testing.T) { h := newHarness(t, writePolicy(), nil) - script := "#!/bin/bash\n#SBATCH -J md\n#SBATCH -p gpu\n#SBATCH -t 02:00:00\n#SBATCH -A abc123\n#SBATCH -N 1\n#SBATCH --qos=high\nmodule load gromacs/2024\ngmx mdrun -s topol.tpr\n" + script := "#!/bin/bash\n#SBATCH -J md\n#SBATCH -p gpu\n#SBATCH -t 02:00:00\n#SBATCH -A abc123\n#SBATCH -N 1\n#SBATCH --exclusive\nmodule load gromacs/2024\ngmx mdrun -s topol.tpr\n" out := h.mustCall("convert_sbatch_script", map[string]any{"script": script, "cluster_id": clusterID, "inputs": []any{map[string]any{"name": "tpr", "type": "FILE", "literal": "topol.tpr"}}}) if out["registrable"] != false || out["proposal_handle"] != nil { - t.Errorf("a script with --qos was offered for registration: %v", out["problems"]) + t.Errorf("a script with --exclusive was offered for registration: %v", out["problems"]) } if out["round_trip_diff"] == "" { t.Error("no round-trip diff") } - clean := strings.Replace(script, "#SBATCH --qos=high\n", "", 1) + clean := strings.Replace(script, "#SBATCH --exclusive\n", "", 1) out = h.mustCall("convert_sbatch_script", map[string]any{"script": clean, "cluster_id": clusterID, "inputs": []any{map[string]any{"name": "tpr", "type": "FILE", "literal": "topol.tpr"}}}) if out["proposal_handle"] == nil { diff --git a/internal/mcp/tools/applications/proposal.go b/internal/mcp/tools/applications/proposal.go index fcb95f629a..730175f70b 100644 --- a/internal/mcp/tools/applications/proposal.go +++ b/internal/mcp/tools/applications/proposal.go @@ -251,5 +251,5 @@ func FromJobConfig(j slurmconv.JobConfig) estimate.Request { return estimate.Request{WallTimeMinutes: j.WallTimeMinutes, Allocation: j.Allocation, Nodes: j.Nodes, Ntasks: j.Ntasks, NtasksPerNode: j.NtasksPerNode, Cpus: j.Cpus, CpusPerTask: j.CpusPerTask, Mem: j.Mem, MemPerCpu: j.MemPerCpu, Gpus: j.Gpus, GpusPerNode: j.GpusPerNode, MemPerGpu: j.MemPerGpu, CpusPerGpu: j.CpusPerGpu, Gres: j.Gres, - Constraints: j.Constraints} + Constraints: j.Constraints, Qos: j.Qos} } diff --git a/internal/mcp/tools/processes/plan.go b/internal/mcp/tools/processes/plan.go index 24b84ea3ec..a10936d002 100644 --- a/internal/mcp/tools/processes/plan.go +++ b/internal/mcp/tools/processes/plan.go @@ -278,7 +278,7 @@ func buildPlan(ctx context.Context, d *tk.Deps, dep *client.BatchDeploymentRespo if strings.TrimSpace(plan.Job.Allocation) == "" { problems = append(problems, "no allocation (Slurm account): pass resources.allocation") } - for _, s := range []*string{plan.Job.Mem, plan.Job.Gres, plan.Job.Constraints, plan.Job.MemPerCpu, plan.Job.MemPerGpu, plan.Job.CpusPerGpu} { + for _, s := range []*string{plan.Job.Mem, plan.Job.Gres, plan.Job.Constraints, plan.Job.Qos, plan.Job.MemPerCpu, plan.Job.MemPerGpu, plan.Job.CpusPerGpu} { if s != nil && strings.ContainsAny(*s, "\r\n") { problems = append(problems, "resource values must be on one line") } diff --git a/internal/orchestration/tasks/batch/slurm.go b/internal/orchestration/tasks/batch/slurm.go index 585ef9761d..63bcaf9133 100644 --- a/internal/orchestration/tasks/batch/slurm.go +++ b/internal/orchestration/tasks/batch/slurm.go @@ -89,6 +89,9 @@ const slurmScriptTemplate = `#!/bin/bash {% if constraints %} #SBATCH --constraint={{ constraints }} {% endif %} +{% if qos %} +#SBATCH --qos={{ qos }} +{% endif %} echo "Airavata process {{ process_id }} starting on $(hostname) at $(date)" cd {{ work_dir_quoted }} || exit 1 @@ -165,6 +168,7 @@ func buildSlurmScript( "mem_per_gpu": optional(jobConfig.MemPerGPU), "cpus_per_gpu": optional(jobConfig.CPUsPerGPU), "constraints": optional(jobConfig.Constraints), + "qos": optional(jobConfig.QOS), "inputs": inputs, "outputs": outputs, @@ -187,7 +191,7 @@ func buildSlurmScript( // are checked here rather than escaped, because none of them has any business // spanning lines. for _, key := range []string{"job_name", "work_dir", "stdout_file", "stderr_file", - "wall_time", "account", "partition", "gres", "constraints", "mem", "mem_per_cpu", + "wall_time", "account", "partition", "gres", "constraints", "qos", "mem", "mem_per_cpu", "mem_per_gpu", "cpus_per_gpu"} { if value, ok := ctx[key].(string); ok && strings.ContainsAny(value, "\r\n") { return "", fmt.Errorf("process %s: %s contains a line break, which cannot be written into an SBATCH directive", process.ID, key) diff --git a/internal/orchestration/tasks/batch/slurm_test.go b/internal/orchestration/tasks/batch/slurm_test.go index ff1ef89ff1..067e49d945 100644 --- a/internal/orchestration/tasks/batch/slurm_test.go +++ b/internal/orchestration/tasks/batch/slurm_test.go @@ -134,7 +134,7 @@ func TestBuildSlurmScript(t *testing.T) { // A resource the run did not ask for leaves no directive behind, and no blank line // where one would have been. - for _, unwanted := range []string{"--ntasks", "--mem-per-cpu", "--gres", "--constraint", "\n\n\n"} { + for _, unwanted := range []string{"--ntasks", "--mem-per-cpu", "--gres", "--constraint", "--qos", "\n\n\n"} { if strings.Contains(script, unwanted) { t.Errorf("script should not contain %q\n---\n%s", unwanted, script) } @@ -296,3 +296,18 @@ func TestBuildSlurmScriptSourcesTheLinkEnvFile(t *testing.T) { t.Errorf("script carries a token\n---\n%s", script) } } + +// A QOS on the run's resource request becomes a --qos directive. +func TestBuildSlurmScriptQOS(t *testing.T) { + process, deployment, template, clusterConfig := scriptFixture() + qos := "high" + process.BatchProcess.BatchJobConfig.QOS = &qos + + script, err := buildSlurmScript(process, deployment, template, clusterConfig, &execution.GlobalJobConfigs{}, nil, "") + if err != nil { + t.Fatalf("buildSlurmScript: %v", err) + } + if !strings.Contains(script, "#SBATCH --qos=high\n") { + t.Errorf("script is missing the qos directive\n---\n%s", script) + } +} diff --git a/internal/slurmconv/convert.go b/internal/slurmconv/convert.go index 1160ad14ea..61bd4f2e2d 100644 --- a/internal/slurmconv/convert.go +++ b/internal/slurmconv/convert.go @@ -44,6 +44,7 @@ type JobConfig struct { CpusPerGpu *string `json:"cpusPerGpu,omitempty"` Gres *string `json:"gres,omitempty"` Constraints *string `json:"constraints,omitempty"` + Qos *string `json:"qos,omitempty"` } type ArrayRange struct { @@ -209,6 +210,8 @@ func Convert(s *Script) *Conversion { setStr(o, &jc.Gres) case "constraint": setStr(o, &jc.Constraints) + case "qos": + setStr(o, &jc.Qos) case "gpus": gpus = &s.Options[i] case "gpus-per-node": diff --git a/internal/slurmconv/render.go b/internal/slurmconv/render.go index 16014ac01c..f45558a543 100644 --- a/internal/slurmconv/render.go +++ b/internal/slurmconv/render.go @@ -73,6 +73,7 @@ func Render(c *Conversion) string { str("mem-per-gpu", jc.MemPerGpu) str("cpus-per-gpu", jc.CpusPerGpu) str("constraint", jc.Constraints) + str("qos", jc.Qos) for _, o := range c.Unsupported { name := "--" + o.Name if o.Unknown { diff --git a/internal/slurmconv/slurmconv_test.go b/internal/slurmconv/slurmconv_test.go index 5d1234efa8..5ac135aff6 100644 --- a/internal/slurmconv/slurmconv_test.go +++ b/internal/slurmconv/slurmconv_test.go @@ -233,7 +233,7 @@ srun ./app if got := names(c.Replaced); !reflect.DeepEqual(got, []string{"job-name", "output", "error", "chdir", "mail-user", "mail-type"}) { t.Fatalf("replaced %v", got) } - if got := names(c.Unsupported); !reflect.DeepEqual(got, []string{"qos", "exclusive", "signal"}) { + if got := names(c.Unsupported); !reflect.DeepEqual(got, []string{"exclusive", "signal"}) { t.Fatalf("unsupported %v", got) } if len(c.Mapped)+len(c.Replaced)+len(c.Unsupported) != len(s.Options) { @@ -243,7 +243,7 @@ srun ./app if jc.WallTimeMinutes != 1440 || jc.Allocation != "proj" || c.Partition != "gpu" || *jc.Nodes != 2 || *jc.Ntasks != 8 || *jc.NtasksPerNode != 4 || *jc.CpusPerTask != 2 || *jc.Mem != "16G" || *jc.MemPerCpu != "2G" || *jc.MemPerGpu != "8G" || *jc.CpusPerGpu != "4" || *jc.Gres != "gpu:1" || - *jc.Constraints != "skylake" || *jc.Gpus != 4 || *jc.GpusPerNode != 2 { + *jc.Constraints != "skylake" || *jc.Gpus != 4 || *jc.GpusPerNode != 2 || *jc.Qos != "high" { t.Fatalf("job config %+v", jc) } if c.Registrable { @@ -416,7 +416,7 @@ run_fold --in protein.fa } func TestRenderUnsupportedAndInputs(t *testing.T) { - c := Convert(mustParse(t, "#!/bin/bash\n#SBATCH -t 5\n#SBATCH -A a\n#SBATCH --qos=\"long q\"\n#SBATCH --exclusive\n#SBATCH -Z9\n\nrun --in data.txt\n")) + c := Convert(mustParse(t, "#!/bin/bash\n#SBATCH -t 5\n#SBATCH -A a\n#SBATCH --reservation=\"long q\"\n#SBATCH --exclusive\n#SBATCH -Z9\n\nrun --in data.txt\n")) if _, err := ApplyInputs(c, []InputSuggestion{{Name: "data", Type: "FILE", Literal: "data.txt"}}); err != nil { t.Fatal(err) } @@ -424,7 +424,7 @@ func TestRenderUnsupportedAndInputs(t *testing.T) { want := `#!/bin/bash #SBATCH --time=00:05:00 #SBATCH --account=a -#SBATCH --qos="long q" # not registrable +#SBATCH --reservation="long q" # not registrable #SBATCH --exclusive # not registrable #SBATCH -Z9 # not registrable
