|
31 | 31 | if not p in sys.path: sys.path.append(p) |
32 | 32 |
|
33 | 33 |
|
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) |
50 | 83 |
|
51 | 84 |
|
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') |
55 | 102 | unified_url = unified_url_eos |
56 | 103 | 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') |
61 | 106 |
|
62 | 107 | FORMAT = "%(module)s.%(funcName)s(%(lineno)s) => %(message)s (%(asctime)s)" |
63 | 108 | DATEFMT = "%Y-%m-%d %H:%M:%S" |
@@ -833,10 +878,6 @@ def tell(self, comment): |
833 | 878 | print "------"+"-"*len(comment) |
834 | 879 |
|
835 | 880 |
|
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 | | - |
840 | 881 | class statusHistory: |
841 | 882 | def __init__(self): |
842 | 883 | self.client = mongo_client() |
@@ -971,39 +1012,6 @@ def purge(self, now, since_in_days): |
971 | 1012 | self.db.delete_many( { 'start' : {'$lt': then }}) |
972 | 1013 |
|
973 | 1014 |
|
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 | | - |
1007 | 1015 | def checkDownTime(): |
1008 | 1016 | conn = make_x509_conn() |
1009 | 1017 | #conn = httplib.HTTPSConnection(reqmgr_url, cert_file = os.getenv('X509_USER_PROXY'), key_file = os.getenv('X509_USER_PROXY')) |
|
0 commit comments