3 # Copyright © 2018-2019 AT&T Intellectual Property.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from google.protobuf.json_format import MessageToJson
19 from .proto import BluePrintProcessing_pb2_grpc as BluePrintProcessing_pb2_grpc
20 from .script_executor_configuration import ScriptExecutorConfiguration
21 from .executor_utils import instance_for_input
24 class AbstractScriptFunction:
26 def set_context(self, context):
27 self.context = context
29 def process(self, request):
32 def recover(self, runtime_exception, execution_request):
36 class BluePrintProcessingServer(BluePrintProcessing_pb2_grpc.BluePrintProcessingServiceServicer):
38 def __init__(self, configuration: ScriptExecutorConfiguration):
39 self.logger = logging.getLogger(self.__class__.__name__)
40 self.configuration = configuration
42 def process(self, request_iterator, context):
43 for request in request_iterator:
44 jsonObj = MessageToJson(request.payload)
45 self.logger.info(jsonObj)
46 # Get the Dynamic Process Instance based on request
47 instance: AbstractScriptFunction = instance_for_input(self.configuration, request)
48 instance.set_context(context)
49 yield from instance.process(request)