|
14 | 14 | # limitations under the License. |
15 | 15 | # |
16 | 16 |
|
| 17 | +import ray |
17 | 18 | import time |
18 | 19 | from rayvens.core import kamel |
19 | 20 |
|
20 | 21 |
|
21 | | -def verify_do(stream, _global_camel, action, *args, **kwargs): |
| 22 | +def verify_do(handle, _global_camel, action, *args, **kwargs): |
22 | 23 | if action == 'verify_log': |
23 | | - return _verify_log(stream, _global_camel, *args, **kwargs) |
| 24 | + return _verify_log(handle, _global_camel, *args, **kwargs) |
24 | 25 | raise RuntimeError('invalid meta action') |
25 | 26 |
|
26 | 27 |
|
27 | | -def _verify_log(stream, |
| 28 | +def wait_for_event(handle): |
| 29 | + event_count = 0 |
| 30 | + countdown = 20 |
| 31 | + while event_count == 0: |
| 32 | + event_count = ray.get(handle.event_count.remote()) |
| 33 | + time.sleep(1) |
| 34 | + countdown -= 1 |
| 35 | + if countdown == 0: |
| 36 | + break |
| 37 | + if event_count == 0: |
| 38 | + return False |
| 39 | + return True |
| 40 | + |
| 41 | + |
| 42 | +def _verify_log(handle, |
28 | 43 | _global_camel, |
29 | 44 | sink_source_name, |
30 | 45 | message, |
31 | 46 | wait_for_events=False): |
32 | | - # Get integration: |
33 | | - integration = None |
34 | | - if sink_source_name in stream._sinks: |
35 | | - integration = stream._sinks[sink_source_name] |
36 | | - if sink_source_name in stream._sources: |
37 | | - integration = stream._sources[sink_source_name] |
38 | | - if integration is None: |
39 | | - raise RuntimeError( |
40 | | - f'{sink_source_name} not found on stream {stream.name}') |
41 | | - |
42 | 47 | log = "FAIL" |
43 | 48 |
|
44 | 49 | # Wait for at least one event to happen. |
45 | 50 | if wait_for_events: |
46 | | - event_count = 0 |
47 | | - countdown = 20 |
48 | | - while event_count == 0: |
49 | | - event_count = stream.event_count() |
50 | | - time.sleep(1) |
51 | | - countdown -= 1 |
52 | | - if countdown == 0: |
53 | | - break |
54 | | - if event_count == 0: |
55 | | - print("[LOG CHECK]:", log) |
| 51 | + if not wait_for_event(handle): |
| 52 | + print("[LOG CHECK]:", "NO EVENTS RECEIVED") |
56 | 53 | return False |
57 | 54 |
|
58 | 55 | if _global_camel.mode.is_local(): |
59 | 56 | # In the local case the integration run is ongoing and we can |
60 | 57 | # access the logs directly. |
61 | | - outcome = integration.invocation.invoke(message) |
| 58 | + outcome = ray.get( |
| 59 | + handle._integration_invoke.remote(sink_source_name, message)) |
62 | 60 | else: |
63 | 61 | # When running using the operator then the integration run command |
64 | 62 | # is non-blocking and returns immediately. The logs can be queried |
65 | 63 | # using the kamel log command. |
66 | | - invocation = kamel.log(_global_camel.mode, |
67 | | - integration.integration_name, message) |
| 64 | + integration_name = ray.get( |
| 65 | + handle._get_integration_name.remote(sink_source_name)) |
| 66 | + invocation = kamel.log(_global_camel.mode, integration_name, message) |
68 | 67 | outcome = invocation is not None |
69 | 68 | invocation.kill() |
70 | 69 |
|
|
0 commit comments