Marek Szwalkiewicz | be4c464 | 2020-01-30 13:49:18 +0000 | [diff] [blame] | 1 | """Copyright 2019 Deutsche Telekom. |
| 2 | |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | |
| 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | |
| 9 | Unless required by applicable law or agreed to in writing, software |
| 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | """ |
| 15 | |
| 16 | from concurrent.futures import ThreadPoolExecutor |
| 17 | |
| 18 | import click |
| 19 | from grpc import server as grpc_server |
| 20 | from manager.configuration import config |
| 21 | from manager.servicer import ArtifactManagerServicer |
| 22 | from proto.BluePrintManagement_pb2_grpc import add_BluePrintManagementServiceServicer_to_server |
| 23 | |
| 24 | |
| 25 | @click.command() |
| 26 | def run_server(): |
| 27 | """Run Artifact Manager gRPC server. |
| 28 | |
| 29 | Values like 'maxWorkers' and 'port' must be specified in a config file in .ini format. |
| 30 | |
| 31 | Config file path is specified by 'CONFIGURATION' environment variable. |
| 32 | |
| 33 | """ |
| 34 | max_workers: int = int(config["artifactManagerServer"]["maxWorkers"]) |
| 35 | server: grpc_server = grpc_server(ThreadPoolExecutor(max_workers=max_workers)) |
| 36 | |
| 37 | add_BluePrintManagementServiceServicer_to_server(ArtifactManagerServicer(), server) |
| 38 | port_number: int = int(config["artifactManagerServer"]["port"]) |
| 39 | server.add_insecure_port(f"[::]:{port_number}") |
| 40 | |
| 41 | click.echo(f"Server starts on port {port_number} using {max_workers} workers.") |
| 42 | server.start() |
| 43 | server.wait_for_termination() |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | run_server() |