Skip to content

Commit

Permalink
feature: Agent 配置重载功能优化 (closed #1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyyalt committed Oct 25, 2023
1 parent 79d60af commit cc843c6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@

class RenderAndPushGseConfigService(AgentPushConfigService):
def get_config_info_list(self, data, common_data: AgentCommonData, host: models.Host) -> List[Dict[str, Any]]:
file_name = common_data.agent_step_adapter.get_main_config_filename()
file_name_list: List[str] = common_data.agent_step_adapter.get_config_filename_by_node_type(host.node_type)
general_node_type = self.get_general_node_type(host.node_type)
host_ap: models.AccessPoint = self.get_host_ap(common_data=common_data, host=host)
content = common_data.agent_step_adapter.get_config(
host=host, filename=file_name, node_type=general_node_type, ap=host_ap
)
return [{"file_name": file_name, "content": content}]

config_file_list: List[Dict[str, Any]] = []
for file_name in file_name_list:
config_file_list.append(
{
"file_name": file_name,
"content": common_data.agent_step_adapter.get_config(
host=host, filename=file_name, node_type=general_node_type, ap=host_ap
),
}
)
return config_file_list

def get_file_target_path(self, data, common_data: AgentCommonData, host: models.Host) -> str:
general_node_type = self.get_general_node_type(host.node_type)
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,8 @@ class SubscriptionSwithBizAction(enum.EnhanceEnum):
@classmethod
def _get_member__alias_map(cls) -> Dict[Enum, str]:
return {cls.ENABLE: _("启用"), cls.DISABLE: _("禁用")}


class ProxyConfigFile(enum.EnhanceEnum):
V1 = ["agent.conf", "btsvr.conf", "transit.conf", "opts.conf", "plugin_info.json", "data.conf", "dataflow.conf"]
V2 = ["gse_agent.conf", "gse_data_proxy.conf", "gse_file_proxy.conf"]
6 changes: 6 additions & 0 deletions apps/backend/subscription/steps/agent_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from apps.backend import exceptions
from apps.backend.agent.tools import fetch_proxies
from apps.backend.constants import ProxyConfigFile
from apps.core.tag.constants import AGENT_NAME_TARGET_ID_MAP, TargetType
from apps.core.tag.targets import get_target_helper
from apps.node_man import constants, models
Expand Down Expand Up @@ -74,6 +75,11 @@ def config(self) -> OrderedDict:
def get_main_config_filename(self) -> str:
return ("gse_agent.conf", "agent.conf")[self.is_legacy]

def get_config_filename_by_node_type(self, node_type: str) -> typing.List[str]:
if node_type == constants.NodeType.PROXY:
return (ProxyConfigFile.V2.value, ProxyConfigFile.V1.value)[self.is_legacy]
return [self.get_main_config_filename()]

def _get_config(
self,
host: models.Host,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from apps.backend.components.collections.agent_new import components
from apps.backend.subscription.steps.agent_adapter import legacy
from apps.node_man import constants
from apps.node_man.models import Host
from common.api import JobApi
from env.constants import GseVersion

from . import base

Expand Down Expand Up @@ -52,3 +54,43 @@ def tearDown(self) -> None:
)
self.assertEqual(except_content, config_content)
super().tearDown()


class RenderAndPushGseV1ProxyGseConfigTestCase(RenderAndPushGseConfigTestCase):
def setUp(self) -> None:
super().setUp()
Host.objects.update(node_type=constants.NodeType.PROXY)

@classmethod
def get_default_case_name(cls) -> str:
return "渲染并下发1.0Proxy配置成功"

def get_push_config_file_query_params(self):
record = self.job_api_mock_client.call_recorder.record
# 该接口仅调用一次
self.assertEqual(len(record[JobApi.push_config_file]), 1)
push_config_file_query_params = record[JobApi.push_config_file][0].args[0]
return push_config_file_query_params

def tearDown(self) -> None:

push_config_file_query_params = self.get_push_config_file_query_params()
# 1.0Proxy仅下发7个配置文件
self.assertEqual(len(push_config_file_query_params["file_list"]), 7)


class RenderAndPushGseV2ProxyGseConfigTestCase(RenderAndPushGseV1ProxyGseConfigTestCase):
@classmethod
def get_default_case_name(cls) -> str:
return "渲染并下发2.0Proxy配置成功"

def structure_common_inputs(self):
inputs = super().structure_common_inputs()
inputs["meta"] = {"GSE_VERSION": GseVersion.V2.value}
return inputs

def tearDown(self) -> None:

push_config_file_query_params = self.get_push_config_file_query_params()
# 2.0Proxy仅下发3个配置文件
self.assertEqual(len(push_config_file_query_params["file_list"]), 3)

0 comments on commit cc843c6

Please sign in to comment.