Skip to content

Commit 00161a6

Browse files
authored
Merge pull request #248 from DiamondLightSource/slurm_rest_api_v40
Upgrade to Slurm REST API v0.0.40
2 parents 22fcd05 + 3d56a47 commit 00161a6

File tree

5 files changed

+3453
-602
lines changed

5 files changed

+3453
-602
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jmx = "zocalo.configuration.plugin_jmx:JMX"
6868
logging = "zocalo.configuration.plugin_logging:Logging"
6969
rabbitmqapi = "zocalo.configuration.plugin_rabbitmqapi:RabbitAPI"
7070
slurm = "zocalo.configuration.plugin_slurm:Slurm"
71+
iris = "zocalo.configuration.plugin_slurm:Slurm"
7172
smtp = "zocalo.configuration.plugin_smtp:SMTP"
7273
storage = "zocalo.configuration.plugin_storage:Storage"
7374

src/zocalo/util/slurm/__init__.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import requests
88

9-
import zocalo.configuration
9+
from zocalo.configuration import Configuration
1010

1111
from . import models
1212

@@ -15,7 +15,7 @@ class SlurmRestApi:
1515
def __init__(
1616
self,
1717
url: str,
18-
version: str = "v0.0.36",
18+
version: str = "v0.0.40",
1919
user_name: str | None = None,
2020
user_token: str | pathlib.Path | None = None,
2121
):
@@ -35,12 +35,13 @@ def __init__(
3535
self.session.headers["X-SLURM-USER-TOKEN"] = self.user_token
3636

3737
@classmethod
38-
def from_zocalo_configuration(cls, zc: zocalo.configuration.Configuration):
38+
def from_zocalo_configuration(cls, zc: Configuration, cluster: str = "slurm"):
39+
cluster_config = getattr(zc, cluster)
3940
return cls(
40-
url=zc.slurm["url"],
41-
version=zc.slurm["api_version"],
42-
user_name=zc.slurm.get("user"),
43-
user_token=zc.slurm.get("user_token"),
41+
url=cluster_config["url"],
42+
version=cluster_config["api_version"],
43+
user_name=cluster_config.get("user"),
44+
user_token=cluster_config.get("user_token"),
4445
)
4546

4647
def get(
@@ -93,19 +94,21 @@ def delete(
9394
response.raise_for_status()
9495
return response
9596

96-
def get_jobs(self) -> models.JobsResponse:
97+
def get_jobs(self) -> models.OpenapiJobInfoResp:
9798
endpoint = f"slurm/{self.version}/jobs"
9899
response = self.get(endpoint)
99-
return models.JobsResponse(**response.json())
100+
return models.OpenapiJobInfoResp(**response.json())
100101

101-
def get_job_info(self, job_id: int) -> models.JobsResponse:
102+
def get_job_info(self, job_id: int) -> models.JobInfo:
102103
endpoint = f"slurm/{self.version}/job/{job_id}"
103104
response = self.get(endpoint)
104-
return models.JobsResponse(**response.json())
105+
job_info_resp = models.OpenapiJobInfoResp(**response.json())
106+
jobinfo = next(iter(dict(job_info_resp.jobs).get("__root__", [])))
107+
return jobinfo
105108

106109
def submit_job(
107-
self, job_submission: models.JobSubmission
108-
) -> models.JobSubmissionResponse:
110+
self, job_submission: models.JobSubmitReq
111+
) -> models.JobSubmitResponseMsg:
109112
endpoint = f"slurm/{self.version}/job/submit"
110113
response = self.post(endpoint, json=job_submission.dict(exclude_defaults=True))
111-
return models.JobSubmissionResponse(**response.json())
114+
return models.JobSubmitResponseMsg(**response.json())

0 commit comments

Comments
 (0)