1919import time
2020import threading
2121import os
22+ import json
2223from pathlib import Path
2324from confluent_kafka import Consumer , Producer
2425from rayvens .core import kamel
@@ -37,21 +38,51 @@ def get_run_mode(camel_mode):
3738 return mode
3839
3940
41+ def _wait_for_ready_integration (mode , integration ):
42+ server_address = mode .server_address (integration )
43+ health_check_address = f"{ server_address } /q/health"
44+ while True :
45+ response = requests .get (health_check_address , timeout = (5 , None ))
46+ json_response = json .loads (response .content )
47+ all_routes_are_up = True
48+ for check in json_response ['checks' ]:
49+ if check ['name' ] == 'camel-readiness-checks' and check [
50+ 'status' ] == 'UP' :
51+ data = check ['data' ]
52+ if data ['context' ] == 'UP' :
53+ # Ensure all routes are up.
54+ route_index = 1
55+ route = f'route:route{ route_index } '
56+ while route in data :
57+ if data [route ] != 'UP' :
58+ all_routes_are_up = False
59+ break
60+ route_index += 1
61+ route = f'route:route{ route_index } '
62+ if all_routes_are_up :
63+ break
64+ time .sleep (1 )
65+
66+
4067# Wait for an integration to reach its running state and not only that but
4168# also be in a state where it can immediately execute incoming requests.
42- def await_start (mode , integration_name ):
69+ def await_start (mode , integration ):
4370 # Only needed when operator is used.
4471 if mode .is_local ():
4572 return True
4673
4774 # Check logs of the integration to make sure it was installed properly.
48- invocation = kamel .log (mode , integration_name , "Installed features:" )
75+ invocation = kamel .log (mode , integration .integration_name ,
76+ "Installed features:" )
4977 integration_is_running = invocation is not None
5078 if integration_is_running :
51- print (f'Integration { integration_name } is running.' )
79+ print (f'Integration { integration . integration_name } is running.' )
5280 else :
5381 print ('Integration did not start correctly.' )
5482
83+ # Perform health check and wait for integration to be ready.
84+ _wait_for_ready_integration (mode , integration )
85+
5586 return integration_is_running
5687
5788
0 commit comments