import json from services.tests.base import BaseTestCase from services.model_server.models import Model from services import db, create_app app = create_app() def add_model(model_name, api_endpoint): model = Model(model_name=model_name, api_endpoint=api_endpoint) db.session.add(model) db.session.commit() return model class TestModel(BaseTestCase): def test_add_model(self): """Check if model is added to database""" with self.client: response = self.client.post( '/model/add', data=json.dumps({'model_name': 'iris', 'api_endpoint': 'iris'}), content_type='application/json' ) self.assertResponse(response, status_code=201, status='success', message='added') model = Model.query.filter(Model.api_endpoint == 'iris').first() if not model: raise AssertionError('No model found in database')
import services app = services.create_app() if __name__ == '__main__': app.run(debug=True, host="0.0.0.0")
# @Site : # @File : manage.py # @Software: PyCharm """ from flask import make_response from werkzeug.exceptions import HTTPException from services import create_app, socketio, celery_app from utils.base_response.response import ResponseMsg from utils.base_response.response_message import ResponseMessage, ResponseCode from utils.errors.base_errors.error import APIException from utils.errors.error_codes.error_code import ServerError from models.base.base import db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand app = create_app("development") manage = Manager(app) Migrate(app, db) manage.add_command("db", MigrateCommand) @app.errorhandler(Exception) def framework_err(e): if isinstance(e, APIException): return e if isinstance(e, HTTPException): code = e.code message = e.description result = "" return APIException(message=message, returncode=code,
def main(): app_list = get_app_list() for app in app_list: app_name = app["app_name"].lower() app_status = app["current_status"] task_single_app = "trans_app_{app_id}_{app_name}".format(app_id=app["uuid"], app_name=app_name) if utils.no_task_record(task_single_app): # skipped excluded services in consts.ExcludedServiceNames if app_name in consts.ExcludedApps: print "skipped app {} because configed in consts.ExcludedApps".format(app_name) continue if app_status not in consts.IncludeAppStatus: raw_tips = "{app_name} status is {app_status}, input Yes/No for continue or skip ". \ format(app_name=app_name, app_status=app_status) answer = raw_input(raw_tips) if answer.lower() == "no": print "skipped app {} because current_status is {}".format(app_name, app_status) continue print "begin trans application data to new app data for application {}".format(app_name) app_data = trans_app_data(app) print "app data for application {}".format(app_name) print app_data print "\nbegin delete application old application {}".format(app_name) delete_old_application(app["uuid"]) print "\nwaiting application {} for delete ".format(app_name) for count in range(50): time.sleep(3) v1_application_info = get_v1_app_by_api(app["uuid"]) if isinstance(v1_application_info, dict) and "errors" in v1_application_info: print "\n app {} delete done".format(app_name) break print "\nbegin create app for application {} ".format(app_name) app_info = services.create_app(app_data) if isinstance(app_info, dict) and "errors" in app_info: search_apps = services.get_app_by_name(app_data["resource"]["name"]) if len(search_apps) == 0: exit("create app error!!!!") app_info = search_apps[0] is_running = True if app_status not in ["Running", "Warning"]: is_running = False content = "{}-{}-{}\n".format(utils.get_current_project(), app_name, app_status) utils.file_writer("not_running_app.list", content, "a+") print "app {} current status is {}, will not waiting for created done".format(app_name,app_status) if consts.Configs["wait_for_create_done"] and is_running: # print app_info print "\nwaiting new app {} for create ".format(app_name) create_done = False for count in range(50): time.sleep(3) app = services.get_app_by_api(app_info["resource"]["uuid"]) app_current_state = app["resource"]["status"] if app_current_state == "Running": print "\n app {} create done".format(app_name) create_done = True break else: print "\n app {} current status is {}, continue waiting...".format(app_name, app_current_state) if not create_done: print "application create too slow , please check!" # exit(1) if create_done and consts.Configs["update_app"]: # begin update app for bind old tag app = services.get_app_by_api(app_info["resource"]["uuid"]) update_done = False services.update_app(app) print "\nwaiting app {} for update ".format(app_name) for count in range(50): time.sleep(3) app = services.get_app_by_api(app_info["resource"]["uuid"]) app_current_state = app["resource"]["status"] if app_current_state == "Running": print "\n app {} update done".format(app_name) update_done = True break else: print "\n app {} current status is {}, continue waiting...".format(app_name, app_current_state) if not update_done: print "application update too slow , please check!" # exit(1) else: time.sleep(3) # handle lb binding for app_service in app["services"]: if "resource" in app_service and "name" in app_service["resource"]: lb.handle_lb_for_svc(app_service["resource"]["name"].lower()) elif "service_name" in app_service: lb.handle_lb_for_svc(app_service["service_name"].lower()) # if service_status == "Stopped": # app_id = app_info["resource"]["uuid"] # utils.send_request("PUT", consts.URLS["stop_app"].format(app_id=app_id)) utils.task_record(task_single_app) print "!!!!!Status Confirm: old app status is {}, " \ "please check if should change by hands".format(app_status) exit(1)