diff --git a/client/src/main/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider b/client-basic/src/main/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider similarity index 100% rename from client/src/main/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider rename to client-basic/src/main/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider diff --git a/client/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider b/client-basic/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider similarity index 100% rename from client/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider rename to client-basic/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider diff --git a/maintainer-client/pom.xml b/maintainer-client/pom.xml index d422d08e0e..11899d1316 100644 --- a/maintainer-client/pom.xml +++ b/maintainer-client/pom.xml @@ -40,10 +40,6 @@ commons-collections commons-collections - - org.springframework.boot - spring-boot-starter-web - com.alibaba.nacos nacos-common diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/NacosMaintainerFactory.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/NacosMaintainerFactory.java index 73bbc32e05..eea3ca383e 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/NacosMaintainerFactory.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/NacosMaintainerFactory.java @@ -29,8 +29,7 @@ import java.util.Properties; */ public class NacosMaintainerFactory { - public static ConfigMaintainerService createConfigMaintainerService(String serverList) - throws NacosException, NacosException { + public static ConfigMaintainerService createConfigMaintainerService(String serverList) throws NacosException { return ConfigMaintainerFactory.createConfigMaintainerService(serverList); } diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/address/DefaultServerListManager.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/address/DefaultServerListManager.java index f7a3f818bb..d92413395e 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/address/DefaultServerListManager.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/address/DefaultServerListManager.java @@ -24,7 +24,6 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.maintainer.client.remote.HttpClientManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Collections; @@ -37,7 +36,6 @@ import java.util.Random; * * @author Nacos */ -@Service public class DefaultServerListManager extends AbstractServerListManager { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultServerListManager.class); diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactory.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactory.java index 3903c6834f..f2fa3b3e52 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactory.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactory.java @@ -37,7 +37,7 @@ public class ConfigMaintainerFactory { public static ConfigMaintainerService createConfigMaintainerService(String serverList) throws NacosException { Properties properties = new Properties(); properties.setProperty("serverAddr", serverList); - return new NacosConfigMaintainerService(properties); + return new NacosConfigMaintainerServiceImpl(properties); } /** @@ -51,6 +51,6 @@ public class ConfigMaintainerFactory { if (properties == null) { throw new NacosException(NacosException.INVALID_PARAM, "Properties cannot be null"); } - return new NacosConfigMaintainerService(properties); + return new NacosConfigMaintainerServiceImpl(properties); } } \ No newline at end of file diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerService.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerService.java index 87f22ff8f0..e9e36b658c 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerService.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerService.java @@ -17,7 +17,6 @@ package com.alibaba.nacos.maintainer.client.config; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.exception.api.NacosApiException; import com.alibaba.nacos.maintainer.client.model.config.Capacity; import com.alibaba.nacos.maintainer.client.model.config.ConfigAdvanceInfo; import com.alibaba.nacos.maintainer.client.model.config.ConfigAllInfo; @@ -33,9 +32,6 @@ import com.alibaba.nacos.maintainer.client.model.core.Connection; import com.alibaba.nacos.maintainer.client.model.core.IdGeneratorVO; import com.alibaba.nacos.maintainer.client.model.core.Member; import com.alibaba.nacos.maintainer.client.model.core.ServerLoaderMetrics; -import org.springframework.http.ResponseEntity; -import org.springframework.web.context.request.async.DeferredResult; -import org.springframework.web.multipart.MultipartFile; import java.util.Collection; import java.util.List; @@ -56,7 +52,7 @@ public interface ConfigMaintainerService { * @return Configuration information. * @throws NacosException If the query fails. */ - ConfigAllInfo getConfig(String dataId, String groupName) throws Exception; + ConfigAllInfo getConfig(String dataId, String groupName) throws NacosException; /** * Get configuration information by dataId, groupName, and namespaceId. @@ -67,7 +63,7 @@ public interface ConfigMaintainerService { * @return Configuration information. * @throws NacosException If the query fails. */ - ConfigAllInfo getConfig(String dataId, String groupName, String namespaceId) throws Exception; + ConfigAllInfo getConfig(String dataId, String groupName, String namespaceId) throws NacosException; /** * Publish a configuration by dataId and groupName. @@ -78,7 +74,7 @@ public interface ConfigMaintainerService { * @return Whether the configuration was published successfully. * @throws NacosException If the publish operation fails. */ - boolean publishConfig(String dataId, String groupName, String content) throws Exception; + boolean publishConfig(String dataId, String groupName, String content) throws NacosException; /** * Publish a configuration by dataId, groupName, and namespaceId. @@ -90,30 +86,30 @@ public interface ConfigMaintainerService { * @return Whether the configuration was published successfully. * @throws NacosException If the publish operation fails. */ - boolean publishConfig(String dataId, String groupName, String namespaceId, String content) throws Exception; + boolean publishConfig(String dataId, String groupName, String namespaceId, String content) throws NacosException; /** - * Publish a configuration. + * Publish a configuration with additional metadata. * - * @param dataId Configuration data ID (required) - * @param groupName Configuration group name (required) - * @param namespaceId Namespace ID (optional, default is "public") - * @param content Configuration content (required) - * @param tag Configuration tag (optional) - * @param appName Application name (optional) - * @param srcUser Source user (optional) - * @param configTags Configuration tags, multiple tags separated by commas (optional) - * @param desc Configuration description (optional) - * @param use Configuration usage (optional) - * @param effect Configuration effect (optional) - * @param type Configuration type (optional) - * @param schema Configuration schema (optional) - * @return Whether the configuration was published successfully - * @throws NacosException If publishing fails + * @param dataId Configuration data ID (required). + * @param groupName Configuration group name (required). + * @param namespaceId Namespace ID (optional, defaults to "public"). + * @param content Configuration content (required). + * @param tag Configuration tag (optional). + * @param appName Application name (optional). + * @param srcUser Source user (optional). + * @param configTags Configuration tags, multiple tags separated by commas (optional). + * @param desc Configuration description (optional). + * @param use Configuration usage (optional). + * @param effect Configuration effect (optional). + * @param type Configuration type (optional). + * @param schema Configuration schema (optional). + * @return Whether the configuration was published successfully. + * @throws NacosException If publishing fails. */ - boolean publishConfig(String dataId, String groupName, String namespaceId, String content, String tag, String appName, - String srcUser, String configTags, String desc, String use, String effect, String type, String schema) - throws Exception; + boolean publishConfig(String dataId, String groupName, String namespaceId, String content, String tag, + String appName, String srcUser, String configTags, String desc, String use, String effect, String type, + String schema) throws NacosException; /** * Delete a configuration by dataId and groupName. @@ -123,21 +119,21 @@ public interface ConfigMaintainerService { * @return Whether the configuration was deleted successfully. * @throws NacosException If deletion fails. */ - boolean deleteConfig(String dataId, String groupName) throws Exception; + boolean deleteConfig(String dataId, String groupName) throws NacosException; /** - * Delete a configuration. + * Delete a configuration by dataId, groupName, and namespaceId. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). * @param namespaceId Namespace ID (optional, defaults to "public"). * @return Whether the configuration was deleted successfully. - * @throws Exception If deletion fails. + * @throws NacosException If deletion fails. */ - boolean deleteConfig(String dataId, String groupName, String namespaceId) throws Exception; + boolean deleteConfig(String dataId, String groupName, String namespaceId) throws NacosException; /** - * Delete a configuration. + * Delete a configuration by dataId, groupName, namespaceId, and tag. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). @@ -146,29 +142,29 @@ public interface ConfigMaintainerService { * @return Whether the configuration was deleted successfully. * @throws NacosException If deletion fails. */ - boolean deleteConfig(String dataId, String groupName, String namespaceId, String tag) throws Exception; + boolean deleteConfig(String dataId, String groupName, String namespaceId, String tag) throws NacosException; /** - * Delete multiple configurations. + * Delete multiple configurations by their IDs. * * @param ids List of configuration IDs to delete. * @return Whether the configurations were deleted successfully. * @throws NacosException If deletion fails. */ - boolean deleteConfigs(List ids) throws Exception; + boolean deleteConfigs(List ids) throws NacosException; /** - * Get the advanced information of a configuration. + * Get the advanced information of a configuration by dataId and groupName. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). * @return Advanced information of the configuration. * @throws NacosException If retrieval fails. */ - ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName) throws Exception; + ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName) throws NacosException; /** - * Get the advanced information of a configuration. + * Get the advanced information of a configuration by dataId, groupName, and namespaceId. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). @@ -176,37 +172,37 @@ public interface ConfigMaintainerService { * @return Advanced information of the configuration. * @throws NacosException If retrieval fails. */ - ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName, String namespaceId) throws Exception; + ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName, String namespaceId) throws NacosException; /** - * Get the listeners of a configuration. + * Get the listeners of a configuration by dataId and groupName. * - * @param dataId Configuration data ID (required). - * @param groupName Configuration group name (required). + * @param dataId Configuration data ID (required). + * @param groupName Configuration group name (required). * @return List of listeners for the configuration. - * @throws Exception If retrieval fails. + * @throws NacosException If retrieval fails. */ - GroupkeyListenserStatus getListeners(String dataId, String groupName) throws Exception; + GroupkeyListenserStatus getListeners(String dataId, String groupName) throws NacosException; /** - * Get the advanced information of a configuration. + * Get the listeners of a configuration by dataId, groupName, namespaceId, and sampleTime. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). * @param namespaceId Namespace ID (optional, defaults to "public"). * @param sampleTime Sample time (optional). - * @return Advanced information of the configuration. + * @return List of listeners for the configuration. * @throws NacosException If retrieval fails. */ - GroupkeyListenserStatus getListeners(String dataId, String groupName, String namespaceId, int sampleTime) throws Exception; - + GroupkeyListenserStatus getListeners(String dataId, String groupName, String namespaceId, int sampleTime) + throws NacosException; /** * Search configurations by details. * - * @param namespaceId Namespace ID (optional, defaults to "public"). * @param dataId Configuration data ID (optional, defaults to ""). * @param groupName Configuration group name (optional, defaults to ""). + * @param namespaceId Namespace ID (optional, defaults to "public"). * @param configDetail Configuration detail (optional). * @param search Search mode ("blur" or "exact", optional, defaults to "blur"). * @param pageNo Page number (required, defaults to 1). @@ -215,20 +211,20 @@ public interface ConfigMaintainerService { * @throws NacosException If the search fails. */ Page searchConfigByDetails(String dataId, String groupName, String namespaceId, String configDetail, - String search, int pageNo, int pageSize) throws Exception; - + String search, int pageNo, int pageSize) throws NacosException; + /** - * Stop a beta configuration. + * Stop a beta configuration by dataId and groupName. * - * @param dataId Configuration data ID (required). - * @param groupName Configuration group name (required). + * @param dataId Configuration data ID (required). + * @param groupName Configuration group name (required). * @return Whether the beta configuration was stopped successfully. * @throws NacosException If stopping fails. */ - boolean stopBeta(String dataId, String groupName) throws Exception; + boolean stopBeta(String dataId, String groupName) throws NacosException; /** - * Stop a beta configuration. + * Stop a beta configuration by dataId, groupName, and namespaceId. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). @@ -236,7 +232,7 @@ public interface ConfigMaintainerService { * @return Whether the beta configuration was stopped successfully. * @throws NacosException If stopping fails. */ - boolean stopBeta(String dataId, String groupName, String namespaceId) throws Exception; + boolean stopBeta(String dataId, String groupName, String namespaceId) throws NacosException; /** * Query beta configuration by dataId and groupName. @@ -246,7 +242,7 @@ public interface ConfigMaintainerService { * @return Beta configuration information. * @throws NacosException If the query fails. */ - ConfigInfo4Beta queryBeta(String dataId, String groupName) throws Exception; + ConfigInfo4Beta queryBeta(String dataId, String groupName) throws NacosException; /** * Query beta configuration by dataId, groupName, and namespaceId. @@ -257,49 +253,23 @@ public interface ConfigMaintainerService { * @return Beta configuration information. * @throws NacosException If the query fails. */ - ConfigInfo4Beta queryBeta(String dataId, String groupName, String namespaceId) throws Exception; - - /** - * Import and publish configurations from a file. - * - * @param namespaceId Namespace ID (optional, defaults to "public"). - * @param srcUser Source user (optional). - * @param policy Conflict resolution policy (required). - * @param file Configuration file to import (required). - * @return A map containing the import result (e.g., success count, unrecognized data). - * @throws NacosException If the import fails. - */ - Map importAndPublishConfig(String namespaceId, String srcUser, SameConfigPolicy policy, MultipartFile file) - throws Exception; - - /** - * Export configurations as a zip file. - * - * @param dataId Configuration data ID (optional). - * @param groupName Configuration group name (optional). - * @param namespaceId Namespace ID (optional, defaults to "public"). - * @param ids List of configuration IDs to export (optional). - * @return A ResponseEntity containing the exported zip file. - * @throws NacosException If the export fails. - */ - ResponseEntity exportConfig(String dataId, String groupName, String namespaceId, List ids) - throws Exception; + ConfigInfo4Beta queryBeta(String dataId, String groupName, String namespaceId) throws NacosException; /** * Clone configurations within the same namespace. * - * @param namespaceId Namespace ID (optional, defaults to "public"). - * @param configBeansList List of configurations to clone (required). - * @param srcUser Source user (optional). - * @param policy Conflict resolution policy (required). + * @param namespaceId Namespace ID (optional, defaults to "public"). + * @param configBeansList List of configurations to clone (required). + * @param srcUser Source user (optional). + * @param policy Conflict resolution policy (required). * @return A map containing the clone result (e.g., success count, unrecognized data). * @throws NacosException If the clone operation fails. */ - Map cloneConfig(String namespaceId, List configBeansList, String srcUser, SameConfigPolicy policy) - throws Exception; + Map cloneConfig(String namespaceId, List configBeansList, + String srcUser, SameConfigPolicy policy) throws NacosException; /** - * Query the list of configuration history. + * Query the list of configuration history by dataId, groupName, namespaceId, pageNo, and pageSize. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). @@ -307,45 +277,45 @@ public interface ConfigMaintainerService { * @param pageNo Page number (required). * @param pageSize Page size (required, max 500). * @return A paginated list of configuration history. - * @throws NacosApiException If the query fails. + * @throws NacosException If the query fails. */ - Page listConfigHistory(String dataId, String groupName, String namespaceId, int pageNo, int pageSize) - throws Exception; + Page listConfigHistory(String dataId, String groupName, String namespaceId, int pageNo, + int pageSize) throws NacosException; /** - * Query detailed configuration history information. + * Query detailed configuration history information by dataId, groupName, namespaceId, and nid. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). * @param namespaceId Namespace ID (optional, defaults to "public"). * @param nid History record ID (required). * @return Detailed configuration history information. - * @throws NacosApiException If the history record does not exist or the query fails. + * @throws NacosException If the history record does not exist or the query fails. */ ConfigHistoryInfo getConfigHistoryInfo(String dataId, String groupName, String namespaceId, Long nid) - throws Exception; + throws NacosException; /** - * Query previous configuration history information. + * Query previous configuration history information by dataId, groupName, namespaceId, and id. * * @param dataId Configuration data ID (required). * @param groupName Configuration group name (required). * @param namespaceId Namespace ID (optional, defaults to "public"). * @param id Current history record ID (required). * @return Previous configuration history information. - * @throws NacosApiException If the previous history record does not exist or the query fails. + * @throws NacosException If the previous history record does not exist or the query fails. */ ConfigHistoryInfo getPreviousConfigHistoryInfo(String dataId, String groupName, String namespaceId, Long id) - throws Exception; + throws NacosException; /** * Query configurations list by namespace. * * @param namespaceId Namespace ID (required). * @return A list of configurations in the specified namespace. - * @throws NacosApiException If the namespace is invalid or the query fails. + * @throws NacosException If the namespace is invalid or the query fails. */ - List getConfigListByNamespace(String namespaceId) throws Exception; + List getConfigListByNamespace(String namespaceId) throws NacosException; /** * Get capacity information for a specific group or namespace. @@ -353,31 +323,32 @@ public interface ConfigMaintainerService { * @param groupName Group name (optional). * @param namespaceId Namespace ID (optional). * @return Capacity information. - * @throws NacosApiException If the query fails or parameters are invalid. + * @throws NacosException If the query fails or parameters are invalid. */ - Capacity getCapacityWithDefault(String groupName, String namespaceId) throws Exception; + Capacity getCapacityWithDefault(String groupName, String namespaceId) throws NacosException; /** * Insert or update capacity information. * - * @param groupName Group name (required). - * @param namespaceId Namespace ID (required). - * @param quota Quota value (required). - * @param maxSize Maximum size (required). - * @param maxAggrCount Maximum aggregation count (required). - * @param maxAggrSize Maximum aggregation size (required). + * @param groupName Group name (required). + * @param namespaceId Namespace ID (required). + * @param quota Quota value (required). + * @param maxSize Maximum size (required). + * @param maxAggrCount Maximum aggregation count (required). + * @param maxAggrSize Maximum aggregation size (required). * @return Whether the operation was successful. - * @throws NacosApiException If the operation fails. + * @throws NacosException If the operation fails. */ boolean insertOrUpdateCapacity(String groupName, String namespaceId, Integer quota, Integer maxSize, - Integer maxAggrCount, Integer maxAggrSize) throws Exception; + Integer maxAggrCount, Integer maxAggrSize) throws NacosException; /** * Manually trigger dump of local configuration files from the store. * * @return A success message or error details. + * @throws NacosException if the operation fails. */ - String updateLocalCacheFromStore() throws Exception; + String updateLocalCacheFromStore() throws NacosException; /** * Set the log level for a specific module. @@ -385,36 +356,31 @@ public interface ConfigMaintainerService { * @param logName Name of the log module (required). * @param logLevel Desired log level (required). * @return A success message or error details. + * @throws NacosException if the operation fails. */ - String setLogLevel(String logName, String logLevel) throws Exception; + String setLogLevel(String logName, String logLevel) throws NacosException; /** * Execute a SQL query on the embedded Derby database. * * @param sql SQL query to execute (required). * @return Query results or an error message. + * @throws NacosException if the operation fails. */ - Object derbyOps(String sql) throws Exception; + Object derbyOps(String sql) throws NacosException; /** - * Import data into the embedded Derby database from a file. - * - * @param multipartFile File containing the data to import (required). - * @return A deferred result indicating success or failure. - */ - DeferredResult importDerby(MultipartFile multipartFile) throws Exception; - - /** - * Get all subscribed client configurations by IP. + * Get the status of all subscriptions for a specific IP. * * @param ip Client IP address (required). - * @param all Whether to retrieve all configurations (optional, default is false). + * @param all Whether to include all subscriptions (optional, defaults to false). * @param namespaceId Namespace ID (optional). - * @param sampleTime Sampling time in seconds (optional, default is 1). - * @return Client subscription status. + * @param sampleTime Sample time (optional, defaults to 0). + * @return the subscription status. + * @throws NacosException if the operation fails. */ GroupkeyListenserStatus getAllSubClientConfigByIp(String ip, boolean all, String namespaceId, int sampleTime) - throws Exception; + throws NacosException; /** * Get client metrics for a specific IP. @@ -423,10 +389,11 @@ public interface ConfigMaintainerService { * @param dataId Configuration data ID (optional). * @param groupName Configuration group name (optional). * @param namespaceId Namespace ID (optional). - * @return Client metrics. - * @throws NacosException If the operation fails. + * @return a map containing the client metrics. + * @throws NacosException if the operation fails. */ - Map getClientMetrics(String ip, String dataId, String groupName, String namespaceId) throws Exception; + Map getClientMetrics(String ip, String dataId, String groupName, String namespaceId) + throws NacosException; /** * Get cluster-wide metrics for a specific IP. @@ -435,118 +402,129 @@ public interface ConfigMaintainerService { * @param dataId Configuration data ID (optional). * @param groupName Configuration group name (optional). * @param namespaceId Namespace ID (optional). - * @return Cluster-wide metrics. - * @throws NacosException If the operation fails. + * @return a map containing the cluster-wide metrics. + * @throws NacosException if the operation fails. */ Map getClusterMetrics(String ip, String dataId, String groupName, String namespaceId) - throws Exception; + throws NacosException; // ------------------------- Core Operations ------------------------- /** * Execute a Raft operation with the specified command, value, and group ID. * - * @param command the command to execute - * @param value the value associated with the command - * @param groupId the group ID for the operation - * @return the result of the Raft operation + * @param command the command to execute. + * @param value the value associated with the command. + * @param groupId the group ID for the operation. + * @return the result of the Raft operation. + * @throws NacosException if the operation fails. */ - String raftOps(String command, String value, String groupId) throws Exception; + String raftOps(String command, String value, String groupId) throws NacosException; /** * Retrieve the current health status of the ID generator. * - * @return a list of ID generator status objects + * @return a list of ID generator status objects. + * @throws NacosException if the operation fails. */ - List getIdsHealth() throws Exception; + List getIdsHealth() throws NacosException; /** * Update the log level for a specific logger. * - * @param logName the name of the logger to update - * @param logLevel the new log level to set + * @param logName the name of the logger to update. + * @param logLevel the new log level to set. + * @throws NacosException if the operation fails. */ - void updateLogLevel(String logName, String logLevel) throws Exception; + void updateLogLevel(String logName, String logLevel) throws NacosException; /** * Retrieve information about the current node. * - * @return the current node's information + * @return the current node's information. + * @throws NacosException if the operation fails. */ - Member getSelfNode() throws Exception; + Member getSelfNode() throws NacosException; /** * List cluster nodes based on the specified address and state. * - * @param address the address to filter nodes by - * @param state the state to filter nodes by - * @return a collection of matching nodes - * @throws NacosException if an error occurs during the operation + * @param address the address to filter nodes by. + * @param state the state to filter nodes by. + * @return a collection of matching nodes. + * @throws NacosException if an error occurs during the operation. */ - Collection listClusterNodes(String address, String state) throws Exception; + Collection listClusterNodes(String address, String state) throws NacosException; /** * Retrieve the health status of the current node. * - * @return the health status of the current node + * @return the health status of the current node. + * @throws NacosException if the operation fails. */ - String getSelfNodeHealth() throws Exception; + String getSelfNodeHealth() throws NacosException; /** * Update the list of cluster nodes. * - * @param nodes the list of nodes to update - * @return true if the operation was successful, false otherwise - * @throws NacosApiException if an error occurs during the operation + * @param nodes the list of nodes to update. + * @return true if the operation was successful, false otherwise. + * @throws NacosException if an error occurs during the operation. */ - Boolean updateClusterNodes(List nodes) throws Exception; + Boolean updateClusterNodes(List nodes) throws NacosException; /** * Update the lookup mode for the cluster. * - * @param type the type of lookup mode to set - * @return true if the operation was successful, false otherwise - * @throws NacosException if an error occurs during the operation + * @param type the type of lookup mode to set. + * @return true if the operation was successful, false otherwise. + * @throws NacosException if an error occurs during the operation. */ - Boolean updateLookupMode(String type) throws Exception; + Boolean updateLookupMode(String type) throws NacosException; /** * Retrieve the current client connections. * - * @return a map of current client connections + * @return a map of current client connections. + * @throws NacosException if the operation fails. */ - Map getCurrentClients() throws Exception; + Map getCurrentClients() throws NacosException; /** * Reload the number of SDK connections on the current server. * - * @param count the number of connections to reload - * @param redirectAddress the address to redirect connections to - * @return the result of the operation + * @param count the number of connections to reload. + * @param redirectAddress the address to redirect connections to. + * @return the result of the operation. + * @throws NacosException if the operation fails. */ - String reloadConnectionCount(Integer count, String redirectAddress) throws Exception; + String reloadConnectionCount(Integer count, String redirectAddress) throws NacosException; /** * Smartly reload the cluster based on the specified loader factor. * - * @param loaderFactorStr the loader factor string - * @return the result of the operation + * @param loaderFactorStr the loader factor string. + * @return the result of the operation. + * @throws NacosException if the operation fails. */ - String smartReloadCluster(String loaderFactorStr) throws Exception; + String smartReloadCluster(String loaderFactorStr) throws NacosException; /** * Reload a single client connection. * - * @param connectionId the ID of the connection to reload - * @param redirectAddress the address to redirect the connection to - * @return the result of the operation + * @param connectionId the ID of the connection to reload. + * @param redirectAddress the address to redirect the connection to. + * @return the result of the operation. + * @throws NacosException if the operation fails. */ - String reloadSingleClient(String connectionId, String redirectAddress) throws Exception; + String reloadSingleClient(String connectionId, String redirectAddress) throws NacosException; /** * Retrieve the current cluster loader metrics. * - * @return the loader metrics for the cluster + * @return the loader metrics for the cluster. + * @throws NacosException if the operation fails. */ - ServerLoaderMetrics getClusterLoaderMetrics() throws Exception; + ServerLoaderMetrics getClusterLoaderMetrics() throws NacosException; + } diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerService.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceImpl.java similarity index 83% rename from maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerService.java rename to maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceImpl.java index 219960aa09..a41325cb1d 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerService.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceImpl.java @@ -18,10 +18,7 @@ package com.alibaba.nacos.maintainer.client.config; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.model.v2.Result; -import com.alibaba.nacos.common.constant.HttpHeaderConsts; -import com.alibaba.nacos.common.http.Callback; import com.alibaba.nacos.common.http.HttpRestResult; -import com.alibaba.nacos.common.model.RestResult; import com.alibaba.nacos.common.utils.HttpMethod; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.maintainer.client.constants.Constants; @@ -46,45 +43,35 @@ import com.alibaba.nacos.maintainer.client.utils.ParamUtil; import com.fasterxml.jackson.core.type.TypeReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.context.request.async.DeferredResult; -import org.springframework.web.multipart.MultipartFile; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.stream.Collectors; /** * Configuration management. * * @author Nacos */ -public class NacosConfigMaintainerService implements ConfigMaintainerService { +public class NacosConfigMaintainerServiceImpl implements ConfigMaintainerService { - private static final Logger LOGGER = LoggerFactory.getLogger(NacosConfigMaintainerService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(NacosConfigMaintainerServiceImpl.class); private final ClientHttpProxy clientHttpProxy; - public NacosConfigMaintainerService(Properties properties) throws NacosException { + public NacosConfigMaintainerServiceImpl(Properties properties) throws NacosException { this.clientHttpProxy = new ClientHttpProxy(properties); } @Override - public ConfigAllInfo getConfig(String dataId, String groupName) throws Exception { + public ConfigAllInfo getConfig(String dataId, String groupName) throws NacosException { return getConfig(dataId, groupName, ParamUtil.getDefaultNamespaceId()); } @Override - public ConfigAllInfo getConfig(String dataId, String groupName, String namespaceId) throws Exception { + public ConfigAllInfo getConfig(String dataId, String groupName, String namespaceId) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -103,12 +90,12 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public boolean publishConfig(String dataId, String groupName, String content) throws Exception { + public boolean publishConfig(String dataId, String groupName, String content) throws NacosException { return publishConfig(dataId, groupName, ParamUtil.getDefaultNamespaceId(), content); } @Override - public boolean publishConfig(String dataId, String groupName, String namespaceId, String content) throws Exception { + public boolean publishConfig(String dataId, String groupName, String namespaceId, String content) throws NacosException { return publishConfig(dataId, groupName, namespaceId, content, null, null, null, null, null, null, null, null, null); } @@ -116,7 +103,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public boolean publishConfig(String dataId, String groupName, String namespaceId, String content, String tag, String appName, String srcUser, String configTags, String desc, String use, String effect, String type, - String schema) throws Exception { + String schema) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -144,17 +131,17 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public boolean deleteConfig(String dataId, String groupName) throws Exception { + public boolean deleteConfig(String dataId, String groupName) throws NacosException { return deleteConfig(dataId, groupName, ParamUtil.getDefaultNamespaceId(), null); } @Override - public boolean deleteConfig(String dataId, String groupName, String namespaceId) throws Exception { + public boolean deleteConfig(String dataId, String groupName, String namespaceId) throws NacosException { return deleteConfig(dataId, groupName, namespaceId, null); } @Override - public boolean deleteConfig(String dataId, String groupName, String namespaceId, String tag) throws Exception { + public boolean deleteConfig(String dataId, String groupName, String namespaceId, String tag) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -173,7 +160,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public boolean deleteConfigs(List ids) throws Exception { + public boolean deleteConfigs(List ids) throws NacosException { Map params = new HashMap<>(8); StringBuilder idStr = new StringBuilder(); for (Long id : ids) { @@ -196,13 +183,13 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName) throws Exception { + public ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName) throws NacosException { return getConfigAdvanceInfo(dataId, groupName, ParamUtil.getDefaultNamespaceId()); } @Override public ConfigAdvanceInfo getConfigAdvanceInfo(String dataId, String groupName, String namespaceId) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -222,7 +209,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public Page searchConfigByDetails(String dataId, String groupName, String namespaceId, - String configDetail, String search, int pageNo, int pageSize) throws Exception { + String configDetail, String search, int pageNo, int pageSize) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -245,13 +232,13 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public GroupkeyListenserStatus getListeners(String dataId, String groupName) throws Exception { + public GroupkeyListenserStatus getListeners(String dataId, String groupName) throws NacosException { return getListeners(dataId, groupName, ParamUtil.getDefaultNamespaceId(), 1); } @Override public GroupkeyListenserStatus getListeners(String dataId, String groupName, String namespaceId, int sampleTime) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -271,12 +258,12 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public boolean stopBeta(String dataId, String groupName) throws Exception { + public boolean stopBeta(String dataId, String groupName) throws NacosException { return stopBeta(dataId, groupName, ParamUtil.getDefaultNamespaceId()); } @Override - public boolean stopBeta(String dataId, String groupName, String namespaceId) throws Exception { + public boolean stopBeta(String dataId, String groupName, String namespaceId) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -294,12 +281,12 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public ConfigInfo4Beta queryBeta(String dataId, String groupName) throws Exception { + public ConfigInfo4Beta queryBeta(String dataId, String groupName) throws NacosException { return queryBeta(dataId, groupName, ParamUtil.getDefaultNamespaceId()); } @Override - public ConfigInfo4Beta queryBeta(String dataId, String groupName, String namespaceId) throws Exception { + public ConfigInfo4Beta queryBeta(String dataId, String groupName, String namespaceId) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -317,61 +304,9 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { return result.getData(); } - @Override - public Map importAndPublishConfig(String namespaceId, String srcUser, SameConfigPolicy policy, - MultipartFile multipartFile) throws Exception { - if (multipartFile == null) { - return new HashMap<>(8); - } - File file = convertToFile(multipartFile); - try { - Map params = new HashMap<>(8); - params.put("namespaceId", namespaceId); - params.put("srcUser", srcUser); - params.put("policy", policy.toString()); - - HttpRequest httpRequest = new HttpRequest.Builder() - .setHttpMethod(HttpMethod.POST) - .setPath(Constants.AdminApiPath.CONFIG_ADMIN_PATH + "/import") - .setParamValue(params) - .setFile(file) - .build(); - HttpRestResult httpRestResult = clientHttpProxy.executeSyncHttpRequest(httpRequest); - Result> result = JacksonUtils.toObj(httpRestResult.getData(), - new TypeReference>>() { - }); - return result.getData(); - } finally { - if (!file.delete()) { - LOGGER.warn("delete file failed: {}", file.getAbsolutePath()); - } - } - } - - @Override - public ResponseEntity exportConfig(String dataId, String groupName, String namespaceId, List ids) - throws Exception { - Map params = new HashMap<>(8); - params.put("dataId", dataId); - params.put("groupName", groupName); - params.put("namespaceId", namespaceId); - params.put("ids", ids.stream().map(String::valueOf).collect(Collectors.joining(","))); - - HttpRequest httpRequest = new HttpRequest.Builder() - .setHttpMethod(HttpMethod.GET) - .setPath(Constants.AdminApiPath.CONFIG_ADMIN_PATH + "/export") - .setParamValue(params) - .build(); - HttpRestResult httpRestResult = clientHttpProxy.executeSyncHttpRequest(httpRequest); - byte[] responseBody = httpRestResult.getData().getBytes(StandardCharsets.UTF_8); - return ResponseEntity.ok().header(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE) - .header(HttpHeaderConsts.CONTENT_DISPOSITION, "attachment; filename=\"config_export.zip\"") - .body(responseBody); - } - @Override public Map cloneConfig(String namespaceId, List configBeansList, - String srcUser, SameConfigPolicy policy) throws Exception { + String srcUser, SameConfigPolicy policy) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("srcUser", srcUser); @@ -392,7 +327,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public Page listConfigHistory(String dataId, String groupName, String namespaceId, int pageNo, - int pageSize) throws Exception { + int pageSize) throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -414,7 +349,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public ConfigHistoryInfo getConfigHistoryInfo(String dataId, String groupName, String namespaceId, Long nid) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -435,7 +370,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public ConfigHistoryInfo getPreviousConfigHistoryInfo(String dataId, String groupName, String namespaceId, Long id) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("dataId", dataId); params.put("groupName", groupName); @@ -455,7 +390,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public List getConfigListByNamespace(String namespaceId) throws Exception { + public List getConfigListByNamespace(String namespaceId) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); @@ -472,7 +407,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Capacity getCapacityWithDefault(String groupName, String namespaceId) throws Exception { + public Capacity getCapacityWithDefault(String groupName, String namespaceId) throws NacosException { Map params = new HashMap<>(8); params.put("groupName", groupName); params.put("namespaceId", namespaceId); @@ -491,7 +426,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public boolean insertOrUpdateCapacity(String groupName, String namespaceId, Integer quota, Integer maxSize, - Integer maxAggrCount, Integer maxAggrSize) throws Exception { + Integer maxAggrCount, Integer maxAggrSize) throws NacosException { Map params = new HashMap<>(8); params.put("groupName", groupName); params.put("namespaceId", namespaceId); @@ -513,7 +448,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String updateLocalCacheFromStore() throws Exception { + public String updateLocalCacheFromStore() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.POST) .setPath(Constants.AdminApiPath.CONFIG_OPS_ADMIN_PATH + "/localCache") @@ -526,7 +461,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String setLogLevel(String logName, String logLevel) throws Exception { + public String setLogLevel(String logName, String logLevel) throws NacosException { Map params = new HashMap<>(8); params.put("logName", logName); params.put("logLevel", logLevel); @@ -544,7 +479,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Object derbyOps(String sql) throws Exception { + public Object derbyOps(String sql) throws NacosException { Map params = new HashMap<>(8); params.put("sql", sql); @@ -560,40 +495,9 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { return result.getData(); } - @Override - public DeferredResult importDerby(MultipartFile multipartFile) throws Exception { - File file = convertToFile(multipartFile); - HttpRequest httpRequest = new HttpRequest.Builder() - .setHttpMethod(HttpMethod.POST) - .setPath(Constants.AdminApiPath.CONFIG_OPS_ADMIN_PATH + "/derby/import") - .setFile(file) - .build(); - DeferredResult deferredResult = new DeferredResult<>(); - Callback callback = new Callback() { - @Override - public void onReceive(RestResult result) { - String res = JacksonUtils.toObj(result.getData(), new TypeReference() { - }); - deferredResult.setResult(res); - } - - @Override - public void onError(Throwable throwable) { - deferredResult.setErrorResult(throwable); - } - - @Override - public void onCancel() { - // - } - }; - clientHttpProxy.executeAsyncHttpRequest(httpRequest, callback); - return deferredResult; - } - @Override public GroupkeyListenserStatus getAllSubClientConfigByIp(String ip, boolean all, String namespaceId, - int sampleTime) throws Exception { + int sampleTime) throws NacosException { Map params = new HashMap<>(8); params.put("ip", ip); params.put("all", String.valueOf(all)); @@ -614,7 +518,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public Map getClientMetrics(String ip, String dataId, String groupName, String namespaceId) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("ip", ip); params.put("dataId", dataId); @@ -635,7 +539,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { @Override public Map getClusterMetrics(String ip, String dataId, String groupName, String namespaceId) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("ip", ip); params.put("dataId", dataId); @@ -655,7 +559,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String raftOps(String command, String value, String groupId) throws Exception { + public String raftOps(String command, String value, String groupId) throws NacosException { Map params = new HashMap<>(8); params.put("command", command); params.put("value", value); @@ -674,7 +578,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public List getIdsHealth() throws Exception { + public List getIdsHealth() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_OPS_ADMIN_PATH + "/ids") @@ -687,7 +591,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public void updateLogLevel(String logName, String logLevel) throws Exception { + public void updateLogLevel(String logName, String logLevel) throws NacosException { Map params = new HashMap<>(8); params.put("logName", logName); params.put("logLevel", logLevel); @@ -701,7 +605,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Member getSelfNode() throws Exception { + public Member getSelfNode() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_CLUSTER_ADMIN_PATH + "/node/self") @@ -714,7 +618,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Collection listClusterNodes(String address, String state) throws Exception { + public Collection listClusterNodes(String address, String state) throws NacosException { Map params = new HashMap<>(8); params.put("address", address); params.put("state", state); @@ -732,7 +636,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String getSelfNodeHealth() throws Exception { + public String getSelfNodeHealth() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_CLUSTER_ADMIN_PATH + "/node/self/health") @@ -745,7 +649,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Boolean updateClusterNodes(List nodes) throws Exception { + public Boolean updateClusterNodes(List nodes) throws NacosException { Map params = new HashMap<>(8); params.put("nodes", JacksonUtils.toJson(nodes)); @@ -762,7 +666,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Boolean updateLookupMode(String type) throws Exception { + public Boolean updateLookupMode(String type) throws NacosException { Map params = new HashMap<>(8); params.put("type", type); @@ -779,7 +683,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public Map getCurrentClients() throws Exception { + public Map getCurrentClients() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_LOADER_ADMIN_PATH + "/current") @@ -792,7 +696,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String reloadConnectionCount(Integer count, String redirectAddress) throws Exception { + public String reloadConnectionCount(Integer count, String redirectAddress) throws NacosException { Map params = new HashMap<>(8); params.put("count", String.valueOf(count)); params.put("redirectAddress", redirectAddress); @@ -810,7 +714,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String smartReloadCluster(String loaderFactorStr) throws Exception { + public String smartReloadCluster(String loaderFactorStr) throws NacosException { Map params = new HashMap<>(8); params.put("loaderFactorStr", loaderFactorStr); @@ -827,7 +731,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public String reloadSingleClient(String connectionId, String redirectAddress) throws Exception { + public String reloadSingleClient(String connectionId, String redirectAddress) throws NacosException { Map params = new HashMap<>(8); params.put("connectionId", connectionId); params.put("redirectAddress", redirectAddress); @@ -845,7 +749,7 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { } @Override - public ServerLoaderMetrics getClusterLoaderMetrics() throws Exception { + public ServerLoaderMetrics getClusterLoaderMetrics() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_LOADER_ADMIN_PATH + "/cluster") @@ -856,16 +760,4 @@ public class NacosConfigMaintainerService implements ConfigMaintainerService { }); return result.getData(); } - - private File convertToFile(MultipartFile multipartFile) throws IOException { - File tempFile = File.createTempFile("config-", ".tmp"); - try (InputStream in = multipartFile.getInputStream(); FileOutputStream out = new FileOutputStream(tempFile)) { - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - } - } - return tempFile; - } } \ No newline at end of file diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/core/ServerLoaderMetrics.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/core/ServerLoaderMetrics.java index 0937763d07..3efcca322f 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/core/ServerLoaderMetrics.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/core/ServerLoaderMetrics.java @@ -19,6 +19,11 @@ package com.alibaba.nacos.maintainer.client.model.core; import java.util.HashMap; import java.util.Map; +/** + * ServerLoaderMetrics. + * + * @author Nacos + */ public class ServerLoaderMetrics { String address; diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/naming/SwitchDomain.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/naming/SwitchDomain.java index 93755af093..80213fba44 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/naming/SwitchDomain.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/model/naming/SwitchDomain.java @@ -17,7 +17,6 @@ package com.alibaba.nacos.maintainer.client.model.naming; import com.alibaba.nacos.common.utils.JacksonUtils; -import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; @@ -32,7 +31,6 @@ import java.util.concurrent.TimeUnit; * * @author nacos */ -@Component @SuppressWarnings("PMD") public class SwitchDomain implements Record, Cloneable { diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerService.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImpl.java similarity index 94% rename from maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerService.java rename to maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImpl.java index 67703ec0a5..5179d5bd20 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerService.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImpl.java @@ -45,22 +45,27 @@ import java.util.List; import java.util.Map; import java.util.Properties; -public class NacosNamingMaintainerService implements NamingMaintainerService { +/** + * NacosNamingMaintainerServiceImpl. + * + * @author Nacos + */ +public class NacosNamingMaintainerServiceImpl implements NamingMaintainerService { private final ClientHttpProxy clientHttpProxy; - public NacosNamingMaintainerService(Properties properties) throws NacosException { + public NacosNamingMaintainerServiceImpl(Properties properties) throws NacosException { this.clientHttpProxy = new ClientHttpProxy(properties); } @Override - public String createService(String serviceName) throws Exception { + public String createService(String serviceName) throws NacosException { return createService(ParamUtil.getDefaultNamespaceId(), ParamUtil.getDefaultGroupName(), serviceName, "", false, 0.0f, ""); } @Override public String createService(String namespaceId, String groupName, String serviceName, String metadata, - boolean ephemeral, float protectThreshold, String selector) throws Exception { + boolean ephemeral, float protectThreshold, String selector) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -83,7 +88,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String updateService(String namespaceId, String groupName, String serviceName, String metadata, - boolean ephemeral, float protectThreshold, String selector) throws Exception { + boolean ephemeral, float protectThreshold, String selector) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -106,7 +111,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String removeService(String namespaceId, String groupName, String serviceName) throws Exception { + public String removeService(String namespaceId, String groupName, String serviceName) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -125,7 +130,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public ServiceDetailInfo getServiceDetail(String namespaceId, String groupName, String serviceName) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -145,7 +150,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public Object listServices(String namespaceId, String groupName, String selector, int pageNo, int pageSize) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -163,7 +168,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public ObjectNode searchService(String namespaceId, String expr) throws Exception { + public ObjectNode searchService(String namespaceId, String expr) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("expr", expr); @@ -179,7 +184,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public Result getSubscribers(String namespaceId, String groupName, String serviceName, int pageNo, - int pageSize, boolean aggregation) throws Exception { + int pageSize, boolean aggregation) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -199,7 +204,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public List listSelectorTypes() throws Exception { + public List listSelectorTypes() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.NAMING_SERVICE_ADMIN_PATH + "/selector/types") @@ -209,7 +214,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public SwitchDomain getSwitches() throws Exception { + public SwitchDomain getSwitches() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.NAMING_OPS_ADMIN_PATH + "/switches") @@ -219,7 +224,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String updateSwitch(String entry, String value, boolean debug) throws Exception { + public String updateSwitch(String entry, String value, boolean debug) throws NacosException { Map params = new HashMap<>(8); params.put("entry", entry); params.put("value", value); @@ -236,7 +241,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public MetricsInfoVo getMetrics(boolean onlyStatus) throws Exception { + public MetricsInfoVo getMetrics(boolean onlyStatus) throws NacosException { Map params = new HashMap<>(8); params.put("onlyStatus", String.valueOf(onlyStatus)); @@ -250,7 +255,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String setLogLevel(String logName, String logLevel) throws Exception { + public String setLogLevel(String logName, String logLevel) throws NacosException { Map params = new HashMap<>(8); params.put("logName", logName); params.put("logLevel", logLevel); @@ -268,7 +273,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String registerInstance(String namespaceId, String groupName, String serviceName, String clusterName, String ip, int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -295,7 +300,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String deregisterInstance(String namespaceId, String groupName, String serviceName, String clusterName, String ip, int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -322,7 +327,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String updateInstance(String namespaceId, String groupName, String serviceName, String clusterName, String ip, int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -349,7 +354,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public InstanceMetadataBatchOperationVo batchUpdateInstanceMetadata(String namespaceId, String groupName, String serviceName, String instance, Map metadata, String consistencyType) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -370,7 +375,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public InstanceMetadataBatchOperationVo batchDeleteInstanceMetadata(String namespaceId, String groupName, String serviceName, String instance, Map metadata, String consistencyType) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -390,7 +395,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String partialUpdateInstance(String namespaceId, String serviceName, String clusterName, int ip, int port, - double weight, boolean enabled, String metadata) throws Exception { + double weight, boolean enabled, String metadata) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("serviceName", serviceName); @@ -413,7 +418,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public ServiceInfo listInstances(String namespaceId, String groupName, String serviceName, String clusterName, - String ip, int port, boolean healthyOnly) throws Exception { + String ip, int port, boolean healthyOnly) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -434,7 +439,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public InstanceDetailInfoVo getInstanceDetail(String namespaceId, String groupName, String serviceName, - String clusterName, String ip, int port) throws Exception { + String clusterName, String ip, int port) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -455,7 +460,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String updateInstanceHealthStatus(String namespaceId, String groupName, String serviceName, String clusterName, String metadata, boolean ephemeral, float protectThreshold, String selector) - throws Exception { + throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -478,7 +483,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public Map getHealthCheckers() throws Exception { + public Map getHealthCheckers() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.NAMING_HEALTH_ADMIN_PATH + "/checkers") @@ -489,7 +494,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public String updateCluster(String namespaceId, String groupName, String clusterName, Integer checkPort, - Boolean useInstancePort4Check, String healthChecker, Map metadata) throws Exception { + Boolean useInstancePort4Check, String healthChecker, Map metadata) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -510,7 +515,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public List getClientList() throws Exception { + public List getClientList() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.NAMING_CLIENT_ADMIN_PATH + "/list") @@ -520,7 +525,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public ObjectNode getClientDetail(String clientId) throws Exception { + public ObjectNode getClientDetail(String clientId) throws NacosException { Map params = new HashMap<>(8); params.put("clientId", clientId); @@ -534,7 +539,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public List getPublishedServiceList(String clientId) throws Exception { + public List getPublishedServiceList(String clientId) throws NacosException { Map params = new HashMap<>(8); params.put("clientId", clientId); @@ -548,7 +553,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public List getSubscribeServiceList(String clientId) throws Exception { + public List getSubscribeServiceList(String clientId) throws NacosException { Map params = new HashMap<>(8); params.put("clientId", clientId); @@ -563,7 +568,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public List getPublishedClientList(String namespaceId, String groupName, String serviceName, - boolean ephemeral, String ip, Integer port) throws Exception { + boolean ephemeral, String ip, Integer port) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -583,7 +588,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { @Override public List getSubscribeClientList(String namespaceId, String groupName, String serviceName, - boolean ephemeral, String ip, Integer port) throws Exception { + boolean ephemeral, String ip, Integer port) throws NacosException { Map params = new HashMap<>(8); params.put("namespaceId", namespaceId); params.put("groupName", groupName); @@ -602,7 +607,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public ObjectNode getResponsibleServerForClient(String ip, String port) throws Exception { + public ObjectNode getResponsibleServerForClient(String ip, String port) throws NacosException { Map params = new HashMap<>(8); params.put("ip", ip); params.put("port", port); @@ -617,7 +622,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String raftOps(String command, String value, String groupId) throws Exception { + public String raftOps(String command, String value, String groupId) throws NacosException { Map params = new HashMap<>(8); params.put("command", command); params.put("value", value); @@ -636,7 +641,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public List getIdsHealth() throws Exception { + public List getIdsHealth() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_OPS_ADMIN_PATH + "/ids") @@ -649,7 +654,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public void updateLogLevel(String logName, String logLevel) throws Exception { + public void updateLogLevel(String logName, String logLevel) throws NacosException { Map params = new HashMap<>(8); params.put("logName", logName); params.put("logLevel", logLevel); @@ -663,7 +668,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public Member getSelfNode() throws Exception { + public Member getSelfNode() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_CLUSTER_ADMIN_PATH + "/node/self") @@ -676,7 +681,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public Collection listClusterNodes(String address, String state) throws Exception { + public Collection listClusterNodes(String address, String state) throws NacosException { Map params = new HashMap<>(8); params.put("address", address); params.put("state", state); @@ -694,7 +699,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String getSelfNodeHealth() throws Exception { + public String getSelfNodeHealth() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_CLUSTER_ADMIN_PATH + "/node/self/health") @@ -707,7 +712,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public Boolean updateClusterNodes(List nodes) throws Exception { + public Boolean updateClusterNodes(List nodes) throws NacosException { Map params = new HashMap<>(8); params.put("nodes", JacksonUtils.toJson(nodes)); @@ -724,7 +729,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public Boolean updateLookupMode(String type) throws Exception { + public Boolean updateLookupMode(String type) throws NacosException { Map params = new HashMap<>(8); params.put("type", type); @@ -741,7 +746,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public Map getCurrentClients() throws Exception { + public Map getCurrentClients() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_LOADER_ADMIN_PATH + "/current") @@ -754,7 +759,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String reloadConnectionCount(Integer count, String redirectAddress) throws Exception { + public String reloadConnectionCount(Integer count, String redirectAddress) throws NacosException { Map params = new HashMap<>(8); params.put("count", String.valueOf(count)); params.put("redirectAddress", redirectAddress); @@ -772,7 +777,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String smartReloadCluster(String loaderFactorStr) throws Exception { + public String smartReloadCluster(String loaderFactorStr) throws NacosException { Map params = new HashMap<>(8); params.put("loaderFactorStr", loaderFactorStr); @@ -789,7 +794,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public String reloadSingleClient(String connectionId, String redirectAddress) throws Exception { + public String reloadSingleClient(String connectionId, String redirectAddress) throws NacosException { Map params = new HashMap<>(8); params.put("connectionId", connectionId); params.put("redirectAddress", redirectAddress); @@ -807,7 +812,7 @@ public class NacosNamingMaintainerService implements NamingMaintainerService { } @Override - public ServerLoaderMetrics getClusterLoaderMetrics() throws Exception { + public ServerLoaderMetrics getClusterLoaderMetrics() throws NacosException { HttpRequest httpRequest = new HttpRequest.Builder() .setHttpMethod(HttpMethod.GET) .setPath(Constants.AdminApiPath.CORE_LOADER_ADMIN_PATH + "/cluster") diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactory.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactory.java index 7ec99b327f..a3536c2ac6 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactory.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactory.java @@ -37,7 +37,7 @@ public class NamingMaintainerFactory { public static NamingMaintainerService createNamingMaintainerService(String serverList) throws NacosException { Properties properties = new Properties(); properties.setProperty("serverAddr", serverList); - return new NacosNamingMaintainerService(properties); + return new NacosNamingMaintainerServiceImpl(properties); } /** @@ -51,6 +51,6 @@ public class NamingMaintainerFactory { if (properties == null) { throw new NacosException(NacosException.INVALID_PARAM, "properties is null"); } - return new NacosNamingMaintainerService(properties); + return new NacosNamingMaintainerServiceImpl(properties); } } \ No newline at end of file diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerService.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerService.java index 2a51e5a4b2..78af40baac 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerService.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerService.java @@ -17,7 +17,6 @@ package com.alibaba.nacos.maintainer.client.naming; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.exception.api.NacosApiException; import com.alibaba.nacos.api.model.v2.Result; import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker; @@ -37,12 +36,13 @@ import java.util.List; import java.util.Map; /** - * Naming service maintenance interface, providing operations for managing services, instances, health checks, clusters, and clients. + * Nacos Naming module maintainer service. + * + * @author Nacos */ public interface NamingMaintainerService { // ------------------------- Service Operations ------------------------- - /** * Create a new service with the given service name. * @@ -50,7 +50,7 @@ public interface NamingMaintainerService { * @return the result of the operation * @throws NacosException if an error occurs */ - String createService(String serviceName) throws Exception; + String createService(String serviceName) throws NacosException; /** * Create a new service with detailed parameters. @@ -65,8 +65,8 @@ public interface NamingMaintainerService { * @return the result of the operation * @throws NacosException if an error occurs */ - String createService(String namespaceId, String groupName, String serviceName, String metadata, - boolean ephemeral, float protectThreshold, String selector) throws Exception; + String createService(String namespaceId, String groupName, String serviceName, String metadata, boolean ephemeral, + float protectThreshold, String selector) throws NacosException; /** * Update an existing service. @@ -79,10 +79,10 @@ public interface NamingMaintainerService { * @param protectThreshold the updated protect threshold * @param selector the updated selector * @return the result of the operation - * @throws Exception if an error occurs + * @throws NacosException if an error occurs */ - String updateService(String namespaceId, String groupName, String serviceName, String metadata, - boolean ephemeral, float protectThreshold, String selector) throws Exception; + String updateService(String namespaceId, String groupName, String serviceName, String metadata, boolean ephemeral, + float protectThreshold, String selector) throws NacosException; /** * Remove a service. @@ -93,7 +93,7 @@ public interface NamingMaintainerService { * @return the result of the operation * @throws NacosException if an error occurs */ - String removeService(String namespaceId, String groupName, String serviceName) throws Exception; + String removeService(String namespaceId, String groupName, String serviceName) throws NacosException; /** * Get detailed information of a service. @@ -104,7 +104,7 @@ public interface NamingMaintainerService { * @return the service detail information * @throws NacosException if an error occurs */ - ServiceDetailInfo getServiceDetail(String namespaceId, String groupName, String serviceName) throws Exception; + ServiceDetailInfo getServiceDetail(String namespaceId, String groupName, String serviceName) throws NacosException; /** * List services with pagination. @@ -115,9 +115,10 @@ public interface NamingMaintainerService { * @param pageNo the page number * @param pageSize the page size * @return the list of services - * @throws Exception if an error occurs + * @throws NacosException if an error occurs */ - Object listServices(String namespaceId, String groupName, String selector, int pageNo, int pageSize) throws Exception; + Object listServices(String namespaceId, String groupName, String selector, int pageNo, int pageSize) + throws NacosException; /** * Search service names by expression. @@ -127,7 +128,7 @@ public interface NamingMaintainerService { * @return the search result * @throws NacosException if an error occurs */ - ObjectNode searchService(String namespaceId, String expr) throws Exception; + ObjectNode searchService(String namespaceId, String expr) throws NacosException; /** * Get subscribers of a service with pagination. @@ -141,22 +142,24 @@ public interface NamingMaintainerService { * @return the list of subscribers * @throws NacosException if an error occurs */ - Result getSubscribers(String namespaceId, String groupName, String serviceName, - int pageNo, int pageSize, boolean aggregation) throws Exception; + Result getSubscribers(String namespaceId, String groupName, String serviceName, int pageNo, + int pageSize, boolean aggregation) throws NacosException; /** * List all selector types. * * @return the list of selector types + * @throws NacosException if an error occurs */ - List listSelectorTypes() throws Exception; + List listSelectorTypes() throws NacosException; /** * Get the current switch configuration. * * @return the switch domain + * @throws NacosException if an error occurs */ - SwitchDomain getSwitches() throws Exception; + SwitchDomain getSwitches() throws NacosException; /** * Update the switch configuration. @@ -165,17 +168,18 @@ public interface NamingMaintainerService { * @param value the new value * @param debug whether to enable debug mode * @return the result of the operation - * @throws Exception if an error occurs + * @throws NacosException if an error occurs */ - String updateSwitch(String entry, String value, boolean debug) throws Exception; + String updateSwitch(String entry, String value, boolean debug) throws NacosException; /** * Get system metrics. * * @param onlyStatus whether to return only status information * @return the metrics information + * @throws NacosException if an error occurs */ - MetricsInfoVo getMetrics(boolean onlyStatus) throws Exception; + MetricsInfoVo getMetrics(boolean onlyStatus) throws NacosException; /** * Set the log level. @@ -183,8 +187,9 @@ public interface NamingMaintainerService { * @param logName the name of the logger * @param logLevel the new log level * @return the result of the operation + * @throws NacosException if an error occurs */ - String setLogLevel(String logName, String logLevel) throws Exception; + String setLogLevel(String logName, String logLevel) throws NacosException; // ------------------------- Instance Operations ------------------------- @@ -207,7 +212,7 @@ public interface NamingMaintainerService { */ String registerInstance(String namespaceId, String groupName, String serviceName, String clusterName, String ip, int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) - throws Exception; + throws NacosException; /** * Deregister an instance. @@ -227,7 +232,8 @@ public interface NamingMaintainerService { * @throws NacosException if an error occurs */ String deregisterInstance(String namespaceId, String groupName, String serviceName, String clusterName, String ip, - int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) throws NacosException, Exception; + int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) + throws NacosException; /** * Update an existing instance. @@ -248,37 +254,39 @@ public interface NamingMaintainerService { */ String updateInstance(String namespaceId, String groupName, String serviceName, String clusterName, String ip, int port, String weight, boolean healthy, boolean enabled, String ephemeral, String metadata) - throws Exception; + throws NacosException; /** * Batch update instance metadata. * - * @param namespaceId the namespace ID - * @param groupName the group name - * @param serviceName the service name - * @param instance the instance information - * @param metadata the metadata to update - * @param consistencyType the consistency type + * @param namespaceId the namespace ID + * @param groupName the group name + * @param serviceName the service name + * @param instance the instance information + * @param metadata the metadata to update + * @param consistencyType the consistency type * @return the result of the operation * @throws NacosException if an error occurs */ - InstanceMetadataBatchOperationVo batchUpdateInstanceMetadata(String namespaceId, String groupName, String serviceName, String instance, - Map metadata, String consistencyType) throws Exception; + InstanceMetadataBatchOperationVo batchUpdateInstanceMetadata(String namespaceId, String groupName, + String serviceName, String instance, Map metadata, String consistencyType) + throws NacosException; /** * Batch delete instance metadata. * - * @param namespaceId the namespace ID - * @param groupName the group name - * @param serviceName the service name - * @param instance the instance information - * @param metadata the metadata to delete - * @param consistencyType the consistency type + * @param namespaceId the namespace ID + * @param groupName the group name + * @param serviceName the service name + * @param instance the instance information + * @param metadata the metadata to delete + * @param consistencyType the consistency type * @return the result of the operation * @throws NacosException if an error occurs */ - InstanceMetadataBatchOperationVo batchDeleteInstanceMetadata(String namespaceId, String groupName, String serviceName, String instance, - Map metadata, String consistencyType) throws Exception; + InstanceMetadataBatchOperationVo batchDeleteInstanceMetadata(String namespaceId, String groupName, + String serviceName, String instance, Map metadata, String consistencyType) + throws NacosException; /** * Partially update an instance. @@ -295,7 +303,7 @@ public interface NamingMaintainerService { * @throws NacosException if an error occurs */ String partialUpdateInstance(String namespaceId, String serviceName, String clusterName, int ip, int port, - double weight, boolean enabled, String metadata) throws Exception; + double weight, boolean enabled, String metadata) throws NacosException; /** * List instances of a service. @@ -304,14 +312,14 @@ public interface NamingMaintainerService { * @param groupName the group name * @param serviceName the service name * @param clusterName the cluster name - * @param ip the IP address of the instance - * @param port the port of the instance + * @param ip the IP address of the instance (optional) + * @param port the port of the instance (optional) * @param healthyOnly whether to list only healthy instances * @return the list of instances * @throws NacosException if an error occurs */ - ServiceInfo listInstances(String namespaceId, String groupName, String serviceName, String clusterName, - String ip, int port, boolean healthyOnly) throws Exception; + ServiceInfo listInstances(String namespaceId, String groupName, String serviceName, String clusterName, String ip, + int port, boolean healthyOnly) throws NacosException; /** * Get detailed information of an instance. @@ -325,8 +333,8 @@ public interface NamingMaintainerService { * @return the instance detail information * @throws NacosException if an error occurs */ - InstanceDetailInfoVo getInstanceDetail(String namespaceId, String groupName, String serviceName, - String clusterName, String ip, int port) throws Exception; + InstanceDetailInfoVo getInstanceDetail(String namespaceId, String groupName, String serviceName, String clusterName, + String ip, int port) throws NacosException; // ------------------------- Health Check Operations ------------------------- @@ -344,33 +352,34 @@ public interface NamingMaintainerService { * @return the result of the operation * @throws NacosException if an error occurs */ - String updateInstanceHealthStatus(String namespaceId, String groupName, String serviceName, String clusterName, String metadata, - boolean ephemeral, float protectThreshold, String selector) throws Exception; + String updateInstanceHealthStatus(String namespaceId, String groupName, String serviceName, String clusterName, + String metadata, boolean ephemeral, float protectThreshold, String selector) throws NacosException; /** * Get all health checkers. * - * @return the map of health checkers + * @return a map of health checkers + * @throws NacosException if an error occurs */ - Map getHealthCheckers() throws Exception; + Map getHealthCheckers() throws NacosException; // ------------------------- Cluster Operations ------------------------- /** * Update cluster configuration. * - * @param namespaceId the namespace ID - * @param groupName the group name - * @param clusterName the cluster name - * @param checkPort the health check port - * @param useInstancePort4Check whether to use instance port for health check - * @param healthChecker the health checker configuration - * @param metadata the metadata of the cluster + * @param namespaceId the namespace ID + * @param groupName the group name + * @param clusterName the cluster name + * @param checkPort the health check port + * @param useInstancePort4Check whether to use the instance port for health check + * @param healthChecker the health checker configuration + * @param metadata the metadata of the cluster * @return the result of the operation - * @throws Exception if an error occurs + * @throws NacosException if an error occurs */ String updateCluster(String namespaceId, String groupName, String clusterName, Integer checkPort, - Boolean useInstancePort4Check, String healthChecker, Map metadata) throws Exception; + Boolean useInstancePort4Check, String healthChecker, Map metadata) throws NacosException; // ------------------------- Client Operations ------------------------- @@ -378,8 +387,9 @@ public interface NamingMaintainerService { * Get the list of all clients. * * @return the list of client IDs + * @throws NacosException if an error occurs */ - List getClientList() throws Exception; + List getClientList() throws NacosException; /** * Get detailed information of a client. @@ -388,7 +398,7 @@ public interface NamingMaintainerService { * @return the client detail information * @throws NacosException if an error occurs */ - ObjectNode getClientDetail(String clientId) throws Exception; + ObjectNode getClientDetail(String clientId) throws NacosException; /** * Get the list of services published by a client. @@ -397,7 +407,7 @@ public interface NamingMaintainerService { * @return the list of published services * @throws NacosException if an error occurs */ - List getPublishedServiceList(String clientId) throws Exception; + List getPublishedServiceList(String clientId) throws NacosException; /** * Get the list of services subscribed by a client. @@ -406,7 +416,7 @@ public interface NamingMaintainerService { * @return the list of subscribed services * @throws NacosException if an error occurs */ - List getSubscribeServiceList(String clientId) throws Exception; + List getSubscribeServiceList(String clientId) throws NacosException; /** * Get the list of clients that published a specific service. @@ -420,8 +430,8 @@ public interface NamingMaintainerService { * @return the list of clients * @throws NacosException if an error occurs */ - List getPublishedClientList(String namespaceId, String groupName, - String serviceName, boolean ephemeral, String ip, Integer port) throws Exception; + List getPublishedClientList(String namespaceId, String groupName, String serviceName, boolean ephemeral, + String ip, Integer port) throws NacosException; /** * Get the list of clients that subscribed to a specific service. @@ -435,8 +445,8 @@ public interface NamingMaintainerService { * @return the list of clients * @throws NacosException if an error occurs */ - List getSubscribeClientList(String namespaceId, String groupName, - String serviceName, boolean ephemeral, String ip, Integer port) throws Exception; + List getSubscribeClientList(String namespaceId, String groupName, String serviceName, boolean ephemeral, + String ip, Integer port) throws NacosException; /** * Get the responsible server for a client based on its IP and port. @@ -444,115 +454,126 @@ public interface NamingMaintainerService { * @param ip the IP address of the client * @param port the port of the client * @return the responsible server information + * @throws NacosException if an error occurs */ - ObjectNode getResponsibleServerForClient(String ip, String port) throws Exception; + ObjectNode getResponsibleServerForClient(String ip, String port) throws NacosException; // ------------------------- Core Operations ------------------------- /** * Execute a Raft operation with the specified command, value, and group ID. * - * @param command the command to execute - * @param value the value associated with the command - * @param groupId the group ID for the operation - * @return the result of the Raft operation + * @param command the command to execute. + * @param value the value associated with the command. + * @param groupId the group ID for the operation. + * @return the result of the Raft operation. + * @throws NacosException if the operation fails. */ - String raftOps(String command, String value, String groupId) throws Exception; + String raftOps(String command, String value, String groupId) throws NacosException; /** * Retrieve the current health status of the ID generator. * - * @return a list of ID generator status objects + * @return a list of ID generator status objects. + * @throws NacosException if the operation fails. */ - List getIdsHealth() throws Exception; + List getIdsHealth() throws NacosException; /** * Update the log level for a specific logger. * - * @param logName the name of the logger to update - * @param logLevel the new log level to set + * @param logName the name of the logger to update. + * @param logLevel the new log level to set. + * @throws NacosException if the operation fails. */ - void updateLogLevel(String logName, String logLevel) throws Exception; + void updateLogLevel(String logName, String logLevel) throws NacosException; /** * Retrieve information about the current node. * - * @return the current node's information + * @return the current node's information. + * @throws NacosException if the operation fails. */ - Member getSelfNode() throws Exception; + Member getSelfNode() throws NacosException; /** * List cluster nodes based on the specified address and state. * - * @param address the address to filter nodes by - * @param state the state to filter nodes by - * @return a collection of matching nodes - * @throws NacosException if an error occurs during the operation + * @param address the address to filter nodes by. + * @param state the state to filter nodes by. + * @return a collection of matching nodes. + * @throws NacosException if an error occurs during the operation. */ - Collection listClusterNodes(String address, String state) throws NacosException, Exception; + Collection listClusterNodes(String address, String state) throws NacosException; /** * Retrieve the health status of the current node. * - * @return the health status of the current node + * @return the health status of the current node. + * @throws NacosException if the operation fails. */ - String getSelfNodeHealth() throws Exception; + String getSelfNodeHealth() throws NacosException; /** * Update the list of cluster nodes. * - * @param nodes the list of nodes to update - * @return true if the operation was successful, false otherwise - * @throws NacosApiException if an error occurs during the operation + * @param nodes the list of nodes to update. + * @return true if the operation was successful, false otherwise. + * @throws NacosException if an error occurs during the operation. */ - Boolean updateClusterNodes(List nodes) throws NacosException, Exception; + Boolean updateClusterNodes(List nodes) throws NacosException; /** * Update the lookup mode for the cluster. * - * @param type the type of lookup mode to set - * @return true if the operation was successful, false otherwise - * @throws NacosException if an error occurs during the operation + * @param type the type of lookup mode to set. + * @return true if the operation was successful, false otherwise. + * @throws NacosException if an error occurs during the operation. */ - Boolean updateLookupMode(String type) throws NacosException, Exception; + Boolean updateLookupMode(String type) throws NacosException; /** * Retrieve the current client connections. * - * @return a map of current client connections + * @return a map of current client connections. + * @throws NacosException if the operation fails. */ - Map getCurrentClients() throws Exception; + Map getCurrentClients() throws NacosException; /** * Reload the number of SDK connections on the current server. * - * @param count the number of connections to reload - * @param redirectAddress the address to redirect connections to - * @return the result of the operation + * @param count the number of connections to reload. + * @param redirectAddress the address to redirect connections to. + * @return the result of the operation. + * @throws NacosException if the operation fails. */ - String reloadConnectionCount(Integer count, String redirectAddress) throws Exception; + String reloadConnectionCount(Integer count, String redirectAddress) throws NacosException; /** * Smartly reload the cluster based on the specified loader factor. * - * @param loaderFactorStr the loader factor string - * @return the result of the operation + * @param loaderFactorStr the loader factor string. + * @return the result of the operation. + * @throws NacosException if the operation fails. */ - String smartReloadCluster(String loaderFactorStr) throws Exception; + String smartReloadCluster(String loaderFactorStr) throws NacosException; /** * Reload a single client connection. * - * @param connectionId the ID of the connection to reload - * @param redirectAddress the address to redirect the connection to - * @return the result of the operation + * @param connectionId the ID of the connection to reload. + * @param redirectAddress the address to redirect the connection to. + * @return the result of the operation. + * @throws NacosException if the operation fails. */ - String reloadSingleClient(String connectionId, String redirectAddress) throws Exception; + String reloadSingleClient(String connectionId, String redirectAddress) throws NacosException; /** * Retrieve the current cluster loader metrics. * - * @return the loader metrics for the cluster + * @return the loader metrics for the cluster. + * @throws NacosException if the operation fails. */ - ServerLoaderMetrics getClusterLoaderMetrics() throws Exception; + ServerLoaderMetrics getClusterLoaderMetrics() throws NacosException; } \ No newline at end of file diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxy.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxy.java index c4fb96bc6f..e7936da791 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxy.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxy.java @@ -76,9 +76,9 @@ public class ClientHttpProxy { * * @param request http request * @return http result - * @throws Exception exception + * @throws NacosException exception when request */ - public HttpRestResult executeSyncHttpRequest(HttpRequest request) throws Exception { + public HttpRestResult executeSyncHttpRequest(HttpRequest request) throws NacosException { long endTime = System.currentTimeMillis() + ParamUtil.getReadTimeout(); String currentServerAddr = serverListManager.getCurrentServer(); int retryCount = maxRetry; @@ -104,7 +104,7 @@ public class ClientHttpProxy { } } - throw new ConnectException( + throw new NacosException(NacosException.BAD_GATEWAY, "No available server after " + maxRetry + " retries, last tried server: " + currentServerAddr); } @@ -147,9 +147,9 @@ public class ClientHttpProxy { * Execute async http request. * * @param request http request - * @throws Exception exception + * @throws NacosException exception when request */ - public void executeAsyncHttpRequest(HttpRequest request, Callback callback) throws Exception { + public void executeAsyncHttpRequest(HttpRequest request, Callback callback) throws NacosException { long endTime = System.currentTimeMillis() + ParamUtil.getReadTimeout(); String currentServerAddr = serverListManager.getCurrentServer(); executeAsyncWithRetry(request, callback, endTime, currentServerAddr, maxRetry); diff --git a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/utils/ParamUtil.java b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/utils/ParamUtil.java index dc5db3bdf2..7da7e41d6d 100644 --- a/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/utils/ParamUtil.java +++ b/maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/utils/ParamUtil.java @@ -52,7 +52,6 @@ public class ParamUtil { private static final int DEFAULT_MAX_RETRY_TIMES = 3; static { - // Client identity information connectTimeout = initConnectionTimeout(); LOGGER.info("[settings] [maintainer-http-client] connect timeout:{}", connectTimeout); @@ -69,7 +68,7 @@ public class ParamUtil { return Integer.parseInt(connectTimeout); } catch (NumberFormatException e) { final String msg = "[http-client] invalid connect timeout:" + connectTimeout; - LOGGER.error("[settings] " + msg, e); + LOGGER.error("[settings] {}", msg, e); throw new IllegalArgumentException(msg, e); } } @@ -80,7 +79,7 @@ public class ParamUtil { return Integer.parseInt(readTimeout); } catch (NumberFormatException e) { final String msg = "[http-client] invalid read timeout:" + readTimeout; - LOGGER.error("[settings] " + msg, e); + LOGGER.error("[settings] {}", msg, e); throw new IllegalArgumentException(msg, e); } } @@ -91,7 +90,7 @@ public class ParamUtil { String.valueOf(DEFAULT_MAX_RETRY_TIMES))); } catch (NumberFormatException e) { final String msg = "[http-client] invalid max retry times:" + maxRetryTimes; - LOGGER.error("[settings] " + msg, e); + LOGGER.error("[settings] {}", msg, e); throw new IllegalArgumentException(msg, e); } } diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactoryTest.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactoryTest.java index a116246c53..076d442730 100644 --- a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactoryTest.java +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/ConfigMaintainerFactoryTest.java @@ -37,7 +37,7 @@ public class ConfigMaintainerFactoryTest { // Assert assertNotNull(service); - assertInstanceOf(NacosConfigMaintainerService.class, service); + assertInstanceOf(NacosConfigMaintainerServiceImpl.class, service); } @Test @@ -51,7 +51,7 @@ public class ConfigMaintainerFactoryTest { // Assert assertNotNull(service); - assertInstanceOf(NacosConfigMaintainerService.class, service); + assertInstanceOf(NacosConfigMaintainerServiceImpl.class, service); } @Test diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceTest.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceImplTest.java similarity index 82% rename from maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceTest.java rename to maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceImplTest.java index 001c879a25..541c7a9dd4 100644 --- a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceTest.java +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/config/NacosConfigMaintainerServiceImplTest.java @@ -41,15 +41,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.http.ResponseEntity; -import org.springframework.web.context.request.async.DeferredResult; -import org.springframework.web.multipart.MultipartFile; -import java.io.ByteArrayInputStream; import java.lang.reflect.Field; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -60,27 +55,26 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -class NacosConfigMaintainerServiceTest { +class NacosConfigMaintainerServiceImplTest { @Mock private ClientHttpProxy clientHttpProxy; - private NacosConfigMaintainerService nacosConfigMaintainerService; + private NacosConfigMaintainerServiceImpl nacosConfigMaintainerServiceImpl; @BeforeEach void setUp() throws Exception { MockitoAnnotations.openMocks(this); Properties properties = new Properties(); properties.setProperty("serverAddr", "localhost:8848"); - nacosConfigMaintainerService = new NacosConfigMaintainerService(properties); - Field clientHttpProxyField = NacosConfigMaintainerService.class.getDeclaredField("clientHttpProxy"); + nacosConfigMaintainerServiceImpl = new NacosConfigMaintainerServiceImpl(properties); + Field clientHttpProxyField = NacosConfigMaintainerServiceImpl.class.getDeclaredField("clientHttpProxy"); clientHttpProxyField.setAccessible(true); - clientHttpProxyField.set(nacosConfigMaintainerService, clientHttpProxy); + clientHttpProxyField.set(nacosConfigMaintainerServiceImpl, clientHttpProxy); } @Test @@ -100,7 +94,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - ConfigAllInfo result = nacosConfigMaintainerService.getConfig(dataId, groupName, namespaceId); + ConfigAllInfo result = nacosConfigMaintainerServiceImpl.getConfig(dataId, groupName, namespaceId); // Assert assertNotNull(result); @@ -124,7 +118,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - boolean result = nacosConfigMaintainerService.publishConfig(dataId, groupName, namespaceId, content); + boolean result = nacosConfigMaintainerServiceImpl.publishConfig(dataId, groupName, namespaceId, content); // Assert assertTrue(result); @@ -144,7 +138,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - boolean result = nacosConfigMaintainerService.deleteConfig(dataId, groupName, namespaceId); + boolean result = nacosConfigMaintainerServiceImpl.deleteConfig(dataId, groupName, namespaceId); // Assert assertTrue(result); @@ -169,7 +163,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - ConfigAdvanceInfo result = nacosConfigMaintainerService.getConfigAdvanceInfo(dataId, groupName, namespaceId); + ConfigAdvanceInfo result = nacosConfigMaintainerServiceImpl.getConfigAdvanceInfo(dataId, groupName, namespaceId); // Assert assertNotNull(result); @@ -199,7 +193,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - Page result = nacosConfigMaintainerService.searchConfigByDetails(dataId, groupName, namespaceId, + Page result = nacosConfigMaintainerServiceImpl.searchConfigByDetails(dataId, groupName, namespaceId, configDetail, search, pageNo, pageSize); // Assert @@ -228,7 +222,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - GroupkeyListenserStatus result = nacosConfigMaintainerService.getListeners(dataId, groupName, namespaceId, sampleTime); + GroupkeyListenserStatus result = nacosConfigMaintainerServiceImpl.getListeners(dataId, groupName, namespaceId, sampleTime); // Assert assertNotNull(result); @@ -250,7 +244,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - boolean result = nacosConfigMaintainerService.stopBeta(dataId, groupName, namespaceId); + boolean result = nacosConfigMaintainerServiceImpl.stopBeta(dataId, groupName, namespaceId); // Assert assertTrue(result); @@ -274,7 +268,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - ConfigInfo4Beta result = nacosConfigMaintainerService.queryBeta(dataId, groupName, namespaceId); + ConfigInfo4Beta result = nacosConfigMaintainerServiceImpl.queryBeta(dataId, groupName, namespaceId); // Assert assertNotNull(result); @@ -283,55 +277,6 @@ class NacosConfigMaintainerServiceTest { verify(clientHttpProxy, times(1)).executeSyncHttpRequest(any(HttpRequest.class)); } - @Test - void testImportAndPublishConfig() throws Exception { - // Arrange - final String namespaceId = "testNamespace"; - final String srcUser = "testUser"; - final SameConfigPolicy policy = SameConfigPolicy.ABORT; - MultipartFile multipartFile = mock(MultipartFile.class); - when(multipartFile.getInputStream()).thenReturn(new ByteArrayInputStream("testContent".getBytes())); - - Map expectedResult = new HashMap<>(); - expectedResult.put("success", true); - - HttpRestResult mockHttpRestResult = new HttpRestResult<>(); - mockHttpRestResult.setData(JacksonUtils.toJson(new Result<>(expectedResult))); - - when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); - - // Act - Map result = nacosConfigMaintainerService.importAndPublishConfig(namespaceId, srcUser, policy, multipartFile); - - // Assert - assertNotNull(result); - assertTrue((Boolean) result.get("success")); - verify(clientHttpProxy, times(1)).executeSyncHttpRequest(any(HttpRequest.class)); - } - - @Test - void testExportConfig() throws Exception { - // Arrange - String dataId = "testDataId"; - String groupName = "testGroup"; - String namespaceId = "testNamespace"; - List ids = Arrays.asList(1L, 2L, 3L); - - HttpRestResult mockHttpRestResult = new HttpRestResult<>(); - mockHttpRestResult.setData("testContent"); - - when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); - - // Act - ResponseEntity result = nacosConfigMaintainerService.exportConfig(dataId, groupName, namespaceId, ids); - - // Assert - assertNotNull(result); - assertNotNull(result.getBody()); - assertEquals("testContent", new String(result.getBody())); - verify(clientHttpProxy, times(1)).executeSyncHttpRequest(any(HttpRequest.class)); - } - @Test void testCloneConfig() throws Exception { // Arrange @@ -349,7 +294,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any(HttpRequest.class))).thenReturn(mockHttpRestResult); // Act - Map result = nacosConfigMaintainerService.cloneConfig(namespaceId, configBeansList, srcUser, policy); + Map result = nacosConfigMaintainerServiceImpl.cloneConfig(namespaceId, configBeansList, srcUser, policy); // Assert assertNotNull(result); @@ -373,7 +318,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Page result = nacosConfigMaintainerService.listConfigHistory(dataId, groupName, namespaceId, pageNo, pageSize); + Page result = nacosConfigMaintainerServiceImpl.listConfigHistory(dataId, groupName, namespaceId, pageNo, pageSize); // Assert assertNotNull(result); @@ -397,7 +342,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - ConfigHistoryInfo result = nacosConfigMaintainerService.getConfigHistoryInfo(dataId, groupName, namespaceId, nid); + ConfigHistoryInfo result = nacosConfigMaintainerServiceImpl.getConfigHistoryInfo(dataId, groupName, namespaceId, nid); // Assert assertNotNull(result); @@ -421,7 +366,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - ConfigHistoryInfo result = nacosConfigMaintainerService.getPreviousConfigHistoryInfo(dataId, groupName, namespaceId, id); + ConfigHistoryInfo result = nacosConfigMaintainerServiceImpl.getPreviousConfigHistoryInfo(dataId, groupName, namespaceId, id); // Assert assertNotNull(result); @@ -440,7 +385,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - List result = nacosConfigMaintainerService.getConfigListByNamespace(namespaceId); + List result = nacosConfigMaintainerServiceImpl.getConfigListByNamespace(namespaceId); // Assert assertNotNull(result); @@ -460,7 +405,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Capacity result = nacosConfigMaintainerService.getCapacityWithDefault(groupName, namespaceId); + Capacity result = nacosConfigMaintainerServiceImpl.getCapacityWithDefault(groupName, namespaceId); // Assert assertNotNull(result); @@ -483,7 +428,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - boolean result = nacosConfigMaintainerService.insertOrUpdateCapacity(groupName, namespaceId, quota, maxSize, maxAggrCount, maxAggrSize); + boolean result = nacosConfigMaintainerServiceImpl.insertOrUpdateCapacity(groupName, namespaceId, quota, maxSize, maxAggrCount, maxAggrSize); // Assert assertTrue(result); @@ -499,7 +444,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.updateLocalCacheFromStore(); + String result = nacosConfigMaintainerServiceImpl.updateLocalCacheFromStore(); // Assert assertEquals("success", result); @@ -518,7 +463,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.setLogLevel(logName, logLevel); + String result = nacosConfigMaintainerServiceImpl.setLogLevel(logName, logLevel); // Assert assertEquals("success", result); @@ -536,26 +481,13 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Object result = nacosConfigMaintainerService.derbyOps(sql); + Object result = nacosConfigMaintainerServiceImpl.derbyOps(sql); // Assert assertEquals("success", result); verify(clientHttpProxy, times(1)).executeSyncHttpRequest(any()); } - @Test - void testImportDerby() throws Exception { - // Arrange - MultipartFile multipartFile = mock(MultipartFile.class); - when(multipartFile.getInputStream()).thenReturn(new ByteArrayInputStream("testContent".getBytes())); - - // Act - DeferredResult result = nacosConfigMaintainerService.importDerby(multipartFile); - - // Assert - verify(clientHttpProxy, times(1)).executeAsyncHttpRequest(any(), any()); - } - @Test void testGetAllSubClientConfigByIp() throws Exception { // Arrange @@ -571,7 +503,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - GroupkeyListenserStatus result = nacosConfigMaintainerService.getAllSubClientConfigByIp(ip, all, namespaceId, sampleTime); + GroupkeyListenserStatus result = nacosConfigMaintainerServiceImpl.getAllSubClientConfigByIp(ip, all, namespaceId, sampleTime); // Assert assertNotNull(result); @@ -593,7 +525,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Map result = nacosConfigMaintainerService.getClientMetrics(ip, dataId, groupName, namespaceId); + Map result = nacosConfigMaintainerServiceImpl.getClientMetrics(ip, dataId, groupName, namespaceId); // Assert assertNotNull(result); @@ -615,7 +547,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Map result = nacosConfigMaintainerService.getClusterMetrics(ip, dataId, groupName, namespaceId); + Map result = nacosConfigMaintainerServiceImpl.getClusterMetrics(ip, dataId, groupName, namespaceId); // Assert assertNotNull(result); @@ -635,7 +567,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.raftOps(command, value, groupId); + String result = nacosConfigMaintainerServiceImpl.raftOps(command, value, groupId); // Assert assertEquals("success", result); @@ -652,7 +584,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - List result = nacosConfigMaintainerService.getIdsHealth(); + List result = nacosConfigMaintainerServiceImpl.getIdsHealth(); // Assert assertNotNull(result); @@ -666,7 +598,7 @@ class NacosConfigMaintainerServiceTest { String logLevel = "INFO"; // Act - nacosConfigMaintainerService.updateLogLevel(logName, logLevel); + nacosConfigMaintainerServiceImpl.updateLogLevel(logName, logLevel); // Assert verify(clientHttpProxy, times(1)).executeSyncHttpRequest(any()); @@ -682,7 +614,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Member result = nacosConfigMaintainerService.getSelfNode(); + Member result = nacosConfigMaintainerServiceImpl.getSelfNode(); // Assert assertNotNull(result); @@ -702,7 +634,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Collection result = nacosConfigMaintainerService.listClusterNodes(address, state); + Collection result = nacosConfigMaintainerServiceImpl.listClusterNodes(address, state); // Assert assertNotNull(result); @@ -719,7 +651,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.getSelfNodeHealth(); + String result = nacosConfigMaintainerServiceImpl.getSelfNodeHealth(); // Assert assertEquals(expectedHealth, result); @@ -736,7 +668,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Boolean result = nacosConfigMaintainerService.updateClusterNodes(nodes); + Boolean result = nacosConfigMaintainerServiceImpl.updateClusterNodes(nodes); // Assert assertTrue(result); @@ -753,7 +685,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Boolean result = nacosConfigMaintainerService.updateLookupMode(type); + Boolean result = nacosConfigMaintainerServiceImpl.updateLookupMode(type); // Assert assertTrue(result); @@ -770,7 +702,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - Map result = nacosConfigMaintainerService.getCurrentClients(); + Map result = nacosConfigMaintainerServiceImpl.getCurrentClients(); // Assert assertNotNull(result); @@ -789,7 +721,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.reloadConnectionCount(count, redirectAddress); + String result = nacosConfigMaintainerServiceImpl.reloadConnectionCount(count, redirectAddress); // Assert assertEquals("success", result); @@ -807,7 +739,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.smartReloadCluster(loaderFactorStr); + String result = nacosConfigMaintainerServiceImpl.smartReloadCluster(loaderFactorStr); // Assert assertEquals("success", result); @@ -826,7 +758,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - String result = nacosConfigMaintainerService.reloadSingleClient(connectionId, redirectAddress); + String result = nacosConfigMaintainerServiceImpl.reloadSingleClient(connectionId, redirectAddress); // Assert assertEquals("success", result); @@ -843,7 +775,7 @@ class NacosConfigMaintainerServiceTest { when(clientHttpProxy.executeSyncHttpRequest(any())).thenReturn(mockHttpRestResult); // Act - ServerLoaderMetrics result = nacosConfigMaintainerService.getClusterLoaderMetrics(); + ServerLoaderMetrics result = nacosConfigMaintainerServiceImpl.getClusterLoaderMetrics(); // Assert assertNotNull(result); diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceTest.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImplTest.java similarity index 99% rename from maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceTest.java rename to maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImplTest.java index 9c0c837f37..9e7695f727 100644 --- a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceTest.java +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NacosNamingMaintainerServiceImplTest.java @@ -54,7 +54,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class NacosNamingMaintainerServiceTest { +public class NacosNamingMaintainerServiceImplTest { @Mock private ClientHttpProxy clientHttpProxy; @@ -66,8 +66,8 @@ public class NacosNamingMaintainerServiceTest { MockitoAnnotations.openMocks(this); Properties properties = new Properties(); properties.setProperty("serverAddr", "localhost:8848"); - nacosNamingMaintainerService = new NacosNamingMaintainerService(properties); - Field clientHttpProxyField = NacosNamingMaintainerService.class.getDeclaredField("clientHttpProxy"); + nacosNamingMaintainerService = new NacosNamingMaintainerServiceImpl(properties); + Field clientHttpProxyField = NacosNamingMaintainerServiceImpl.class.getDeclaredField("clientHttpProxy"); clientHttpProxyField.setAccessible(true); clientHttpProxyField.set(nacosNamingMaintainerService, clientHttpProxy); } diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactoryTest.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactoryTest.java index 5a7d427e26..e63f4e36d2 100644 --- a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactoryTest.java +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/naming/NamingMaintainerFactoryTest.java @@ -37,7 +37,7 @@ public class NamingMaintainerFactoryTest { // Assert assertNotNull(service); - assertInstanceOf(NacosNamingMaintainerService.class, service); + assertInstanceOf(NacosNamingMaintainerServiceImpl.class, service); } @Test @@ -51,7 +51,7 @@ public class NamingMaintainerFactoryTest { // Assert assertNotNull(service); - assertInstanceOf(NacosNamingMaintainerService.class, service); + assertInstanceOf(NacosNamingMaintainerServiceImpl.class, service); } @Test diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxyTest.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxyTest.java index 423afcac26..2441090965 100644 --- a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxyTest.java +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/ClientHttpProxyTest.java @@ -16,6 +16,7 @@ package com.alibaba.nacos.maintainer.client.remote; +import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.common.http.Callback; import com.alibaba.nacos.common.http.HttpRestResult; import com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate; @@ -138,7 +139,7 @@ public class ClientHttpProxyTest { HttpRequest request = new HttpRequest("GET", "/test", new HashMap<>(), new HashMap<>(), null); - Exception exception = assertThrows(ConnectException.class, () -> { + Exception exception = assertThrows(NacosException.class, () -> { clientHttpProxy.executeSyncHttpRequest(request); }); diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/mock/MockServerListProvider.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/mock/MockServerListProvider.java new file mode 100644 index 0000000000..c2bed4bede --- /dev/null +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/remote/mock/MockServerListProvider.java @@ -0,0 +1,102 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on 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. + */ + +package com.alibaba.nacos.maintainer.client.remote.mock; + +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.client.address.ServerListProvider; +import com.alibaba.nacos.client.env.NacosClientProperties; +import com.alibaba.nacos.common.http.client.NacosRestTemplate; + +import java.util.Collections; +import java.util.List; + +public class MockServerListProvider implements ServerListProvider { + + private NacosClientProperties properties; + + @Override + public void init(NacosClientProperties properties, NacosRestTemplate nacosRestTemplate) throws NacosException { + this.properties = properties; + nacosRestTemplate.getInterceptors(); + } + + @Override + public List getServerList() { + if (properties.containsKey("EmptyList")) { + return Collections.emptyList(); + } + return Collections.singletonList("mock-server-list"); + } + + @Override + public int getOrder() { + return Integer.MIN_VALUE; + } + + @Override + public boolean match(NacosClientProperties properties) { + return properties.containsKey("MockTest"); + } + + @Override + public void shutdown() throws NacosException { + } + + @Override + public String getServerName() { + if (isReturnMock()) { + return "MockServerName"; + } + return ServerListProvider.super.getServerName(); + } + + @Override + public String getNamespace() { + if (isReturnMock()) { + return "MockNamespace"; + } + return ServerListProvider.super.getNamespace(); + } + + @Override + public String getContextPath() { + if (isReturnMock()) { + return "MockContextPath"; + } + return ServerListProvider.super.getContextPath(); + } + + @Override + public boolean isFixed() { + if (isReturnMock()) { + return true; + } + return ServerListProvider.super.isFixed(); + } + + @Override + public String getAddressSource() { + if (isReturnMock()) { + return "MockAddressSource"; + } + return ServerListProvider.super.getAddressSource(); + } + + private boolean isReturnMock() { + return properties.getBoolean("ReturnMock", false); + } +} diff --git a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/utils/ParamUtilTest.java b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/utils/ParamUtilTest.java index 6a01e5d1fb..c7e395b1f1 100644 --- a/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/utils/ParamUtilTest.java +++ b/maintainer-client/src/test/java/com/alibaba/nacos/maintainer/client/utils/ParamUtilTest.java @@ -18,7 +18,6 @@ package com.alibaba.nacos.maintainer.client.utils; -import com.alibaba.nacos.api.PropertyKeyConst; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,18 +36,16 @@ class ParamUtilTest { @BeforeEach void before() { - defaultConnectTimeout = 1000; - defaultReadTimeout = 3000; + defaultConnectTimeout = ParamUtil.getConnectTimeout(); + defaultReadTimeout = ParamUtil.getReadTimeout(); } @AfterEach void after() { ParamUtil.setConnectTimeout(defaultConnectTimeout); ParamUtil.setReadTimeout(defaultReadTimeout); - System.clearProperty("NACOS.CONNECT.TIMEOUT"); - System.clearProperty("NACOS_READ_TIMEOUT"); - System.clearProperty("PER_TASK_CONFIG_SIZE"); - System.clearProperty(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL); + System.clearProperty("MAINTAINER.CLIENT.CONNECT.TIMEOUT"); + System.clearProperty("MAINTAINER.CLIENT.READ.TIMEOUT"); } @Test @@ -76,7 +73,7 @@ class ParamUtilTest { assertThrows(IllegalArgumentException.class, () -> { Method method = ParamUtil.class.getDeclaredMethod("initConnectionTimeout"); method.setAccessible(true); - System.setProperty("NACOS.CONNECT.TIMEOUT", "test"); + System.setProperty("MAINTAINER.CLIENT.CONNECT.TIMEOUT", "test"); try { method.invoke(null); } catch (InvocationTargetException e) { @@ -90,7 +87,7 @@ class ParamUtilTest { assertThrows(IllegalArgumentException.class, () -> { Method method = ParamUtil.class.getDeclaredMethod("initReadTimeout"); method.setAccessible(true); - System.setProperty("NACOS.READ.TIMEOUT", "test"); + System.setProperty("MAINTAINER.CLIENT.READ.TIMEOUT", "test"); try { method.invoke(null); } catch (InvocationTargetException e) { @@ -98,18 +95,4 @@ class ParamUtilTest { } }); } - - @Test - void testInitPerTaskConfigSizeWithException() throws Throwable { - assertThrows(IllegalArgumentException.class, () -> { - Method method = ParamUtil.class.getDeclaredMethod("initPerTaskConfigSize"); - method.setAccessible(true); - System.setProperty("PER_TASK_CONFIG_SIZE", "test"); - try { - method.invoke(null); - } catch (InvocationTargetException e) { - throw e.getCause(); - } - }); - } -} \ No newline at end of file +} diff --git a/maintainer-client/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider b/maintainer-client/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider new file mode 100644 index 0000000000..fe0bb86e79 --- /dev/null +++ b/maintainer-client/src/test/resources/META-INF/services/com.alibaba.nacos.client.address.ServerListProvider @@ -0,0 +1,18 @@ +# +# Copyright 1999-2024 Alibaba Group Holding Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on 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. +# +# + +com.alibaba.nacos.maintainer.client.remote.mock.MockServerListProvider \ No newline at end of file