Forked from
DM / dm-docs
261 commits behind, 202 commits ahead of the upstream repository.
-
sveseli authored
add first functional DS web service with user, experiment and auth controllers that allow retrieving user and experiment information from the db, start/stop experiment, and principal authorization; added corresponding API and CLI classes; added storage manager skeleton
sveseli authoredadd first functional DS web service with user, experiment and auth controllers that allow retrieving user and experiment information from the db, start/stop experiment, and principal authorization; added corresponding API and CLI classes; added storage manager skeleton
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
experimentRestApi.py 3.32 KiB
#!/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.experiment import Experiment
from dm.common.objects.experimentType import ExperimentType
from dsRestApi import DsRestApi
class ExperimentRestApi(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 getExperimentTypes(self):
url = '%s/experimentTypes' % (self.getContextRoot())
responseData = self.sendSessionRequest(url=url, method='GET')
return self.toDmObjectList(responseData, ExperimentType)
@DsRestApi.execute
def getExperiments(self):
url = '%s/experiments' % (self.getContextRoot())
responseData = self.sendSessionRequest(url=url, method='GET')
return self.toDmObjectList(responseData, Experiment)
@DsRestApi.execute
def getExperimentByName(self, name):
url = '%s/experimentsByName/%s' % (self.getContextRoot(), name)
if name is None or not len(name):
raise InvalidRequest('Experiment name must be provided.')
responseDict = self.sendSessionRequest(url=url, method='GET')
return Experiment(responseDict)
@DsRestApi.execute
def getExperimentById(self, id):
url = '%s/experiments/%s' % (self.getContextRoot(), id)
if id is None:
raise InvalidRequest('Experiment id must be provided.')
responseDict = self.sendSessionRequest(url=url, method='GET')
return Experiment(responseDict)
@DsRestApi.execute
def startExperiment(self, name):
url = '%s/experiments/start' % (self.getContextRoot())
if name is None or not len(name):
raise InvalidRequest('Experiment name must be provided.')
url += '?name=%s' % Encoder.encode(name)
responseDict = self.sendSessionRequest(url=url, method='PUT')
return Experiment(responseDict)
@DsRestApi.execute
def stopExperiment(self, name):
url = '%s/experiments/stop' % (self.getContextRoot())
if name is None or not len(name):
raise InvalidRequest('Experiment name must be provided.')
url += '?name=%s' % Encoder.encode(name)
responseDict = self.sendSessionRequest(url=url, method='PUT')
return Experiment(responseDict)
@DsRestApi.execute
def addExperiment(self, name, experimentTypeId, description):
url = '%s/experiments' % (self.getContextRoot())
if name is None or not len(name):
raise InvalidRequest('Experiment name must be provided.')
url += '?name=%s' % Encoder.encode(name)
if experimentTypeId is None:
raise InvalidRequest('Experiment type id must be provided.')
url += '&experimentTypeId=%s' % experimentTypeId
if description is not None:
url += '&description=%s' % Encoder.encode(description)
responseDict = self.sendSessionRequest(url=url, method='POST')
return Experiment(responseDict)
#######################################################################
# Testing.
if __name__ == '__main__':
api = ExperimentRestApi('sveseli', 'sveseli', 'zagreb.svdev.net', 33336, 'http')
print api.startExperiment('experiment1')