Пример #1
0
    def update_service_plugin_config(self, service, plugin_id, build_version,
                                     config_bean):
        config_bean = Dict(config_bean)
        service_plugin_var = []
        undefine_env = config_bean.undefine_env
        if undefine_env:
            attrs_map = {
                c.attr_name: c.attr_value
                for c in undefine_env.config
            }
            service_plugin_var.append(
                ServicePluginConfigVar(
                    service_id=service.service_id,
                    plugin_id=plugin_id,
                    build_version=build_version,
                    service_meta_type=undefine_env.service_meta_type,
                    injection=undefine_env.injection,
                    dest_service_id="",
                    dest_service_alias="",
                    container_port=0,
                    attrs=json.dumps(attrs_map),
                    protocol=""))
        upstream_config_list = config_bean.upstream_env
        for upstream_config in upstream_config_list:
            attrs_map = {
                c.attr_name: c.attr_value
                for c in upstream_config.config
            }
            service_plugin_var.append(
                ServicePluginConfigVar(
                    service_id=service.service_id,
                    plugin_id=plugin_id,
                    build_version=build_version,
                    service_meta_type=upstream_config.service_meta_type,
                    injection=upstream_config.injection,
                    dest_service_id="",
                    dest_service_alias="",
                    container_port=upstream_config.port,
                    attrs=json.dumps(attrs_map),
                    protocol=upstream_config.protocol))
        dowstream_config_list = config_bean.downstream_env
        for dowstream_config in dowstream_config_list:
            attrs_map = {
                c.attr_name: c.attr_value
                for c in dowstream_config.config
            }
            service_plugin_var.append(
                ServicePluginConfigVar(
                    service_id=service.service_id,
                    plugin_id=plugin_id,
                    build_version=build_version,
                    service_meta_type=dowstream_config.service_meta_type,
                    injection=dowstream_config.injection,
                    dest_service_id=dowstream_config.dest_service_id,
                    dest_service_alias=dowstream_config.dest_service_alias,
                    container_port=dowstream_config.port,
                    attrs=json.dumps(attrs_map),
                    protocol=dowstream_config.protocol))

        ServicePluginConfigVar.objects.bulk_create(service_plugin_var)
Пример #2
0
 def __save_service_plugin_config(self, sid, service_plugin_configs):
     if not service_plugin_configs:
         return
     new_configs = []
     for cfg in service_plugin_configs:
         cfg.pop("ID")
         new_cfg = ServicePluginConfigVar(**cfg)
         new_cfg.service_id = sid
         new_configs.append(new_cfg)
     ServicePluginConfigVar.objects.bulk_create(new_configs)
Пример #3
0
    def create_plugin_cfg_4marketsvc(self, tenant, service, version, plugin_id,
                                     build_version,
                                     service_plugin_config_vars):
        service_source = service_source_repo.get_service_source(
            tenant.tenant_id, service.service_id)
        config_list = []
        for config in service_plugin_config_vars:
            dest_service_id, dest_service_alias = "", ""
            if config["service_meta_type"] == "downstream_port":
                service_key = rbd_center_app_service.get_service_key_by_service_id(
                    tenant, service_source, version, config["dest_service_id"])
                dest_service = app_service.get_service_by_service_key(
                    service, service_key)
                dest_service_id = dest_service.service_id
                dest_service_alias = dest_service.service_alias

            config_list.append(
                ServicePluginConfigVar(
                    service_id=service.service_id,
                    plugin_id=plugin_id,
                    build_version=build_version,
                    service_meta_type=config["service_meta_type"],
                    injection=config["injection"],
                    dest_service_id=dest_service_id,
                    dest_service_alias=dest_service_alias,
                    container_port=config["container_port"],
                    attrs=config["attrs"],
                    protocol=config["protocol"]))

        ServicePluginConfigVar.objects.bulk_create(config_list)
Пример #4
0
    def create_plugin_cfg_4marketsvc(self, tenant, service, version, plugin_id, build_version, components,
                                     service_plugin_config_vars):
        config_list = []
        component_id_key_map = {}
        for com in components:
            if type(com) == dict:
                component_id_key_map[com["service_id"]] = com["service_share_uuid"]
        for config in service_plugin_config_vars:
            dest_service_id, dest_service_alias = "", ""
            if config["service_meta_type"] == "downstream_port":
                # step1: get dep component key
                dep_service_key = component_id_key_map.get(config["dest_service_id"])
                dest_service = app_service.get_service_by_service_key(service, dep_service_key)
                if dest_service:
                    dest_service_id = dest_service.get("service_id", "")
                    dest_service_alias = dest_service.get("service_alias", "")

            config_list.append(
                ServicePluginConfigVar(
                    service_id=service.service_id,
                    plugin_id=plugin_id,
                    build_version=build_version,
                    service_meta_type=config["service_meta_type"],
                    injection=config["injection"],
                    dest_service_id=dest_service_id,
                    dest_service_alias=dest_service_alias,
                    container_port=config["container_port"],
                    attrs=config["attrs"],
                    protocol=config["protocol"]))
        if config_list and len(config_list) > 0:
            ServicePluginConfigVar.objects.bulk_create(config_list)
Пример #5
0
    def _create_plugin_configs(component: Component, plugin: Plugin,
                               plugin_configs, component_keys: [str],
                               components):
        """
        return new_plugin_configs, ignore_plugin
        new_plugin_configs: new plugin configs created from app template
        ignore_plugin: ignore the plugin if the dependent component not found
        """
        new_plugin_configs = []
        for plugin_config in plugin_configs:
            new_plugin_config = ServicePluginConfigVar(
                service_id=component.component.component_id,
                plugin_id=plugin.plugin.plugin_id,
                build_version=plugin.build_version.build_version,
                service_meta_type=plugin_config["service_meta_type"],
                injection=plugin_config["injection"],
                container_port=plugin_config["container_port"],
                attrs=plugin_config["attrs"],
                protocol=plugin_config["protocol"],
            )

            # dest_service_id, dest_service_alias
            dest_service_id = plugin_config.get("dest_service_id")
            if dest_service_id:
                dep_component_key = component_keys.get(dest_service_id)
                if not dep_component_key:
                    logger.info("dependent component key {} not found".format(
                        dest_service_id))
                    return [], True
                dep_component = components.get(dep_component_key)
                if not dep_component:
                    logger.info("dependent component {} not found".format(
                        dep_component_key))
                    return [], True
                new_plugin_config.dest_service_id = dep_component.component.component_id
                new_plugin_config.dest_service_alias = dep_component.component.service_alias
            new_plugin_configs.append(new_plugin_config)

        return new_plugin_configs, False
Пример #6
0
    def save_default_plugin_config(self, tenant, service, plugin_id,
                                   build_version):
        """console层保存默认的数据"""
        config_groups = plugin_config_service.get_config_group(
            plugin_id, build_version)
        service_plugin_var = []
        for config_group in config_groups:

            items = plugin_config_service.get_config_items(
                plugin_id, build_version, config_group.service_meta_type)

            if config_group.service_meta_type == PluginMetaType.UNDEFINE:
                attrs_map = {
                    item.attr_name: item.attr_default_value
                    for item in items
                }
                service_plugin_var.append(
                    ServicePluginConfigVar(
                        service_id=service.service_id,
                        plugin_id=plugin_id,
                        build_version=build_version,
                        service_meta_type=config_group.service_meta_type,
                        injection=config_group.injection,
                        dest_service_id="",
                        dest_service_alias="",
                        container_port=0,
                        attrs=json.dumps(attrs_map),
                        protocol=""))
            if config_group.service_meta_type == PluginMetaType.UPSTREAM_PORT:
                ports = port_repo.get_service_ports(service.tenant_id,
                                                    service.service_id)
                if not self.__check_ports_for_config_items(ports, items):
                    return 409, "插件支持的协议与组件端口协议不一致"
                for port in ports:
                    attrs_map = dict()
                    for item in items:
                        if item.protocol == "" or (
                                port.protocol in item.protocol.split(",")):
                            attrs_map[item.attr_name] = item.attr_default_value
                    service_plugin_var.append(
                        ServicePluginConfigVar(
                            service_id=service.service_id,
                            plugin_id=plugin_id,
                            build_version=build_version,
                            service_meta_type=config_group.service_meta_type,
                            injection=config_group.injection,
                            dest_service_id="",
                            dest_service_alias="",
                            container_port=port.container_port,
                            attrs=json.dumps(attrs_map),
                            protocol=port.protocol))

            if config_group.service_meta_type == PluginMetaType.DOWNSTREAM_PORT:
                dep_services = dependency_service.get_service_dependencies(
                    tenant, service)
                if not dep_services:
                    return 409, "组件没有依赖其他组件,不能安装此插件"
                for dep_service in dep_services:
                    ports = port_repo.get_service_ports(
                        dep_service.tenant_id, dep_service.service_id)
                    if not self.__check_ports_for_config_items(ports, items):
                        return 409, "该组件依赖的组件的端口协议与插件支持的协议不一致"
                    for port in ports:
                        attrs_map = dict()
                        for item in items:
                            if item.protocol == "" or (
                                    port.protocol in item.protocol.split(",")):
                                attrs_map[
                                    item.attr_name] = item.attr_default_value
                        service_plugin_var.append(
                            ServicePluginConfigVar(
                                service_id=service.service_id,
                                plugin_id=plugin_id,
                                build_version=build_version,
                                service_meta_type=config_group.
                                service_meta_type,
                                injection=config_group.injection,
                                dest_service_id=dep_service.service_id,
                                dest_service_alias=dep_service.service_alias,
                                container_port=port.container_port,
                                attrs=json.dumps(attrs_map),
                                protocol=port.protocol))
        # 保存数据
        ServicePluginConfigVar.objects.bulk_create(service_plugin_var)
        return 200, "success"
Пример #7
0
 def _create_plugins_configs(self):
     plugin_configs = []
     for component in self.snapshot["components"]:
         for plugin_config in component["service_plugin_config"]:
             plugin_configs.append(ServicePluginConfigVar(**plugin_config))
     return plugin_configs