def get_remote_market_apps(self, tenant, page, page_size, app_name):
     body = market_api.get_service_group_list(tenant.tenant_id, page,
                                              page_size, app_name)
     remote_apps = body["data"]['list']
     total = body["data"]['total']
     result_list = []
     for app in remote_apps:
         rbc = rainbond_app_repo.get_enterpirse_app_by_key_and_version(
             tenant.enterprise_id, app["group_key"], app["group_version"])
         is_upgrade = 0
         is_complete = False
         if rbc:
             if rbc.is_complete:
                 is_complete = True
             # 判断云市应用是否有小版本更新
             if rbc.upgrade_time < app["upgrade_time"]:
                 is_upgrade = 1
         rbapp = {
             "group_key": app["group_key"],
             "group_name": app["group_name"],
             "version": app["group_version"],
             "source": "market",
             "scope": "goodrain",
             "pic": app['pic'],
             "describe": app['info'],
             "template_version": app.get("template_version", ""),
             "is_complete": is_complete,
             "is_official": app["is_official"],
             "details": app["desc"],
             "upgrade_time": app["upgrade_time"],
             "is_upgrade": is_upgrade
         }
         result_list.append(rbapp)
     return total, result_list
Example #2
0
    def get_version_app(self, eid, version, service_source):
        """
        Get the specified version of the rainbond center(market) application
        raise: RecordNotFound
        raise: RbdAppNotFound
        """
        rain_app = rainbond_app_repo.get_enterpirse_app_by_key_and_version(
            eid, service_source.group_key, version)
        if rain_app is None:
            raise RecordNotFound("Enterprice id: {0}; Group key: {1}; version: {2}; \
                RainbondCenterApp not found.".format(eid, service_source.group_key, version))

        apps_template = json.loads(rain_app.app_template)
        apps = apps_template.get("apps")

        def func(x):
            result = x.get("service_share_uuid", None) == service_source.service_share_uuid\
                or x.get("service_key", None) == service_source.service_share_uuid
            return result
        app = next(iter(filter(lambda x: func(x), apps)), None)
        if app is None:
            fmt = "Group key: {0}; version: {1}; service_share_uuid: {2}; Rainbond app not found."
            raise RbdAppNotFound(fmt.format(service_source.group_key,
                                            version,
                                            service_source.service_share_uuid))

        return app
Example #3
0
 def get_plugins(self, eid, version, service_source):
     rain_app = rainbond_app_repo.get_enterpirse_app_by_key_and_version(eid, service_source.group_key, version)
     if rain_app is None:
         raise RecordNotFound("Enterprice id: {0}; Group key: {1}; version: {2}; \
             RainbondCenterApp not found.".format(eid, service_source.group_key, version))
     apps_template = json.loads(rain_app.app_template)
     return apps_template.get("plugins", [])
    def save_market_app_template(self, user, tenant, app_templates):
        template_version = app_templates["template_version"]
        is_v1 = bool(template_version == "v1")
        if is_v1:
            v2_template = template_transform_service.v1_to_v2(app_templates)
        else:
            v2_template = app_templates
        rainbond_app = rainbond_app_repo.get_enterpirse_app_by_key_and_version(
            tenant.enterprise_id, v2_template["group_key"],
            v2_template["group_version"])

        if not rainbond_app:
            if common_services.is_public() and user.is_sys_admin:
                enterprise_id = "public"
            else:
                enterprise_id = tenant.enterprise_id
            rainbond_app = RainbondCenterApp(
                group_key=app_templates["group_key"],
                group_name=app_templates["group_name"],
                version=app_templates['group_version'],
                share_user=0,
                record_id=0,
                share_team="",
                source="market",
                scope="goodrain",
                describe=app_templates["info"],
                pic=app_templates["pic"],
                app_template="",
                enterprise_id=enterprise_id,
                template_version=app_templates.get("template_version", ""))
        if is_v1:
            rainbond_app.share_user = v2_template["share_user"]
            rainbond_app.share_team = v2_template["share_team"]
            rainbond_app.pic = v2_template["pic"]
            rainbond_app.describe = v2_template["describe"]
            rainbond_app.app_template = json.dumps(v2_template)
            rainbond_app.is_complete = True
            rainbond_app.update_time = current_time_str("%Y-%m-%d %H:%M:%S")
            rainbond_app.save()
        else:
            user_name = v2_template.get("publish_user", None)
            user_id = 0
            if user_name:
                try:
                    user = user_repo.get_user_by_username(user_name)
                    user_id = user.user_id
                except Exception as e:
                    logger.exception(e)
            rainbond_app.share_user = user_id
            rainbond_app.share_team = v2_template.get("publish_team", "")
            rainbond_app.pic = v2_template.get("pic", rainbond_app.pic)
            rainbond_app.describe = v2_template.get("update_note",
                                                    rainbond_app.describe)
            rainbond_app.app_template = v2_template["template_content"]
            rainbond_app.is_complete = True
            rainbond_app.update_time = current_time_str("%Y-%m-%d %H:%M:%S")
            rainbond_app.save()
Example #5
0
    def get_version_apps(self, eid, version, service_source):
        """
        get rainbond center(market) application
        raise: RecordNotFound
        raise: RbdAppNotFound
        """
        rain_app = rainbond_app_repo.get_enterpirse_app_by_key_and_version(eid, service_source.group_key, version)
        if rain_app is None:
            raise RecordNotFound("Enterprice id: {0}; Group key: {1}; version: {2}; \
                RainbondCenterApp not found.".format(eid, service_source.group_key, version))

        apps_template = json.loads(rain_app.app_template)
        return apps_template.get("apps")
 def get_market_version_apps(self, tenant, app_name, group_key, version):
     body = market_api.get_service_group_list(tenant.tenant_id, 1, 20,
                                              app_name)
     remote_apps = body["data"]['list']
     total = body["data"]['total']
     result_list = []
     app_list = []
     for app in remote_apps:
         if app["group_key"] == group_key and app[
                 "group_version"] == version:
             app_list.append(app)
     if len(app_list) > 0:
         for app in app_list:
             rbc = rainbond_app_repo.get_enterpirse_app_by_key_and_version(
                 tenant.enterprise_id, app["group_key"],
                 app["group_version"])
             is_upgrade = 0
             is_complete = False
             if rbc:
                 if rbc.is_complete:
                     is_complete = True
             if rbc and rbc.source != "local" and rbc.upgrade_time:
                 # 判断云市应用是否有小版本更新
                 try:
                     old_version = int(rbc.upgrade_time)
                     new_version = int(app["update_version"])
                     if old_version < new_version:
                         is_upgrade = 1
                 except Exception as e:
                     logger.exception(e)
             rbapp = {
                 "group_key": app["group_key"],
                 "group_name": app["group_name"],
                 "version": app["group_version"],
                 "source": "market",
                 "scope": "goodrain",
                 "pic": app['pic'],
                 "describe": app['info'],
                 "template_version": app.get("template_version", ""),
                 "is_complete": is_complete,
                 "is_official": app["is_official"],
                 "details": app["desc"],
                 "upgrade_time": app["update_version"],
                 "is_upgrade": is_upgrade
             }
             result_list.append(rbapp)
     return total, result_list
Example #7
0
def get_upgrade_app_template(tenant, version, pc):
    template = None
    if pc.install_from_cloud:
        data = app_market_service.get_market_app_model_version(
            pc.market, pc.service_source.group_key, version, get_template=True)
        template = json.loads(data.template)
        pc.template_updatetime = data.update_time
    else:
        data = rainbond_app_repo.get_enterpirse_app_by_key_and_version(tenant.enterprise_id, pc.service_source.group_key,
                                                                       version)
        if not data:
            raise ServiceHandleException(msg="app version {} can not exist".format(version), msg_show="应用模版版本不存在")
        template = json.loads(data.app_template)
        pc.template_updatetime = data.update_time
    if template:
        return template
    raise ServiceHandleException(msg="app version {} can not exist".format(version), msg_show="应用模版版本不存在")
    def get_remote_market_apps(self, tenant, page, page_size, app_name):
        body = market_api.get_service_group_list(tenant.tenant_id, page,
                                                 page_size, app_name)
        remote_apps = body["data"]['list']
        total = body["data"]['total']
        # 创造数据格式app_list = [{group_key:xxx, "group_version_list":[]}, {}]
        app_list = []
        result_list = []
        group_key_list = []
        for app in remote_apps:
            if app["group_key"] not in group_key_list:
                group_key_list.append(app["group_key"])
        logger.debug('==========0=================0{0}'.format(group_key_list))
        if group_key_list:
            for group_key in group_key_list:
                app_dict = dict()
                group_version_list = []
                for app in remote_apps:
                    if app["group_key"] == group_key:
                        if app["group_version"] not in group_version_list:
                            group_version_list.append(app["group_version"])
                group_version_list.sort(reverse=True)
                logger.debug('----------group_version_list------__>{0}'.format(
                    group_version_list))
                logger.debug(
                    '----------group_key------__>{0}'.format(group_key))

                for app in remote_apps:
                    if app["group_version"] == group_version_list[0] and app[
                            "group_key"] == group_key:
                        app_dict["group_key"] = group_key
                        app_dict["group_version_list"] = group_version_list
                        app_dict["update_version"] = app["update_version"]
                        app_dict["group_name"] = app["group_name"]
                        app_dict["pic"] = app["pic"]
                        app_dict["info"] = app["info"]
                        app_dict["template_version"] = app.get(
                            "template_version", "")
                        app_dict["is_official"] = app["is_official"]
                        app_dict["desc"] = app["desc"]
                        app_dict["update_version"] = app["update_version"]
                        app_list.append(app_dict)

        for app in app_list:
            rbc = rainbond_app_repo.get_enterpirse_app_by_key_and_version(
                tenant.enterprise_id, app["group_key"],
                app["group_version_list"][0])

            is_upgrade = 0
            is_complete = False
            if rbc:
                if rbc.is_complete:
                    is_complete = True
            if rbc and rbc.source != "local" and rbc.upgrade_time:
                # 判断云市应用是否有小版本更新
                try:
                    old_version = int(rbc.upgrade_time)
                    new_version = int(app["update_version"])
                    if old_version < new_version:
                        is_upgrade = 1
                except Exception as e:
                    logger.exception(e)
            rbapp = {
                "group_key": app["group_key"],
                "group_name": app["group_name"],
                "version": app["group_version_list"],
                "source": "market",
                "scope": "goodrain",
                "pic": app['pic'],
                "describe": app['info'],
                "template_version": app.get("template_version", ""),
                "is_complete": is_complete,
                "is_official": app["is_official"],
                "details": app["desc"],
                "upgrade_time": app["update_version"],
                "is_upgrade": is_upgrade
            }
            result_list.append(rbapp)
        return total, result_list
Example #9
0
    def get(self, request, *args, **kwargs):
        try:
            bean = dict()
            upgrate_version_list = []

            # 判断服务状态,未部署的服务不提供升级数据
            try:
                body = region_api.check_service_status(
                    self.service.service_region, self.tenant.tenant_name,
                    self.service.service_alias, self.tenant.enterprise_id)

                bean = body["bean"]
                status = bean["cur_status"]
            except Exception as e:
                logger.exception(e)
                status = "unKnow"
            if status == "undeploy":
                result = general_message(200,
                                         "success",
                                         "查询成功",
                                         bean=bean,
                                         list=upgrate_version_list)
                return Response(result, status=result["code"])

            if self.service.service_source != "market":
                return Response(general_message(
                    400,
                    "non-cloud installed applications require no judgment",
                    "非云市安装的应用无需判断"),
                                status=400)
            # 获取组对象
            group_obj = tenant_service_group_repo.get_group_by_service_group_id(
                self.service.tenant_service_group_id)
            if group_obj:
                # 获取内部市场对象
                rain_app = rainbond_app_repo.get_enterpirse_app_by_key_and_version(
                    self.tenant.enterprise_id, group_obj.group_key,
                    group_obj.group_version)
                if not rain_app:
                    result = general_message(200, "success", "当前云市应用已删除")
                    return Response(result, status=result["code"])
                else:
                    apps_template = json.loads(rain_app.app_template)
                    apps_list = apps_template.get("apps")
                    for app in apps_list:
                        if app["service_key"] == self.service.service_key:
                            if app["deploy_version"] > self.service.deploy_version:
                                self.service.is_upgrate = True
                                self.service.save()
                    try:
                        apps_template = json.loads(rain_app.app_template)
                        apps_list = apps_template.get("apps")
                        service_source = service_source_repo.get_service_source(
                            self.service.tenant_id, self.service.service_id)
                        if service_source and service_source.extend_info:
                            extend_info = json.loads(
                                service_source.extend_info)
                            if extend_info:
                                for app in apps_list:
                                    logger.debug(
                                        '---------====app===============>{0}'.
                                        format(json.dumps(app)))
                                    logger.debug(
                                        '---------=====extend_info==============>{0}'
                                        .format(json.dumps(extend_info)))
                                    if app.has_key("service_share_uuid"):
                                        if app["service_share_uuid"] == extend_info[
                                                "source_service_share_uuid"]:
                                            new_version = int(
                                                app["deploy_version"])
                                            old_version = int(extend_info[
                                                "source_deploy_version"])
                                            if new_version > old_version:
                                                self.service.is_upgrate = True
                                                self.service.save()
                                    elif not app.has_key("service_share_uuid"
                                                         ) and app.has_key(
                                                             "service_key"):
                                        if app["service_key"] == extend_info[
                                                "source_service_share_uuid"]:
                                            new_version = int(
                                                app["deploy_version"])
                                            old_version = int(extend_info[
                                                "source_deploy_version"])
                                            if new_version > old_version:
                                                self.service.is_upgrate = True
                                                self.service.save()
                        bean["is_upgrate"] = self.service.is_upgrate
                    except Exception as e:
                        logger.exception(e)
                        result = error_message(e.message)
                        return Response(result, status=result["code"])

                # 通过group_key获取不同版本的应用市场对象
                rain_apps = rainbond_app_repo.get_rainbond_app_by_key(
                    group_obj.group_key)
                if rain_apps:
                    for r_app in rain_apps:
                        if r_app.version > group_obj.group_version and r_app.version not in upgrate_version_list:
                            upgrate_version_list.append(r_app.version)
                        elif r_app.version == group_obj.group_version and self.service.is_upgrate:
                            upgrate_version_list.append(r_app.version)

            upgrate_version_list.sort()
            result = general_message(200,
                                     "success",
                                     "查询成功",
                                     bean=bean,
                                     list=upgrate_version_list)

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])