markap14 commented on code in PR #7003:
URL: https://github.com/apache/nifi/pull/7003#discussion_r1142691974


##########
nifi-nar-bundles/nifi-py4j-bundle/nifi-python-framework/src/main/python/framework/Controller.py:
##########
@@ -0,0 +1,101 @@
+# 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 os
+import logging
+import ExtensionManager
+from py4j.java_gateway import JavaGateway, CallbackServerParameters, 
GatewayParameters
+
+import PythonProcessorAdapter
+
+# Initialize logging
+logger = logging.getLogger("org.apache.nifi.py4j.Controller")
+logger.setLevel(logging.INFO)
+
+logging.getLogger("py4j").setLevel(logging.WARN)
+
+logsDir = os.getenv('LOGS_DIR')
+logging.basicConfig(filename=logsDir + '/python.log',
+                    format='%(asctime)s %(levelname)s %(name)s %(message)s',
+                    encoding='utf-8',
+                    level=logging.INFO)
+
+
+class Controller:
+
+    def ping(self):
+        return "pong"
+
+    def getProcessorTypes(self):
+        types = self.extensionManager.getProcessorTypes()
+        typesList = self.gateway.jvm.java.util.ArrayList()
+        for type in types:
+            typesList.add(type)
+        return typesList
+
+    def discoverExtensions(self, dirs, work_dir):
+        self.extensionManager.discoverExtensions(dirs, work_dir)
+
+    def createProcessor(self, processorType, version, work_dir):
+        processorClass = 
self.extensionManager.getProcessorClass(processorType, version, work_dir)
+        processor = processorClass(jvm=self.gateway.jvm)
+        adapter = PythonProcessorAdapter.PythonProcessorAdapter(self.gateway, 
processor, self.extensionManager, self.controllerServiceTypeLookup)
+        return adapter
+
+    def reloadProcessor(self, processorType, version, workDirectory):
+        self.extensionManager.reload_processor(processorType, version, 
workDirectory)
+
+    def getModuleFile(self, processorType, version):
+        module_file = self.extensionManager.get_module_file(processorType, 
version)
+        return module_file
+
+    def getProcessorDependencies(self, processorType, version):
+        deps = 
self.extensionManager.__get_dependencies_for_extension_type__(processorType, 
version)
+        dependencyList = self.gateway.jvm.java.util.ArrayList()
+        for dep in deps:
+            dependencyList.add(dep)
+
+        return dependencyList
+
+    def setGateway(self, gateway):
+        self.gateway = gateway
+        self.extensionManager = ExtensionManager.ExtensionManager(gateway)
+
+    def setControllerServiceTypeLookup(self, typeLookup):
+        self.controllerServiceTypeLookup = typeLookup
+
+    class Java:
+        implements = ["org.apache.nifi.py4j.PythonController"]
+
+
+# Create the Controller
+controller = Controller()
+
+# Create the Java Gateway for communicating with NiFi Java process
+java_port = int(os.getenv('JAVA_PORT'))
+gateway = JavaGateway(
+   callback_server_parameters=CallbackServerParameters(port=0),
+   gateway_parameters=GatewayParameters(port=java_port, read_timeout=None, 
enable_memory_management=True),

Review Comment:
   True. But they are important details, so want to remain explicit.



-- 
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