From db3c0272d04e9ba7e817f2a7942acf948f95cd5b Mon Sep 17 00:00:00 2001 From: Raymond Wiker Date: Mon, 20 Nov 2023 15:24:44 +0100 Subject: [PATCH] _sumo_parent_object is the same as fmu.case.uuid; no need to... (#15) * _sumo.parent_object is the same as fmu.case.uuid; no need to check for parent object. * Cleanup, and add back warning for non-existent case. * Re-instate info message to user when the parent object appears to be missing. --------- Co-authored-by: Raymond Wiker --- src/fmu/sumo/uploader/_sumocase.py | 62 ++++---------------- src/fmu/sumo/uploader/scripts/sumo_upload.py | 2 +- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/src/fmu/sumo/uploader/_sumocase.py b/src/fmu/sumo/uploader/_sumocase.py index 59df905..37f468f 100644 --- a/src/fmu/sumo/uploader/_sumocase.py +++ b/src/fmu/sumo/uploader/_sumocase.py @@ -28,7 +28,7 @@ def __init__(self, case_metadata: str, sumo_connection, verbosity): self.case_metadata = _sanitize_datetimes(case_metadata) self._fmu_case_uuid = self._get_fmu_case_uuid() logger.debug("self._fmu_case_uuid is %s", self._fmu_case_uuid) - self._sumo_parent_id = self._get_sumo_parent_id() + self._sumo_parent_id = self._fmu_case_uuid logger.debug("self._sumo_parent_id is %s", self._sumo_parent_id) self._files = [] @@ -44,59 +44,14 @@ def _get_fmu_case_uuid(self): return fmu_case_uuid - def _get_sumo_parent_id(self): - try: - self.sumo_connection.api.get(f"/objects('{self._fmu_case_uuid}')") - return self.fmu_case_uuid - except httpx.HTTPStatusError as err: - if err.response.status_code != 404: - logger.warning( - f"Unexpected status code: {err.response.status_code}" - ) - return - - def upload(self, threads=4, max_attempts=1, register_case=False): + def upload(self, threads=4): """Trigger upload of files. - Get sumo_parent_id. If None, case is not registered on Sumo. - Upload all indexed files. Collect the files that have been uploaded OK, the ones that have failed and the ones that have been rejected. Retry the failed uploads X times.""" - if self.sumo_parent_id is None: - logger.info("Case is not registered on Sumo") - - if register_case: - self.register() - logger.info( - "Waiting 1 minute for Sumo to create the case container" - ) - time.sleep(20) # Wait for Sumo to create the container - else: - # We catch the situation where case is not registered on Sumo but - # an upload is attempted anyway. In the FMU context, this can happen - # if something goes wrong with the initial case metadata creation and - # upload. If, for some reason, this fails and the case is never uploaded - # to Sumo, we (currently) want this script to not fail (and stop the - # workflow). Outside FMU context, this can be different and we retain - # the possibility for allowing this script to register the case. - - logger.info( - "Case was not found on Sumo. If you are in the FMU context " - "something may have gone wrong with the case registration " - "or you have not specified that the case shall be uploaded." - "A warning will be issued, and the script will stop. " - "If you are NOT in the FMU context, you can specify that " - "this script also registers the case by passing " - "register=True. This should not be done in the FMU context." - ) - warnings.warn( - "Case is not registered on Sumo.", - UserWarning, - ) - return if not self.files: raise FileExistsError("No files to upload. Check search string.") @@ -106,7 +61,6 @@ def upload(self, threads=4, max_attempts=1, register_case=False): rejected_uploads = [] files_to_upload = [f for f in self.files] - attempts = 0 _t0 = time.perf_counter() logger.debug("files_to_upload: %s", files_to_upload) @@ -123,7 +77,17 @@ def upload(self, threads=4, max_attempts=1, register_case=False): failed_uploads = upload_results.get("failed_uploads") if failed_uploads: - warnings.warn("Stopping after {} attempts".format(attempts)) + if any([res.get("metadata_upload_response_status_code") == 404 for res in failed_uploads]): + warnings.warn("Case is not registered on Sumo") + logger.info( + "Case was not found on Sumo. If you are in the FMU context " + "something may have gone wrong with the case registration " + "or you have not specified that the case shall be uploaded." + "A warning will be issued, and the script will stop. " + "If you are NOT in the FMU context, you can specify that " + "this script also registers the case by passing " + "register=True. This should not be done in the FMU context." + ) _dt = time.perf_counter() - _t0 diff --git a/src/fmu/sumo/uploader/scripts/sumo_upload.py b/src/fmu/sumo/uploader/scripts/sumo_upload.py index 27c9770..18eff63 100644 --- a/src/fmu/sumo/uploader/scripts/sumo_upload.py +++ b/src/fmu/sumo/uploader/scripts/sumo_upload.py @@ -116,7 +116,7 @@ def sumo_upload_main( # upload the indexed files logger.info("Starting upload") - e.upload(threads=threads, register_case=False) + e.upload(threads=threads) e.upload_parameters_txt(glob_var_path=config_path) logger.info("Upload done") except Exception as err: