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