Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions serviceConfiguration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"mongo_db_url": {
"value": "vocms0274.cern.ch",
"description": "The mongodb instance."
},
"dbs_url": {
"value": "https://cmsweb.cern.ch/dbs/prod/global/DBSReader",
"description": "The base Url for DBS Reader "
},
"dbs_url_writer": {
"value": "https://cmsweb.cern.ch/dbs/prod/global/DBSWriter",
"description": "The base Url for DBS Writer."
},
"phedex_url": {
"value" : "cmsweb.cern.ch",
"description" : "The base url for PhEDEx service."
},
"reqmgr_url": {
"value": "cmsweb.cern.ch",
"description": "The base Url for ReqMgr service."
},
"monitor_dir": {
"value": "/data/unified/www/",
"description": "The local monitor dir."
},
"monitor_eos_dir": {
"value": "/eos/cms/store/unified/www/",
"description": "The monitor dir at EOS."
},
"monitor_pub_dir": {
"value": "/data/unified/www/public/",
"description": "The public monitor dir."
},
"monitor_pub_eos_dir": {
"value": "/eos/cms/store/unified/www/public/",
"description": "The public monitor dir at EOS."
},
"base_dir": {
"value": "/data/unified/",
"description": "The base dir for the unified code."
},
"base_eos_dir": {
"value": "/eos/cms/store/unified/",
"description": "The base dir for unified at EOS."
},
"unified_url": {
"value": "https://cms-unified.web.cern.ch/cms-unified/",
"description": "The base Url for Unified."
},
"unified_url_eos": {
"value": "https://cms-unified.web.cern.ch/cms-unified/",
"description": "The base Url for Unified at EOS."
},
"unified_pub_url": {
"value": "https://cms-unified.web.cern.ch/cms-unified/public/",
"description": "The public Url for Unified."
},
"cache_dir": {
"value": "/data/unified-cache/",
"description": "Cache dir."
}
}
128 changes: 68 additions & 60 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,78 @@
if not p in sys.path: sys.path.append(p)


dbs_url = os.getenv('UNIFIED_DBS3_READER' ,'https://cmsweb.cern.ch/dbs/prod/global/DBSReader')
dbs_url_writer = os.getenv('UNIFIED_DBS3_WRITER','https://cmsweb.cern.ch/dbs/prod/global/DBSWriter')

phedex_url = os.getenv('UNIFIED_PHEDEX','cmsweb.cern.ch')
reqmgr_url = os.getenv('UNIFIED_REQMGR','cmsweb.cern.ch')
monitor_dir = os.getenv('UNIFIED_MON','/data/unified/www/')
#monitor_eos_dir = "/eos/project/c/cms-unified-logs/www/"
monitor_eos_dir = '/eos/cms/store/unified/www/'
monitor_dir = monitor_eos_dir
monitor_pub_dir = os.getenv('UNIFIED_MON','/data/unified/www/public/')
#monitor_pub_eos_dir = "/eos/project/c/cms-unified-logs/www/public/"
monitor_pub_eos_dir = "/eos/cms/store/unified/www/public/"
monitor_pub_dir = monitor_pub_eos_dir
base_dir = os.getenv('UNIFIED_DIR','/data/unified/')
#base_eos_dir = "/eos/project/c/cms-unified-logs/"
base_eos_dir = "/eos/cms/store/unified/"
def mongo_client():
import pymongo, ssl
return pymongo.MongoClient('mongodb://%s/?ssl=true' % mongo_db_url,
ssl_cert_reqs=ssl.CERT_NONE)


class unifiedConfiguration:
def __init__(self, configFile='unifiedConfiguration.json'):
# Explicitly set configFile to 'None' once you want to read from MongoDB
self.configFile = configFile
if self.configFile is None:
self.configs = self.configFile
else:
try:
self.configs = json.loads(open(self.configFile).read())
except Exception as ex:
print("Could not read configuration file: %s\nException: %s" %
(self.configFile, str(ex)))
sys.exit(124)

if self.configs is None:
try:
self.client = mongo_client()
self.db = self.client.unified.unifiedConfiguration
# quest = self.db.find_one()
except Exception as ex:
print ("Could not reach pymongo.\n Exception: \n%s" % str(ex))
# self.configs = json.loads(open(self.configFile).read())
sys.exit(124)

def get(self, parameter):
if self.configs:
if parameter in self.configs:
return self.configs[parameter]['value']
else:
print parameter, 'is not defined in global configuration'
print ','.join(self.configs.keys()), 'possible'
sys.exit(124)
else:
found = self.db.find_one({"name": parameter})
if found:
found.pop("_id")
found.pop("name")
return found
else:
availables = [o['name'] for o in self.db.find_one()]
print parameter, 'is not defined in mongo configuration'
print ','.join(availables), 'possible'
sys.exit(124)


#unified_url = os.getenv('UNIFIED_URL','https://vocms049.cern.ch/unified/')
unified_url = os.getenv('UNIFIED_URL','https://cms-unified.web.cern.ch/cms-unified/')
unified_url_eos = "https://cms-unified.web.cern.ch/cms-unified/"
SC = unifiedConfiguration('serviceConfiguration.json')

mongo_db_url = SC.get('mongo_db_url')
dbs_url = os.getenv('UNIFIED_DBS3_READER', SC.get('dbs_url'))
dbs_url_writer = os.getenv('UNIFIED_DBS3_WRITER', SC.get('dbs_url_writer'))
phedex_url = os.getenv('UNIFIED_PHEDEX', SC.get('phedex_url'))
reqmgr_url = os.getenv('UNIFIED_REQMGR', SC.get('reqmgr_url'))
monitor_dir = os.getenv('UNIFIED_MON', SC.get('monitor_dir'))
monitor_eos_dir = SC.get('monitor_eos_dir')
monitor_dir = monitor_eos_dir
monitor_pub_dir = os.getenv('UNIFIED_MON', SC.get('monitor_pub_eos_dir'))
monitor_pub_eos_dir = SC.get('monitor_pub_eos_dir')
monitor_pub_dir = monitor_pub_eos_dir
base_dir = os.getenv('UNIFIED_DIR', SC.get('base_dir'))
base_eos_dir = SC.get('base_eos_dir')
unified_url = os.getenv('UNIFIED_URL', SC.get('unified_url'))
unified_url_eos = SC.get('unified_url_eos')
unified_url = unified_url_eos
url_eos = unified_url_eos
#unified_pub_url = os.getenv('UNIFIED_URL','https://vocms049.cern.ch/unified/public/')
unified_pub_url = os.getenv('UNIFIED_URL','https://cms-unified.web.cern.ch/cms-unified/public/')
cache_dir = '/data/unified-cache/'
mongo_db_url = 'vocms0274.cern.ch'
unified_pub_url = os.getenv('UNIFIED_URL', SC.get('unified_pub_url'))
cache_dir = SC.get('cache_dir')

FORMAT = "%(module)s.%(funcName)s(%(lineno)s) => %(message)s (%(asctime)s)"
DATEFMT = "%Y-%m-%d %H:%M:%S"
Expand Down Expand Up @@ -833,10 +878,6 @@ def tell(self, comment):
print "------"+"-"*len(comment)


def mongo_client():
import pymongo,ssl
return pymongo.MongoClient('mongodb://%s/?ssl=true'%mongo_db_url, ssl_cert_reqs=ssl.CERT_NONE)

class statusHistory:
def __init__(self):
self.client = mongo_client()
Expand Down Expand Up @@ -971,39 +1012,6 @@ def purge(self, now, since_in_days):
self.db.delete_many( { 'start' : {'$lt': then }})


class unifiedConfiguration:
def __init__(self):
self.configs = json.loads(open('unifiedConfiguration.json').read()) ## switch to None once you want to read it from mongodb
if self.configs is None:
try:
self.client = mongo_client()
self.db = self.client.unified.unifiedConfiguration
quest = self.db.find_one()
except:
print "could not reach pymongo"
self.configs = json.loads(open('unifiedConfiguration.json').read())

def get(self, parameter):
if self.configs:
if parameter in self.configs:
return self.configs[parameter]['value']
else:
print parameter,'is not defined in global configuration'
print ','.join(self.configs.keys()),'possible'
sys.exit(124)
else:
found = self.db.find_one({"name": parameter})
if found:
found.pop("_id")
found.pop("name")
return found
else:
availables = [o['name'] for o in self.db.find_one()]
print parameter,'is not defined in mongo configuration'
print ','.join(availables),'possible'
sys.exit(124)


def checkDownTime():
conn = make_x509_conn()
#conn = httplib.HTTPSConnection(reqmgr_url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))
Expand Down