You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by "SvenO3 (via GitHub)" <gi...@apache.org> on 2023/02/14 16:47:24 UTC

[PR] Update data stream generator (#1258) (streampipes)

SvenO3 opened a new pull request, #1286:
URL: https://github.com/apache/streampipes/pull/1286

   <!--
     ~ Licensed to the Apache Software Foundation (ASF) under one or more
     ~ contributor license agreements.  See the NOTICE file distributed with
     ~ this work for additional information regarding copyright ownership.
     ~ The ASF licenses this file to You under the Apache License, Version 2.0
     ~ (the "License"); you may not use this file except in compliance with
     ~ the License.  You may obtain a copy of the License at
     ~
     ~    http://www.apache.org/licenses/LICENSE-2.0
     ~
     ~ Unless required by applicable law or agreed to in writing, software
     ~ distributed under the License is distributed on an "AS IS" BASIS,
     ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     ~ See the License for the specific language governing permissions and
     ~ limitations under the License.
     ~
     -->
     
     <!--
   Thanks for contributing! Here are some tips you can follow to help us incorporate your contribution quickly and easily:
   1. If this is your first time, please read our contributor guidelines:
       - https://streampipes.apache.org/getinvolved.html
       - https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
   2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title ...`
   3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., `[WIP][#<GitHub issue id>] PR title ...`.
   4. Please write your PR title to summarize what this PR proposes/fixes.
   5. Link the PR to the corresponding GitHub issue (if present) in the `Development` section in the right menu bar. 
   6. Be sure to keep the PR description updated to reflect all changes.
   7. If possible, provide a concise example to reproduce the issue for a faster review.
   8. Make sure tests pass via `mvn clean install`.
   9. (Optional) If the contribution is large, please file an Apache ICLA
       - http://apache.org/licenses/icla.pdf
   -->
   
   ### Purpose
   <!--
   Please clarify what changes you are proposing and describe how those changes will address the issue.
   Furthermore, describe potential consequences the changes might have.
   -->
   This PR resolves #1258
   
   ### Remarks
   <!--
   Is there anything left we need to pay attention on?
   Are there some references that might be important? E.g. links to Confluence, or discussions
   on the mailing list or GitHub.
   -->
   PR introduces (a) breaking change(s): no
   
   PR introduces (a) deprecation(s): no
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1106369806


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -73,17 +87,19 @@ class EventProperty(BasicModel):
     Data model of an `EventProperty` in compliance to the StreamPipes Backend.
     """
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    element_id: Optional[StrictStr]
+    class_name: StrictStr = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.schema.EventPropertyPrimitive"
+    )
+    element_id: StrictStr = Field(default_factory=lambda: f"sp:eventproperty:{random_letters(6)}")
     label: Optional[StrictStr]
     description: Optional[StrictStr]
     runtime_name: StrictStr
-    required: StrictBool
-    domain_properties: List[StrictStr]
-    property_scope: Optional[StrictStr]
-    index: StrictInt
+    required: StrictBool = False

Review Comment:
   it would be beneficial to use the pydantic functionality here, so in this case `Field(default=False)`
   Some applies for the upcoming rows, for an empty array you can use the `default_factory`



##########
streampipes-client-python/streampipes/model/resource/data_stream.py:
##########
@@ -72,26 +73,31 @@ def convert_to_pandas_representation(self):
             "num_included_locales": len(self.included_locales) if self.included_locales is not None else 0,
         }
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    element_id: StrictStr
-    name: Optional[StrictStr]
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
+        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)}")
+    name: StrictStr = "Unnamed"
     description: Optional[StrictStr]
     icon_url: Optional[StrictStr]
     app_id: Optional[StrictStr]
-    includes_assets: Optional[StrictBool]
-    includes_locales: Optional[StrictBool]
-    included_assets: Optional[List[Optional[StrictStr]]]
-    included_locales: Optional[List[Optional[StrictStr]]]
-    application_links: Optional[List[Optional[ApplicationLink]]]
-    internally_managed: Optional[StrictBool]
-    connected_to: Optional[List[Optional[StrictStr]]]
-    event_grounding: EventGrounding
+    includes_assets: StrictBool = False
+    includes_locales: StrictBool = False
+    included_assets: List[StrictStr] = []
+    included_locales: List[StrictStr] = []
+    application_links: List[ApplicationLink] = []
+    internally_managed: StrictBool = False
+    connected_to: Optional[List[StrictStr]]
+    event_grounding: EventGrounding = Field(default_factory=EventGrounding)
     event_schema: Optional[EventSchema]
-    measurement_capability: Optional[List[Optional[MeasurementCapability]]]
-    measurement_object: Optional[List[Optional[MeasurementObject]]]
-    index: Optional[StrictInt]
+    measurement_capability: Optional[List[MeasurementCapability]]
+    measurement_object: Optional[List[MeasurementObject]]
+    index: StrictInt = 0

Review Comment:
   same as above



##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -73,17 +87,19 @@ class EventProperty(BasicModel):
     Data model of an `EventProperty` in compliance to the StreamPipes Backend.
     """
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    element_id: Optional[StrictStr]
+    class_name: StrictStr = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.schema.EventPropertyPrimitive"

Review Comment:
   In this case you could simply use `default` and provide the string value



##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -30,6 +33,17 @@
 ]
 
 
+def random_letters(n: int):

Review Comment:
   I'm not really happy with this function, but don't really have a better idea 🤔 
   I'll try to come with one



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1106700973


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -115,37 +131,41 @@ class TopicDefinition(BasicModel):
     Data model of a `TopicDefinition` in compliance to the StreamPipes Backend.
     """
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    actual_topic_name: StrictStr
+    class_name: Optional[StrictStr] = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.grounding.SimpleTopicDefinition"
+    )
+    actual_topic_name: StrictStr = Field(default_factory=lambda: f"org.apache.streampipes.connect.{uuid4()}")
 
 
 class TransportProtocol(BasicModel):
     """
     Data model of a `TransportProtocol` in compliance to the StreamPipes Backend.
     """
 
-    class_name: StrictStr = Field(alias="@class")
-    element_id: Optional[StrictStr]
-    broker_hostname: StrictStr
-    topic_definition: TopicDefinition
-    port: StrictInt = Field(alias="kafkaPort")
+    class_name: StrictStr = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.grounding.NatsTransportProtocol"
+    )
+    element_id: StrictStr = Field(default_factory=lambda: f"sp:transportprotocol:{random_letters(6)}")
+    broker_hostname: StrictStr = "nats"
+    topic_definition: TopicDefinition = Field(default_factory=TopicDefinition)
+    port: StrictInt = Field(alias="kafkaPort", default_factory=lambda: 4222)

Review Comment:
   Is `4222` the default port for all protocols?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "SvenO3 (via GitHub)" <gi...@apache.org>.
SvenO3 commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1106812400


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -30,6 +33,17 @@
 ]
 
 
+def random_letters(n: int):

Review Comment:
   What don't you like about it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "SvenO3 (via GitHub)" <gi...@apache.org>.
SvenO3 commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1106815291


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -115,37 +131,41 @@ class TopicDefinition(BasicModel):
     Data model of a `TopicDefinition` in compliance to the StreamPipes Backend.
     """
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    actual_topic_name: StrictStr
+    class_name: Optional[StrictStr] = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.grounding.SimpleTopicDefinition"
+    )
+    actual_topic_name: StrictStr = Field(default_factory=lambda: f"org.apache.streampipes.connect.{uuid4()}")
 
 
 class TransportProtocol(BasicModel):
     """
     Data model of a `TransportProtocol` in compliance to the StreamPipes Backend.
     """
 
-    class_name: StrictStr = Field(alias="@class")
-    element_id: Optional[StrictStr]
-    broker_hostname: StrictStr
-    topic_definition: TopicDefinition
-    port: StrictInt = Field(alias="kafkaPort")
+    class_name: StrictStr = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.grounding.NatsTransportProtocol"
+    )
+    element_id: StrictStr = Field(default_factory=lambda: f"sp:transportprotocol:{random_letters(6)}")
+    broker_hostname: StrictStr = "nats"
+    topic_definition: TopicDefinition = Field(default_factory=TopicDefinition)
+    port: StrictInt = Field(alias="kafkaPort", default_factory=lambda: 4222)

Review Comment:
   I think it's only for Nats, but the idea was to use Nats as default and you would need to configure this if you want to use other transport protocols.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1110158933


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -30,6 +33,17 @@
 ]
 
 
+def random_letters(n: int):

Review Comment:
   It's not about the implementation itself, it's more about that we only need it as default factory and that it does not really suit into the rest of the module 🤔 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1110158933


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -30,6 +33,17 @@
 ]
 
 
+def random_letters(n: int):

Review Comment:
   It's not about the implementation itself, it's more about that we only need it as default factory and does not really suit into the rest of the module 🤔 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "SvenO3 (via GitHub)" <gi...@apache.org>.
SvenO3 commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1106815291


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -115,37 +131,41 @@ class TopicDefinition(BasicModel):
     Data model of a `TopicDefinition` in compliance to the StreamPipes Backend.
     """
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    actual_topic_name: StrictStr
+    class_name: Optional[StrictStr] = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.grounding.SimpleTopicDefinition"
+    )
+    actual_topic_name: StrictStr = Field(default_factory=lambda: f"org.apache.streampipes.connect.{uuid4()}")
 
 
 class TransportProtocol(BasicModel):
     """
     Data model of a `TransportProtocol` in compliance to the StreamPipes Backend.
     """
 
-    class_name: StrictStr = Field(alias="@class")
-    element_id: Optional[StrictStr]
-    broker_hostname: StrictStr
-    topic_definition: TopicDefinition
-    port: StrictInt = Field(alias="kafkaPort")
+    class_name: StrictStr = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.grounding.NatsTransportProtocol"
+    )
+    element_id: StrictStr = Field(default_factory=lambda: f"sp:transportprotocol:{random_letters(6)}")
+    broker_hostname: StrictStr = "nats"
+    topic_definition: TopicDefinition = Field(default_factory=TopicDefinition)
+    port: StrictInt = Field(alias="kafkaPort", default_factory=lambda: 4222)

Review Comment:
   I think it only for Nats, but the idea was to use Nats as default and you would need to configure this if you want to use other transport protocols.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "SvenO3 (via GitHub)" <gi...@apache.org>.
SvenO3 commented on code in PR #1286:
URL: https://github.com/apache/streampipes/pull/1286#discussion_r1106810566


##########
streampipes-client-python/streampipes/model/common.py:
##########
@@ -73,17 +87,19 @@ class EventProperty(BasicModel):
     Data model of an `EventProperty` in compliance to the StreamPipes Backend.
     """
 
-    class_name: Optional[StrictStr] = Field(alias="@class")
-    element_id: Optional[StrictStr]
+    class_name: StrictStr = Field(
+        alias="@class", default_factory=lambda: "org.apache.streampipes.model.schema.EventPropertyPrimitive"

Review Comment:
   Yes, this makes a lot more sense.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Update data stream generator (#1258) (streampipes)

Posted by "SvenO3 (via GitHub)" <gi...@apache.org>.
SvenO3 merged PR #1286:
URL: https://github.com/apache/streampipes/pull/1286


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org