5 # Copyright (C) 2019 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
27 import proto.CommandExecutor_pb2_grpc as CommandExecutor_pb2_grpc
29 from request_header_validator_interceptor import RequestHeaderValidatorInterceptor
30 from command_executor_server import CommandExecutorServer
32 logger = logging.getLogger("Server")
34 _ONE_DAY_IN_SECONDS = 60 * 60 * 24
39 basic_auth = sys.argv[2] + ' ' + sys.argv[3]
41 header_validator = RequestHeaderValidatorInterceptor(
42 'authorization', basic_auth, grpc.StatusCode.UNAUTHENTICATED,
46 futures.ThreadPoolExecutor(max_workers=10),
47 interceptors=(header_validator,))
49 CommandExecutor_pb2_grpc.add_CommandExecutorServiceServicer_to_server(
50 CommandExecutorServer(), server)
52 server.add_insecure_port('[::]:' + port)
55 logger.info("Command Executor Server started on %s" % port)
59 time.sleep(_ONE_DAY_IN_SECONDS)
60 except KeyboardInterrupt:
64 if __name__ == '__main__':
65 logging_formater = '%(asctime)s - %(name)s - %(threadName)s - %(levelname)s - %(message)s'
66 logging.basicConfig(filename='/opt/app/onap/logs/application.log', level=logging.DEBUG,
67 format=logging_formater)
68 console = logging.StreamHandler()
69 console.setLevel(logging.INFO)
70 formatter = logging.Formatter(logging_formater)
71 console.setFormatter(formatter)
72 logging.getLogger('').addHandler(console)