You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by tl...@apache.org on 2022/05/27 20:39:11 UTC
[incubator-sdap-nexus] branch sdap-388-proxy updated: first version of the code ready, but still not tested
This is an automated email from the ASF dual-hosted git repository.
tloubrieu pushed a commit to branch sdap-388-proxy
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git
The following commit(s) were added to refs/heads/sdap-388-proxy by this push:
new d18d0ad first version of the code ready, but still not tested
d18d0ad is described below
commit d18d0ad2dc65f379273043014be2d6a9b25e9963
Author: Thomas Loubrieu <lo...@jpl.nasa.gov>
AuthorDate: Fri May 27 13:39:02 2022 -0700
first version of the code ready, but still not tested
---
analysis/conda-requirements.txt | 1 +
analysis/webservice/redirect/RedirectHandler.py | 17 +++++++++++++
.../webservice/redirect/RemoteCollectionMatcher.py | 29 ++++++++++++++++++++++
analysis/webservice/redirect/__init__.py | 2 ++
analysis/webservice/webapp.py | 19 +++++++++++++-
helm/templates/webapp.yml | 1 +
6 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/analysis/conda-requirements.txt b/analysis/conda-requirements.txt
index 7c8ae8a..775cf29 100644
--- a/analysis/conda-requirements.txt
+++ b/analysis/conda-requirements.txt
@@ -10,6 +10,7 @@ pillow==8.1.0
mpld3=0.5.1
tornado==6.1
pyproj==2.6.1.post1
+pyyaml==6.0
geos==3.8.1
gdal==3.2.1
mock==4.0.3
diff --git a/analysis/webservice/redirect/RedirectHandler.py b/analysis/webservice/redirect/RedirectHandler.py
new file mode 100644
index 0000000..bad0482
--- /dev/null
+++ b/analysis/webservice/redirect/RedirectHandler.py
@@ -0,0 +1,17 @@
+import tornado
+from webservice.webmodel.RequestParameters import RequestParameters
+
+
+class RedirectHandler(tornado.web.RequestHandler):
+
+ def initialize(self, redirected_collections):
+ self._redirected_collections = redirected_collections
+
+ def get(self, *args, **kwargs):
+ ds = self.get_arguments(ds=request.get_argument(RequestParameters.DATASET, None))
+ self.redirect(
+ self._redirected_collections[ds]['url'],
+ permanent=True
+ )
+
+
diff --git a/analysis/webservice/redirect/RemoteCollectionMatcher.py b/analysis/webservice/redirect/RemoteCollectionMatcher.py
new file mode 100644
index 0000000..f7656ff
--- /dev/null
+++ b/analysis/webservice/redirect/RemoteCollectionMatcher.py
@@ -0,0 +1,29 @@
+import yaml
+from webservice.webmodel.RequestParameters import RequestParameters
+
+
+class RemoteCollectionMatcher(Matcher):
+ def __init__(self, collections_config: str):
+ self._collections_config = collections_config
+ self._redirected_collections = None
+
+ def get_redirected_collections(self):
+ if self._redirected_collections is None:
+ self._redirected_collections = self.get_redirected_collections(self._collections_config)
+ return self._redicted_collections
+
+ @staticmethod
+ def _get_redirected_collections(collections_config: str):
+ _redirected_collections = {}
+ with open(collections_config, 'r') as f:
+ collections_yaml = yaml.load(f, Loader=yaml.FullLoader)
+ for collection in collections_yaml['collections']:
+ if "url" in collection:
+ _redirected_collections[collection["id"]] = collection
+
+ return _redirected_collections
+
+ def match(self, request):
+ ds = request.get_argument(RequestParameters.DATASET, None)
+ if ds in self._redicted_collections:
+ return self._redicted_collection[ds]
\ No newline at end of file
diff --git a/analysis/webservice/redirect/__init__.py b/analysis/webservice/redirect/__init__.py
new file mode 100644
index 0000000..201e7a2
--- /dev/null
+++ b/analysis/webservice/redirect/__init__.py
@@ -0,0 +1,2 @@
+from .RedirectHandler import RedirectHandler
+from .RemoteCollectionMatcher import RemoteCollectionMatcher
\ No newline at end of file
diff --git a/analysis/webservice/webapp.py b/analysis/webservice/webapp.py
index abb09b8..f2f42b1 100644
--- a/analysis/webservice/webapp.py
+++ b/analysis/webservice/webapp.py
@@ -20,6 +20,7 @@ import sys
import os
from pathlib import Path
from functools import partial
+import yaml
import pkg_resources
import tornado.web
@@ -29,6 +30,8 @@ import webservice.algorithms_spark.NexusCalcSparkHandler
from nexustiles.nexustiles import NexusTileService
from webservice import NexusHandler
from webservice.nexus_tornado.request.handlers import NexusRequestHandler
+from webservice.redirect import RedirectHandler
+from webservice.redirect import RemoteCollectionMatcher
def inject_args_in_config(args, config):
@@ -76,6 +79,7 @@ if __name__ == "__main__":
define('cassandra_host', help='cassandra host')
define('cassandra_username', help='cassandra username')
define('cassandra_password', help='cassandra password')
+ define('collections_path', help='collection config path')
parse_command_line()
algorithm_config = inject_args_in_config(options, algorithm_config)
@@ -157,7 +161,20 @@ if __name__ == "__main__":
default_host=options.address,
debug=options.debug
)
- app.listen(options.port)
+ remote_collection_matcher = RemoteCollectionMatcher(options.collections_path)
+ redirect_handler = (r'/(.*)', RedirectHandler(), remote_collection_matcher.get_redirected_collections())
+ redirect_app = tornado.web.Application(
+ [redirect_handler],
+ default_host=options.address,
+ debug=options.debug)
+
+ router = RuleRouter([
+ Rule(remote_collection_matcher, redirect_app),
+ Rule(AnyMatches(), app)
+ ])
+
+ server = HTTPServer(router)
+ server.listen(options.port)
log.info("Starting HTTP listener...")
tornado.ioloop.IOLoop.current().start()
diff --git a/helm/templates/webapp.yml b/helm/templates/webapp.yml
index 063fe18..5203bed 100644
--- a/helm/templates/webapp.yml
+++ b/helm/templates/webapp.yml
@@ -16,6 +16,7 @@ spec:
- --cassandra-username={{ include "nexus.credentials.cassandra.username" . }}
- --cassandra-password={{ include "nexus.credentials.cassandra.password" . }}
- --solr-host={{ include "nexus.urls.solr" . }}
+ - --collections-path={{ include "nexus.collectionsConfig.mountPath" . }}/collections.yml
sparkVersion: "3.1.1"
volumes:
- name: collections-config-volume