From f706f1e9866ab95551370c3f836ecd0943c11681 Mon Sep 17 00:00:00 2001 From: Sinisa Veseli <sveseli@aps.anl.gov> Date: Tue, 23 Jun 2015 20:22:54 +0000 Subject: [PATCH] add new file processing interfaces --- .../dm/ds_web_service/service/dsWebService.py | 6 ++- .../service/dsWebServiceRouteMapper.py | 2 + .../service/experimentRouteDescriptor.py | 2 +- .../service/fileRouteDescriptor.py | 35 +++++++++++++++++ .../service/fileSessionController.py | 38 +++++++++++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100755 src/python/dm/ds_web_service/service/fileRouteDescriptor.py create mode 100755 src/python/dm/ds_web_service/service/fileSessionController.py diff --git a/src/python/dm/ds_web_service/service/dsWebService.py b/src/python/dm/ds_web_service/service/dsWebService.py index acf8654b..6081e779 100755 --- a/src/python/dm/ds_web_service/service/dsWebService.py +++ b/src/python/dm/ds_web_service/service/dsWebService.py @@ -9,7 +9,8 @@ from dm.common.service.dmRestWebServiceBase import DmRestWebServiceBase from dm.common.utility.dmModuleManager import DmModuleManager from dm.common.utility.configurationManager import ConfigurationManager -from dm.ds_web_service.service.impl.storageManager import StorageManager +from dm.common.processing.fileProcessingManager import FileProcessingManager +from dm.ds_web_service.service.impl.experimentManager import ExperimentManager from dsWebServiceRouteMapper import DsWebServiceRouteMapper #################################################################### @@ -24,7 +25,8 @@ class DsWebService(DmRestWebServiceBase): # Add modules that will be started. moduleManager = DmModuleManager.getInstance() - moduleManager.addModule(StorageManager.getInstance()) + moduleManager.addModule(ExperimentManager.getInstance()) + moduleManager.addModule(FileProcessingManager.getInstance()) self.logger.debug('Initialized dm modules') def getDefaultServerHost(self): diff --git a/src/python/dm/ds_web_service/service/dsWebServiceRouteMapper.py b/src/python/dm/ds_web_service/service/dsWebServiceRouteMapper.py index ba377b8b..4f94d36d 100755 --- a/src/python/dm/ds_web_service/service/dsWebServiceRouteMapper.py +++ b/src/python/dm/ds_web_service/service/dsWebServiceRouteMapper.py @@ -13,6 +13,7 @@ from dm.common.utility.configurationManager import ConfigurationManager from dm.common.service.loginRouteDescriptor import LoginRouteDescriptor from userRouteDescriptor import UserRouteDescriptor from experimentRouteDescriptor import ExperimentRouteDescriptor +from fileRouteDescriptor import FileRouteDescriptor from authRouteDescriptor import AuthRouteDescriptor class DsWebServiceRouteMapper: @@ -29,6 +30,7 @@ class DsWebServiceRouteMapper: routes += AuthRouteDescriptor.getRoutes() routes += UserRouteDescriptor.getRoutes() routes += ExperimentRouteDescriptor.getRoutes() + routes += FileRouteDescriptor.getRoutes() # Add routes to dispatcher. d = cherrypy.dispatch.RoutesDispatcher() diff --git a/src/python/dm/ds_web_service/service/experimentRouteDescriptor.py b/src/python/dm/ds_web_service/service/experimentRouteDescriptor.py index 736795fb..18a27d81 100755 --- a/src/python/dm/ds_web_service/service/experimentRouteDescriptor.py +++ b/src/python/dm/ds_web_service/service/experimentRouteDescriptor.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# User route descriptor. +# Experiment route descriptor. # from dm.common.utility.configurationManager import ConfigurationManager diff --git a/src/python/dm/ds_web_service/service/fileRouteDescriptor.py b/src/python/dm/ds_web_service/service/fileRouteDescriptor.py new file mode 100755 index 00000000..375298c5 --- /dev/null +++ b/src/python/dm/ds_web_service/service/fileRouteDescriptor.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# +# File route descriptor. +# + +from dm.common.utility.configurationManager import ConfigurationManager +from fileSessionController import FileSessionController + +class FileRouteDescriptor: + + @classmethod + def getRoutes(cls): + contextRoot = ConfigurationManager.getInstance().getContextRoot() + + # Static instances shared between different routes + fileSessionController = FileSessionController() + + # Define routes. + routes = [ + + # Process file + { + 'name' : 'processFile', + 'path' : '%s/files/processFile' % contextRoot, + 'controller' : fileSessionController, + 'action' : 'processFile', + 'method' : ['POST'] + }, + + ] + + return routes + + diff --git a/src/python/dm/ds_web_service/service/fileSessionController.py b/src/python/dm/ds_web_service/service/fileSessionController.py new file mode 100755 index 00000000..5652a39f --- /dev/null +++ b/src/python/dm/ds_web_service/service/fileSessionController.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import cherrypy + +from dm.common.service.dmSessionController import DmSessionController +from dm.common.exceptions.invalidRequest import InvalidRequest +from dm.common.utility.encoder import Encoder + +from dm.ds_web_service.service.impl.fileSessionControllerImpl import FileSessionControllerImpl + + +class FileSessionController(DmSessionController): + + def __init__(self): + DmSessionController.__init__(self) + self.fileSessionControllerImpl = FileSessionControllerImpl() + + @cherrypy.expose + @DmSessionController.require(DmSessionController.isAdministrator()) + @DmSessionController.execute + def processFile(self, **kwargs): + fileName = kwargs.get('fileName') + if not fileName: + raise InvalidRequest('Missing file name.') + fileName = Encoder.decode(fileName) + filePath = kwargs.get('filePath') + if not filePath: + raise InvalidRequest('Missing file path.') + filePath = Encoder.decode(filePath) + experimentName = kwargs.get('experimentName') + if not experimentName: + raise InvalidRequest('Missing experiment name.') + experimentName = Encoder.decode(experimentName) + + response = self.fileSessionControllerImpl.processFile(fileName, filePath, experimentName).getFullJsonRep() + self.logger.debug('Returning: %s' % response) + return response + -- GitLab