-
Notifications
You must be signed in to change notification settings - Fork 1
/
microservice_flask.py
71 lines (53 loc) · 2.51 KB
/
microservice_flask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# ===============LICENSE_START=======================================================
# Acumos Apache-2.0
# ===================================================================================
# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
# ===================================================================================
# This Acumos software file is distributed by AT&T
# under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============LICENSE_END=========================================================
from flask import Flask
from predictor.api.custom_api import custom_api, blueprint
from predictor.api.endpoints.predictor import api as predictor_namespace
import argparse
import configparser
import logging
import os
app = Flask(__name__)
DEFAULT_HOST = '0.0.0.0'
DEFAULT_PORT = 8061
def get_default_properties_path():
dir_path = os.path.dirname(os.path.join(os.path.realpath(__file__)))
return os.path.join(dir_path, 'properties', 'settings.cfg')
def load_properties(config_path):
parser = configparser.ConfigParser()
parser.read(config_path)
def initialize_app(flask_app):
custom_api.namespaces.clear()
custom_api.add_namespace(predictor_namespace)
flask_app.register_blueprint(blueprint)
def parse_args():
default_path = get_default_properties_path()
parser = argparse.ArgumentParser(description='Run a development server.')
parser.add_argument('--host', default=DEFAULT_HOST,
help='specify the host used to run the development server (default: {})'.format(DEFAULT_HOST))
parser.add_argument('--settings', default=get_default_properties_path(),
help='specify the location of the configuration: (default: {})'.format(default_path))
parser.add_argument('--port', default=DEFAULT_PORT, type=int,
help='specify the port used to run the development server (default: {})'.format(DEFAULT_PORT))
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
load_properties(args.settings)
initialize_app(app)
app.run(host=args.host, debug=True, port=args.port)