-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcache_collector_hosts.py
70 lines (60 loc) · 2.87 KB
/
cache_collector_hosts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import re
import htcondor
import pickle
from pathlib import Path
CUSTOM_MAPPING = {
"osg-login2.pace.gatech.edu": {"osg-login2.pace.gatech.edu"},
"ce1.opensciencegrid.org": {"cm-2.ospool.osg-htc.org", "cm-1.ospool.osg-htc.org"},
"login-test.osgconnect.net": {"cm-2.ospool.osg-htc.org", "cm-1.ospool.osg-htc.org"},
"scosg16.jlab.org": {"scicollector.jlab.org", "osg-jlab-1.t2.ucsd.edu"},
"scosgdev16.jlab.org": {"scicollector.jlab.org", "osg-jlab-1.t2.ucsd.edu"},
"submit6.chtc.wisc.edu": {"htcondor-cm-path.osg.chtc.io"},
"login-el7.xenon.ci-connect.net": {"cm-2.ospool.osg-htc.org", "cm-1.ospool.osg-htc.org"},
"login.collab.ci-connect.net": {"cm-2.ospool.osg-htc.org", "cm-1.ospool.osg-htc.org"},
"uclhc-2.ps.uci.edu": {"uclhc-2.ps.uci.edu"},
"osgsub01.sdcc.bnl.gov": {"scicollector.jlab.org", "osg-jlab-1.t2.ucsd.edu"},
}
def main():
collector_host = "cm-1.ospool.osg-htc.org"
collector_hosts = {"cm-1.ospool.osg-htc.org", "cm-2.ospool.osg-htc.org"}
schedd_collector_host_map_pickle = Path("ospool-host-map.pkl")
schedd_collector_host_map = {}
if schedd_collector_host_map_pickle.exists():
try:
schedd_collector_host_map = pickle.load(open(schedd_collector_host_map_pickle, "rb"))
except IOError:
pass
schedd_collector_host_map.update(CUSTOM_MAPPING)
collector = htcondor.Collector(collector_host)
schedds = [ad["Machine"] for ad in collector.locateAll(htcondor.DaemonTypes.Schedd)]
for schedd in schedds:
schedd_collector_host_map[schedd] = set()
for collector_host in collector_hosts:
collector = htcondor.Collector(collector_host)
ads = collector.query(
htcondor.AdTypes.Schedd,
constraint=f'''Machine == "{schedd.split('@')[-1]}"''',
projection=["Machine", "CollectorHost"],
)
ads = list(ads)
if len(ads) == 0:
continue
if len(ads) > 1:
print(f'Got multiple Schedd ClassAds for Machine == "{schedd}"')
# Cache the CollectorHost in the map
if "CollectorHost" in ads[0]:
schedd_collector_hosts = set()
for schedd_collector_host in re.split(r'[, ]+', ads[0]["CollectorHost"]):
schedd_collector_host = schedd_collector_host.strip().split(":")[0]
if schedd_collector_host:
schedd_collector_hosts.add(schedd_collector_host)
if schedd_collector_hosts:
schedd_collector_host_map[schedd] = schedd_collector_hosts
break
else:
print(f"Did not find Machine == {schedd} in collectors")
# Update the pickle
with open(schedd_collector_host_map_pickle, "wb") as f:
pickle.dump(schedd_collector_host_map, f)
if __name__ == "__main__":
main()