From 64f29ddd7884f0972031885e9d5473211a91e90e Mon Sep 17 00:00:00 2001 From: nkorange Date: Tue, 18 Dec 2018 16:03:26 +0800 Subject: [PATCH] #187 Add label dump task --- CHANGELOG.md | 108 ++++++++++-------- .../nacos/api/cmdb/spi/CmdbService.java | 8 +- .../cmdb/controllers/OperationController.java | 2 + .../nacos/cmdb/core/SwitchAndOptions.java | 11 ++ .../nacos/cmdb/memory/CmdbProvider.java | 35 +++++- .../META-INF/nacos-default.properties | 1 + distribution/conf/application.properties | 1 + 7 files changed, 113 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61864897..5169d21d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,21 @@ +## 0.7.0(Dec, 2018) + +* [ #461 ] Registration failed when instance port is set to 0 +* [ #455 ] The console can't change the change code +* [ #447 ] 集群模式server挂掉一台后,提供方注册失败 +* [ #445 ] 0.6.1控制台创建配置发布提交时,提示信息有问题 +* [ #442 ] Typos in class names and variables. +* [ #413 ] The console has some uncaught exceptions +* [ #395 ] nacos surport mysql in the case of stand-alone mode +* [ #393 ] Support operation of selector on console +* [ #365 ] NodeJs SDK support +* [ #362 ] The metadata will lost when online or offline instance through web ui +* [ #187 ] Provide Label ability for Naming Service into NACOS for complex multi-DC scenario. + ## 0.6.1(Dec, 2018) -[#421] NamingService's serivce name can't use colon(:) in Windows -[#432] When packing nacos-core, ${user.home} is replaced in the logback configuration file (nacos.xml) +* [#421] NamingService's serivce name can't use colon(:) in Windows +* [#432] When packing nacos-core, ${user.home} is replaced in the logback configuration file (nacos.xml) ## 0.6.0(Dec, 2018) @@ -16,61 +30,61 @@ ## 0.5.0(Nov, 2018) -[#148] Naming write performace. -[#175] Support deregistering instance automatically. -[#176] Naming client query instance method should bypass local cache at client start. -[#177] Console supports registering new empty service and delete empty service. -[#181] NPE when adding a instance if no leader in the raft cluster. -[#193] Configure host domain name cause nacos server cluster is unavailable. -[#209] Disable service and cluster level customization in client registerInstance method. -[#214] Please support Java 11. -[#222] print more nacos server start status info in start.log. -[#231] Refactoring: Parsing the Nacos home directory and the cluster.conf file. -[#246] "mvn -B clean apache-rat:check findbugs:findbugs" did not work as expected. -[#251] Console Editor Optimization. -[#254] DataId and group are required in historical version and listener query. -[#256] Whether the service discovery data needs to add a newline link symbol. -[#257] Listening query switching query dimension data is not refreshed. -[#258] Remove the Balloon of DataId/Group. -[#259] Listening query paging size problem. -[#272] "#it is ip" is also parsed into an instance IP. -[#275] nacos coredns plugin to support DNS. -[#281] We should lint the console code. -[#302] Maven build project supports java 11. -[#316] In stand alone mode, Nacos still checks the cluster.conf. +* [#148] Naming write performace. +* [#175] Support deregistering instance automatically. +* [#176] Naming client query instance method should bypass local cache at client start. +* [#177] Console supports registering new empty service and delete empty service. +* [#181] NPE when adding a instance if no leader in the raft cluster. +* [#193] Configure host domain name cause nacos server cluster is unavailable. +* [#209] Disable service and cluster level customization in client registerInstance method. +* [#214] Please support Java 11. +* [#222] print more nacos server start status info in start.log. +* [#231] Refactoring: Parsing the Nacos home directory and the cluster.conf file. +* [#246] "mvn -B clean apache-rat:check findbugs:findbugs" did not work as expected. +* [#251] Console Editor Optimization. +* [#254] DataId and group are required in historical version and listener query. +* [#256] Whether the service discovery data needs to add a newline link symbol. +* [#257] Listening query switching query dimension data is not refreshed. +* [#258] Remove the Balloon of DataId/Group. +* [#259] Listening query paging size problem. +* [#272] "#it is ip" is also parsed into an instance IP. +* [#275] nacos coredns plugin to support DNS. +* [#281] We should lint the console code. +* [#302] Maven build project supports java 11. +* [#316] In stand alone mode, Nacos still checks the cluster.conf. ## 0.4.0(Nov 7, 2018) -[#216] Fix tenant dir problem -[#197] Service update ignored some properties -[#190] Client beat lose weight info and metadata info -[#188] Console delete data cannot be updated in time -[#179] Listening query fail when namespace is not blank -[#157] Lack information in readme.md to describe the related project repositories for Nacos echosystem -[#144] There have a error and something are not clear -[#106] Snapshot file create error -[#92] Eliminate warnings, refactor code, show start.log detail +* [#216] Fix tenant dir problem +* [#197] Service update ignored some properties +* [#190] Client beat lose weight info and metadata info +* [#188] Console delete data cannot be updated in time +* [#179] Listening query fail when namespace is not blank +* [#157] Lack information in readme.md to describe the related project repositories for Nacos echosystem +* [#144] There have a error and something are not clear +* [#106] Snapshot file create error +* [#92] Eliminate warnings, refactor code, show start.log detail ## 0.3.0(Oct 26, 2018) -[#171] UI debug errors -[#156] Web UI 404 problem -[#155] use local resource -[#145] nacos-example not found :org.apache.logging.log4j.core.Logger -[#142] UI console show Group -[#149] Fix naming client beat process failed bug. -[#150] Fix naming service registration hangs bug. +* [#171] UI debug errors +* [#156] Web UI 404 problem +* [#155] use local resource +* [#145] nacos-example not found :org.apache.logging.log4j.core.Logger +* [#142] UI console show Group +* [#149] Fix naming client beat process failed bug. +* [#150] Fix naming service registration hangs bug. ## 0.3.0-RC1(Oct 19, 2018) -[#33] Support console for config management. -[#51] Support console for naming service. -[#121] Fix get instance method hanging bug. -[#138] Add a flag to indicate if instance is offline. -[#130] Fix health check disabled if machine has one CPU core bug. -[#139] Fix still get instance with zero weight bug. -[#128] Fix console layout bug. +* [#33] Support console for config management. +* [#51] Support console for naming service. +* [#121] Fix get instance method hanging bug. +* [#138] Add a flag to indicate if instance is offline. +* [#130] Fix health check disabled if machine has one CPU core bug. +* [#139] Fix still get instance with zero weight bug. +* [#128] Fix console layout bug. diff --git a/api/src/main/java/com/alibaba/nacos/api/cmdb/spi/CmdbService.java b/api/src/main/java/com/alibaba/nacos/api/cmdb/spi/CmdbService.java index 7442ae129..eadee776f 100644 --- a/api/src/main/java/com/alibaba/nacos/api/cmdb/spi/CmdbService.java +++ b/api/src/main/java/com/alibaba/nacos/api/cmdb/spi/CmdbService.java @@ -55,21 +55,21 @@ public interface CmdbService { /** * Get label value of label name of ip * + * @param entityName entity name * @param entityType entity type - * @param entityValue entity value * @param labelName target label name * @return label value */ - String getLabelValue(String entityValue, String entityType, String labelName); + String getLabelValue(String entityName, String entityType, String labelName); /** * Get all label value of ip * + * @param entityName entity name * @param entityType entity type - * @param entityValue entity value * @return all label values */ - Map getLabelValues(String entityValue, String entityType); + Map getLabelValues(String entityName, String entityType); /** * Dump all entities in CMDB diff --git a/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java b/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java index 020439232..9860d8e87 100644 --- a/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java +++ b/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java @@ -55,6 +55,8 @@ public class OperationController { case "loadDataAtStart": switches.setLoadDataAtStart(Boolean.parseBoolean(value)); break; + case "labelTaskInterval": + switches.setLabelTaskInterval(Integer.parseInt(value)); default: break; } diff --git a/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java b/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java index cf2927a81..dc199ae27 100644 --- a/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java +++ b/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java @@ -30,6 +30,9 @@ public class SwitchAndOptions { @Value("${nacos.cmdb.eventTaskInterval}") private int eventTaskInterval; + @Value("${nacos.cmdb.labelTaskInterval}") + private int labelTaskInterval; + @Value("${nacos.cmdb.loadDataAtStart}") private boolean loadDataAtStart; @@ -49,6 +52,14 @@ public class SwitchAndOptions { this.eventTaskInterval = eventTaskInterval; } + public int getLabelTaskInterval() { + return labelTaskInterval; + } + + public void setLabelTaskInterval(int labelTaskInterval) { + this.labelTaskInterval = labelTaskInterval; + } + public boolean isLoadDataAtStart() { return loadDataAtStart; } diff --git a/cmdb/src/main/java/com/alibaba/nacos/cmdb/memory/CmdbProvider.java b/cmdb/src/main/java/com/alibaba/nacos/cmdb/memory/CmdbProvider.java index f6ca6ae88..d36974aac 100644 --- a/cmdb/src/main/java/com/alibaba/nacos/cmdb/memory/CmdbProvider.java +++ b/cmdb/src/main/java/com/alibaba/nacos/cmdb/memory/CmdbProvider.java @@ -76,8 +76,6 @@ public class CmdbProvider implements CmdbReader, CmdbWriter { return; } - // TODO load data on disk: - // init label map: Set labelNames = cmdbService.getLabelNames(); if (labelNames == null || labelNames.isEmpty()) { @@ -103,6 +101,7 @@ public class CmdbProvider implements CmdbReader, CmdbWriter { load(); UtilsAndCommons.GLOBAL_EXECUTOR.schedule(new CmdbDumpTask(), switches.getDumpTaskInterval(), TimeUnit.SECONDS); + UtilsAndCommons.GLOBAL_EXECUTOR.schedule(new CmdbLabelTask(), switches.getLabelTaskInterval(), TimeUnit.SECONDS); UtilsAndCommons.GLOBAL_EXECUTOR.schedule(new CmdbEventTask(), switches.getEventTaskInterval(), TimeUnit.SECONDS); } @@ -142,6 +141,38 @@ public class CmdbProvider implements CmdbReader, CmdbWriter { entityMap.get(entity.getType()).put(entity.getName(), entity); } + public class CmdbLabelTask implements Runnable { + + @Override + public void run() { + + if (cmdbService == null) { + return; + } + + try { + + Map tmpLabelMap = new HashMap<>(); + + Set labelNames = cmdbService.getLabelNames(); + if (labelNames == null || labelNames.isEmpty()) { + Loggers.MAIN.warn("CMDB-LABEL-TASK {}", "load label names failed!"); + } else { + for (String labelName : labelNames) { + // If get null label, it's still ok. We will try it later when we meet this label: + tmpLabelMap.put(labelName, cmdbService.getLabel(labelName)); + } + labelMap = tmpLabelMap; + } + + } catch (Exception e) { + Loggers.MAIN.error("CMDB-LABEL-TASK {}", "dump failed!", e); + } finally { + UtilsAndCommons.GLOBAL_EXECUTOR.schedule(this, switches.getLabelTaskInterval(), TimeUnit.SECONDS); + } + } + } + public class CmdbDumpTask implements Runnable { @Override diff --git a/console/src/main/resources/META-INF/nacos-default.properties b/console/src/main/resources/META-INF/nacos-default.properties index bb5b2b23b..019d315ac 100644 --- a/console/src/main/resources/META-INF/nacos-default.properties +++ b/console/src/main/resources/META-INF/nacos-default.properties @@ -32,6 +32,7 @@ OPEN_SPAS=true nacos.cmdb.dumpTaskInterval=3600 nacos.cmdb.eventTaskInterval=10 +nacos.cmdb.labelTaskInterval=300 nacos.cmdb.loadDataAtStart=false db.num=2 diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index 76cb46687..9ee31fdf2 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -6,6 +6,7 @@ server.port=8848 nacos.cmdb.dumpTaskInterval=3600 nacos.cmdb.eventTaskInterval=10 +nacos.cmdb.labelTaskInterval=300 nacos.cmdb.loadDataAtStart=false #db.num=2