From 82a4c89aa83d9eec260762e5cef9df3e513a7694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20=20Man=20Man=20=28=E6=BB=A1=E6=96=87=E6=98=9F=29?= =?UTF-8?q?-=E6=B5=AA=E6=BD=AE=E6=95=B0=E5=AD=97=E4=BC=81=E4=B8=9A?= Date: Mon, 29 Sep 2025 13:54:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96su=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edp/caf/commons/runtime/FileOperator.java | 5 -- .../runtime/msu/MsuConfigVariable.java | 4 ++ .../runtime/msu/ServiceUnitConfigService.java | 72 ++++++++++--------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/FileOperator.java b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/FileOperator.java index 6f5a16113..1176ea544 100644 --- a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/FileOperator.java +++ b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/FileOperator.java @@ -50,11 +50,6 @@ public class FileOperator { input = new FileInputStream(yamlFile); Yaml yaml = new Yaml(); yamlContent = yaml.load(input); - - //从yaml中获取到相关配置 - if (yamlContent.containsKey("msu-config")) { - - } } catch (Throwable e) { throw new RuntimeException(e); } finally { diff --git a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/MsuConfigVariable.java b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/MsuConfigVariable.java index 0331c9ec4..d6c82f5dd 100644 --- a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/MsuConfigVariable.java +++ b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/MsuConfigVariable.java @@ -40,4 +40,8 @@ public class MsuConfigVariable { static final public String CAF_YAML_STRATEGY = "strategy"; static final public String CAF_YAML_SU = "serviceunits"; + // deployment-unit + static final public String DU_NAME = "deployment-unit.name"; + static final public String DU_SU = "deployment-unit.su"; + } diff --git a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java index 22d2db70c..4c9005b4d 100644 --- a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java +++ b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java @@ -36,11 +36,12 @@ import java.util.stream.Collectors; public class ServiceUnitConfigService { private static final Lock locker = new ReentrantLock(); - //private static List> allSuInfo = new ArrayList<>(); //环境内所有su的名称集合 private static final List allSu = new ArrayList<>(); //环境内所有启用的su的名称集合 private static final List enabledSu = new ArrayList<>(); + // 启动的SU名称集合(DU模式) + private static final List enabledSuInDuMode = new ArrayList<>(); //serviceUnit.json集合 private static final List allSuEntity = new ArrayList<>(); //service-unit.yaml集合 @@ -104,27 +105,8 @@ public class ServiceUnitConfigService { ensureInitialized(); // 判断是否分DU启动,DU启动下根据环境变量获取启用su - String duName = System.getProperty("deployment-unit.name"); - if (duName != null) { - String property = System.getProperty("deployment-unit.su"); - if (property != null) { - // 以英文逗号分隔 - String[] array = property.split(","); - if (array.length == 0) { - log.error("Current Deployment-Unit is " + duName + ". There is no msu available, please check your environment."); - } else { - log.info("Current Deployment-Unit is " + duName + ". Enable service units: [" + String.join(",", array) + "]"); - } - - return new ArrayList<>(Arrays.asList(array)); - } else { - log.error("Current Deployment-Unit is " + duName + ". The System property [deployment-unit.su] is null, please check your environment."); - - return new ArrayList<>(); - } - } - - return enabledSu; + if (System.getProperty(MsuConfigVariable.DU_NAME) != null) return enabledSuInDuMode; + else return enabledSu; } /** @@ -148,6 +130,25 @@ public class ServiceUnitConfigService { msuYamlConfig = ServiceUnitConfigUtil.loadYamlConfig(serverPath); enabledSu.addAll(ServiceUnitConfigUtil.getEnableSu(msuYamlConfig, msuJsonConfig, allSu)); + + // 判断是否DU模式启动,DU启动下根据环境变量获取启用su + String duName = System.getProperty(MsuConfigVariable.DU_NAME); + if (duName != null) { + String property = System.getProperty(MsuConfigVariable.DU_SU); + if (property != null) { + // 以英文逗号分隔 + String[] array = property.split(","); + if (array.length == 0) { + log.error("The Deployment-Unit is " + duName + ". There is no msu available, please check your environment!"); + } else { + log.info("The Deployment-Unit is " + duName + ". Enable service units: [" + Arrays.stream(array).sorted().collect(Collectors.joining(",")) + "]"); + } + + enabledSuInDuMode.addAll(Arrays.asList(array)); + } else { + log.error("The Deployment-Unit is " + duName + ". The System property [" + MsuConfigVariable.DU_SU + "] is null, please check your environment."); + } + } } } finally { isInitialized = true; @@ -232,7 +233,6 @@ public class ServiceUnitConfigService { File[] files = fileInfo.listFiles((dir, name) -> (name != null && name.equalsIgnoreCase(MsuConfigVariable.SU_JSON_FILE)||name.equalsIgnoreCase(MsuConfigVariable.SU_YAML_FILE)||name.equalsIgnoreCase(MsuConfigVariable.SU_YML_FILE)) && dir.isDirectory()); //识别为su目录 if (files != null && files.length > 0) { - //if(files.length>1) log.debug("There are complex serviceUnit files. File path is :"+fileInfo.getAbsolutePath()); MsuCommonInfo suEntity = null; ServiceUnitYaml suYaml = null; for(File file:files){ @@ -257,11 +257,18 @@ public class ServiceUnitConfigService { suEntity.setPath(fileInfo.getAbsolutePath()); } } - String su = suEntity==null?null:suEntity.getName(); - if(su!=null&&!allSu.contains(su)&&!allSu.contains(su.toLowerCase())){ - allSu.add(su); - allSuEntity.add(suEntity); - //allSuInfo.add(map); + String su = suEntity == null ? null : suEntity.getName(); + if (su != null) { + if (!allSu.contains(su.toLowerCase())) { + allSu.add(su); + allSuEntity.add(suEntity); + } else { + List conflict = allSuEntity.stream().filter(info -> info.getName().equalsIgnoreCase(su)).collect(Collectors.toList()); + conflict.add(suEntity); + log.error("ERROR: Naming conflict su: " + su.toLowerCase() + + ", finally loaded is: " + conflict.get(0).getPath() + + ", details are: " + conflict.stream().map(info -> info.getName() + "=" + info.getPath()).collect(Collectors.toList())); + } } } else { //非su目录,继续递归,仅查找目录 @@ -289,8 +296,7 @@ public class ServiceUnitConfigService { * 读取application.yaml中关于su启停的配置 */ public static Map loadYamlConfig(String serverPath){ - //String yamlPath = serverPath + File.separator +"runtime" + File.separator +"application.yaml"; - String yamlPath = CafEnvironment.getStartupPath()+System.getProperty("file.separator")+"application.yaml"; + String yamlPath = CafEnvironment.getStartupPath() + File.separator + "application.yaml"; //todo read cloud config return FileOperator.getYaml(yamlPath); } @@ -316,9 +322,11 @@ public class ServiceUnitConfigService { if(enableSuList.size()==0){ log.error("There is no msu available, please check your environment."); } - //log.info("enable service units: " + enableSuList); - log.info("Enable service units: [" + String.join(",", enableSuList) +"]"); + // 非DU模式打印启用SU信息 + if (System.getProperty(MsuConfigVariable.DU_NAME) == null) + log.info("Enable service units: [" + enableSuList.stream().sorted().collect(Collectors.joining(",")) + "]"); + return enableSuList; } -- Gitee From e5172c53f9e680cb7dd23783de9abc473541250a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20=20Man=20Man=20=28=E6=BB=A1=E6=96=87=E6=98=9F=29?= =?UTF-8?q?-=E6=B5=AA=E6=BD=AE=E6=95=B0=E5=AD=97=E4=BC=81=E4=B8=9A?= Date: Mon, 29 Sep 2025 13:59:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../caf/commons/runtime/msu/ServiceUnitConfigService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java index 4c9005b4d..6bfa54bd7 100644 --- a/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java +++ b/caf-commons/caf-commons-runtime/src/main/java/io/iec/edp/caf/commons/runtime/msu/ServiceUnitConfigService.java @@ -265,9 +265,9 @@ public class ServiceUnitConfigService { } else { List conflict = allSuEntity.stream().filter(info -> info.getName().equalsIgnoreCase(su)).collect(Collectors.toList()); conflict.add(suEntity); - log.error("ERROR: Naming conflict su: " + su.toLowerCase() - + ", finally loaded is: " + conflict.get(0).getPath() - + ", details are: " + conflict.stream().map(info -> info.getName() + "=" + info.getPath()).collect(Collectors.toList())); + log.error("ERROR: Naming conflict for su: " + su.toLowerCase() + + ". The finally loaded is: " + conflict.get(0).getPath() + + ". Details: " + conflict.stream().map(info -> info.getName() + "=" + info.getPath()).collect(Collectors.toList())); } } } else { -- Gitee