コード例 #1
0
 def getCeleryCore(self, core: PC2Core, **kwargs ) -> PC2Core:
     for key, core_celery_params in core.config.items():
         if core_celery_params.get('type') == 'celery':
             celery_settings = core_celery_params.get( "settings")
             if celery_settings is not None:
                 return PC2Core(celery_settings)
     return core
コード例 #2
0
ファイル: shell.py プロジェクト: nasa-nccs-cds/pc2
 def __init__(self, settingsFilePath: str, **kwargs):
     Cmd.__init__(self)
     self.parms = kwargs
     self.logger = PC2Logger.getLogger()
     settings: str = self.abs_path(settingsFilePath)
     self.core = PC2Core(settings)
     self.client: PC2Client = self.core.getClient()
     self.results: Dict[str, TaskHandle] = {}
コード例 #3
0
 def initHandler( self, clientSpec: Dict[str,Dict] ):
     if self._handlers is None:
         hspec: Dict[str,Dict] = { clientSpec['name']: clientSpec, "server": { 'type': "celery", 'name':"pc2" } }
         logger.info(f"Init Celery Task Handler with spec: {hspec}")
         self.core = PC2Core( hspec )
         self._handlers = Handlers( self.core, hspec )
         self._name, handlerSpec = list(hspec.items())[0]
         self._handler: Handler = self._handlers.available[ self._name ]
コード例 #4
0
from pc2.app.core import PC2Core
from pc2base.module.handler.base import TaskHandle
from pc2.util.test import TestDataManager as mgr

settings = dict( server = dict( type="rest", API="wps", host_address="http://127.0.0.1:5000/wps/cwt" ) )
core = PC2Core(settings)
client = core.getClient()

local_request = dict(
    domain=[{"name": "d0", "lat": {"start": 50, "end": 55, "system": "values"},
             "lon": {"start": 40, "end": 42, "system": "values"},
             "time": {"start": "1980-01-01", "end": "1981-12-31", "crs": "timestamps"}}],
    input=[{"uri": mgr.getAddress("merra2", "tas"), "name": "tas:v0", "domain": "d0"}],
    operation=[{'name': "xarray.ave", 'axes': "t", "input": "v0"}]
)

task: TaskHandle = client.request(local_request)
result = task.getResult(type="data")
print( "Got Result: " + str(result.header) )
for data_array in result.data:
    print( "Got Data array: " + str(data_array.values() ) )

コード例 #5
0
                    self.apis.append(rest_api)
                except Exception as err:
                    self.logger.error(
                        f"Error instantiating api {apiName}: {str(err)}\n" +
                        traceback.format_exc())

    @staticmethod
    def render_server_error(ex: Exception):
        print(str(ex))
        traceback.print_exc()
        return Response(response=json.dumps({
            'message':
            getattr(ex, 'message', repr(ex)),
            "code":
            500,
            "rid":
            "",
            "status":
            "error"
        }),
                        status=500,
                        mimetype="application/json")


if __name__ == "__main__":
    HERE = os.path.dirname(os.path.abspath(__file__))
    SETTINGS_FILE = os.path.join(HERE, "wps_server_edas_settings.ini")
    core = PC2Core(SETTINGS_FILE)
    app: PC2App = core.getApplication()
    app.start()
コード例 #6
0
ファイル: server.py プロジェクト: nasa-nccs-cds/pc2
from pc2.handlers.zeromq.app import PC2App
from pc2.app.core import PC2Core
import os, sys
HERE: str = os.getcwd()


def abs_path(relpath: str) -> str:
    if relpath is None: return HERE
    return relpath if relpath.startswith("/") else os.path.join(HERE, relpath)


if __name__ == '__main__':
    if len(sys.argv) == 1:
        print("Usage: >> python -m pc2.app.server <settingsFilePath>")
    else:
        core: PC2Core = PC2Core(abs_path(sys.argv[1]))
        app: PC2App = core.getApplication()
        app.run()
コード例 #7
0
from pc2.app.core import PC2Core

if __name__ == "__main__":

    settings = dict(server=dict(
        type="rest", host="127.0.0.1", port="5000", API="wps",
        route="wps/cwt"))
    pc2 = PC2Core(settings)
    client = pc2.getClient()
    response = client.capabilities("process")
    print(response["xml"])
コード例 #8
0
ファイル: edas_test.py プロジェクト: nasa-nccs-cds/pc2
from pc2base.module.handler.base import TaskHandle, TaskResult
from typing import Sequence, List, Dict, Mapping, Optional, Any
from edas.process.test import TestDataManager as mgr
import os, xarray as xa
from pc2.app.core import PC2Core
HERE: str = os.path.dirname(os.path.abspath(__file__))
certificate_path = "/att/nobackup/tpmaxwel/.pc2/zmq/"
# zmq_settings = dict( pc2 = dict( type="zeromq", client_address = "127.0.0.1", request_port = "4556", response_port = "4557", certificate_path = certificate_path  ) )
# rest_settings = dict( server=dict(type="rest", host="127.0.0.1", port="5000" ) )

SETTINGS: str = os.path.join( HERE, "edas_test_settings.ini" )

if __name__ == "__main__":

    pc2 = PC2Core( SETTINGS )
    client = pc2.getClient()
    uri =  mgr.getAddress("merra2", "tas")

    requestSpec = dict(
        domain=[ dict( name="d0", time={"start": "1980-01-01", "end": "2001-12-31", "crs": "timestamps"} )  ],
        input=[ dict( uri=uri, name="tas:v0", domain="d0" ) ],
        operation=[ dict( name="edas:ave", axis="xy", input="v0", result="r0" ),  dict( name="demo:log", input="r0" )  ]
    )

    task: TaskHandle = client.request( requestSpec )
    result: Optional[TaskResult] = task.getResult( block=True )
    dsets: List[xa.Dataset] = result.data
    print(f"Completed Request, NResults = {len(dsets)}" )
    dvar: xa.Variable
    for index,dset in enumerate(dsets):
        fileName =  f"/tmp/edas_module_test_result-{index}.nc"
コード例 #9
0
ファイル: clientApp.py プロジェクト: nasa-nccs-cds/pc2
 def __init__(self, core: PC2Core, type: str, **kwargs):
     PC2Client.__init__(self, type, **kwargs)
     self.app: PC2AppBase = core.getApplication()
コード例 #10
0
ファイル: rest_client_test.py プロジェクト: nasa-nccs-cds/pc2
from pc2.app.core import PC2Core
import os
HERE = os.path.dirname(os.path.abspath(__file__))
SETTINGS_FILE = os.path.join( HERE, "settings.ini" )

if __name__ == "__main__":

    pc2 = PC2Core( SETTINGS_FILE )
    server = pc2.getClient()

    variables=[ dict( name='tas:v0', uri='collection://merra2')  ]
    bounds = [ dict( axis='lat', start=-50, end=50, crs='values' ) ]
    domains=[ dict( name='d0', bounds=bounds) ]
    operations=[ dict( name='hpda.test1', axis='t', input='v0', domain='d0' )  ]
    request=dict(variables=variables, domains=domains, operations=operations )

    response = server.request( "exe", request=request )
    print( response )

    response = server.request( "stat", id=response['id'] )
    print( response )

    response = server.request( "kill", id=response['id'] )
    print( response )

コード例 #11
0
        tb = traceback.format_exc()
        self.logger.error("@@PC2-APP: Execution error: " + str(ex))
        self.logger.error(tb)
        response = {"status": "error", "error": str(ex), "traceback": tb}
        self.sendResponseMessage(PC2Response(rid, response))

    def updateInteractions(self):
        self.processRequests()
        self.processResults()

    def term(self, msg):
        self.logger.info("@@PC2-APP: !!EDAS Shutdown: " + msg)
        self.active = False
        self.auth.stop()
        self.logger.info("@@PC2-APP: QUIT PythonWorkerPortal")
        try:
            self.request_socket.close()
        except Exception:
            pass
        self.logger.info("@@PC2-APP: CLOSE request_socket")
        self.responder.close_connection()
        self.logger.info("@@PC2-APP: TERM responder")
        self.shutdown()
        self.logger.info("@@PC2-APP: shutdown complete")


if __name__ == "__main__":
    core = PC2Core("test_settings1.ini")
    app = core.getApplication()
    app.start()