Use ProcessPool rather than ThreadPool Executor 71/94771/2
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Mon, 2 Sep 2019 18:36:25 +0000 (14:36 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Tue, 3 Sep 2019 13:03:22 +0000 (13:03 +0000)
Change-Id: I66a800bf30cabce35123b0ac24b3b3e00eef6026
Issue-ID: CCSDK-1681
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
ms/command-executor/pom.xml
ms/command-executor/src/main/python/command_executor_handler.py
ms/command-executor/src/main/python/server.py
ms/command-executor/src/main/python/utils.py

index 5a73fa0..e99c4ec 100755 (executable)
@@ -14,7 +14,8 @@
   ~  See the License for the specific language governing permissions and
   ~  limitations under the License.
   -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.onap.ccsdk.cds</groupId>
@@ -34,7 +35,7 @@
         <docker.verbose>true</docker.verbose>
         <ccsdk.project.version>${project.version}</ccsdk.project.version>
         <ccsdk.build.timestamp>${maven.build.timestamp}</ccsdk.build.timestamp>
-               <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
+        <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
     </properties>
 
     <build>
index 972dad6..abea4d4 100644 (file)
@@ -35,6 +35,7 @@ class CommandExecutorHandler():
         self.request = request
         self.logger = logging.getLogger(self.__class__.__name__)
         self.blueprint_id = utils.get_blueprint_id(request)
+        # FIXME parameterize path
         self.venv_home = '/opt/app/onap/blueprints/deploy/' + self.blueprint_id
         self.installed = self.venv_home + '/.installed'
 
@@ -60,7 +61,6 @@ class CommandExecutorHandler():
             results.append(f.read())
             f.close()
 
-        # deactivate_venv(blueprint_id)
         return True
 
     def execute_command(self, request, results):
@@ -73,6 +73,7 @@ class CommandExecutorHandler():
         if "ansible-playbook" in request.command:
             cmd = cmd + "; " + request.command + " -e 'ansible_python_interpreter=" + self.venv_home + "/bin/python'"
         else:
+            # we append the properties as last agr to the script
             cmd = cmd + "; " + request.command + " " + re.escape(MessageToJson(request.properties))
 
         try:
@@ -170,8 +171,8 @@ class CommandExecutorHandler():
 
         path = "%s/bin/activate_this.py" % self.venv_home
         try:
-            exec (open(path).read(), {'__file__': path})
-            exec (fixpathenvvar)
+            exec(open(path).read(), {'__file__': path})
+            exec(fixpathenvvar)
             self.logger.info("Running with PATH : {}".format(os.environ['PATH']))
             return True
         except Exception as err:
index 453d751..0ed3d32 100644 (file)
@@ -1,5 +1,4 @@
-
-#!/usr/bin/python
+# !/usr/bin/python
 
 #
 # Copyright (C) 2019 Bell Canada.
@@ -43,7 +42,7 @@ def serve():
         'Access denied!')
 
     server = grpc.server(
-        futures.ThreadPoolExecutor(max_workers=10),
+        futures.ProcessPoolExecutor(),
         interceptors=(header_validator,))
 
     CommandExecutor_pb2_grpc.add_CommandExecutorServiceServicer_to_server(
index dc5d008..4314b28 100644 (file)
@@ -17,6 +17,7 @@ from google.protobuf.timestamp_pb2 import Timestamp
 
 import proto.CommandExecutor_pb2 as CommandExecutor_pb2
 
+
 def get_blueprint_id(request):
     blueprint_name = request.identifiers.blueprintName
     blueprint_version = request.identifiers.blueprintVersion