File tree 6 files changed +75
-30
lines changed
6 files changed +75
-30
lines changed Original file line number Diff line number Diff line change 16
16
17
17
import flask
18
18
import flask_restplus
19
+ from oslo_log import log as logging
19
20
20
21
import deepaas
21
22
from deepaas .api import v1
22
23
from deepaas import model
23
24
24
- app = flask .Flask (__name__ )
25
- app .config .SWAGGER_UI_DOC_EXPANSION = 'list'
25
+ LOG = logging .getLogger (__name__ )
26
26
27
- api = flask_restplus .Api (
28
- app ,
29
- version = deepaas .__version__ ,
30
- title = 'DEEP as a Service API endpoint' ,
31
- description = 'DEEP as a Service (DEEPaaS) API endpoint.' ,
32
- )
33
-
34
- api .add_namespace (v1 .api , path = "/models" )
27
+ APP = None
35
28
36
29
37
30
def get_app ():
38
- print ("Loaded models: %s" % model .MODELS .keys ())
39
- return app
31
+ global APP
32
+
33
+ if APP :
34
+ return APP
35
+
36
+ model .register_models ()
37
+
38
+ APP = flask .Flask (__name__ )
39
+ APP .config .SWAGGER_UI_DOC_EXPANSION = 'list'
40
+
41
+ api = flask_restplus .Api (
42
+ APP ,
43
+ version = deepaas .__version__ ,
44
+ title = 'DEEP as a Service API endpoint' ,
45
+ description = 'DEEP as a Service (DEEPaaS) API endpoint.' ,
46
+ )
47
+
48
+ api .add_namespace (v1 .api , path = "/models" )
49
+
50
+ LOG .info ("Serving loaded models: %s" , model .MODELS .keys ())
51
+
52
+ return APP
Original file line number Diff line number Diff line change 18
18
import sys
19
19
20
20
from oslo_config import cfg
21
+ from oslo_log import log as logging
21
22
23
+ import deepaas
22
24
from deepaas import api
23
25
from deepaas import config
24
26
47
49
48
50
def main ():
49
51
config .parse_args (sys .argv )
52
+ logging .setup (CONF , "deepaas" )
53
+ log = logging .getLogger (__name__ )
54
+
55
+ log .info ("Starting DEEPaaS version %s" , deepaas .__version__ )
56
+
50
57
app = api .get_app ()
51
58
app .run (
52
- debug = True ,
53
59
host = CONF .listen_ip ,
54
60
port = CONF .listen_port ,
61
+ debug = CONF .debug ,
55
62
)
56
63
57
64
Original file line number Diff line number Diff line change 14
14
# License for the specific language governing permissions and limitations
15
15
# under the License.
16
16
17
+ import logging
18
+ import warnings
19
+
17
20
from oslo_config import cfg
21
+ from oslo_log import log
18
22
19
23
import deepaas
20
24
25
+ logging .captureWarnings (True )
26
+ warnings .simplefilter ("default" , DeprecationWarning )
27
+
21
28
22
29
def parse_args (argv , default_config_files = None ):
30
+ log .register_options (cfg .CONF )
31
+
32
+ log .set_defaults (default_log_levels = log .get_default_log_levels ())
33
+
23
34
cfg .CONF (argv [1 :],
24
35
project = 'deepaas' ,
25
36
version = deepaas .__version__ ,
Original file line number Diff line number Diff line change 14
14
# License for the specific language governing permissions and limitations
15
15
# under the License.
16
16
17
+ from oslo_log import log
17
18
import werkzeug .exceptions as exceptions
18
19
19
20
from deepaas import loading
20
21
22
+ LOG = log .getLogger (__name__ )
23
+
24
+ # Model registry
25
+ MODELS = {}
26
+ MODELS_LOADED = False
27
+
28
+
29
+ def register_models ():
30
+ global MODELS
31
+ global MODELS_LOADED
32
+
33
+ if MODELS_LOADED :
34
+ return
35
+
36
+ MODELS = {}
37
+ try :
38
+ for name , model in loading .get_available_models ().items ():
39
+ MODELS [name ] = BaseModel (name , model )
40
+ except Exception as e :
41
+ LOG .warning ("Error loading models %s" , e )
42
+
43
+ if not MODELS :
44
+ LOG .info ("No models found, loading test model" )
45
+ MODELS ["deepaas-test" ] = TestModel ("deepaas-test" )
46
+ MODELS_LOADED = True
47
+
21
48
22
49
class BaseModel (object ):
23
50
def __init__ (self , name , model ):
@@ -74,19 +101,3 @@ def get_metadata(self):
74
101
"version" : "0.0.1" ,
75
102
}
76
103
return d
77
-
78
-
79
- def populate_models ():
80
- models = {}
81
- try :
82
- for name , model in loading .get_available_models ().items ():
83
- models [name ] = BaseModel (name , model )
84
- except Exception as e :
85
- # TODO(aloga): use logging, not prints
86
- print ("Cannot load any models: %s" % e )
87
- if not models :
88
- print ("Loading test model" )
89
- models ["deepaas-test" ] = TestModel ("deepaas-test" )
90
- return models
91
-
92
- MODELS = populate_models ()
Original file line number Diff line number Diff line change 30
30
31
31
32
32
class TestApi (base .TestCase ):
33
- @mock .patch ('deepaas.api.app ' )
33
+ @mock .patch ('deepaas.api.APP ' )
34
34
def test_get_app (self , mock_app ):
35
35
self .assertEqual (mock_app , api .get_app ())
36
36
@@ -62,6 +62,8 @@ def setUp(self):
62
62
api = flask_restplus .Api (app , doc = False )
63
63
api .add_namespace (v1 .api )
64
64
65
+ deepaas .model .register_models ()
66
+
65
67
self .app = app .test_client ()
66
68
self .assertEqual (app .debug , True )
67
69
Original file line number Diff line number Diff line change 3
3
# process, which may cause wedges in the gate later.
4
4
pbr >= 1.8
5
5
6
+ oslo.log >= 1.8.0 # Apache-2.0
6
7
oslo.config >= 2.3.0 # Apache-2.0
7
8
8
9
enum34
You can’t perform that action at this time.
0 commit comments