Merge pull request #5 from Aignosi/SIENTIAPDE-1100-rever-erros-nao-lancados-lancando-os-se-necessario

Sientiapde 1100 rever erros nao lancados lancando os se necessario
This commit is contained in:
Matheus Demoner
2025-06-12 10:41:53 -03:00
committed by GitHub
6 changed files with 48 additions and 15 deletions

View File

@@ -229,7 +229,7 @@ class Gates(BaseActivity):
return None, 0, "" return None, 0, ""
@activity.defn(name="format_prediction") @activity.defn(name="format_prediction")
async def format_prediction(self, input_data: dict[str, Any]) -> dict[str, Any]: async def format_prediction(self, input_data: dict[str, Any]) -> dict[Any, Any]:
""" """
Formats the prediction data. Formats the prediction data.
Args: Args:
@@ -254,7 +254,7 @@ class Gates(BaseActivity):
return data.to_dict() return data.to_dict()
@activity.defn(name="format_default_prediction") @activity.defn(name="format_default_prediction")
async def format_default_prediction(self, input_data: dict[str, Any]) -> dict[str, Any]: async def format_default_prediction(self, input_data: dict[str, Any]) -> dict[Any, Any]:
""" """
Creates and formats the default prediction data, with zero value in prediction, Creates and formats the default prediction data, with zero value in prediction,
and usefull information in the other fields. and usefull information in the other fields.

View File

@@ -63,7 +63,7 @@ class OPC(BaseActivity):
level=NotificationLevel.ERROR, level=NotificationLevel.ERROR,
attachment_content=trace attachment_content=trace
) )
self.logger.error(trace) raise e
@activity.defn(name='write_opc_data') @activity.defn(name='write_opc_data')
async def write_opc_data(self, input_data: dict[str, Any]): async def write_opc_data(self, input_data: dict[str, Any]):

View File

@@ -218,6 +218,15 @@ class OpcRepository():
self.error_count += 1 self.error_count += 1
return return
if data_type not in data_type_map:
self.notification_handler.build_and_send_notification(
notification_id=f"OPC_WRITE_DATA_TYPE_ERROR_{self.name}",
message=f"Unsupported data type: {data_type}",
block="opc_repository",
level=NotificationLevel.ERROR
)
return
data = data_type_map[data_type]['converter'](value) data = data_type_map[data_type]['converter'](value)
self.logger.info(f'Writing {data} - {type(data)} to {node}') self.logger.info(f'Writing {data} - {type(data)} to {node}')
ua_data = DataValue( ua_data = DataValue(

View File

@@ -112,16 +112,22 @@ def test_write_data_success(opc, tag, data_type, data):
def test_write_data_exception(opc): def test_write_data_exception(opc):
opc.opc_repository['server1'].write_data.side_effect = Exception( opc.opc_repository['server1'].write_data.side_effect = Exception(
"Test error") "Test error")
opc.write_data(server='server1', tag='tag1', data=50,
data_type='int', tag_type='prediction') try:
opc.notification_handler.build_and_send_notification.assert_called_once_with( opc.write_data(server='server1', tag='tag1', data=50,
notification_id="WRITE_OPC_PREDICTION_ERROR", data_type='int', tag_type='prediction')
message="Error writing data to OPC server: Test error",
block="write_opc_data", except Exception:
level=NotificationLevel.ERROR, opc.notification_handler.build_and_send_notification.assert_called_once_with(
attachment_content=ANY notification_id="WRITE_OPC_PREDICTION_ERROR",
) message="Error writing data to OPC server: Test error",
opc.logger.error.assert_called_once() block="write_opc_data",
level=NotificationLevel.ERROR,
attachment_content=ANY
)
else:
assert False, "Expected an exception to be raised"
@mark.asyncio @mark.asyncio

View File

@@ -224,6 +224,24 @@ def test_write_data_get_node_failed(opc_repository):
assert opc_repository.error_count == 1 assert opc_repository.error_count == 1
def test_write_data_invalid_data_type(opc_repository, mock_client):
opc_repository.validate_connection = MagicMock(return_value=True)
opc_repository.client = mock_client
mock_node = MagicMock()
mock_client.get_node.return_value = mock_node
opc_repository.write_data("ns=2;s=TestNode", 42.0, "invalid_type")
opc_repository.validate_connection.assert_called_once()
mock_client.get_node.assert_called_once_with("ns=2;s=TestNode")
opc_repository.notification_handler.build_and_send_notification.assert_called_once_with(
notification_id=f"OPC_WRITE_DATA_TYPE_ERROR_{opc_repository.name}",
message="Unsupported data type: invalid_type",
block="opc_repository",
level=NotificationLevel.ERROR
)
def test_write_data(opc_repository, mock_client): def test_write_data(opc_repository, mock_client):
opc_repository.validate_connection = MagicMock(return_value=True) opc_repository.validate_connection = MagicMock(return_value=True)
opc_repository.client = mock_client opc_repository.client = mock_client

View File

@@ -152,7 +152,7 @@ env:
- name: MLFLOW_PASSWORD - name: MLFLOW_PASSWORD
value: "aignosi" value: "aignosi"
- name: OPC_NAME - name: OPC_ID
value: "server-1" value: "server-1"
- name: OPC_URL - name: OPC_URL
value: "opc.tcp://sientia-opc-simulator.sientia.svc.cluster.local:4840" value: "opc.tcp://sientia-opc-simulator.sientia.svc.cluster.local:4840"
@@ -183,4 +183,4 @@ ssh:
# kubectl create secret generic git-ssh-key-sientia-laborious-worker \ # kubectl create secret generic git-ssh-key-sientia-laborious-worker \
# --namespace sientia \ # --namespace sientia \
# --from-file=ssh-privatekey=git_key \ # --from-file=ssh-privatekey=git_key \
# --type=kubernetes.io/ssh-auth # --type=kubernetes.io/ssh-auth