Matteo Scandolo | 920e8fd | 2017-08-08 13:05:24 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 17 | import os |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 18 | from xosconfig import Config |
Matteo Scandolo | 5a07a2c | 2018-06-05 18:04:00 -0700 | [diff] [blame] | 19 | from multistructlog import create_logger |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 20 | |
| 21 | current_dir = os.path.dirname(os.path.realpath(__file__)) |
Matteo Scandolo | 89c1f56 | 2017-10-19 19:09:45 +0200 | [diff] [blame] | 22 | config_file = os.path.join(current_dir, 'xos-tosca.config.yaml') |
| 23 | config_schema = os.path.join(current_dir, 'xos-tosca-config-schema.yaml') |
| 24 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 25 | Config.init(config_file, config_schema) |
Matteo Scandolo | 5a07a2c | 2018-06-05 18:04:00 -0700 | [diff] [blame] | 26 | log = create_logger(Config().get('logging')) |
| 27 | |
| 28 | from grpc_client.main import GRPC_Client |
| 29 | from tosca.generator import TOSCA_Generator |
| 30 | from web_server.main import TOSCA_WebServer |
| 31 | from twisted.internet import defer |
| 32 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 33 | |
| 34 | class Main: |
| 35 | |
| 36 | def __init__(self): |
| 37 | self.grpc_client = None |
| 38 | |
| 39 | def generate_tosca(self, client): |
| 40 | |
| 41 | deferred = defer.Deferred() |
| 42 | |
| 43 | TOSCA_Generator().generate(client) |
| 44 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 45 | return deferred |
| 46 | |
| 47 | def start(self): |
Matteo Scandolo | 5a07a2c | 2018-06-05 18:04:00 -0700 | [diff] [blame] | 48 | log.info("[XOS-TOSCA] Starting") |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 49 | |
Scott Baker | 3f7739c | 2018-02-20 20:17:34 -0800 | [diff] [blame] | 50 | # Remove generated TOSCA and KEYS that may have been downloaded by a previous session. This is done here, rather |
| 51 | # than in the generator, to cover the case where the TOSCA engine is restarted and a web request is received |
| 52 | # and processed before generate_tosca() has completed. |
| 53 | TOSCA_Generator().clean() |
| 54 | TOSCA_Generator().clean_keys() |
| 55 | |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 56 | grpc_setup = GRPC_Client().start() |
| 57 | grpc_setup.addCallback(self.generate_tosca) |
| 58 | |
Matteo Scandolo | 21dde41 | 2017-07-11 18:54:12 -0700 | [diff] [blame] | 59 | # NOTE that TOSCA_WebServer create a Klein app that call reactor.run() |
| 60 | TOSCA_WebServer() |
Matteo Scandolo | 9ce1825 | 2017-06-22 10:48:25 -0700 | [diff] [blame] | 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | Main().start() |