Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 1671749

Browse files
authored
Merge pull request #617 from CMSCompOps/testing
add a serviceconfig file to change endpoint urls
2 parents d4fbc26 + 998972f commit 1671749

File tree

2 files changed

+130
-60
lines changed

2 files changed

+130
-60
lines changed

serviceConfiguration.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"mongo_db_url": {
3+
"value": "vocms0274.cern.ch",
4+
"description": "The mongodb instance."
5+
},
6+
"dbs_url": {
7+
"value": "https://cmsweb.cern.ch/dbs/prod/global/DBSReader",
8+
"description": "The base Url for DBS Reader "
9+
},
10+
"dbs_url_writer": {
11+
"value": "https://cmsweb.cern.ch/dbs/prod/global/DBSWriter",
12+
"description": "The base Url for DBS Writer."
13+
},
14+
"phedex_url": {
15+
"value" : "cmsweb.cern.ch",
16+
"description" : "The base url for PhEDEx service."
17+
},
18+
"reqmgr_url": {
19+
"value": "cmsweb.cern.ch",
20+
"description": "The base Url for ReqMgr service."
21+
},
22+
"monitor_dir": {
23+
"value": "/data/unified/www/",
24+
"description": "The local monitor dir."
25+
},
26+
"monitor_eos_dir": {
27+
"value": "/eos/cms/store/unified/www/",
28+
"description": "The monitor dir at EOS."
29+
},
30+
"monitor_pub_dir": {
31+
"value": "/data/unified/www/public/",
32+
"description": "The public monitor dir."
33+
},
34+
"monitor_pub_eos_dir": {
35+
"value": "/eos/cms/store/unified/www/public/",
36+
"description": "The public monitor dir at EOS."
37+
},
38+
"base_dir": {
39+
"value": "/data/unified/",
40+
"description": "The base dir for the unified code."
41+
},
42+
"base_eos_dir": {
43+
"value": "/eos/cms/store/unified/",
44+
"description": "The base dir for unified at EOS."
45+
},
46+
"unified_url": {
47+
"value": "https://cms-unified.web.cern.ch/cms-unified/",
48+
"description": "The base Url for Unified."
49+
},
50+
"unified_url_eos": {
51+
"value": "https://cms-unified.web.cern.ch/cms-unified/",
52+
"description": "The base Url for Unified at EOS."
53+
},
54+
"unified_pub_url": {
55+
"value": "https://cms-unified.web.cern.ch/cms-unified/public/",
56+
"description": "The public Url for Unified."
57+
},
58+
"cache_dir": {
59+
"value": "/data/unified-cache/",
60+
"description": "Cache dir."
61+
}
62+
}

utils.py

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,78 @@
3131
if not p in sys.path: sys.path.append(p)
3232

3333

34-
dbs_url = os.getenv('UNIFIED_DBS3_READER' ,'https://cmsweb.cern.ch/dbs/prod/global/DBSReader')
35-
dbs_url_writer = os.getenv('UNIFIED_DBS3_WRITER','https://cmsweb.cern.ch/dbs/prod/global/DBSWriter')
36-
37-
phedex_url = os.getenv('UNIFIED_PHEDEX','cmsweb.cern.ch')
38-
reqmgr_url = os.getenv('UNIFIED_REQMGR','cmsweb.cern.ch')
39-
monitor_dir = os.getenv('UNIFIED_MON','/data/unified/www/')
40-
#monitor_eos_dir = "/eos/project/c/cms-unified-logs/www/"
41-
monitor_eos_dir = '/eos/cms/store/unified/www/'
42-
monitor_dir = monitor_eos_dir
43-
monitor_pub_dir = os.getenv('UNIFIED_MON','/data/unified/www/public/')
44-
#monitor_pub_eos_dir = "/eos/project/c/cms-unified-logs/www/public/"
45-
monitor_pub_eos_dir = "/eos/cms/store/unified/www/public/"
46-
monitor_pub_dir = monitor_pub_eos_dir
47-
base_dir = os.getenv('UNIFIED_DIR','/data/unified/')
48-
#base_eos_dir = "/eos/project/c/cms-unified-logs/"
49-
base_eos_dir = "/eos/cms/store/unified/"
34+
def mongo_client():
35+
import pymongo, ssl
36+
return pymongo.MongoClient('mongodb://%s/?ssl=true' % mongo_db_url,
37+
ssl_cert_reqs=ssl.CERT_NONE)
38+
39+
40+
class unifiedConfiguration:
41+
def __init__(self, configFile='unifiedConfiguration.json'):
42+
# Explicitly set configFile to 'None' once you want to read from MongoDB
43+
self.configFile = configFile
44+
if self.configFile is None:
45+
self.configs = self.configFile
46+
else:
47+
try:
48+
self.configs = json.loads(open(self.configFile).read())
49+
except Exception as ex:
50+
print("Could not read configuration file: %s\nException: %s" %
51+
(self.configFile, str(ex)))
52+
sys.exit(124)
53+
54+
if self.configs is None:
55+
try:
56+
self.client = mongo_client()
57+
self.db = self.client.unified.unifiedConfiguration
58+
# quest = self.db.find_one()
59+
except Exception as ex:
60+
print ("Could not reach pymongo.\n Exception: \n%s" % str(ex))
61+
# self.configs = json.loads(open(self.configFile).read())
62+
sys.exit(124)
63+
64+
def get(self, parameter):
65+
if self.configs:
66+
if parameter in self.configs:
67+
return self.configs[parameter]['value']
68+
else:
69+
print parameter, 'is not defined in global configuration'
70+
print ','.join(self.configs.keys()), 'possible'
71+
sys.exit(124)
72+
else:
73+
found = self.db.find_one({"name": parameter})
74+
if found:
75+
found.pop("_id")
76+
found.pop("name")
77+
return found
78+
else:
79+
availables = [o['name'] for o in self.db.find_one()]
80+
print parameter, 'is not defined in mongo configuration'
81+
print ','.join(availables), 'possible'
82+
sys.exit(124)
5083

5184

52-
#unified_url = os.getenv('UNIFIED_URL','https://vocms049.cern.ch/unified/')
53-
unified_url = os.getenv('UNIFIED_URL','https://cms-unified.web.cern.ch/cms-unified/')
54-
unified_url_eos = "https://cms-unified.web.cern.ch/cms-unified/"
85+
SC = unifiedConfiguration('serviceConfiguration.json')
86+
87+
mongo_db_url = SC.get('mongo_db_url')
88+
dbs_url = os.getenv('UNIFIED_DBS3_READER', SC.get('dbs_url'))
89+
dbs_url_writer = os.getenv('UNIFIED_DBS3_WRITER', SC.get('dbs_url_writer'))
90+
phedex_url = os.getenv('UNIFIED_PHEDEX', SC.get('phedex_url'))
91+
reqmgr_url = os.getenv('UNIFIED_REQMGR', SC.get('reqmgr_url'))
92+
monitor_dir = os.getenv('UNIFIED_MON', SC.get('monitor_dir'))
93+
monitor_eos_dir = SC.get('monitor_eos_dir')
94+
monitor_dir = monitor_eos_dir
95+
monitor_pub_dir = os.getenv('UNIFIED_MON', SC.get('monitor_pub_eos_dir'))
96+
monitor_pub_eos_dir = SC.get('monitor_pub_eos_dir')
97+
monitor_pub_dir = monitor_pub_eos_dir
98+
base_dir = os.getenv('UNIFIED_DIR', SC.get('base_dir'))
99+
base_eos_dir = SC.get('base_eos_dir')
100+
unified_url = os.getenv('UNIFIED_URL', SC.get('unified_url'))
101+
unified_url_eos = SC.get('unified_url_eos')
55102
unified_url = unified_url_eos
56103
url_eos = unified_url_eos
57-
#unified_pub_url = os.getenv('UNIFIED_URL','https://vocms049.cern.ch/unified/public/')
58-
unified_pub_url = os.getenv('UNIFIED_URL','https://cms-unified.web.cern.ch/cms-unified/public/')
59-
cache_dir = '/data/unified-cache/'
60-
mongo_db_url = 'vocms0274.cern.ch'
104+
unified_pub_url = os.getenv('UNIFIED_URL', SC.get('unified_pub_url'))
105+
cache_dir = SC.get('cache_dir')
61106

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

835880

836-
def mongo_client():
837-
import pymongo,ssl
838-
return pymongo.MongoClient('mongodb://%s/?ssl=true'%mongo_db_url, ssl_cert_reqs=ssl.CERT_NONE)
839-
840881
class statusHistory:
841882
def __init__(self):
842883
self.client = mongo_client()
@@ -971,39 +1012,6 @@ def purge(self, now, since_in_days):
9711012
self.db.delete_many( { 'start' : {'$lt': then }})
9721013

9731014

974-
class unifiedConfiguration:
975-
def __init__(self):
976-
self.configs = json.loads(open('unifiedConfiguration.json').read()) ## switch to None once you want to read it from mongodb
977-
if self.configs is None:
978-
try:
979-
self.client = mongo_client()
980-
self.db = self.client.unified.unifiedConfiguration
981-
quest = self.db.find_one()
982-
except:
983-
print "could not reach pymongo"
984-
self.configs = json.loads(open('unifiedConfiguration.json').read())
985-
986-
def get(self, parameter):
987-
if self.configs:
988-
if parameter in self.configs:
989-
return self.configs[parameter]['value']
990-
else:
991-
print parameter,'is not defined in global configuration'
992-
print ','.join(self.configs.keys()),'possible'
993-
sys.exit(124)
994-
else:
995-
found = self.db.find_one({"name": parameter})
996-
if found:
997-
found.pop("_id")
998-
found.pop("name")
999-
return found
1000-
else:
1001-
availables = [o['name'] for o in self.db.find_one()]
1002-
print parameter,'is not defined in mongo configuration'
1003-
print ','.join(availables),'possible'
1004-
sys.exit(124)
1005-
1006-
10071015
def checkDownTime():
10081016
conn = make_x509_conn()
10091017
#conn = httplib.HTTPSConnection(reqmgr_url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY'))

0 commit comments

Comments
 (0)