From 4b0578ec7c89880bc3d6b11d62ed26e4fa7e0230 Mon Sep 17 00:00:00 2001 From: xcwang <1366993017@qq.com> Date: Mon, 28 Aug 2023 14:55:28 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=202.0=20Proxy=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E4=BC=A0?= =?UTF-8?q?=E8=BE=93=E8=B7=AF=E5=BE=84=20(closed=20#1757)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/subscription/steps/agent_adapter/base.py | 12 ++++++++++++ .../agent_adapter/config_context/context_helper.py | 7 ++++++- .../subscription/steps/agent_adapter/legacy.py | 9 +++++++-- apps/node_man/serializers/ap.py | 10 ++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/backend/subscription/steps/agent_adapter/base.py b/apps/backend/subscription/steps/agent_adapter/base.py index dd5883ed5..842bde6fc 100644 --- a/apps/backend/subscription/steps/agent_adapter/base.py +++ b/apps/backend/subscription/steps/agent_adapter/base.py @@ -8,6 +8,7 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ +import os import typing from dataclasses import dataclass @@ -35,3 +36,14 @@ class AgentSetupInfo: # extra setup info # 是否强制更新 AgentID,True:注册 AgentID 前会先 force_update_agent_id: bool = False + + +class AgentSetupTools: + @staticmethod + def generate_gse_file_cache_dir(path: str, is_legacy: bool) -> str: + gse_file_cache_prefix: str = "/data" + if is_legacy: + file_cache_dir: str = os.path.join(gse_file_cache_prefix, os.path.basename(path)) + else: + file_cache_dir: str = os.path.join(gse_file_cache_prefix, os.path.basename(path), "file_cache") + return file_cache_dir diff --git a/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py b/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py index 6ca52f294..2e827d9e8 100644 --- a/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py +++ b/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py @@ -20,6 +20,7 @@ from apps.backend.agent import tools from apps.backend.agent.solution_maker import ExecutionSolutionTools +from apps.backend.subscription.steps.agent_adapter.base import AgentSetupTools from apps.backend.utils.data_renderer import nested_render_data from apps.node_man import constants, models @@ -212,7 +213,11 @@ def __post_init__(self): tls_cli_cert_file=proxy_tls_cli_cert_file, tls_cli_key_file=proxy_tls_cli_key_file, ), - context_dataclass.FileCacheConfigContext(), + context_dataclass.FileCacheConfigContext( + dirs=self.host.extra_data.get( + "data_path", AgentSetupTools.generate_gse_file_cache_dir(path=setup_path, is_legacy=False) + ), + ), context_dataclass.FileMetricConfigContext( exporter_bind_port=self.ap.port_config.get( "file_metric_bind_port", constants.GSE_PORT_DEFAULT_VALUE["file_metric_bind_port"] diff --git a/apps/backend/subscription/steps/agent_adapter/legacy.py b/apps/backend/subscription/steps/agent_adapter/legacy.py index 37995219a..3648991c8 100644 --- a/apps/backend/subscription/steps/agent_adapter/legacy.py +++ b/apps/backend/subscription/steps/agent_adapter/legacy.py @@ -15,7 +15,10 @@ from django.conf import settings from apps.backend.agent.tools import fetch_gse_servers_info -from apps.backend.subscription.steps.agent_adapter.base import AgentSetupInfo +from apps.backend.subscription.steps.agent_adapter.base import ( + AgentSetupInfo, + AgentSetupTools, +) from apps.backend.utils.data_renderer import nested_render_data from apps.backend.utils.encrypted import GseEncrypted from apps.node_man import constants, models @@ -470,7 +473,9 @@ def generate_gse_config( setup_path = agent_config["setup_path"] log_path = agent_config["log_path"] # 如果没有自定义则使用接入点默认配置 - data_path = host.extra_data.get("data_path") or agent_config["data_path"] + data_path = host.extra_data.get("data_path") or AgentSetupTools.generate_gse_file_cache_dir( + path=setup_path, is_legacy=True + ) gse_servers_info: Dict[str, Any] = fetch_gse_servers_info( AgentSetupInfo(is_legacy=True), host, ap, proxies, install_channel diff --git a/apps/node_man/serializers/ap.py b/apps/node_man/serializers/ap.py index efb2c50c0..6407777eb 100644 --- a/apps/node_man/serializers/ap.py +++ b/apps/node_man/serializers/ap.py @@ -13,11 +13,13 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers +from apps.backend.subscription.steps.agent_adapter.base import AgentSetupTools from apps.exceptions import ValidationError from apps.node_man.constants import ( GSE_PORT_DEFAULT_VALUE, GSE_V2_PORT_DEFAULT_VALUE, IamActionType, + OsType, ) from apps.node_man.handlers.iam import IamHandler from apps.node_man.models import AccessPoint @@ -49,6 +51,7 @@ class ListSerializer(serializers.ModelSerializer): is_enabled = serializers.BooleanField(label=_("是否启用")) is_default = serializers.BooleanField(label=_("是否默认接入点,不可删除")) proxy_package = serializers.JSONField(label=_("Proxy上的安装包")) + file_cache_dirs = serializers.SerializerMethodField(label=_("文件缓存目录")) def to_representation(self, instance): ret = super(ListSerializer, self).to_representation(instance) @@ -63,6 +66,13 @@ def to_representation(self, instance): } return ret + def get_file_cache_dirs(self, instance): + is_legacy: bool = instance.gse_version == GseVersion.V1.value + data_path: str = AgentSetupTools.generate_gse_file_cache_dir( + path=instance.agent_config[OsType.LINUX.lower()]["setup_path"], is_legacy=is_legacy + ) + return data_path + class Meta: model = AccessPoint exclude = ("zk_password",)