11
22import os
33import time
4+ from datetime import datetime , timezone , timedelta
45
56from benchmark_runner .common .logger .logger_time_stamp import logger_time_stamp , logger
67from benchmark_runner .common .elasticsearch .elasticsearch_exceptions import ElasticSearchDataNotUploaded
@@ -18,36 +19,57 @@ def __init__(self):
1819 if not self ._windows_url :
1920 raise ValueError ('Missing Windows DV URL' )
2021
21- def wait_for_windows_hammerdb_finished (self ):
22+ def wait_for_windows_hammerdb_finished (self , vm_nums : int = 1 ):
2223 """
23- Wait until the Windows HammerDB workload finishes by checking the 'status ' key in Elasticsearch
24+ Wait until the Windows HammerDB workload finishes by checking the 'vm ' key in Elasticsearch
2425 and verifying that data is not already updated by checking key data_updated.
26+
27+ Args:
28+ vm_nums: Expected number of VMs to complete (for scale support)
29+
2530 Returns:
2631 True if the workload succeeded.
32+
2733 Raises:
2834 Windows_HammerDB_NOT_Succeeded: If the workload did not succeed within the timeout.
2935 """
3036 current_wait_time = 0
3137
3238 while True :
33- response = self ._get_latest_resource_with_key (index = self ._es_index , key = 'status' )
34- # Verify that winmssl elasticsearch data is uploaded by checking 'status', 'vm_os_version'
35- # Checking that this is the latest data by verify that 'data_updated' is not True
36- if response .get ('status' ) == 'Succeeded' and response .get ('vm_os_version' ) == 'winmssql2022' and str (response .get ('data_updated' , '' )).lower () != 'true' :
39+ # Get ALL documents in time window
40+ current_datetime = datetime .now (timezone .utc )
41+ start_datetime = current_datetime - timedelta (hours = 1 )
42+ end_datetime = current_datetime + timedelta (hours = 1 )
43+
44+ es_data = self ._es_operations .get_index_data_between_dates (
45+ index = self ._es_index ,
46+ start_datetime = start_datetime ,
47+ end_datetime = end_datetime
48+ )
49+
50+ # Count documents with 'vm': 'Succeeded' and data_updated != True
51+ succeeded_count = sum (
52+ 1 for doc in es_data
53+ if doc .get ('_source' , {}).get ('vm' ) == 'Succeeded'
54+ and doc .get ('_source' , {}).get ('vm_os_version' ) == 'winmssql2022'
55+ and str (doc .get ('_source' , {}).get ('data_updated' , '' )).lower () != 'true'
56+ )
57+
58+ logger .info (f'Found { succeeded_count } /{ vm_nums } successful VMs' )
59+
60+ if succeeded_count >= vm_nums :
3761 return True
38- else :
39- logger .info ('Waiting for the Windows HammerDB run to finish successfully...' )
4062
41- # check timeout
63+ # Check timeout
4264 if self ._timeout > 0 and current_wait_time >= self ._timeout :
4365 break
4466
45- # sleep before next check
67+ # Sleep before next check
4668 time .sleep (OC .DELAY )
4769 current_wait_time += OC .DELAY
4870
4971 raise Windows_HammerDB_NOT_Succeeded (
50- f"HammerDB did not succeed within { self ._timeout } seconds"
72+ f"Only { succeeded_count } / { vm_nums } VMs completed HammerDB successfully within { self ._timeout } seconds"
5173 )
5274
5375 @logger_time_stamp
@@ -62,32 +84,47 @@ def run(self):
6284 else :
6385 self ._es_index = 'hammerdb-results'
6486 self ._initialize_run ()
65- # create windows dv
66- self ._oc .create_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , 'windows_dv.yaml' ))
67- self ._oc .wait_for_dv_status (status = 'Succeeded' )
68- self ._oc .create_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , f'{ self ._name } .yaml' ))
69- self ._oc .wait_for_vm_status (vm_name = f'{ self ._workload_name } -{ self ._trunc_uuid } ' , status = VMStatus .Stopped )
70- self ._set_bootstorm_vm_first_run_time ()
71- self ._set_bootstorm_vm_start_time (vm_name = self ._vm_name )
72- self ._virtctl .start_vm_sync (vm_name = self ._vm_name )
73- self ._data_dict = self ._get_bootstorm_vm_elapsed_time (vm_name = self ._vm_name , vm_node = '' )
74- self ._data_dict ['run_artifacts_url' ] = os .path .join (self ._run_artifacts_url ,
75- f'{ self ._get_run_artifacts_hierarchy (workload_name = self ._workload_name , is_file = True )} -{ self ._time_stamp_format } .tar.gz' )
76- self .wait_for_windows_hammerdb_finished ()
77- ids = self ._get_index_ids_between_dates (index = self ._es_index , key = 'status' )
78- # Adding data_updated=True to stamp that this data is already updated and enrich with new product versions fields
79- for id in ids :
80- self ._update_elasticsearch_index (index = self ._es_index , id = id , kind = 'vm' , status = 'Succeeded' , run_artifacts_url = self ._data_dict ['run_artifacts_url' ], database = 'mssql' , vm_name = f'{ self ._workload_name } -{ self ._trunc_uuid } ' , data_updated = True )
81- self ._finalize_vm ()
82- if self ._delete_all :
87+ if not self ._verification_only :
88+ # create windows dv
89+ self ._oc .create_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , 'windows_dv.yaml' ))
90+ self ._oc .wait_for_dv_status (status = 'Succeeded' )
91+ if self ._scale :
92+ # Just create the vms
93+ self ._create_vms_only = True
94+ self .run_vm_workload ()
95+ self ._create_vms_only = False
96+ else :
97+ self ._oc .create_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , f'{ self ._name } .yaml' ))
98+ self ._oc .wait_for_vm_status (vm_name = f'{ self ._workload_name } -{ self ._trunc_uuid } ' ,
99+ status = VMStatus .Stopped )
100+ self ._set_bootstorm_vm_first_run_time ()
101+ self ._set_bootstorm_vm_start_time (vm_name = self ._vm_name )
102+ self ._virtctl .start_vm_sync (vm_name = self ._vm_name )
103+ self ._data_dict = self ._get_bootstorm_vm_elapsed_time (vm_name = self ._vm_name , vm_node = '' )
104+ vm_count = int (self ._scale )* len (self ._scale_node_list ) if self ._scale else 1
105+ self .wait_for_windows_hammerdb_finished (vm_nums = vm_count )
106+ if self ._scale :
107+ ids = self ._get_index_ids_between_dates (index = self ._es_index , key = 'status' )
108+ # Adding data_updated=True to stamp that this data is already updated and enrich with new product versions fields
109+ self ._data_dict ['run_artifacts_url' ] = os .path .join (self ._run_artifacts_url , f'{ self ._get_run_artifacts_hierarchy (workload_name = self ._workload_name , is_file = True )} -{ self ._time_stamp_format } .tar.gz' )
110+ for id in ids :
111+ self ._update_elasticsearch_index (index = self ._es_index , id = id , kind = 'vm' , status = 'Succeeded' , run_artifacts_url = self ._data_dict ['run_artifacts_url' ], database = 'mssql' , vm_name = f'{ self ._workload_name } -{ self ._trunc_uuid } ' , data_updated = True , scale = int (self ._scale )* len (self ._scale_node_list ))
112+ self ._only_delete_all = True
113+ self .run_vm_workload ()
114+ else :
115+ ids = self ._get_index_ids_between_dates (index = self ._es_index , key = 'status' )
116+ # Adding data_updated=True to stamp that this data is already updated and enrich with new product versions fields
117+ self ._data_dict ['run_artifacts_url' ] = os .path .join (self ._run_artifacts_url , f'{ self ._get_run_artifacts_hierarchy (workload_name = self ._workload_name , is_file = True )} -{ self ._time_stamp_format } .tar.gz' )
118+ for id in ids :
119+ self ._update_elasticsearch_index (index = self ._es_index , id = id , kind = 'vm' , status = 'Succeeded' , run_artifacts_url = self ._data_dict ['run_artifacts_url' ], database = 'mssql' , vm_name = f'{ self ._workload_name } -{ self ._trunc_uuid } ' , data_updated = True )
120+ self ._finalize_vm ()
83121 self ._oc .delete_vm_sync (
84122 yaml = os .path .join (f'{ self ._run_artifacts_path } ' , f'{ self ._name } .yaml' ),
85123 vm_name = self ._vm_name )
86- if self ._delete_all :
87- # delete windows dv
88- self ._oc .delete_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , 'windows_dv.yaml' ))
89- # delete namespace
90- self ._oc .delete_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , 'namespace.yaml' ))
124+ # delete windows dv
125+ self ._oc .delete_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , 'windows_dv.yaml' ))
126+ # delete namespace
127+ self ._oc .delete_async (yaml = os .path .join (f'{ self ._run_artifacts_path } ' , 'namespace.yaml' ))
91128 except ElasticSearchDataNotUploaded as err :
92129 self ._oc .delete_vm_sync (
93130 yaml = os .path .join (f'{ self ._run_artifacts_path } ' , f'{ self ._name } .yaml' ),
0 commit comments