From a6c8ae55e353dc7eb4ec77f60197e5bc1b296acd Mon Sep 17 00:00:00 2001 From: Sinisa Veseli <sveseli@aps.anl.gov> Date: Tue, 23 Jun 2015 20:23:37 +0000 Subject: [PATCH] new file processing apis added --- src/python/dm/ds_web_service/api/dsRestApi.py | 5 ++- .../dm/ds_web_service/api/dsRestApiFactory.py | 6 +++ .../dm/ds_web_service/api/fileRestApi.py | 37 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100755 src/python/dm/ds_web_service/api/fileRestApi.py diff --git a/src/python/dm/ds_web_service/api/dsRestApi.py b/src/python/dm/ds_web_service/api/dsRestApi.py index 0465538a..d41b64d9 100755 --- a/src/python/dm/ds_web_service/api/dsRestApi.py +++ b/src/python/dm/ds_web_service/api/dsRestApi.py @@ -1,15 +1,16 @@ #!/usr/bin/env python from dm.common.api.dmRestApi import DmRestApi +from dm.common.utility.configurationManager import ConfigurationManager class DsRestApi(DmRestApi): """ Base DS DM REST api class. """ def __init__(self, username=None, password=None, host=None, port=None, protocol=None): if host == None: - host = self.configurationManager.getDsWebServiceHost() + host = ConfigurationManager.getInstance().getDsWebServiceHost() if port == None: - port = self.configurationManager.getDsWebServicePort() + port = ConfigurationManager.getInstance().getDsWebServicePort() DmRestApi.__init__(self, username, password, host, port, protocol) ####################################################################### diff --git a/src/python/dm/ds_web_service/api/dsRestApiFactory.py b/src/python/dm/ds_web_service/api/dsRestApiFactory.py index c5e309b6..6b9e3dad 100755 --- a/src/python/dm/ds_web_service/api/dsRestApiFactory.py +++ b/src/python/dm/ds_web_service/api/dsRestApiFactory.py @@ -56,6 +56,12 @@ class DsRestApiFactory: api = ExperimentRestApi(username, password, host, port, protocol) return api + @classmethod + def getFileRestApi(cls): + from fileRestApi import FileRestApi + (username, password, host, port, protocol) = cls.__getConfiguration() + api = FileRestApi(username, password, host, port, protocol) + return api #################################################################### # Testing diff --git a/src/python/dm/ds_web_service/api/fileRestApi.py b/src/python/dm/ds_web_service/api/fileRestApi.py new file mode 100755 index 00000000..a0de650d --- /dev/null +++ b/src/python/dm/ds_web_service/api/fileRestApi.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import os +import urllib + +from dm.common.utility.encoder import Encoder +from dm.common.exceptions.dmException import DmException +from dm.common.objects.fileMetadata import FileMetadata +from dsRestApi import DsRestApi + +class FileRestApi(DsRestApi): + + def __init__(self, username=None, password=None, host=None, port=None, protocol=None): + DsRestApi.__init__(self, username, password, host, port, protocol) + + @DsRestApi.execute + def processFile(self, fileName, filePath, experimentName): + url = '%s/files/processFile' % (self.getContextRoot()) + if not fileName: + raise InvalidRequest('File name must be provided.') + url += '?fileName=%s' % Encoder.encode(fileName) + if not filePath: + raise InvalidRequest('File path must be provided.') + url += '&filePath=%s' % Encoder.encode(filePath) + if not experimentName: + raise InvalidRequest('Experiment name must be provided.') + url += '&experimentName=%s' % Encoder.encode(experimentName) + responseDict = self.sendSessionRequest(url=url, method='POST') + return FileMetadata(responseDict) + +####################################################################### +# Testing. + +if __name__ == '__main__': + api = FileRestApi('sveseli', 'sveseli', 'zagreb.svdev.net', 22236, 'http') + print api.processFile('file1', '/ESAF/exp1', 'exp1') + -- GitLab