This is an automated email from the ASF dual-hosted git repository.

skperez pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ce794e  Insitu schema (#206)
9ce794e is described below

commit 9ce794e351ee11b32204b4491ad7ad5283f51f29
Author: Riley Kuttruff <[email protected]>
AuthorDate: Mon Oct 10 17:18:01 2022 -0700

    Insitu schema (#206)
    
    * Changed matchup storage of insitu schema
    
    Now will load lazily upon being used in the code instead of upon import
    
    * Changelog
    
    Co-authored-by: rileykk <[email protected]>
---
 CHANGELOG.md                                    |  1 +
 analysis/webservice/algorithms/doms/insitu.py   |  1 +
 analysis/webservice/algorithms_spark/Matchup.py | 20 +++++++++++++++++---
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1434e4f..6b0e897 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,7 @@ and this project adheres to [Semantic 
Versioning](https://semver.org/spec/v2.0.0
 - Fixed bug where domsresults no longer worked after successful matchup
 - Fixed certificate error in Dockerfile
 - SDAP-403: Remote timeout fix and HofMoeller bug fix
+- Fixed matchup insitu query loading on import; loads when needed instead
 ### Security
 
 
diff --git a/analysis/webservice/algorithms/doms/insitu.py 
b/analysis/webservice/algorithms/doms/insitu.py
index 6368a03..30d4dbd 100644
--- a/analysis/webservice/algorithms/doms/insitu.py
+++ b/analysis/webservice/algorithms/doms/insitu.py
@@ -14,6 +14,7 @@ def query_insitu_schema():
     metadata
     """
     schema_endpoint = insitu_endpoints.getSchemaEndpoint()
+    logging.info("Querying schema")
     response = requests.get(schema_endpoint)
     response.raise_for_status()
     return response.json()
diff --git a/analysis/webservice/algorithms_spark/Matchup.py 
b/analysis/webservice/algorithms_spark/Matchup.py
index 5dafb31..7711691 100644
--- a/analysis/webservice/algorithms_spark/Matchup.py
+++ b/analysis/webservice/algorithms_spark/Matchup.py
@@ -43,7 +43,21 @@ from webservice.webmodel import NexusProcessingException
 
 EPOCH = timezone('UTC').localize(datetime(1970, 1, 1))
 ISO_8601 = '%Y-%m-%dT%H:%M:%S%z'
-insitu_schema = query_insitu_schema()
+
+
+class Schema:
+    def __init__(self):
+        self.schema = None
+
+    def get(self):
+        if self.schema is None:
+            logging.info("No local schema; fetching")
+            self.schema = query_insitu_schema()
+
+        return self.schema
+
+
+insitu_schema = Schema()
 
 
 def iso_time_to_epoch(str_time):
@@ -155,7 +169,7 @@ class Matchup(NexusCalcSparkHandler):
             raise NexusProcessingException(reason="'secondary' argument is 
required", code=400)
 
         parameter_s = request.get_argument('parameter')
-        insitu_params = get_insitu_params(insitu_schema)
+        insitu_params = get_insitu_params(insitu_schema.get())
         if parameter_s and parameter_s not in insitu_params:
             raise NexusProcessingException(
                 reason=f"Parameter {parameter_s} not supported. Must be one of 
{insitu_params}", code=400)
@@ -505,7 +519,7 @@ class DomsPoint(object):
             val = edge_point.get(name)
             if not val:
                 continue
-            unit = get_insitu_unit(name, insitu_schema)
+            unit = get_insitu_unit(name, insitu_schema.get())
             data.append(DataPoint(
                 variable_name=name,
                 cf_variable_name=name,

Reply via email to