lordgamez commented on code in PR #1702:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1702#discussion_r1425132359


##########
docker/test/integration/minifi/flow_serialization/Nifi_flow_json_serializer.py:
##########
@@ -0,0 +1,226 @@
+# 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.
+
+
+import uuid
+import json
+
+from ..core.Processor import Processor
+from ..core.InputPort import InputPort
+
+
+class Nifi_flow_json_serializer:
+    def serialize(self, start_nodes, nifi_version=None):
+        res = {
+            "encodingVersion": {
+                "majorVersion": 2,
+                "minorVersion": 0
+            },
+            "maxTimerDrivenThreadCount": 10,
+            "maxEventDrivenThreadCount": 1,
+            "registries": [],
+            "parameterContexts": [],
+            "parameterProviders": [],
+            "controllerServices": [],
+            "reportingTasks": [],
+            "templates": [],
+            "rootGroup": {
+                "identifier": "9802c873-3322-3b60-a71d-732d02bd60f8",
+                "instanceIdentifier": str(uuid.uuid4()),
+                "name": "NiFi Flow",
+                "comments": "",
+                "position": {
+                    "x": 0,
+                    "y": 0
+                },
+                "processGroups": [],
+                "remoteProcessGroups": [],
+                "processors": [],
+                "inputPorts": [],
+                "outputPorts": [],
+                "connections": [],
+                "labels": [],
+                "funnels": [],
+                "controllerServices": [],
+                "defaultFlowFileExpiration": "0 sec",
+                "defaultBackPressureObjectThreshold": 10000,
+                "defaultBackPressureDataSizeThreshold": "1 GB",
+                "scheduledState": "RUNNING",
+                "executionEngine": "INHERITED",
+                "maxConcurrentTasks": 1,
+                "statelessFlowTimeout": "1 min",
+                "flowFileConcurrency": "UNBOUNDED",
+                "flowFileOutboundPolicy": "STREAM_WHEN_AVAILABLE",
+                "componentType": "PROCESS_GROUP"
+            }
+        }
+        visited = []
+
+        for node in start_nodes:
+            self.serialize_node(node, nifi_version, res['rootGroup'], visited)
+
+        return json.dumps(res)
+
+    def serialize_node(self, connectable, nifi_version, root, visited):
+        if visited is None:
+            visited = []
+
+        visited.append(connectable)
+
+        if hasattr(connectable, 'name'):
+            connectable_name_text = connectable.name
+        else:
+            connectable_name_text = str(connectable.uuid)
+
+        if isinstance(connectable, InputPort):
+            root['inputPorts'].append({
+                'identifier': str(connectable.uuid),
+                'instanceIdentifier': str(connectable.instance_id),
+                'name': connectable_name_text,
+                "comments": "",
+                'position': {
+                    'x': 0,
+                    'y': 0
+                },
+                'type': 'INPUT_PORT',
+                'concurrentlySchedulableTaskCount': 1,
+                'scheduledState': 'RUNNING',
+                'allowRemoteAccess': True,
+                'portFunction': 'STANDARD',
+                'componentType': 'INPUT_PORT',
+                "groupIdentifier": "9802c873-3322-3b60-a71d-732d02bd60f8"
+            })
+
+        if isinstance(connectable, Processor):
+            root['processors'].append({
+                "identifier": str(connectable.uuid),
+                "instanceIdentifier": str(connectable.instance_id),
+                "name": connectable_name_text,
+                "comments": "",
+                "position": {
+                    "x": 0,
+                    "y": 0
+                },
+                "type": 'org.apache.nifi.processors.standard.' + 
connectable.clazz,
+                "bundle": {
+                    "group": "org.apache.nifi",
+                    "artifact": "nifi-standard-nar",
+                    "version": nifi_version
+                },
+                "properties": {key: value for key, value in 
connectable.properties.items() if connectable.nifi_property_key(key)},
+                "propertyDescriptors": {},
+                "style": {},
+                "schedulingPeriod": "0 sec" if 
connectable.schedule['scheduling strategy'] == "EVENT_DRIVEN" else 
connectable.schedule['scheduling period'],
+                "schedulingStrategy": "TIMER_DRIVEN",
+                "executionNode": "ALL",
+                "penaltyDuration": connectable.schedule['penalization period'],
+                "yieldDuration": connectable.schedule['yield period'],
+                "bulletinLevel": "WARN",
+                "runDurationMillis": str(connectable.schedule['run duration 
nanos']),

Review Comment:
   As I checked the NiFi requires this parameter to be set in the flow config, 
so I kept it in the tests for now



-- 
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: issues-unsubscr...@nifi.apache.org

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

Reply via email to