Skip to content

Commit

Permalink
_sumo_parent_object is the same as fmu.case.uuid; no need to... (#15)
Browse files Browse the repository at this point in the history
* _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 <[email protected]>
  • Loading branch information
rwiker and rwiker authored Nov 20, 2023
1 parent cfac899 commit db3c027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 50 deletions.
62 changes: 13 additions & 49 deletions src/fmu/sumo/uploader/_sumocase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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.")
Expand All @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/fmu/sumo/uploader/scripts/sumo_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit db3c027

Please sign in to comment.