Esempio n. 1
0
def deployment_app():
    """
    重新部署应用
    :return:
    """

    user_id = get_login_user_id()
    app_id = request.forms.app_id
    # 防止越权操作
    AppModel.select().where(AppModel.user_id == user_id).get()

    if TaskQueueModel.select().where(TaskQueueModel.app_id == app_id, TaskQueueModel.command_code == 3).count():
        return {"code": -1}

    obj = TaskQueueModel(app_id=app_id, user_id=user_id, command_code=3, command_content='{}', create_time=datetime.datetime.now())
    obj.save()

    return {"code": 0}
Esempio n. 2
0
def deployment_app():
    """
    重新部署应用
    :return:
    """

    user_id = get_login_user_id()
    app_id = request.forms.app_id
    # 防止越权操作
    AppModel.select().where(AppModel.user_id == user_id).get()

    if TaskQueueModel.select().where(TaskQueueModel.app_id == app_id,
                                     TaskQueueModel.command_code == 3).count():
        return {"code": -1}

    obj = TaskQueueModel(app_id=app_id,
                         user_id=user_id,
                         command_code=3,
                         command_content='{}',
                         create_time=datetime.datetime.now())
    obj.save()

    return {"code": 0}
Esempio n. 3
0
def handle_app(app):
    """
    处理每一个APP
    :param app: app对象
    :return:
    """
    container_nums = AppContainModel.select().where(
        AppContainModel.app_id == app.id).count()

    cpu, memory = get_app_avg_message(app.id)

    # 判断是否需要增加容器
    if container_nums < app.min_container_number:
        add_sign = 1
    else:
        if cpu > 5.0 and memory > 95.5 and container_nums < app.max_container_number:
            add_sign = 1
        else:
            add_sign = 0

    # 判断是否需要减少容器
    if container_nums > app.max_container_number:
        add_sign = 0
        reduce_sign = -1
    else:
        if cpu < 1.5 and memory < 90 and container_nums > app.min_container_number:
            reduce_sign = -1
        else:
            reduce_sign = 0

    if container_nums >= app.max_container_number:
        add_sign = 0

    if container_nums <= app.min_container_number:
        reduce_sign = 0

    sign = add_sign + reduce_sign
    if sign == 0:
        return None

    obj = TaskQueueModel(user_id=0,
                         app_id=app.id,
                         create_time=datetime.datetime.now())
    obj.command_content = '{}'
    if sign == 1:
        obj.command_code = 1  # 增加容器
    elif sign == -1:
        obj.command_code = 2  # 减少容器

    # 判断命令有没有重复
    if TaskQueueModel.select().where(
            TaskQueueModel.user_id == obj.user_id,
            TaskQueueModel.app_id == obj.app_id,
            TaskQueueModel.command_code == obj.command_code).count():
        return None

    # 删除同应用不同操作
    dao = TaskQueueModel.delete().where(TaskQueueModel.user_id == obj.user_id,
                                        TaskQueueModel.app_id == obj.app_id)
    dao.execute()

    obj.save()
Esempio n. 4
0
def handle_app(app):
    """
    处理每一个APP
    :param app: app对象
    :return:
    """
    container_nums = AppContainModel.select().where(AppContainModel.app_id == app.id).count()

    cpu, memory = get_app_avg_message(app.id)

    # 判断是否需要增加容器
    if container_nums < app.min_container_number:
        add_sign = 1
    else:
        if cpu > 5.0 and memory > 95.5 and container_nums < app.max_container_number:
            add_sign = 1
        else:
            add_sign = 0

    # 判断是否需要减少容器
    if container_nums > app.max_container_number:
        add_sign = 0
        reduce_sign = -1
    else:
        if cpu < 1.5 and memory < 90 and container_nums > app.min_container_number:
            reduce_sign = -1
        else:
            reduce_sign = 0

    if container_nums >= app.max_container_number:
        add_sign = 0

    if container_nums <= app.min_container_number:
        reduce_sign = 0

    sign = add_sign + reduce_sign
    if sign == 0:
        return None

    obj = TaskQueueModel(user_id=0, app_id=app.id, create_time=datetime.datetime.now())
    obj.command_content = "{}"
    if sign == 1:
        obj.command_code = 1  # 增加容器
    elif sign == -1:
        obj.command_code = 2  # 减少容器

    # 判断命令有没有重复
    if (
        TaskQueueModel.select()
        .where(
            TaskQueueModel.user_id == obj.user_id,
            TaskQueueModel.app_id == obj.app_id,
            TaskQueueModel.command_code == obj.command_code,
        )
        .count()
    ):
        return None

    # 删除同应用不同操作
    dao = TaskQueueModel.delete().where(TaskQueueModel.user_id == obj.user_id, TaskQueueModel.app_id == obj.app_id)
    dao.execute()

    obj.save()