Skip to content

Commit

Permalink
Fix config issue and revise slurmrestd inference (#950)
Browse files Browse the repository at this point in the history
Fix issue with generating new config and add slurmrestd API inference
  • Loading branch information
rstyd authored Oct 18, 2024
1 parent 41548d0 commit eda2372
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions beeflow/client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
will be started.
"""
import os
import re
import signal
import subprocess
import socket
Expand All @@ -17,10 +18,12 @@
import datetime
import time
import importlib.metadata
import packaging

import daemon
import typer


from beeflow.client import bee_client
from beeflow.common.config_driver import BeeConfig as bc
from beeflow.common import cli_connection
Expand Down Expand Up @@ -160,6 +163,22 @@ def need_slurmrestd():
and not bc.get('slurm', 'use_commands'))


def get_slurmrestd_version():
"""Get the newest slurmrestd version."""
resp = subprocess.run(["slurmrestd", "-s", "list"], check=True, stderr=subprocess.PIPE,
text=True).stderr
resp = resp.split("\n")
# Confirm slurmrestd format is the same
# If the slurmrestd list outputs has changed potentially something else has broken
if "Possible OpenAPI plugins" not in resp[0]:
print("Slurmrestd OpenAPI format has changed and things may break")
api_versions = [line.split('/')[1] for line in resp[1:] if re.search(r"openapi/v\d+\.\d+\.\d+",
line)]
# Sort the versions and grab the newest one
newest_api = sorted(api_versions, key=packaging.version.Version, reverse=True)[0]
return newest_api


def init_components():
"""Initialize the components and component manager."""
mgr = ComponentManager()
Expand Down Expand Up @@ -242,6 +261,9 @@ def start_slurm_restd():
bee_workdir = bc.get('DEFAULT', 'bee_workdir')
slurmrestd_log = '/'.join([bee_workdir, 'logs', 'restd.log'])
openapi_version = bc.get('slurm', 'openapi_version')
if not openapi_version:
# Detect the newest version of the slurmrestd API
openapi_version = get_slurmrestd_version()
slurm_args = f'-s openapi/{openapi_version}'
# The following adds the db plugin we opted not to use for now
# slurm_args = f'-s openapi/{openapi_version},openapi/db{openapi_version}'
Expand Down
4 changes: 2 additions & 2 deletions beeflow/common/config_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import platform
import random
import shutil
import sys
import textwrap
import typer

Expand Down Expand Up @@ -102,7 +101,8 @@ def init(cls, userconfig=None, **_kwargs):
with open(USERCONFIG_FILE, encoding='utf-8') as fp:
config.read_file(fp)
except FileNotFoundError:
sys.exit('Configuration file does not exist! Please try running `beeflow config new`.')
print("Configuration file is missing! Generating new config file.")
new(USERCONFIG_FILE)
# remove default keys from the other sections
default_keys = list(config['DEFAULT'])
config = {sec_name: {key: config[sec_name][key] for key in config[sec_name]
Expand Down

0 comments on commit eda2372

Please sign in to comment.