def __init__(self, configfile, service='DBS', dbinstance='dev/global', migration_test=False): """migration_test is used to point the DBSRestApi to one specific database, no matter, to which DB the original config file points to.""" log.error_log.setLevel(logging.ERROR) self.migration_test = migration_test config = self.configure(configfile, service, dbinstance) config = config.section_("DBS") config.instance = dbinstance self.rest = RESTApi(config) self.config = config
class DBSRestApi: def __init__(self, configfile, service='DBS', dbinstance='dev/global', migration_test=False): """migration_test is used to point the DBSRestApi to one specific database, no matter, to which DB the original config file points to.""" log.error_log.setLevel(logging.ERROR) self.migration_test = migration_test config = self.configure(configfile, service, dbinstance) config = config.section_("DBS") config.instance = dbinstance self.rest = RESTApi(config) self.config = config def configure(self, configfile, service, dbinstance): cfg = loadConfigurationFile(configfile) wconfig = cfg.section_("Webtools") app = wconfig.application appconfig = cfg.section_(app) dbsconfig = getattr(appconfig.views.active, service) # Either we change formatter # OR change the 'Accept' type to application/json (which we don't know how to do at the moment) dbsconfig.formatter.object = "WMCore.WebTools.RESTFormatter" config = Configuration() config.component_('SecurityModule') config.SecurityModule.dangerously_insecure = True config.component_('DBS') config.DBS.application = app config.DBS.model = dbsconfig.model config.DBS.formatter = dbsconfig.formatter #Does not support instances #config.DBS.instances = cfg.dbs.instances #config.DBS.database = dbsconfig.database if self.migration_test: #Use one specific database cms_dbs3_dev_phys02@int2r for migration unittests from DBSSecrets import dbs3_dp2_i2 config.DBS.section_('database') config.DBS.database.connectUrl = dbs3_dp2_i2['connectUrl'][ 'writer'] config.DBS.database.dbowner = dbs3_dp2_i2['databaseOwner'] config.DBS.database.engineParameters = { 'pool_size': 15, 'max_overflow': 10, 'pool_timeout': 200 } version = getattr(dbsconfig.database.instances, dbinstance).version config.DBS.database.version = version if version else '3.99.98' config.DBS.section_('security') config.DBS.security.params = {} else: #Use dev/global from dbs configuration for the reader, writer and dao unittests dbconfig = getattr(dbsconfig.database.instances, dbinstance) config.DBS.section_('database') config.DBS.database.connectUrl = dbconfig.connectUrl config.DBS.database.dbowner = dbconfig.dbowner config.DBS.database.engineParameters = dbconfig.engineParameters config.DBS.database.version = dbconfig.version if dbconfig.version else '3.99.98' #config.DBS.database.instance = dbconfig.instance try: secconfig = getattr(dbsconfig.security.instances, dbinstance) except AttributeError: pass else: config.DBS.section_('security') config.DBS.security.params = secconfig.params config.DBS.default_expires = 900 return config def list1(self, call, params={}): """takes parameters as a dictionary""" request.method = 'GET' request.user = {'name': getpass.getuser()} return self.rest.default(*[call], **params) def list(self, *args, **kwargs): """ takes individual parameters Example: api.list('files',dataset='/a/b/c') """ #print "List API call ....." request.method = 'GET' request.user = {'name': getpass.getuser()} return self.parseForException(self.rest.default(*args, **kwargs)) def insert(self, call, params={}): request.method = 'POST' request.body = FileLike(params) request.user = {'name': getpass.getuser()} #Forcing NO use of insert buffer during the unit tests if call == 'files': ret = self.rest.default(*[call, False]) else: ret = self.rest.default(*[call]) return self.parseForException(ret) def update(self, *args, **kwargs): request.method = 'PUT' request.user = {'name': getpass.getuser()} ret = self.rest.default(*args, **kwargs) return self.parseForException(ret) def parseForException(self, data): if type(data) == type("abc"): data = json.loads(data) if type(data) == type({}) and data.has_key('exception'): raise Exception("DBS Server raised an exception: HTTPError %s :" % data['exception'] + (data['message'])) return data
class DBSRestApi: def __init__(self, configfile, service='DBS', dbinstance='dev/global', migration_test=False): """migration_test is used to point the DBSRestApi to one specific database, no matter, to which DB the original config file points to.""" log.error_log.setLevel(logging.ERROR) self.migration_test = migration_test config = self.configure(configfile, service, dbinstance) config = config.section_("DBS") config.instance = dbinstance self.rest = RESTApi(config) self.config = config def configure(self, configfile, service, dbinstance): cfg = loadConfigurationFile(configfile) wconfig = cfg.section_("Webtools") app = wconfig.application appconfig = cfg.section_(app) dbsconfig = getattr(appconfig.views.active, service) # Either we change formatter # OR change the 'Accept' type to application/json (which we don't know how to do at the moment) dbsconfig.formatter.object="WMCore.WebTools.RESTFormatter" config = Configuration() config.component_('SecurityModule') config.SecurityModule.dangerously_insecure = True config.component_('DBS') config.DBS.application = app config.DBS.model = dbsconfig.model config.DBS.formatter = dbsconfig.formatter #Does not support instances #config.DBS.instances = cfg.dbs.instances #config.DBS.database = dbsconfig.database if self.migration_test: #Use one specific database cms_dbs3_dev_phys02@int2r for migration unittests from DBSSecrets import dbs3_dp2_i2 config.DBS.section_('database') config.DBS.database.connectUrl = dbs3_dp2_i2['connectUrl']['writer'] config.DBS.database.dbowner = dbs3_dp2_i2['databaseOwner'] config.DBS.database.engineParameters = { 'pool_size' : 15, 'max_overflow' : 10, 'pool_timeout' : 200 } version = getattr(dbsconfig.database.instances, dbinstance).version config.DBS.database.version = version if version else '3.99.98' config.DBS.section_('security') config.DBS.security.params = {} else: #Use dev/global from dbs configuration for the reader, writer and dao unittests dbconfig = getattr(dbsconfig.database.instances, dbinstance) config.DBS.section_('database') config.DBS.database.connectUrl = dbconfig.connectUrl config.DBS.database.dbowner = dbconfig.dbowner config.DBS.database.engineParameters = dbconfig.engineParameters config.DBS.database.version = dbconfig.version if dbconfig.version else '3.99.98' #config.DBS.database.instance = dbconfig.instance try: secconfig = getattr(dbsconfig.security.instances, dbinstance) except AttributeError: pass else: config.DBS.section_('security') config.DBS.security.params = secconfig.params config.DBS.default_expires = 900 return config def list1(self, call, params={}): """takes parameters as a dictionary""" request.method = 'GET' request.user = {'name' : getpass.getuser()} return self.rest.default(*[call], **params) def list(self, *args, **kwargs): """ takes individual parameters Example: api.list('files',dataset='/a/b/c') """ #print "List API call ....." request.method = 'GET' request.user = {'name' : getpass.getuser()} return self.parseForException(self.rest.default(*args, **kwargs)) def insert(self, call, params={}): request.method = 'POST' request.body = FileLike(params) request.user = {'name' : getpass.getuser()} #Forcing NO use of insert buffer during the unit tests if call=='files': ret=self.rest.default(*[call, False]) else: ret=self.rest.default(*[call]) return self.parseForException(ret) def update(self, *args, **kwargs): request.method = 'PUT' request.user = {'name' : getpass.getuser()} ret=self.rest.default(*args, **kwargs) return self.parseForException(ret) def parseForException(self, data): if type(data)==type("abc"): data=json.loads(data) if type(data) == type({}) and 'exception' in data: raise Exception("DBS Server raised an exception: HTTPError %s :" %data['exception'] + (data['message'])) return data
def __init__(self, configfile, service='DBS'): log.error_log.setLevel(logging.ERROR) config = self.configure(configfile, service) config = config.section_("DBS") self.rest = RESTApi(config) self.config = config
class DBSRestApi: def __init__(self, configfile, service='DBS'): log.error_log.setLevel(logging.ERROR) config = self.configure(configfile, service) config = config.section_("DBS") self.rest = RESTApi(config) self.config = config def configure(self, configfile, service): cfg = loadConfigurationFile(configfile) wconfig = cfg.section_("Webtools") app = wconfig.application appconfig = cfg.section_(app) dbsconfig = getattr(appconfig.views.active, service) databasecore = cfg.CoreDatabase # Eitehr we change formatter # OR change the 'Accept' type to application/json (which we don't know how to do at thi moment) dbsconfig.formatter.object="WMCore.WebTools.RESTFormatter" config = Configuration() config.section_("CoreDatabase") config.CoreDatabase = databasecore config.component_('DBS') config.DBS.application = app config.DBS.model = dbsconfig.model config.DBS.formatter = dbsconfig.formatter config.DBS.version = dbsconfig.version config.DBS.default_expires = 300 # DBS uses owner name, directly from app section at the moment (does not pick it from CoreDatabse) config.DBS.dbowner = databasecore.dbowner # Add the CoreDatabase section to DBS config.DBS.database = config.CoreDatabase return config def list1(self, call, params={}): """takes parameters as a dictionary""" request.method = 'GET' return self.rest.default(*[call], **params) def list(self, *args, **kwargs): """ takes individual parameters Example: api.list('files',dataset='/a/b/c') """ #print "List API call ....." request.method = 'GET' return self.parseForException(self.rest.default(*args, **kwargs)) def insert(self, call, params={}): request.method = 'POST' request.body = FileLike(params) #Forcing NO use of insert buffer during the unit tests if call=='files': ret=self.rest.default(*[call, False]) ret=self.rest.default(*[call]) return self.parseForException(ret) def update(self, *args, **kwargs): request.method = 'PUT' ret=self.rest.default(*args, **kwargs) return self.parseForException(ret) def parseForException(self, data): if type(data)==type("abc"): data=json.loads(data) if type(data) == type({}): if type(data) == type({}) and data.has_key('exception'): raise Exception("DBS Server raised an exception: " + (data['message'])) return data