From 0db0812d6839009e1a3826af2fe3b47f88804931 Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Tue, 22 Jul 2014 17:33:33 -0500 Subject: [PATCH] Omaha #3185 harden using DAF through jep, implement new DAF methods for JepRouter Change-Id: Id923a9267eee1242ef826414c037c1391f2effd6 Former-commit-id: 94ad041a46d5f1d9cf7da623e5bec560c3b63fb9 [formerly de69306f1d3804b5c4cb09736aec3fa9a889646c] Former-commit-id: b9caab11c939b09d7d6fc2d3d199ae5ad78bfa42 --- .../base/python/dataaccess/JDataRequest.py | 16 ++++------- .../base/python/dataaccess/JepRouter.py | 28 +++++++++++-------- .../ufpy/dataaccess/DataAccessLayer.py | 28 +++++++++++-------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JDataRequest.py b/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JDataRequest.py index a130290870..733a102857 100644 --- a/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JDataRequest.py +++ b/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JDataRequest.py @@ -27,9 +27,10 @@ # # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- -# 12/17/12 njensen Initial Creation. -# Feb 14, 2013 1614 bsteffen refactor data access framework +# Dec 17, 2012 njensen Initial Creation. +# Feb 14, 2013 1614 bsteffen Refactor data access framework # to use single request. +# Jul 22, 2014 3185 njensen Fix getters to return python objs # # # @@ -85,15 +86,10 @@ class JDataRequest(IDataRequest, JUtil.JavaWrapperClass): def getIdentifiers(self): ids = {} jmap = self.jobj.getIdentifiers() - itr = jmap.keySet().iterator() - while itr.hasNext(): - key = itr.next() - value = JUtil.javaObjToPyVal(jmap.get(key)) - ids[key] = value - return ids + return JUtil.javaObjToPyVal(jmap) def getParameters(self): - return self.jobj.getParameters() + return JUtil.javaObjToPyVal(self.jobj.getParameters()) def getLevels(self): levels = [] @@ -111,7 +107,7 @@ class JDataRequest(IDataRequest, JUtil.JavaWrapperClass): return env def getLocationNames(self): - return self.jobj.getLocationNames() + return JUtil.javaObjToPyVal(self.jobj.getLocationNames()) def toJavaObj(self): return self.jobj diff --git a/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JepRouter.py b/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JepRouter.py index f445e34674..729c96f265 100644 --- a/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JepRouter.py +++ b/edexOsgi/com.raytheon.uf.edex.dataaccess/utility/common_static/base/python/dataaccess/JepRouter.py @@ -34,6 +34,7 @@ # to use single request. # 03/03/14 2673 bsteffen Add ability to query only ref times. # 07/22/14 3185 njensen Added optional/default args to newDataRequest +# and added new methods # # # @@ -49,6 +50,7 @@ from com.raytheon.uf.common.python import PythonNumpyFloatArray import jep import DataTime import JGeometryData, JGridData, JDataRequest +import JUtil def getAvailableTimes(request, refTimeOnly): @@ -90,23 +92,27 @@ def getGeometryData(request, times): return data def getAvailableLocationNames(request): - return JavaDataAccessLayer.getAvailableLocationNames(request.toJavaObj()) + jlocs = JavaDataAccessLayer.getAvailableLocationNames(request.toJavaObj()) + return JUtil.javaObjToPyVal(jlocs) def getAvailableParameters(request): - # TODO - raise Exception('Not implemented yet') + jparams = JavaDataAccessLayer.getAvailableParameters(request.toJavaObj()) + return JUtil.javaObjToPyVal(jparams) def getAvailableLevels(request): - # TODO - raise Exception('Not implemented yet') + jlevels = JavaDataAccessLayer.getAvailableLevels(request.toJavaObj()) + pylevs = [] + for jlev in jlevels: + pylevs.append(str(jlev)) + return pylevs def getRequiredIdentifiers(datatype): - # TODO - raise Exception('Not implemented yet') + jids = JavaDataAccessLayer.getRequiredIdentifiers(datatype) + return JUtil.javaObjToPyVal(jids) def getValidIdentifiers(datatype): - # TODO - raise Exception('Not implemented yet') + jids = JavaDataAccessLayer.getValidIdentifiers(datatype) + return JUtil.javaObjToPyVal(jids) def newDataRequest(datatype, parameters=[], levels=[], locationNames = [], envelope=None, **kwargs): req = JDataRequest.JDataRequest(DefaultDataRequest()) @@ -127,6 +133,6 @@ def newDataRequest(datatype, parameters=[], levels=[], locationNames = [], envel return req def getSupportedDatatypes(): - # TODO - raise Exception('Not implemented yet') + jsupported = JavaDataAccessLayer.getSupportedDatatypes() + return JUtil.javaObjToPyVal(jsupported) diff --git a/pythonPackages/ufpy/dataaccess/DataAccessLayer.py b/pythonPackages/ufpy/dataaccess/DataAccessLayer.py index 6858b6eb12..edd75aaad2 100644 --- a/pythonPackages/ufpy/dataaccess/DataAccessLayer.py +++ b/pythonPackages/ufpy/dataaccess/DataAccessLayer.py @@ -47,10 +47,13 @@ THRIFT_HOST = subprocess.check_output( shell=True).strip() USING_NATIVE_THRIFT = False -try: +if sys.modules.has_key('JavaImporter'): + # intentionally do not catch if this fails to import, we want it to + # be obvious that something is configured wrong when running from within + # Java instead of allowing false confidence and fallback behavior import JepRouter router = JepRouter -except ImportError: +else: from ufpy.dataaccess import ThriftClientRouter router = ThriftClientRouter.ThriftClientRouter(THRIFT_HOST) USING_NATIVE_THRIFT = True @@ -62,10 +65,9 @@ def getAvailableTimes(request, refTimeOnly=False): Args: request: the IDataRequest to get data for - - Args: - refTimeOnly: True if only unique refTimes should be returned(without - a forecastHr) + refTimeOnly: optional, use True if only unique refTimes should be + returned (without a forecastHr) + Returns: a list of DataTimes """ @@ -165,14 +167,13 @@ def getValidIdentifiers(datatype): Returns: a list of strings of valid identifiers """ - return router.getRequiredIdentifiers(datatype) + return router.getValidIdentifiers(datatype) def newDataRequest(datatype=None, **kwargs): """" Creates a new instance of IDataRequest suitable for the runtime environment. - - Args: - + All args are optional and exist solely for convenience. + Args: datatype: the datatype to create a request for parameters: a list of parameters to set on the request @@ -197,10 +198,13 @@ def getSupportedDatatypes(): def changeEDEXHost(newHostName): - """" + """ Changes the EDEX host the Data Access Framework is communicating with. Only - works if using the native Python client implemenation, otherwise, this + works if using the native Python client implementation, otherwise, this method will throw a TypeError. + + Args: + newHostHame: the EDEX host to connect to """ if USING_NATIVE_THRIFT: global THRIFT_HOST