RIC-769: Committing individual files rather than tar archive
[ric-plt/appmgr.git] / xapp_orchestrater / dev / xapp_onboarder / xapp_onboarder / server / server.py
1 ################################################################################
2 #   Copyright (c) 2020 AT&T Intellectual Property.                             #
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 import pkg_resources
17 import logging.config
18 from xapp_onboarder.server import settings
19 import logging
20 from flask import Flask, Blueprint
21 from xapp_onboarder.api.api_reference import api
22 from xapp_onboarder.api.endpoints.onboard_ep import ns as onboard_ns
23 from xapp_onboarder.api.endpoints.health_check_ep import ns as health_check_ns
24 from xapp_onboarder.api.endpoints.charts_ep import ns as charts_ns
25 from xapp_onboarder.helm_controller.artifacts_manager import artifacts_manager
26
27 log = logging.getLogger(__name__)
28
29 class server(object):
30     def __init__(self):
31         self.app = Flask(__name__)
32         self.app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
33         self.app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE
34         self.app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
35         self.app.config['ERROR_404_HELP'] = settings.RESTPLUS_ERROR_404_HELP
36         self.api = api
37         self.api_bp = Blueprint('api', __name__, url_prefix='/api/v1')
38         self.api.init_app(self.api_bp)
39         self.api.add_namespace(onboard_ns)
40         self.api.add_namespace(health_check_ns)
41         self.api.add_namespace(charts_ns)
42         self.app.register_blueprint(self.api_bp)
43         self.artifacts_manager = artifacts_manager()
44         self.artifacts_manager.start()
45
46     def run(self):
47         log.info('>>>>> Starting development xapp_onboarder at http://{}/api/v1/ <<<<<'.format(self.app.config['SERVER_NAME']))
48         self.app.run(debug=settings.FLASK_DEBUG, host='0.0.0.0', port=settings.FLASK_PORT)
49
50
51
52
53
54 def main():
55     logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
56     logging.config.fileConfig(logger_config)
57     server().run()
58
59 if __name__ == "__main__":
60     main()
61