This is an automated email from the ASF dual-hosted git repository.

bossenti pushed a commit to branch 
2551-streampipes-function-does-always-create-a-new-data-stream
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/2551-streampipes-function-does-always-create-a-new-data-stream by 
this push:
     new b155532bbb fix(#2551): create reliable data streams
b155532bbb is described below

commit b155532bbbd595a32527718a5beb967113aa18ec
Author: bossenti <[email protected]>
AuthorDate: Thu Mar 14 16:09:43 2024 +0100

    fix(#2551): create reliable data streams
---
 streampipes-client-python/streampipes/endpoint/endpoint.py    |  1 +
 .../streampipes/functions/function_handler.py                 | 11 ++++++++++-
 .../streampipes/model/resource/data_stream.py                 |  5 +++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/streampipes-client-python/streampipes/endpoint/endpoint.py 
b/streampipes-client-python/streampipes/endpoint/endpoint.py
index b3572d9d11..6a5ca408a8 100644
--- a/streampipes-client-python/streampipes/endpoint/endpoint.py
+++ b/streampipes-client-python/streampipes/endpoint/endpoint.py
@@ -44,6 +44,7 @@ logger = logging.getLogger(__name__)
 
 # define custom logging messages for some specific HTTP status
 _error_code_to_message = {
+    400: "\nThe StreamPipes Backend did not accept the request. Please check 
the logs for details",
     401: "\nThe StreamPipes Backend returned an unauthorized error.\n"
     "Please check your user name and/or password to be correct.",
     403: "\nThere seems to be an issue with the access rights of the given 
user and the resource you queried.\n"
diff --git 
a/streampipes-client-python/streampipes/functions/function_handler.py 
b/streampipes-client-python/streampipes/functions/function_handler.py
index 4eaceb1754..6b774864dd 100644
--- a/streampipes-client-python/streampipes/functions/function_handler.py
+++ b/streampipes-client-python/streampipes/functions/function_handler.py
@@ -19,6 +19,8 @@ import json
 import logging
 from typing import AsyncIterator, Dict, List
 
+from requests import HTTPError
+
 from streampipes.client.client import StreamPipesClient
 from streampipes.functions.broker import Broker, Consumer, get_broker
 from streampipes.functions.registration import Registration
@@ -67,7 +69,14 @@ class FunctionHandler:
         for streampipes_function in self.registration.getFunctions():
             # Create the output data streams for every function
             for stream_id, output_stream in 
streampipes_function.function_definition.get_output_data_streams().items():
-                self.client.dataStreamApi.post(output_stream)
+                try:
+                    self.client.dataStreamApi.post(output_stream)
+                except HTTPError:
+                    logger.error(
+                        "The data stream could not be created - this is likely 
caused by "
+                        "an existing data stream with the same name.\n Please 
use another one."
+                    )
+                    raise RuntimeError
                 logger.info(
                     f'Create output data stream "{stream_id}" '
                     f'for the function 
"{streampipes_function.getFunctionId().id}"'
diff --git 
a/streampipes-client-python/streampipes/model/resource/data_stream.py 
b/streampipes-client-python/streampipes/model/resource/data_stream.py
index 10ea2b34d6..1270e6305f 100644
--- a/streampipes-client-python/streampipes/model/resource/data_stream.py
+++ b/streampipes-client-python/streampipes/model/resource/data_stream.py
@@ -24,7 +24,6 @@ from streampipes.model.common import (
     EventSchema,
     MeasurementCapability,
     MeasurementObject,
-    random_letters,
 )
 from streampipes.model.resource.resource import Resource
 
@@ -81,11 +80,13 @@ class DataStream(Resource):
 
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
+        if not self.element_id:
+            self.element_id = f"sp:spdatastream:{self.name.replace(':', '')}"
         if not self.uri:
             self.uri = self.element_id
 
     class_name: StrictStr = Field(alias="@class", default_factory=lambda: 
"org.apache.streampipes.model.SpDataStream")
-    element_id: StrictStr = Field(default_factory=lambda: 
f"sp:spdatastream:{random_letters(6)}")
+    element_id: Optional[StrictStr] = None
     name: StrictStr = Field(default="Unnamed")
     description: Optional[StrictStr]
     icon_url: Optional[StrictStr]

Reply via email to