-
Notifications
You must be signed in to change notification settings - Fork 3
feat: LHCb modules migration #97
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
base: main
Are you sure you want to change the base?
Changes from all commits
5075547
7a03ef2
fd12496
8317c9f
91cef73
98ccc37
1da58a2
4586f84
0ad8e0e
bd285c3
26de911
b87c180
32e54b4
f02159a
f4d2821
028ca4f
d9e24e9
6907021
1987844
947bc8b
396645e
a81648b
dcb1693
2d16150
ed1c6f0
3a8908d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,20 @@ | ||
| """Command classes for workflow pre/post-processing operations.""" | ||
|
|
||
| from .analyze_xml_summary import AnalyseXmlSummary | ||
| from .bookkeeping_report import BookkeepingReport | ||
| from .core import PostProcessCommand, PreProcessCommand | ||
| from .failover_request import FailoverRequest | ||
| from .upload_log_file import UploadLogFile | ||
| from .upload_output_data import UploadOutputData | ||
| from .workflow_accounting import WorkflowAccounting | ||
|
|
||
| __all__ = ["PreProcessCommand", "PostProcessCommand"] | ||
| __all__ = [ | ||
| "AnalyseXmlSummary", | ||
| "PreProcessCommand", | ||
| "PostProcessCommand", | ||
| "UploadLogFile", | ||
| "BookkeepingReport", | ||
| "FailoverRequest", | ||
| "UploadOutputData", | ||
| "WorkflowAccounting", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """LHCb command for checking the XMLSummary output to ensure that the execution was done correctly.""" | ||
|
|
||
| import logging | ||
| import os | ||
|
|
||
| from LHCbDIRAC.Workflow.Modules.AnalyseXMLSummary import _areInputsOK, _isXMLSummaryOK | ||
|
|
||
| from dirac_cwl.core.exceptions import WorkflowProcessingException | ||
|
|
||
| from .core import PostProcessCommand | ||
| from .workflow_commons import Step, StepStatus, WorkflowCommons | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class AnalyseXmlSummary(PostProcessCommand): | ||
| """Performs a series of checks on the XMLSummary output to make sure the execution was done correctly.""" | ||
|
|
||
| def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **kwargs): | ||
| """Execute the command. | ||
|
|
||
| :param job_path: Path to the job working directory. | ||
| :param workflow_commons: WorkflowCommons object | ||
| :param kwargs: Additional keyword arguments. | ||
| """ | ||
| for step in workflow_commons.steps: | ||
| self._execute_for_step(job_path, workflow_commons, step, **kwargs) | ||
|
|
||
| def _execute_for_step(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, step_commons: Step, **kwargs): | ||
| """Execute the command for a specific step.""" | ||
| job_ok = _isXMLSummaryOK(step_commons.xf_o) | ||
|
|
||
| if job_ok: | ||
| job_ok = _areInputsOK( | ||
| step_commons.xf_o, | ||
| step_commons.inputs, | ||
| step_commons.number_of_events, | ||
| workflow_commons.production_id, | ||
| workflow_commons.file_report, | ||
| ) | ||
| if not job_ok: | ||
| workflow_commons.job_report.setApplicationStatus("XMLSummary reports error") | ||
| raise WorkflowProcessingException("XMLSummary reports error") | ||
|
|
||
| if workflow_commons.step_status == StepStatus.Failed: | ||
| logger.info("Workflow already failed") | ||
| return | ||
|
|
||
| workflow_commons.job_report.setApplicationStatus(f"{step_commons.application_name} Step OK") |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,162 @@ | ||||||
| """LHCb command for bookkeeping report file generation based on the XMLSummary and the XML catalog.""" | ||||||
|
|
||||||
| import copy | ||||||
| import logging | ||||||
| import os | ||||||
| from typing import Any, Dict | ||||||
|
|
||||||
| from DIRAC.Core.Utilities.ReturnValues import SErrorException, returnValueOrRaise | ||||||
| from DIRAC.Workflow.Utilities.Utils import getStepCPUTimes | ||||||
| from LHCbDIRAC.Core.Utilities.ProductionData import constructProductionLFNs | ||||||
| from LHCbDIRAC.Workflow.Modules.BookkeepingReport import ( | ||||||
| _generate_xml_object, | ||||||
| _generateInputFiles, | ||||||
| _generateOutputFiles, | ||||||
| _prepare_job_info, | ||||||
| _process_time, | ||||||
| ) | ||||||
| from LHCbDIRAC.Workflow.Modules.ModulesUtilities import getNumberOfProcessorsToUse | ||||||
|
|
||||||
| from dirac_cwl.core.exceptions import WorkflowProcessingException | ||||||
|
|
||||||
| from .core import PostProcessCommand | ||||||
| from .workflow_commons import Step, StepStatus, WorkflowCommons | ||||||
|
|
||||||
| logger = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
| class BookkeepingReport(PostProcessCommand): | ||||||
| """Generates a bookkeeping report file based on the XMLSummary and the pool XML catalog.""" | ||||||
|
|
||||||
| def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **kwargs): | ||||||
| """Execute the command. | ||||||
|
|
||||||
| :param job_path: Path to the job working directory. | ||||||
| :param workflow_commons: WorkflowCommons object | ||||||
| :param kwargs: Additional keyword arguments. | ||||||
| """ | ||||||
| for step in workflow_commons.steps: | ||||||
| if workflow_commons.step_status == StepStatus.Failed: | ||||||
| return | ||||||
|
|
||||||
| self._execute_for_step(job_path, workflow_commons, step, **kwargs) | ||||||
|
|
||||||
| def _execute_for_step(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, step_commons: Step, **kwargs): | ||||||
| # Setup variables | ||||||
| cpu_times: Dict[str, Any] = {} | ||||||
| if step_commons.start_time: | ||||||
| cpu_times["StartTime"] = step_commons.start_time | ||||||
| if step_commons.start_stats: | ||||||
| cpu_times["StartStats"] = step_commons.start_stats | ||||||
|
|
||||||
| exectime, cputime = getStepCPUTimes(cpu_times) | ||||||
|
|
||||||
| number_of_processors = workflow_commons.number_of_processors | ||||||
|
|
||||||
| if (step_commons.multicore and workflow_commons.multicore) or ( | ||||||
| workflow_commons.job_type.lower() == "user" and workflow_commons.max_number_of_processors | ||||||
| ): | ||||||
| number_of_processors = getNumberOfProcessorsToUse( | ||||||
| workflow_commons.job_id, | ||||||
| workflow_commons.max_number_of_processors, | ||||||
| ) | ||||||
|
|
||||||
| all_outputs = copy.deepcopy(step_commons.outputs) | ||||||
| all_outputs.extend(step_commons.outputs) | ||||||
|
|
||||||
| parameters = { | ||||||
| "PRODUCTION_ID": workflow_commons.production_id, | ||||||
| "JOB_ID": workflow_commons.prod_job_id, | ||||||
| "configVersion": workflow_commons.config_version, | ||||||
| "outputList": all_outputs, | ||||||
| "configName": workflow_commons.config_name, | ||||||
| "outputDataFileMask": workflow_commons.output_data_file_mask, | ||||||
| } | ||||||
|
|
||||||
| if workflow_commons.bookkeeping_lfns and workflow_commons.production_output_data: | ||||||
| bk_lfns = workflow_commons.bookkeeping_lfns | ||||||
|
|
||||||
| if not isinstance(bk_lfns, list): | ||||||
| bk_lfns = [i.strip() for i in bk_lfns.split(";")] | ||||||
|
|
||||||
| else: | ||||||
| logger.info("BookkeepingLFNs parameters not found, creating on the fly") | ||||||
| try: | ||||||
| production_lfns_dict = returnValueOrRaise( | ||||||
| constructProductionLFNs(parameters, workflow_commons.bk_client) | ||||||
| ) | ||||||
| except SErrorException as e: | ||||||
| logger.error("Could not create production LFNs", exc_info=e) | ||||||
| raise WorkflowProcessingException(f"Could not create production LFNs: {e}") from e | ||||||
|
|
||||||
| bk_lfns = production_lfns_dict["BookkeepingLFNs"] | ||||||
|
|
||||||
| ldate, ltime, ldatestart, ltimestart = _process_time(step_commons.start_time) | ||||||
|
|
||||||
| # Obtain XMLSummary | ||||||
| if not step_commons.xf_o: | ||||||
| step_commons.xf_o = _generate_xml_object( | ||||||
| step_commons.cleaned_application_name, | ||||||
| workflow_commons.production_id, | ||||||
| workflow_commons.prod_job_id, | ||||||
| step_commons.number, | ||||||
| step_commons.id, | ||||||
| ) | ||||||
|
|
||||||
| info_dict = { | ||||||
| "exectime": exectime, | ||||||
| "cputime": cputime, | ||||||
| "numberOfProcessors": number_of_processors, | ||||||
| "production_id": workflow_commons.production_id, | ||||||
| "jobID": workflow_commons.job_id, | ||||||
| "siteName": workflow_commons.site_name, | ||||||
| "jobType": workflow_commons.job_type, | ||||||
| "applicationName": step_commons.application_name, | ||||||
| "applicationVersion": step_commons.application_version, | ||||||
| "numberOfEvents": step_commons.number_of_events, | ||||||
| } | ||||||
|
|
||||||
| # Generate job_info object | ||||||
| job_info = _prepare_job_info( | ||||||
| info_dict, | ||||||
| ldatestart, | ||||||
| ltimestart, | ||||||
| ldate, | ||||||
| ltime, | ||||||
| step_commons.xf_o, | ||||||
| step_commons.inputs, | ||||||
| step_commons.id, | ||||||
| step_commons.bk_id, | ||||||
| workflow_commons.bk_client, | ||||||
| workflow_commons.config_name, | ||||||
| workflow_commons.config_version, | ||||||
| ) | ||||||
|
|
||||||
| # Add input files to job_info | ||||||
| _generateInputFiles(job_info, bk_lfns, step_commons.inputs) | ||||||
|
|
||||||
| # Add output files to job_info | ||||||
| _generateOutputFiles( | ||||||
| job_info, | ||||||
| bk_lfns, | ||||||
| step_commons.event_type, | ||||||
| step_commons.application_name, | ||||||
| step_commons.xf_o, | ||||||
| step_commons.outputs, | ||||||
| step_commons.inputs, | ||||||
| step_commons.size, | ||||||
| step_commons.md5, | ||||||
| step_commons.guid, | ||||||
| ) | ||||||
|
|
||||||
| # Generate SimulationConditions | ||||||
| if step_commons.application_name == "Gauss": | ||||||
| job_info.simulation_condition = workflow_commons.sim_description | ||||||
|
|
||||||
| # Convert job_info object to XML | ||||||
| doc = job_info.to_xml() | ||||||
|
|
||||||
| # Write to file | ||||||
| bfilename = f"bookkeeping_{step_commons.id}.xml" | ||||||
| with open(bfilename, "wb") as bfile: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For instance, here you also want this to be part of
Suggested change
|
||||||
| bfile.write(doc) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """LHCb command for committing the status of the files in the file report. | ||
|
|
||
| The status will be "Processed" if everything ended properly or "Unused" if it did not. | ||
| """ | ||
|
|
||
| import logging | ||
| import os | ||
|
|
||
| from DIRAC.Core.Utilities.ReturnValues import SErrorException, returnValueOrRaise | ||
| from LHCbDIRAC.Workflow.Modules.FailoverRequest import _prepareRequest | ||
|
|
||
| from .core import PostProcessCommand | ||
| from .workflow_commons import StepStatus, WorkflowCommons | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class FailoverRequest(PostProcessCommand): | ||
|
AcquaDiGiorgio marked this conversation as resolved.
|
||
| """Commits the status of the files in the file report. | ||
|
|
||
| The status will be "Processed" if everything ended properly or "Unused" if it did not. | ||
| """ | ||
|
|
||
| def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **kwargs): | ||
| """Execute the command. | ||
|
|
||
| :param job_path: Path to the job working directory. | ||
| :param workflow_commons: WorkflowCommons object. | ||
| :param kwargs: Additional keyword arguments. | ||
| """ | ||
| _prepareRequest(workflow_commons.request, workflow_commons.job_id) | ||
|
|
||
| files_in_file_report = workflow_commons.file_report.getFiles() | ||
|
|
||
| for lfn in workflow_commons.inputs: | ||
| if lfn not in files_in_file_report: | ||
| status = "Processed" if workflow_commons.step_status == StepStatus.Done else "Unused" | ||
| if status == "Unused": | ||
| logger.info("Set status of %s to 'Unused' due to workflow failure", lfn) | ||
| else: | ||
| logger.debug("No status populated for %s, setting to 'Processed'", lfn) | ||
|
|
||
| workflow_commons.file_report.setFileStatus(int(workflow_commons.production_id), lfn, status) | ||
|
|
||
| try: | ||
| value = returnValueOrRaise(workflow_commons.file_report.commit()) | ||
| if value: | ||
| logger.info("Status of files have been properly updated in the TransformationDB") | ||
| else: | ||
| logger.warning("No file status update reported. There are no input files?") | ||
| except SErrorException as e: | ||
| logger.error("Something went wrong trying fileReport.commit() %s", e) | ||
|
|
||
| if workflow_commons.file_report.getFiles(): | ||
| logger.error("On first attempt, failed to report file status to TransformationDB") | ||
| try: | ||
| value = returnValueOrRaise(workflow_commons.file_report.generateForwardDISET()) | ||
| if not value: | ||
| logger.info("On second attempt, files correctly reported to TransformationDB") | ||
| elif workflow_commons.step_status == StepStatus.Done: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also based on my previous comment in the Because if this is possible, then may be there is a way to reproduce exactly what we have in the workflow modules with the conditions like |
||
| logger.info("Adding a SetFileStatus operation to the request") | ||
| workflow_commons.request.addOperation(value) | ||
| else: | ||
| logger.info("The job should fail: do not set requests, as the DRA will take care") | ||
| except SErrorException as e: | ||
| logger.warning("Could not generate Operation for file report: %s", e) | ||
|
|
||
| if workflow_commons.step_status == StepStatus.Done: | ||
| workflow_commons.job_report.setApplicationStatus("Job Finished Successfully", True) | ||
|
|
||
| workflow_commons.generate_failover_file() | ||
Uh oh!
There was an error while loading. Please reload this page.