示例#1
0
    def get_app_detail(self, tenant, region_name, app_id):
        # app metadata
        app = group_repo.get_group_by_pk(tenant.tenant_id, region_name, app_id)

        self.sync_app_services(tenant, region_name, app_id)

        res = app.to_dict()
        res['app_id'] = app.ID
        res['app_name'] = app.group_name
        res['service_num'] = group_service_relation_repo.count_service_by_app_id(
            app_id)
        res['backup_num'] = backup_record_repo.count_by_app_id(app_id)
        res['share_num'] = share_repo.count_by_app_id(app_id)
        res['ingress_num'] = self.count_ingress_by_app_id(
            tenant.tenant_id, region_name, app_id)
        res['config_group_num'] = app_config_group_service.count_by_app_id(
            region_name, app_id)

        try:
            principal = user_repo.get_user_by_username(app.username)
            res['principal'] = principal.get_name()
            res['email'] = principal.email
        except ErrUserNotFound:
            res['principal'] = app.username

        res["create_status"] = "complete"
        res["compose_id"] = None
        if app_id != -1:
            compose_group = compose_repo.get_group_compose_by_group_id(app_id)
            if compose_group:
                res["create_status"] = compose_group.create_status
                res["compose_id"] = compose_group.compose_id

        return res
    def create_group_compose(self,
                             tenant,
                             region,
                             group_id,
                             compose_content,
                             hub_user="",
                             hub_pass=""):
        gc = compose_repo.get_group_compose_by_group_id(group_id)
        if gc:
            return 409, "该组已与其他compose组关联", None
        # 将yaml格式信息转成json数据
        group_compose_data = {
            "hub_user": hub_user,
            "hub_pass": hub_pass,
            "group_id": group_id,
            "team_id": tenant.tenant_id,
            "region": region,
            "compose_content": compose_content,
            "compose_id": make_uuid(),
            "create_status": "creating",
            "create_time": current_time_str("%Y-%m-%d %H:%M:%S"),
        }

        group_compose = compose_repo.create_group_compose(**group_compose_data)
        return 200, "创建groupcompose成功", group_compose
示例#3
0
    def get_group_app_metadata(self, group_id, tenant):
        all_data = dict()
        compose_group_info = compose_repo.get_group_compose_by_group_id(
            group_id)
        compose_service_relation = None
        if compose_group_info:
            compose_service_relation = compose_relation_repo.get_compose_service_relation_by_compose_id(
                compose_group_info.compose_id)
        group_info = group_repo.get_group_by_id(group_id)

        service_group_relations = group_service_relation_repo.get_services_by_group(
            group_id)
        service_ids = [sgr.service_id for sgr in service_group_relations]
        services = service_repo.get_services_by_service_ids(*service_ids)
        all_data["compose_group_info"] = compose_group_info.to_dict(
        ) if compose_group_info else None
        all_data["compose_service_relation"] = [
            relation.to_dict() for relation in compose_service_relation
        ] if compose_service_relation else None
        all_data["group_info"] = group_info.to_dict()
        all_data["service_group_relation"] = [
            sgr.to_dict() for sgr in service_group_relations
        ]
        apps = []
        total_memory = 0
        for service in services:
            if service.service_source == "third_party" or service.create_status != "complete":
                continue
            total_memory += service.min_memory * service.min_node
            app_info = self.get_service_details(tenant, service)
            apps.append(app_info)
        all_data["apps"] = apps
        return total_memory, json.dumps(all_data)
示例#4
0
    def get_group_app_metadata(self, group_id, tenant):
        all_data = dict()
        compose_group_info = compose_repo.get_group_compose_by_group_id(
            group_id)
        compose_service_relation = None
        if compose_group_info:
            compose_service_relation = compose_relation_repo.get_compose_service_relation_by_compose_id(
                compose_group_info.compose_id)
        group_info = group_repo.get_group_by_id(group_id)

        service_group_relations = group_service_relation_repo.get_services_by_group(
            group_id)
        service_ids = [sgr.service_id for sgr in service_group_relations]
        services = service_repo.get_services_by_service_ids(*service_ids)
        all_data["compose_group_info"] = compose_group_info.to_dict(
        ) if compose_group_info else None
        all_data["compose_service_relation"] = [
            relation.to_dict() for relation in compose_service_relation
        ] if compose_service_relation else None
        all_data["group_info"] = group_info.to_dict()
        all_data["service_group_relation"] = [
            sgr.to_dict() for sgr in service_group_relations
        ]
        apps = []
        for service in services:
            app_info = self.get_service_details(tenant, service)
            apps.append(app_info)
        all_data["apps"] = apps
        return json.dumps(all_data)
    def get_group_app_metadata(self, group_id, tenant):
        all_data = dict()
        compose_group_info = compose_repo.get_group_compose_by_group_id(group_id)
        compose_service_relation = None
        if compose_group_info:
            compose_service_relation = compose_relation_repo.get_compose_service_relation_by_compose_id(
                compose_group_info.compose_id)
        group_info = group_repo.get_group_by_id(group_id)

        service_group_relations = group_service_relation_repo.get_services_by_group(group_id)
        service_ids = [sgr.service_id for sgr in service_group_relations]
        services = service_repo.get_services_by_service_ids(service_ids)

        all_data["compose_group_info"] = compose_group_info.to_dict() if compose_group_info else None
        all_data["compose_service_relation"] = [
            relation.to_dict() for relation in compose_service_relation] if compose_service_relation else None
        all_data["group_info"] = group_info.to_dict()
        all_data["service_group_relation"] = [sgr.to_dict() for sgr in service_group_relations]
        apps = []
        total_memory = 0
        plugin_ids = []
        for service in services:
            if service.service_source == "third_party" or service.create_status != "complete":
                continue
            total_memory += service.min_memory * service.min_node
            app_info, pids = self.get_service_details(tenant, service)
            plugin_ids.extend(pids)
            apps.append(app_info)
        all_data["apps"] = apps

        # plugin
        plugins = []
        plugin_build_versions = []
        plugin_config_groups = []
        plugin_config_items = []
        for plugin_id in plugin_ids:
            plugin = plugin_repo.get_plugin_by_plugin_id(tenant.tenant_id, plugin_id)
            if plugin is None:
                continue
            plugins.append(plugin.to_dict())
            bv = build_version_repo.get_last_ok_one(plugin_id, tenant.tenant_id)
            if bv is None:
                continue
            plugin_build_versions.append(bv.to_dict())
            pcgs = plugin_config_group_repo.list_by_plugin_id(plugin_id)
            if pcgs:
                plugin_config_groups.extend([p.to_dict() for p in pcgs])
            pcis = plugin_config_items_repo.list_by_plugin_id(plugin_id)
            if pcis:
                plugin_config_items.extend([p.to_dict() for p in pcis])
        all_data["plugin_info"] = {}
        all_data["plugin_info"]["plugins"] = plugins
        all_data["plugin_info"]["plugin_build_versions"] = plugin_build_versions
        all_data["plugin_info"]["plugin_config_groups"] = plugin_config_groups
        all_data["plugin_info"]["plugin_config_items"] = plugin_config_items

        return total_memory, json.dumps(all_data)
示例#6
0
 def get_group_compose_by_group_id(self, group_id):
     return compose_repo.get_group_compose_by_group_id(group_id)