summaryrefslogtreecommitdiffstats
path: root/api/server.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-01-04 17:41:18 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-01-10 10:03:24 +0000
commit63e75aad3b01de4fc20468d5dd9cdb9b15c5e11e (patch)
tree9f3600cb443029e0fbcec03c349d1b452dc2f938 /api/server.py
parent57011bd0769f54a98b90d489df0f38751ca76c0e (diff)
Add API to get the status of async task
JIRA: YARDSTICK-526 Currently there are many API run a task using sub thread. But we don't know the status of this task. So we need to offer a API to query the status of this task. Change-Id: I8d2cc558750bf9270aed4a7abb8bf35d17894d83 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/server.py')
-rw-r--r--api/server.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/api/server.py b/api/server.py
index fac821b00..8cce4de87 100644
--- a/api/server.py
+++ b/api/server.py
@@ -7,13 +7,17 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import logging
+from itertools import ifilter
+import inspect
from flask import Flask
from flask_restful import Api
from flasgger import Swagger
-from api.database import init_db
+from api.database import Base
+from api.database import engine
from api.database import db_session
+from api.database import models
from api.urls import urlpatterns
from yardstick import _init_logging
@@ -21,8 +25,6 @@ logger = logging.getLogger(__name__)
app = Flask(__name__)
-init_db()
-
Swagger(app)
api = Api(app)
@@ -33,6 +35,21 @@ def shutdown_session(exception=None):
db_session.remove()
+def init_db():
+ def func(a):
+ try:
+ if issubclass(a[1], Base):
+ return True
+ except TypeError:
+ pass
+ return False
+
+ subclses = ifilter(func, inspect.getmembers(models, inspect.isclass))
+ logger.debug('Import models: %s', [a[1] for a in subclses])
+ Base.metadata.create_all(bind=engine)
+
+
+init_db()
reduce(lambda a, b: a.add_resource(b.resource, b.url,
endpoint=b.endpoint) or a, urlpatterns, api)