-
Notifications
You must be signed in to change notification settings - Fork 33
InputSB support #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InputSB support #711
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| __all__ = ("create_sandbox", "download_sandbox") | ||
| __all__ = ("create_sandbox", "download_sandbox", "submit_jobs") | ||
|
|
||
| import hashlib | ||
| import logging | ||
|
|
@@ -13,6 +13,8 @@ | |
|
|
||
| import httpx | ||
| import zstandard | ||
| from DIRACCommon.Core.Utilities.ClassAd.ClassAdLight import ClassAd | ||
| from typer import FileText | ||
|
|
||
| from diracx.client.aio import AsyncDiracClient | ||
| from diracx.client.models import SandboxInfo | ||
|
|
@@ -123,3 +125,28 @@ async def download_sandbox(pfn: str, destination: Path, *, client: AsyncDiracCli | |
| with tarfile_open(fh) as tf: | ||
| tf.extractall(path=destination, filter="data") | ||
| logger.debug("Extracted %s to %s", pfn, destination) | ||
|
|
||
|
|
||
| @with_client | ||
| async def submit_jobs(jdls: list[FileText], *, client: AsyncDiracClient): | ||
| # Create and upload InputSandboxes from JDLs | ||
| for i, jdl in enumerate(jdls): | ||
| original_jdl = jdl.read() | ||
|
|
||
| # Fix possible lack of brackets | ||
| if original_jdl.strip()[0] != "[": | ||
| original_jdl = f"[{original_jdl}]" | ||
|
|
||
| class_ad_job = ClassAd(original_jdl) | ||
| if class_ad_job.lookupAttribute("InputSandbox"): | ||
| isb = class_ad_job.getListFromExpression("InputSandbox") | ||
| sandboxes_pfn = await create_sandbox( | ||
| paths=[Path(file_path) for file_path in isb] | ||
| ) | ||
| print(f"InputSandbox created: {sandboxes_pfn[13:]}") | ||
|
||
| class_ad_job.set_expression("InputSandbox", {sandboxes_pfn}) | ||
|
|
||
| jdls[i] = class_ad_job.asJDL() | ||
|
|
||
| jobs = await client.jobs.submit_jdl_jobs(list(jdls)) | ||
| return jobs | ||
Uh oh!
There was an error while loading. Please reload this page.