This commit is contained in:
qiaofeng1227 2023-04-14 05:15:35 +00:00
parent 50727be0f4
commit f104822b88
2 changed files with 32 additions and 50 deletions

View file

@ -78,32 +78,6 @@ def get_app_detail(app_id):
ret['message'] = "AppID is not legal!"
return ret
# 查询某个正在安装的app的 具体状态waiting等待安装pulling拉取镜像initializing初始化running正常运行
def install_app_process(app_id):
ret = {}
ret['code'] = const.RETURN_FAIL
ret['message'] = ""
ret['status'] = ""
app_name = split_app_id(app_id)
if docker.check_app_id(app_id):
info, code = if_app_exits(app_id)
if code:
var_path = "/data/apps/" + app_name + "/variables.json"
real_name = docker.read_var(var_path, 'name')
app_status = docker.get_process_perc(app_name, real_name)
ret["code"] = const.RETURN_SUCCESS
ret['message'] = "This app is installing."
ret['status'] = app_status
else:
ret['message'] = "This app is not currently installed."
else:
ret['message'] = "AppID is not legal!"
ret = ret.dict()
return ret
def install_app(app_name, customer_name, app_version):
myLogger.info_logger("Install app ...")
ret = {}
@ -111,14 +85,14 @@ def install_app(app_name, customer_name, app_version):
app_id = app_name + "_" + customer_name
ret['ResponseData']['app_id'] = app_id
code, message, detail = check_app(app_name, customer_name, app_version)
q.enqueue(install_app_delay, app_name, customer_app_name, app_version, job_id=app_id, timeout=3600)
code, message = check_app(app_name, customer_name, app_version)
if code == None:
q.enqueue(install_app_delay, app_name, customer_name, app_version, job_id=app_id, timeout=3600)
else:
ret['Error'] = get_error_info(code, message,"")
ret = ret.dict()
return ret
def start_app(app_id):
ret = Response(code=const.RETURN_FAIL, message="")
if docker.check_app_id(app_id):
@ -212,28 +186,36 @@ def uninstall_app(app_id, delete_image, delete_data):
return ret
def check_app(app_name, customer_app_name, app_version):
def check_app(app_name, customer_name, app_version):
message = " "
code = None
app_id = app_name + "-" + customer_app_name
if not docker.check_app_websoft9(app_name):
code = 'Param.AppName.NotExis'
message = "不支持安装指定的App"
elif re.match('^[a-z0-9]+$', customer_app_name) == None:
code = 'Param.CustomerAppName.FormatError'
message = "用户自定义APP名称只能是数字和小写字母组成"
elif docker.check_directory("/data/apps/" + customer_app_name):
code = 'Param.CustomerAppName.Repeat'
message = "已经安装了此应用请重新指定APP名称"
app_id = app_name + "-" + customer_name
if app_name == None:
code = const.ERROR_CLIENT_PARAM_BLANK
message = "app_name is null"
elif customer_name == None:
code = const.ERROR_CLIENT_PARAM_BLANK
message = "customer_name is null"
elif app_version == None:
code = const.ERROR_CLIENT_PARAM_BLANK
message = "app_version is null"
elif not docker.check_app_websoft9(app_name):
code = const.ERROR_CLIENT_PARAM_NOTEXIST
message = "It is not support to install " + app_name
elif re.match('^[a-z0-9]+$', customer_name) == None:
code = const.ERROR_CLIENT_PARAM_Format
message = "APP name can only be composed of numbers and lowercase letters"
elif docker.check_directory("/data/apps/" + customer_name):
code = const.ERROR_CLIENT_PARAM_REPEAT
message = "Repeat installation: " + customer_name
elif not docker.check_vm_resource(app_name):
code = 'Requirement.NotEnough'
message = "系统资源cpu内存磁盘空间不足"
elif check_app_wait(app_id):
code = 'Param.CustomerAppName.Wait'
message = "同名应用已经在安装等待中请重新指定APP名称"
code = const.ERROR_SERVER_RESOURCE
message = "Insufficient system resources (cpu, memory, disk space)"
elif check_app_rq(app_id):
code = const.ERROR_CLIENT_PARAM_REPEAT
message = "Repeat installation: " + customer_name
return code, message
def prepare_app(app_name, customer_app_name):
library_path = "/data/library/apps/" + app_name
install_path = "/data/apps/" + customer_app_name
@ -403,7 +385,7 @@ def check_if_official_app(var_path):
return False
def check_app_wait(app_id):
def check_app_rq(app_id):
myLogger.info_logger("check_app_wait")
deferred = DeferredJobRegistry(queue=q)
wait_job_ids = deferred.get_job_ids()

View file

@ -2,7 +2,7 @@
# 错误代码定义
ERROR_CLIENT_PARAM_BLANK="Client.Parameter.Blank.Error"
ERROR_CLIENT_PARAM_BLANK="Client.Parameter.Format.Error"
ERROR_CLIENT_PARAM_Format="Client.Parameter.Format.Error"
ERROR_CLIENT_PARAM_NOTEXIST="Client.Parameter.Value.NotExist.Error"
ERROR_CLIENT_PARAM_REPEAT="Client.Parameter.Value.Repeat.Error"