Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: failed to initialize fix and extended measurement added #70

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion era_5g_client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ python_distribution(
sdist=True,
provides=setup_py(
name="era_5g_client",
version="0.10.1",
version="0.11.0",
description="A client for 5G-ERA Network Applications",
author="Michal Kapinus",
author_email="[email protected]",
Expand Down
26 changes: 15 additions & 11 deletions era_5g_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
logging_level: int = logging.INFO,
socketio_debug: bool = False,
stats: bool = False,
extended_measuring: bool = False,
back_pressure_size: int = 5,
recreate_coder_attempts_count: int = 5,
reconnection_attempts: int = 3,
Expand All @@ -54,23 +55,25 @@ def __init__(
logging_level (int): Logging level.
socketio_debug (bool): Socket.IO debug flag.
stats (bool): Store output data sizes.
extended_measuring (bool): Enable logging of measuring.
back_pressure_size (int): Back pressure size - max size of eio.queue.qsize().
recreate_coder_attempts_count (int): How many times try to recreate the frame encoder/decoder.
reconnection_attempts (int): How many times to try to reconnect if the connection to the server is lost.
disconnect_on_unhandled (bool): Whether to call self.disconnect() if unhandled exception occurs.
"""

super().__init__(
callbacks_info,
command_result_callback,
command_error_callback,
logging_level,
socketio_debug,
stats,
back_pressure_size,
recreate_coder_attempts_count,
reconnection_attempts,
disconnect_on_unhandled,
callbacks_info=callbacks_info,
command_result_callback=command_result_callback,
command_error_callback=command_error_callback,
logging_level=logging_level,
socketio_debug=socketio_debug,
stats=stats,
extended_measuring=extended_measuring,
back_pressure_size=back_pressure_size,
recreate_coder_attempts_count=recreate_coder_attempts_count,
reconnection_attempts=reconnection_attempts,
disconnect_on_unhandled=disconnect_on_unhandled,
)

self.host: Optional[str] = None
Expand Down Expand Up @@ -312,8 +315,9 @@ def delete_all_resources(self) -> None:

if response.ok:
self.logger.debug("Resource deleted")
self.action_plan_id = None
else:
self.logger.warning(f"Resource deletion response: {response}")
self.logger.warning(f"Resource deletion response: {response}, {response.text}")
except HTTPError as e:
if e.response:
self.logger.debug(e.response.status_code)
Expand Down
13 changes: 10 additions & 3 deletions era_5g_client/client_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import statistics
import time
from collections.abc import Callable
Expand All @@ -9,7 +10,7 @@
import ujson
from socketio.exceptions import ConnectionError

from era_5g_client.exceptions import FailedToConnect, FailedToInitialize
from era_5g_client.exceptions import FailedToConnect
from era_5g_interface.channels import (
COMMAND_ERROR_EVENT,
COMMAND_EVENT,
Expand Down Expand Up @@ -48,6 +49,7 @@ def __init__(
logging_level: int = logging.INFO,
socketio_debug: bool = False,
stats: bool = False,
extended_measuring: bool = False,
back_pressure_size: Optional[int] = 5,
recreate_coder_attempts_count: int = 5,
reconnection_attempts: int = 3,
Expand All @@ -65,6 +67,7 @@ def __init__(
logging_level (int): Logging level.
socketio_debug (bool): Socket.IO debug flag.
stats (bool): Store output data sizes.
extended_measuring (bool): Enable logging of measuring.
back_pressure_size (int, optional): Back pressure size - max size of eio.queue.qsize().
recreate_coder_attempts_count (int): How many times try to recreate the frame encoder/decoder.
reconnection_attempts (int): How many times to try to reconnect if the connection to the server is lost.
Expand Down Expand Up @@ -99,6 +102,7 @@ def __init__(
back_pressure_size=back_pressure_size,
recreate_coder_attempts_count=recreate_coder_attempts_count,
stats=stats,
extended_measuring=extended_measuring,
)

# Save custom command callbacks.
Expand Down Expand Up @@ -140,7 +144,6 @@ def register(

Raises:
FailedToConnect: Failed to connect to network application exception.
FailedToInitialize: Failed to initialize the network application.

Returns:
Response: response from the 5G-ERA Network Application.
Expand Down Expand Up @@ -214,7 +217,11 @@ def control_connect_callback(self) -> None:
self.logger.info(f"Initialize the network application using the init command {control_command}")
initialized, message = self.send_control_command(control_command)
if not initialized:
raise FailedToInitialize(f"Failed to initialize the network application: {message}")
self.disconnect()
self.logger.error(f"Failed to initialize the network application: {message}")
logging.shutdown() # should flush the logger
os._exit(1)
# raise FailedToInitialize(f"Failed to initialize the network application: {message}")

def data_disconnect_callback(self) -> None:
"""The callback called once the connection to the 5G-ERA Network Application DATA_NAMESPACE is lost."""
Expand Down
2 changes: 1 addition & 1 deletion era_5g_client/middleware_resource_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(self) -> None:
assert isinstance(self.resource_state, dict)
self.status = self.resource_state.get("serviceStatus", None)
self.url = self.resource_state.get("serviceUrl", None)
logging.debug(f"{self.status=}, {self.url=}")
logger.debug(f"{self.status=}, {self.url=}")
if self.state_callback:
self.state_callback(self.resource_state)
time.sleep(0.5) # TODO: adjust or use something similar to rospy.rate.sleep()
Expand Down
Loading
Loading