-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_ospool_resources_report_json.py
126 lines (110 loc) · 4.17 KB
/
create_ospool_resources_report_json.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
import requests
import json
import datetime
import os
from verification import verify_latest_report
from util import write_document_to_file, get_ospool_aps, OSPOOL_COLLECTORS, OSPOOL_NON_FAIRSHARE_RESOURCES
DATA_DIRECTORY = "data/ospool_resources_report"
SUMMARY_INDEX = "osg-schedd-*"
ENDPOINT = "http://localhost:9200"
def get_ospool_resources_report_json():
query = {
"size": 1000,
"runtime_mappings": {
"ResourceName": {
"type": "keyword",
"script": {
"language": "painless",
"source": """
String res;
if (doc.containsKey("MachineAttrGLIDEIN_ResourceName0") && doc["MachineAttrGLIDEIN_ResourceName0.keyword"].size() > 0) {
res = doc["MachineAttrGLIDEIN_ResourceName0.keyword"].value;
} else if (doc.containsKey("MATCH_EXP_JOBGLIDEIN_ResourceName") && doc["MATCH_EXP_JOBGLIDEIN_ResourceName.keyword"].size() > 0) {
res = doc["MATCH_EXP_JOBGLIDEIN_ResourceName.keyword"].value;
} else {
res = "UNKNOWN";
}
emit(res);
""",
}
}
},
"aggs": {
"resources": {
"terms": {
"field": "ResourceName",
"missing": "UNKNOWN",
"size": 1024
}
}
},
"query": {
"bool": {
"filter": [
{
"term": {
"JobUniverse": 5,
}
},
],
"minimum_should_match": 1,
"should": [
{
"bool": {
"filter": [
{
"terms": {
"ScheddName.keyword": list(get_ospool_aps())
}
},
],
"must_not": [
{
"exists": {
"field": "LastRemotePool",
}
},
],
}
},
{
"terms": {
"LastRemotePool.keyword": list(OSPOOL_COLLECTORS)
}
},
],
"must_not": [
{
"terms": {
"ResourceName": list(OSPOOL_NON_FAIRSHARE_RESOURCES)
}
},
],
}
}
}
# Pull out the document and dump it in a dated file
response = requests.get(
f"{ENDPOINT}/{SUMMARY_INDEX}/_search",
data=json.dumps(query),
headers={'Content-Type': 'application/json'}
)
response_json = response.json()
resource_names = [i['key'] for i in response_json['aggregations']['resources']['buckets']]
return resource_names
def verify_ospool_resources(new_resources):
with open(f"{DATA_DIRECTORY}/ospool_resources.json", "r") as fp:
current_resources = json.load(fp)
current_resources = set(current_resources)
new_resources = set(new_resources)
if not new_resources.issuperset(current_resources):
print(f"resources Missing in New resources{current_resources.difference(new_resources)}")
return new_resources.issuperset(current_resources)
if __name__ == "__main__":
active_ospool_resources = get_ospool_resources_report_json()
if verify_ospool_resources(active_ospool_resources):
clean_resources = sorted(set(active_ospool_resources))
write_document_to_file(clean_resources, DATA_DIRECTORY, f"ospool_resources.json", True)
else:
print("New resources are not a superset of the previous resources!")