forked from DIRACGrid/DIRAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DIRACGrid#7529 from aldbr/v9.0_FEAT_JobWrapperLigh…
…tTemplate [9.0] feat: introduce the `JobWrapperOfflineTemplate` for resources with no external connectivity
- Loading branch information
Showing
13 changed files
with
752 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/DIRAC/WorkloadManagementSystem/JobWrapper/JobWrapperOfflineTemplate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
""" This template will become the job wrapper that's actually executed. | ||
The JobWrapperOfflineTemplate is completed and invoked by the PushJobAgent and uses functionalities from JobWrapper module. | ||
It is executed in environment where external connections are not allowed. | ||
We assume this script is executed in a specific environment where DIRAC is available. | ||
""" | ||
import hashlib | ||
import sys | ||
import json | ||
import os | ||
|
||
sitePython = os.path.realpath("@SITEPYTHON@") | ||
if sitePython: | ||
sys.path.insert(0, sitePython) | ||
|
||
from DIRAC.Core.Base.Script import Script | ||
|
||
Script.parseCommandLine() | ||
|
||
from DIRAC import gLogger | ||
from DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper import JobWrapper | ||
|
||
os.umask(0o22) | ||
|
||
|
||
def execute(jobID: str, arguments: dict): | ||
"""The only real function executed here""" | ||
payloadParams = arguments.pop("Payload", {}) | ||
if not payloadParams: | ||
return 1 | ||
|
||
if not "PayloadResults" in arguments["Job"] or not "Checksum" in arguments["Job"]: | ||
return 1 | ||
|
||
try: | ||
job = JobWrapper(jobID) | ||
job.initialize(arguments) # initialize doesn't return S_OK/S_ERROR | ||
except Exception as exc: # pylint: disable=broad-except | ||
gLogger.exception("JobWrapper failed the initialization phase", lException=exc) | ||
return 1 | ||
|
||
payloadResult = job.process(**payloadParams) | ||
if not payloadResult["OK"]: | ||
return 1 | ||
|
||
# Store the payload result | ||
with open(arguments["Job"]["PayloadResults"], "w") as f: | ||
json.dump(payloadResult, f) | ||
|
||
# Generate the checksum of the files present in the current directory | ||
checksums = {} | ||
for file in os.listdir("."): | ||
if not os.path.isfile(file): | ||
continue | ||
with open(file, "rb") as f: | ||
digest = hashlib.file_digest(f, "sha256") | ||
checksums[file] = digest.hexdigest() | ||
|
||
with open(arguments["Job"]["Checksum"], "w") as f: | ||
json.dump(checksums, f) | ||
|
||
return 0 | ||
|
||
|
||
########################################################## | ||
|
||
|
||
ret = -3 | ||
try: | ||
jsonFileName = os.path.realpath(__file__) + ".json" | ||
with open(jsonFileName) as f: | ||
jobArgs = json.load(f) | ||
if not isinstance(jobArgs, dict): | ||
raise TypeError(f"jobArgs is of type {type(jobArgs)}") | ||
if "Job" not in jobArgs: | ||
raise ValueError(f"jobArgs does not contain 'Job' key: {str(jobArgs)}") | ||
|
||
jobID = jobArgs["Job"].get("JobID", 0) | ||
jobID = int(jobID) | ||
|
||
ret = execute(jobID, jobArgs) | ||
except Exception as exc: # pylint: disable=broad-except | ||
gLogger.exception("JobWrapperTemplate exception") | ||
|
||
sys.exit(ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.