From cd29a05ccd4279d7fb740d03bbeee6a0839b287e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Mon, 2 Sep 2019 14:36:25 -0400 Subject: [PATCH] Use ProcessPool rather than ThreadPool Executor MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I66a800bf30cabce35123b0ac24b3b3e00eef6026 Issue-ID: CCSDK-1681 Signed-off-by: Alexis de Talhouët --- ms/command-executor/pom.xml | 5 +++-- ms/command-executor/src/main/python/command_executor_handler.py | 7 ++++--- ms/command-executor/src/main/python/server.py | 5 ++--- ms/command-executor/src/main/python/utils.py | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ms/command-executor/pom.xml b/ms/command-executor/pom.xml index 5a73fa0af..e99c4ecb2 100755 --- a/ms/command-executor/pom.xml +++ b/ms/command-executor/pom.xml @@ -14,7 +14,8 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - + 4.0.0 org.onap.ccsdk.cds @@ -34,7 +35,7 @@ true ${project.version} ${maven.build.timestamp} - yyyyMMdd'T'HHmmss'Z' + yyyyMMdd'T'HHmmss'Z' diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py index 972dad627..abea4d411 100644 --- a/ms/command-executor/src/main/python/command_executor_handler.py +++ b/ms/command-executor/src/main/python/command_executor_handler.py @@ -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: diff --git a/ms/command-executor/src/main/python/server.py b/ms/command-executor/src/main/python/server.py index 453d751b2..0ed3d3266 100644 --- a/ms/command-executor/src/main/python/server.py +++ b/ms/command-executor/src/main/python/server.py @@ -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( diff --git a/ms/command-executor/src/main/python/utils.py b/ms/command-executor/src/main/python/utils.py index dc5d0089f..4314b287d 100644 --- a/ms/command-executor/src/main/python/utils.py +++ b/ms/command-executor/src/main/python/utils.py @@ -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 -- 2.16.6