Skip to content

Commit 01e87f5

Browse files
committed
WIP - Check readiness
1 parent abb92bf commit 01e87f5

4 files changed

Lines changed: 126 additions & 2 deletions

File tree

automation/argo_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, path: str):
3838
self.web_api_token = automation.get("web_api_token")
3939
self.default_ops_profile_file = automation.get("default_ops_profile_file")
4040
self.hdfs_path = run.get("hdfs_path")
41+
self.hdfs_check_path = run.get("hdfs_check_path")
4142
self.flink_path = run.get("flink_path")
4243
self.batch_jar_path = run.get("batch_jar_path")
4344
self.ingest_jar_path = run.get("ingest_jar_path")

automation/argo_web_api.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
REQUEST_TIMEOUT = 30
1111

12+
class TopoItem(Enum):
13+
ENDPOINTS = "endpoints"
14+
GROUPS = "groups"
15+
SERVICE_TYPES = "service-types"
16+
1217

1318
class ArgoWebApi:
1419

@@ -90,6 +95,29 @@ def update_tenant_db_info(
9095
f"tenant: {tenant_name} ({tenant_id}) - web-api updating db conf updated"
9196
)
9297

98+
def get_topology(
99+
self,
100+
tenant_id: str,
101+
tenant_name: str,
102+
tenant_access_token: str,
103+
topology_item: TopoItem
104+
):
105+
"""Retrieve topology items for specific tenant"""
106+
logger.debug(
107+
f"tenant: {tenant_name} ({tenant_id}) - retrieving report information from web-api..."
108+
)
109+
url = f"https://{self.config.web_api_endpoint}/api/v2/topology/{topology_item.value}"
110+
headers = {
111+
"x-api-key": tenant_access_token,
112+
"Accept": "application/json",
113+
}
114+
115+
response = requests.get(url, headers=headers, timeout=REQUEST_TIMEOUT)
116+
response.raise_for_status()
117+
118+
return response.json().get("data")
119+
120+
93121
def get_reports(
94122
self,
95123
tenant_id: str,
@@ -110,7 +138,16 @@ def get_reports(
110138
response.raise_for_status()
111139

112140
results = response.json().get("data")
113-
return {item["info"]["name"]: item["id"] for item in results}
141+
142+
def get_report_ids(
143+
self,
144+
tenant_id: str,
145+
tenant_name: str,
146+
tenant_access_token: str
147+
):
148+
"""Retrieve report names and ids for specific tenant"""
149+
reports = get_reports(tenant_id,tenant_name,tenant_access_token)
150+
return {item["info"]["name"]: item["id"] for item in reports}
114151

115152
def create_ops_profile(
116153
self,

automation/check_readiness.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
logger = logging.getLogger(__name__)
2+
3+
from argo_config import ArgoConfig
4+
from argo_web_api import ArgoWebApi, TopoItem
5+
from argo_ams_library import (
6+
AmsServiceException,
7+
AmsUser,
8+
AmsUserProject,
9+
ArgoMessagingService,
10+
)
11+
import requests
12+
13+
14+
15+
def check_hdfs(config: ArgoConfig, tenant_id: str, tenant_name: str) -> bool:
16+
"""Checks if data for today exist in hdfs tenant folders"""
17+
18+
logger.debug(
19+
f"tenant: {tenant_name} ({tenant_id}) - retrieving report information from web-api..."
20+
)
21+
today = date.today().strftime('%Y-%m-%d')
22+
url = f"https://{config.hdfs_check_path}/{tenant_name}/mdata/{today}?op=LISTSTATUS"
23+
headers = {
24+
"x-api-key": tenant_access_token,
25+
"Accept": "application/json",
26+
}
27+
28+
response = requests.get(url, headers=headers, timeout=REQUEST_TIMEOUT)
29+
response.raise_for_status()
30+
31+
result = response.json().get("FileStatuses").get("FileStatus")
32+
if len(result) > 0:
33+
return True
34+
return False
35+
36+
37+
38+
def check_readiness(config: ArgoConfig, tenant_id: str, tenant_name: str):
39+
"""Checks tenants readiness by doing web-api requests to see if topology and
40+
reports are defined and also by checking if data are present both in ams and hdfs"""
41+
42+
web_api = ArgoWebApi(config)
43+
44+
# get access token from config file
45+
tenant_token = config.tenants.get(tenant_name,{}).get("web_api_token")
46+
47+
# check if topology exists
48+
topology_ready = True
49+
topology_msg = []
50+
topo_endpoints = web_api.get_topology(tenant_id, tenant_name, tenant_token, TopoItem.ENDPOINTS)
51+
topo_groups = web_api.get_topology(tenant_id, tenant_name, tenant_token, TopoItem.GROUPS)
52+
topo_service_types = web_api.get_topology(tenant_id, tenant_name, tenant_token, TopoItem.SERVICE_TYPES)
53+
54+
if len(topo_endpoints) > 0:
55+
topology_msg.append("Topology endpoints are set.")
56+
else:
57+
topology_msg.append("Topology endpoints are missing!")
58+
topology_ready = False
59+
60+
if len(topo_groups) > 0:
61+
topology_msg.append("Topology groups are set.")
62+
else:
63+
topology_msg.append("Topology groups are missing!")
64+
topology_ready = False
65+
66+
if len(topo_groups) > 0:
67+
topology_msg.append("Topology service-types are set.")
68+
else:
69+
topology_msg.append("Topology service-types are missing!")
70+
topology_ready = False
71+
72+
# check reports
73+
reports_ready = True
74+
reports_msg = "Tenant has at least one report"
75+
76+
reports = web_api.get_reports(tenant_id, tenant_name, tenant_token)
77+
if len(reports) < 0:
78+
reports_msg = "Tenant has no reports!"
79+
80+
# check ams
81+
ams = ArgoMessagingService(
82+
endpoint=config.ams_endpoint, token=config.ams_admin_token, project=tenant_name
83+
)
84+
85+
topic_metric_data = ams.get_topic("metric_data")
86+
topic_metric_data ams.get

automation/run_batch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def main():
141141
)
142142
if not report_id:
143143
# try to update the tenant report configuration
144-
reports = web_api.get_reports(
144+
reports = web_api.get_report_ids(
145145
tenant["id"], args.tenant, tenant["web_api_token"]
146146
)
147147
config.set_tenant_reports(tenant["id"], args.tenant, reports)

0 commit comments

Comments
 (0)