Skip to content

Commit

Permalink
Merge branch 'main' into feature/extra-validation-for-cubes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwiker authored Nov 25, 2024
2 parents 4d5ad5c + c0b70d9 commit bc09429
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
8 changes: 2 additions & 6 deletions src/fmu/sumo/uploader/_sumofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _upload_metadata(self, sumoclient, sumo_parent_id):
response = sumoclient.post(path=path, json=self.metadata)
return response

def _upload_byte_string(self, sumoclient, object_id, blob_url):
def _upload_byte_string(self, blob_url):
blobclient = BlobClient.from_blob_url(blob_url)
content_settings = ContentSettings(
content_type="application/octet-stream"
Expand Down Expand Up @@ -287,11 +287,7 @@ def upload_to_sumo(self, sumo_parent_id, sumoclient, sumo_mode):
)
else: # non-seismic blob
try:
response = self._upload_byte_string(
sumoclient=sumoclient,
object_id=self.sumo_object_id,
blob_url=blob_url,
)
response = self._upload_byte_string(blob_url)
upload_response.update(
{
"status_code": response.status_code,
Expand Down
41 changes: 18 additions & 23 deletions src/fmu/sumo/uploader/_upload_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
logger = get_uploader_logger()


def create_parameter_file(
case_uuid,
realization_id,
parameters_path,
config_path,
sumoclient,
):
"""If not already stored, generate a parameters object from the parameters.txt file
def get_parameter_file(parameters_path, config_path):
"""Return a parameters object from the parameters.txt file
Args:
case_uuid (str): parent uuid for case
Expand All @@ -42,13 +36,6 @@ def create_parameter_file(
bytestring = None
metadata = None

query = f"fmu.case.uuid:{case_uuid} AND fmu.realization.uuid:{realization_id} AND data.content:parameters"

search_res = sumoclient.get("/search", {"$query": query}).json()

if search_res["hits"]["total"]["value"] > 0:
return None

try:
with open(config_path, "r", encoding="utf-8") as variables_yml:
global_config = yaml.safe_load(variables_yml)
Expand Down Expand Up @@ -132,6 +119,8 @@ def _upload_files(
parameters_path="parameters.txt",
):
"""
Upload realization and iteration objects if they do not exist
Upload parameters file if it does not exist or it has changed
Create threads and call _upload in each thread
"""

Expand All @@ -149,15 +138,21 @@ def _upload_files(
e.with_traceback(None),
)

paramfile = create_parameter_file(
sumo_parent_id,
realization_id,
parameters_path,
config_path,
sumoclient,
)
paramfile = get_parameter_file(parameters_path, config_path)
if paramfile is not None:
files.append(paramfile)
query = f"fmu.case.uuid:{sumo_parent_id} AND fmu.realization.uuid:{realization_id} AND data.content:parameters"
search_res = sumoclient.get(
"/search", {"$query": query, "$select": "_sumo.blob_md5"}
).json()
# Check if the parameters file does not exist or has changed
if (
search_res["hits"]["total"]["value"] == 0
or search_res["hits"]["hits"][0]["_source"]["_sumo"][
"blob_md5"
]
!= paramfile.metadata["_sumo"]["blob_md5"]
):
files.append(paramfile)

break

Expand Down

0 comments on commit bc09429

Please sign in to comment.