3535SINGULARITY_RUN_NGEN_FORCING_CMD = f"/usr/bin/time -v singularity exec -B { LOCAL_DATA_DIR } :{ CONTAINER_DATA_DIR } --env NGENCERF_URL={ NGENCERF_URL } { NGEN_FORCING_SINGULARITY_CONTAINER_PATH } /ngen-app/bin/run-ngen-forcing.sh"
3636SINGULARITY_RUN_NGEN_FCST_CMD = f"/usr/bin/time -v singularity run -B { LOCAL_DATA_DIR } :{ CONTAINER_DATA_DIR } --env NGENCERF_URL={ NGENCERF_URL } { NGEN_FCST_SINGULARITY_CONTAINER_PATH } "
3737
38- # Command to obtain git hashes
39- SINGULARITY_EXEC_NGEN_CAL_CMD = f"singularity exec -B { LOCAL_DATA_DIR } :{ CONTAINER_DATA_DIR } --env NGENCERF_URL={ NGENCERF_URL } { NGEN_CAL_SINGULARITY_CONTAINER_PATH } "
40- SINGULARITY_EXEC_NGEN_FORCING_CMD = f"singularity exec -B { LOCAL_DATA_DIR } :{ CONTAINER_DATA_DIR } --env NGENCERF_URL={ NGENCERF_URL } { NGEN_FORCING_SINGULARITY_CONTAINER_PATH } "
41- SINGULARITY_EXEC_NGEN_FCST_CMD = f"singularity exec -B { LOCAL_DATA_DIR } :{ CONTAINER_DATA_DIR } --env NGENCERF_URL={ NGENCERF_URL } { NGEN_FCST_SINGULARITY_CONTAINER_PATH } "
42-
43- # Files with the git hashes within ngen-cal container
44- NGEN_CAL_GIT_HASH_FILES = '/ngen-app/ngen/.git/HEAD /ngen-app/ngen-cal/.git/HEAD'
45- # Files with the git hashes within ngen-forcing container
46- # - FIXME: The function that obtains the commit hash expects two files
47- NGEN_FORCING_GIT_HASH_FILES = '/ngen-app/ngen-forcing/.git/HEAD /ngen-app/ngen-forcing/.git/HEAD'
48- # Files with the git hashes within ngen-forcing container
49- NGEN_FCST_GIT_HASH_FILES = '/ngen-app/ngen/.git/HEAD /ngen-app/ngen-fcst/.git/HEAD'
50-
5138# Slurm job metrics for sacct command
5239SLURM_JOB_METRICS = os .environ .get ('SLURM_JOB_METRICS' )
5340
@@ -123,34 +110,7 @@ def grant_ownership(job_dir):
123110 logger .exception (f"Failed to change ownership for directory { job_dir } " )
124111 return {"success" : False , "message" : str (e )}
125112
126- def get_git_hashes (command ):
127- """Retrieve git commit hashes from the ngen container."""
128- logger .info (f"Command to obtain git hashes: { command } " )
129- try :
130- result = subprocess .run (command , shell = True , capture_output = True , text = True )
131- if result .returncode != 0 :
132- error_msg = f"Failed to retrieve git hashes: { result .stderr .strip ()} "
133- logger .error (error_msg )
134- return None , error_msg
135-
136- # The output should contain two lines, one for each commit hash
137- hashes = result .stdout .strip ().splitlines ()
138- if len (hashes ) != 2 :
139- output = ', ' .join (hashes )
140- error_msg = f"Unexpected output from singularity command: { output } "
141- logger .error (error_msg )
142- return None , error_msg
143-
144- ngen_commit_hash = hashes [0 ].split ()[- 1 ] # Extract the last part of the line
145- ngen_cal_commit_hash = hashes [1 ].split ()[- 1 ]
146- return ngen_commit_hash , ngen_cal_commit_hash
147- except Exception as e :
148- error_msg = str (e )
149- logger .exception (f"Error retrieving git hashes: { error_msg } " )
150- return None , error_msg
151-
152113
153-
154114def get_callback (callback_url , auth_token , ** kwargs ):
155115 # Prepare the data dictionary excluding the auth_token
156116 data = {key : value for key , value in kwargs .items ()}
@@ -334,15 +294,6 @@ def submit_calibration_job():
334294 if not auth_token :
335295 return log_and_return_error ("No auth_token provided" , status_code = 400 )
336296
337- # Get commit hashes before job submission
338- hashes_command = f'{ SINGULARITY_EXEC_NGEN_CAL_CMD } cat { NGEN_CAL_GIT_HASH_FILES } '
339- ngen_commit_hash , ngen_cal_commit_hash = get_git_hashes (hashes_command )
340- if ngen_commit_hash is None : # Check for error during hash retrieval
341- error_msg = f"Failed to retrieve commit hashes: { ngen_cal_commit_hash } "
342- return log_and_return_error (error_msg , status_code = 500 )
343-
344- logger .info (f"Commit hashes retrieved - NGEN: { ngen_commit_hash } , NGEN_CAL: { ngen_cal_commit_hash } " )
345-
346297
347298 singularity_run_cmd = f"{ SINGULARITY_RUN_NGEN_CAL_CMD } calibration { input_file } "
348299
@@ -365,9 +316,9 @@ def submit_calibration_job():
365316
366317 slurm_job_id , exit_code = submit_job (input_file , output_file , calibration_run_id , job_type , singularity_run_cmd , nprocs = nprocs )
367318 if exit_code == 500 :
368- return jsonify ({"error" : slurm_job_id , "ngen_commit_hash" : ngen_commit_hash , "ngen_cal_commit_hash" : ngen_cal_commit_hash }), exit_code
319+ return jsonify ({"error" : slurm_job_id }), exit_code
369320
370- return jsonify ({"slurm_job_id" : slurm_job_id , "ngen_commit_hash" : ngen_commit_hash , "ngen_cal_commit_hash" : ngen_cal_commit_hash }), exit_code
321+ return jsonify ({"slurm_job_id" : slurm_job_id }), exit_code
371322
372323
373324@app .route ('/submit-validation-job' , methods = ['POST' ])
@@ -418,16 +369,6 @@ def submit_validation_job():
418369 except ValueError :
419370 return log_and_return_error ("Invalid iteration provided; must be an integer" , status_code = 400 )
420371
421- # Get commit hashes before job submission
422- hashes_command = f'{ SINGULARITY_EXEC_NGEN_CAL_CMD } cat { NGEN_CAL_GIT_HASH_FILES } '
423- ngen_commit_hash , ngen_cal_commit_hash = get_git_hashes (hashes_command )
424- if ngen_commit_hash is None : # Check for error during hash retrieval
425- error_msg = f"Failed to retrieve commit hashes: { ngen_cal_commit_hash } "
426- return log_and_return_error (error_msg , status_code = 500 )
427-
428- logger .info (f"Commit hashes retrieved - NGEN: { ngen_commit_hash } , NGEN_CAL: { ngen_cal_commit_hash } " )
429-
430-
431372 if validation_type in ['valid_control' , 'valid_best' ]:
432373 singularity_run_cmd = f"{ SINGULARITY_RUN_NGEN_CAL_CMD } validation { input_file } "
433374 elif validation_type == 'valid_iteration' :
@@ -453,8 +394,8 @@ def submit_validation_job():
453394
454395 slurm_job_id , exit_code = submit_job (input_file , output_file , validation_run_id , job_type , singularity_run_cmd , nprocs = nprocs )
455396 if exit_code == 500 :
456- return jsonify ({"error" : slurm_job_id , "ngen_commit_hash" : ngen_commit_hash , "ngen_cal_commit_hash" : ngen_cal_commit_hash }), exit_code
457- return jsonify ({"slurm_job_id" : slurm_job_id , "ngen_commit_hash" : ngen_commit_hash , "ngen_cal_commit_hash" : ngen_cal_commit_hash }), exit_code
397+ return jsonify ({"error" : slurm_job_id }), exit_code
398+ return jsonify ({"slurm_job_id" : slurm_job_id }), exit_code
458399
459400
460401@app .route ('/submit-forecast-job' , methods = ['POST' ])
@@ -495,15 +436,6 @@ def submit_forecast_job():
495436 if not auth_token :
496437 return log_and_return_error ("No auth_token provided" , status_code = 400 )
497438
498- # Get commit hashes before job submission
499- hashes_command = f'{ SINGULARITY_EXEC_NGEN_FCST_CMD } cat { NGEN_FCST_GIT_HASH_FILES } '
500- ngen_commit_hash , ngen_forecast_commit_hash = get_git_hashes (hashes_command )
501- if ngen_commit_hash is None : # Check for error during hash retrieval
502- error_msg = f"Failed to retrieve commit hashes: { ngen_forecast_commit_hash } "
503- return log_and_return_error (error_msg , status_code = 500 )
504-
505- logger .info (f"Commit hashes retrieved - NGEN: { ngen_commit_hash } , NGEN_FORECAST: { ngen_forecast_commit_hash } " )
506-
507439 singularity_run_cmd = f"{ SINGULARITY_RUN_NGEN_FCST_CMD } forecast { forcing_dir } { input_file } { forecast_dir } "
508440
509441 postprocessing_dir = os .path .join ("postprocess" , job_type , forecast_run_id )
@@ -525,9 +457,9 @@ def submit_forecast_job():
525457
526458 slurm_job_id , exit_code = submit_job (input_file , stdout_file , forecast_run_id , job_type , singularity_run_cmd )
527459 if exit_code == 500 :
528- return jsonify ({"error" : slurm_job_id , "ngen_commit_hash" : ngen_commit_hash , "ngen_forecast_commit_hash" : ngen_forecast_commit_hash }), exit_code
460+ return jsonify ({"error" : slurm_job_id }), exit_code
529461
530- return jsonify ({"slurm_job_id" : slurm_job_id , "ngen_commit_hash" : ngen_commit_hash , "ngen_forecast_commit_hash" : ngen_forecast_commit_hash }), exit_code
462+ return jsonify ({"slurm_job_id" : slurm_job_id }), exit_code
531463
532464
533465@app .route ('/submit-forecast-forcing-download-job' , methods = ['POST' ])
@@ -570,15 +502,6 @@ def submit_forecast_forcing_download():
570502 if not auth_token :
571503 return log_and_return_error ("No auth_token provided" , status_code = 400 )
572504
573- # Get commit hashes before job submission
574- hashes_command = f'{ SINGULARITY_EXEC_NGEN_FORCING_CMD } cat { NGEN_FORCING_GIT_HASH_FILES } '
575- ngen_forcing_commit_hash , _ = get_git_hashes (hashes_command )
576- if ngen_forcing_commit_hash is None : # Check for error during hash retrieval
577- error_msg = f"Failed to retrieve commit hashes: { ngen_forcing_commit_hash } "
578- return log_and_return_error (error_msg , status_code = 500 )
579-
580- logger .info (f"Commit hashes retrieved - NGEN_FORCING: { ngen_forcing_commit_hash } " )
581-
582505 singularity_run_cmd = f"{ SINGULARITY_RUN_NGEN_FORCING_CMD } forecast_forcing { cycle_name } { gpkg_file } { config_file } { forcing_dir } "
583506
584507 postprocessing_dir = os .path .join ("postprocess" , job_type , forecast_forcing_download_run_id )
@@ -599,9 +522,9 @@ def submit_forecast_forcing_download():
599522
600523 slurm_job_id , exit_code = submit_job (config_file , stdout_file , forecast_forcing_download_run_id , job_type , singularity_run_cmd )
601524 if exit_code == 500 :
602- return jsonify ({"error" : slurm_job_id , "ngen_forcing_commit_hash" : ngen_forcing_commit_hash }), exit_code
525+ return jsonify ({"error" : slurm_job_id }), exit_code
603526
604- return jsonify ({"slurm_job_id" : slurm_job_id , "ngen_forcing_commit_hash" : ngen_forcing_commit_hash }), exit_code
527+ return jsonify ({"slurm_job_id" : slurm_job_id }), exit_code
605528
606529
607530@app .route ('/job-status' , methods = ['GET' ])
0 commit comments