5 # Copyright (C) 2019 - 2020 Bell Canada.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 from builtins import KeyboardInterrupt
20 from concurrent import futures
28 import proto.CommandExecutor_pb2_grpc as CommandExecutor_pb2_grpc
30 from request_header_validator_interceptor import RequestHeaderValidatorInterceptor
31 from command_executor_server import CommandExecutorServer
33 logger = logging.getLogger("Server")
35 _ONE_DAY_IN_SECONDS = 60 * 60 * 24
40 basic_auth = sys.argv[2] + ' ' + sys.argv[3]
42 header_validator = RequestHeaderValidatorInterceptor(
43 'authorization', basic_auth, grpc.StatusCode.UNAUTHENTICATED,
47 futures.ThreadPoolExecutor(max_workers=15),
48 interceptors=(header_validator,))
50 CommandExecutor_pb2_grpc.add_CommandExecutorServiceServicer_to_server(
51 CommandExecutorServer(), server)
53 server.add_insecure_port('[::]:' + port)
56 logger.info("Command Executor Server started on %s" % port, extra=utils.getExtraLogData())
60 time.sleep(_ONE_DAY_IN_SECONDS)
61 except KeyboardInterrupt:
65 if __name__ == '__main__':
66 logging_formater = '%(asctime)s|%(request_id)s|%(subrequest_id)s|%(originator_id)s|%(threadName)s|%(name)s|%(levelname)s|%(message)s'
67 logging.basicConfig(filename='/opt/app/onap/logs/application.log', level=logging.DEBUG,
68 format=logging_formater)
69 console = logging.StreamHandler()
70 console.setLevel(logging.INFO)
71 formatter = logging.Formatter(logging_formater)
72 console.setFormatter(formatter)
73 logging.getLogger('').addHandler(console)