|
| 1 | +from naeural_core.business.default.web_app.fast_api_web_app import FastApiWebAppPlugin as BasePlugin |
| 2 | + |
| 3 | +__VER__ = '0.1.0.0' |
| 4 | + |
| 5 | +_CONFIG = { |
| 6 | + **BasePlugin.CONFIG, |
| 7 | + |
| 8 | + 'PORT': 44444, |
| 9 | + 'NGROK_ENABLED': False, |
| 10 | + 'NGROK_USE_API': False, |
| 11 | + 'ASSETS': '', |
| 12 | + 'VALIDATION_RULES': { |
| 13 | + **BasePlugin.CONFIG['VALIDATION_RULES'], |
| 14 | + }, |
| 15 | +} |
| 16 | + |
| 17 | +ALPHABET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' |
| 18 | +""" |
| 19 | +In order to deploy this plugin, you have to run the code below: |
| 20 | + node = "node_address" |
| 21 | + session: Session = Session(encrypt_comms=True) |
| 22 | + session.wait_for_node(node) |
| 23 | +
|
| 24 | + pipeline: Pipeline = session.create_pipeline( |
| 25 | + node=node, |
| 26 | + name='edge_node__test', |
| 27 | + ) |
| 28 | +
|
| 29 | + instance: Instance = pipeline.create_plugin_instance( |
| 30 | + signature='EDGE_NODE_PAYLOAD_TESTING', |
| 31 | + instance_id='edge_node_payload_test_001', |
| 32 | +
|
| 33 | + config={ |
| 34 | + 'DEBUG_MODE': True, |
| 35 | + 'ASSETS': '' |
| 36 | + }, |
| 37 | + ) |
| 38 | +
|
| 39 | + pipeline.deploy() |
| 40 | +
|
| 41 | + session.wait( |
| 42 | + seconds=6000, # we wait the session for 6000 seconds |
| 43 | + close_pipelines=True, # we close the pipelines after the session |
| 44 | + close_session=True, # we close the session after the session |
| 45 | + ) |
| 46 | +""" |
| 47 | + |
| 48 | +class EdgeNodePayloadTestingPlugin(BasePlugin): |
| 49 | + CONFIG = _CONFIG |
| 50 | + |
| 51 | + def on_init(self): |
| 52 | + super(EdgeNodePayloadTestingPlugin, self).on_init() |
| 53 | + return |
| 54 | + |
| 55 | + |
| 56 | + @BasePlugin.endpoint(method='post') |
| 57 | + def send_messages(self, count: int = 1, length: int = 46, node_address: str = ''): |
| 58 | + messages = [] |
| 59 | + for i in range(count): |
| 60 | + word = ''.join(ALPHABET[i] for i in self.np.random.randint(len(ALPHABET), size=length)) |
| 61 | + messages.append(word) |
| 62 | + try: |
| 63 | + self.send_encrypted_payload(node_addr=node_address, messages=messages) |
| 64 | + except Exception as e: |
| 65 | + self.P("An error occurred:") |
| 66 | + self.P(e) |
| 67 | + return messages |
| 68 | + |
| 69 | + |
| 70 | + |
0 commit comments