Skip to content

Commit

Permalink
Merge branch 'userjobs' into 'master'
Browse files Browse the repository at this point in the history
Add support for polling jobs for all users

See merge request firecrest/firecrest!322
  • Loading branch information
Juan Pablo Dorsch committed Oct 17, 2024
2 parents 3c0af4e + 8230b11 commit 75c1f06
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added option to follow symbolic links in the `POST /utilities/compress` and `POST /storage/xfer-internal/compress` endpoints
- Added new "general" section to status/parameters describing `FIRECREST_VERSION` and `FIRECREST_BUILD` timestamp
- Environment variable `F7T_HOME_ENABLED` to set `False` if `$HOME` is not mounted on systems executing FirecREST commands
- Add support in the `GET /compute/jobs` endopint to poll for jobs of any user

### Changed

Expand Down
6 changes: 6 additions & 0 deletions doc/openapi/firecrest-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,12 @@ paths:
type: array
items:
type: string
- name: userJobs
in: query
description: When True the ouput will include only the user's jobs. Information about job's files is not available when False.
schema:
type: boolean
default: true
- $ref: '#/components/parameters/pageSize'
- $ref: '#/components/parameters/pageNumber'
responses:
Expand Down
6 changes: 6 additions & 0 deletions doc/openapi/firecrest-developers-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,12 @@ paths:
type: array
items:
type: string
- name: userJobs
in: query
description: When True the ouput will include only the user's jobs. Information about job's files is not available when False.
schema:
type: boolean
default: true
- $ref: '#/components/parameters/pageSize'
- $ref: '#/components/parameters/pageNumber'
responses:
Expand Down
5 changes: 4 additions & 1 deletion src/common/schedulers/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def parse_job_info(self, output):

def poll(self, user, jobids=None):
# In Slurm we implement this with the squeue command
cmd = ["squeue", f"--user={user}"]
cmd = ["squeue"]
if user:
cmd.append(f"--user={user}")

if jobids:
cmd.append(f"--jobs='{','.join(jobids)}'")

Expand Down
36 changes: 24 additions & 12 deletions src/compute/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,19 +571,23 @@ def list_jobs():
return jsonify(description="Failed to retrieve jobs information"), 404, header
return jsonify(description="Failed to retrieve jobs information"), 400, header

is_username_ok = get_username(headers[AUTH_HEADER_NAME])

if not is_username_ok["result"]:
return jsonify(description=is_username_ok["reason"],error="Failed to retrieve jobs information"), 401

username = is_username_ok["username"]

app.logger.info(f"Getting information of jobs from {system_name} ({system_addr})")

# job list comma separated:
jobs = request.args.get("jobs", None)
pageSize = request.args.get("pageSize", None)
pageNumber = request.args.get("pageNumber", None)
userJobs = get_boolean_var(request.args.get("userJobs", True))

if userJobs:
is_username_ok = get_username(headers[AUTH_HEADER_NAME])

if not is_username_ok["result"]:
return jsonify(description=is_username_ok["reason"],error="Failed to retrieve jobs information"), 401

username = is_username_ok["username"]
else:
username = None

app.logger.info(f"Getting information of jobs from {system_name} ({system_addr})")

if pageSize is not None or pageNumber is not None:
if pageSize is not None:
Expand Down Expand Up @@ -638,7 +642,7 @@ def list_jobs():

# asynchronous task creation
aTask = threading.Thread(target=list_job_task, name=ID,
args=(headers, system_name, system_addr, action, task_id, pageSize, pageNumber))
args=(headers, system_name, system_addr, action, task_id, pageSize, pageNumber, userJobs))

aTask.start()

Expand All @@ -653,7 +657,7 @@ def list_jobs():



def list_job_task(headers,system_name, system_addr,action,task_id,pageSize,pageNumber):
def list_job_task(headers,system_name, system_addr,action,task_id,pageSize,pageNumber,userJobs=True):
# exec command
resp = exec_remote_command(headers, system_name, system_addr, action)

Expand Down Expand Up @@ -710,7 +714,15 @@ def list_job_task(headers,system_name, system_addr,action,task_id,pageSize,pageN
jobs = {}
for job_index, jobinfo in enumerate(jobList):
# now looking for log and err files location
jobinfo = get_job_files(headers, system_name, system_addr, jobinfo, output=True)
if userJobs:
jobinfo = get_job_files(headers, system_name, system_addr, jobinfo, output=True)
else:
jobinfo["job_file_out"] = ""
jobinfo["job_file_err"] = ""
jobinfo["job_file"] = ""
jobinfo["job_data_out"] = ""
jobinfo["job_data_err"] = ""
jobinfo["job_info_extra"] = "Job files information is not available when `userJobs` is False"

# add jobinfo to the array
jobs[str(job_index)]=jobinfo
Expand Down

0 comments on commit 75c1f06

Please sign in to comment.