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.
feat: introduce the JobWrapperOfflineTemplate
- Loading branch information
Showing
5 changed files
with
304 additions
and
5 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
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. | ||
""" | ||
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 os.path.isfile(file): | ||
hash_md5 = hashlib.md5() | ||
with open(file, "rb") as f: | ||
while chunk := f.read(128 * hash_md5.block_size): | ||
hash_md5.update(chunk) | ||
checksums[file] = hash_md5.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
""" | ||
import sys | ||
import json | ||
import ast | ||
import os | ||
import errno | ||
import time | ||
|
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