For new codeStyle in nacos-api module (#3190)
This commit is contained in:
parent
51c0eb25ad
commit
c9bf5f2f70
12
api/pom.xml
12
api/pom.xml
@ -15,18 +15,18 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>nacos-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<name>nacos-api ${project.version}</name>
|
||||
<url>http://nacos.io</url>
|
||||
<build>
|
||||
@ -41,11 +41,11 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
@ -13,27 +13,28 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
import java.util.Properties;
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Nacos Factory
|
||||
* Nacos Factory.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class NacosFactory {
|
||||
|
||||
|
||||
/**
|
||||
* Create config service
|
||||
* Create config service.
|
||||
*
|
||||
* @param properties init param
|
||||
* @return config
|
||||
@ -42,9 +43,9 @@ public class NacosFactory {
|
||||
public static ConfigService createConfigService(Properties properties) throws NacosException {
|
||||
return ConfigFactory.createConfigService(properties);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create config service
|
||||
* Create config service.
|
||||
*
|
||||
* @param serverAddr server list
|
||||
* @return config
|
||||
@ -53,9 +54,9 @@ public class NacosFactory {
|
||||
public static ConfigService createConfigService(String serverAddr) throws NacosException {
|
||||
return ConfigFactory.createConfigService(serverAddr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create naming service
|
||||
* Create naming service.
|
||||
*
|
||||
* @param serverAddr server list
|
||||
* @return Naming
|
||||
@ -64,9 +65,9 @@ public class NacosFactory {
|
||||
public static NamingService createNamingService(String serverAddr) throws NacosException {
|
||||
return NamingFactory.createNamingService(serverAddr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create naming service
|
||||
* Create naming service.
|
||||
*
|
||||
* @param properties init param
|
||||
* @return Naming
|
||||
@ -75,22 +76,22 @@ public class NacosFactory {
|
||||
public static NamingService createNamingService(Properties properties) throws NacosException {
|
||||
return NamingFactory.createNamingService(properties);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create maintain service
|
||||
* Create maintain service.
|
||||
*
|
||||
* @param serverAddr
|
||||
* @param serverAddr server address
|
||||
* @return NamingMaintainService
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
public static NamingMaintainService createMaintainService(String serverAddr) throws NacosException {
|
||||
return NamingMaintainFactory.createMaintainService(serverAddr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create maintain service
|
||||
* Create maintain service.
|
||||
*
|
||||
* @param properties
|
||||
* @param properties server address
|
||||
* @return NamingMaintainService
|
||||
* @throws NacosException Exception
|
||||
*/
|
||||
|
@ -13,67 +13,68 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
/**
|
||||
* Property Key Const
|
||||
* Property Key Const.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class PropertyKeyConst {
|
||||
|
||||
public final static String IS_USE_CLOUD_NAMESPACE_PARSING = "isUseCloudNamespaceParsing";
|
||||
|
||||
public final static String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
|
||||
|
||||
public final static String ENDPOINT = "endpoint";
|
||||
|
||||
public final static String ENDPOINT_PORT = "endpointPort";
|
||||
|
||||
public final static String NAMESPACE = "namespace";
|
||||
|
||||
public final static String USERNAME = "username";
|
||||
|
||||
public final static String PASSWORD = "password";
|
||||
|
||||
public final static String ACCESS_KEY = "accessKey";
|
||||
|
||||
public final static String SECRET_KEY = "secretKey";
|
||||
|
||||
public final static String RAM_ROLE_NAME = "ramRoleName";
|
||||
|
||||
public final static String SERVER_ADDR = "serverAddr";
|
||||
|
||||
public final static String CONTEXT_PATH = "contextPath";
|
||||
|
||||
public final static String CLUSTER_NAME = "clusterName";
|
||||
|
||||
public final static String ENCODE = "encode";
|
||||
|
||||
public final static String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
public final static String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
public final static String MAX_RETRY = "maxRetry";
|
||||
|
||||
public final static String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
|
||||
public final static String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
|
||||
|
||||
public final static String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
||||
public final static String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||
|
||||
|
||||
public static final String IS_USE_CLOUD_NAMESPACE_PARSING = "isUseCloudNamespaceParsing";
|
||||
|
||||
public static final String IS_USE_ENDPOINT_PARSING_RULE = "isUseEndpointParsingRule";
|
||||
|
||||
public static final String ENDPOINT = "endpoint";
|
||||
|
||||
public static final String ENDPOINT_PORT = "endpointPort";
|
||||
|
||||
public static final String NAMESPACE = "namespace";
|
||||
|
||||
public static final String USERNAME = "username";
|
||||
|
||||
public static final String PASSWORD = "password";
|
||||
|
||||
public static final String ACCESS_KEY = "accessKey";
|
||||
|
||||
public static final String SECRET_KEY = "secretKey";
|
||||
|
||||
public static final String RAM_ROLE_NAME = "ramRoleName";
|
||||
|
||||
public static final String SERVER_ADDR = "serverAddr";
|
||||
|
||||
public static final String CONTEXT_PATH = "contextPath";
|
||||
|
||||
public static final String CLUSTER_NAME = "clusterName";
|
||||
|
||||
public static final String ENCODE = "encode";
|
||||
|
||||
public static final String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
public static final String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
public static final String MAX_RETRY = "maxRetry";
|
||||
|
||||
public static final String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
|
||||
public static final String NAMING_LOAD_CACHE_AT_START = "namingLoadCacheAtStart";
|
||||
|
||||
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";
|
||||
|
||||
public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";
|
||||
|
||||
/**
|
||||
* Get the key value of some variable value from the system property
|
||||
* Get the key value of some variable value from the system property.
|
||||
*/
|
||||
public static class SystemEnv {
|
||||
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_PORT = "ALIBABA_ALIWARE_ENDPOINT_PORT";
|
||||
|
||||
|
||||
public static final String ALIBABA_ALIWARE_NAMESPACE = "ALIBABA_ALIWARE_NAMESPACE";
|
||||
|
||||
|
||||
public static final String ALIBABA_ALIWARE_ENDPOINT_URL = "ALIBABA_ALIWARE_ENDPOINT_URL";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,38 +13,37 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Support for reading the value of the specified variable from the -D parameter
|
||||
* </P>
|
||||
* Properties that are preferred to which in {@link PropertyKeyConst}
|
||||
* Support for reading the value of the specified variable from the -D parameter.
|
||||
*
|
||||
* <p>Properties that are preferred to which in {@link PropertyKeyConst}
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-02-22 3:38 PM
|
||||
*/
|
||||
public interface SystemPropertyKeyConst {
|
||||
|
||||
|
||||
String NAMING_SERVER_PORT = "nacos.naming.exposed.port";
|
||||
|
||||
|
||||
String NAMING_WEB_CONTEXT = "nacos.naming.web.context";
|
||||
|
||||
|
||||
/**
|
||||
* In the cloud (Alibaba Cloud or other cloud vendors) environment,
|
||||
* whether to enable namespace resolution in the cloud environment.
|
||||
* In the cloud (Alibaba Cloud or other cloud vendors) environment, whether to enable namespace resolution in the
|
||||
* cloud environment.
|
||||
* <p>
|
||||
* The default is on.
|
||||
* </p>
|
||||
*/
|
||||
String IS_USE_CLOUD_NAMESPACE_PARSING = "nacos.use.cloud.namespace.parsing";
|
||||
|
||||
|
||||
/**
|
||||
* In the cloud environment, if the process level requires a globally uniform namespace,
|
||||
* it can be specified with the -D parameter.
|
||||
* In the cloud environment, if the process level requires a globally uniform namespace, it can be specified with
|
||||
* the -D parameter.
|
||||
*/
|
||||
String ANS_NAMESPACE = "ans.namespace";
|
||||
|
||||
|
||||
/**
|
||||
* It is also supported by the -D parameter.
|
||||
*/
|
||||
|
@ -13,12 +13,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation to inject {@link ConfigService} or {@link NamingService} instance into the target Bean.
|
||||
@ -33,12 +38,12 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosInjected {
|
||||
|
||||
|
||||
/**
|
||||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
|
||||
*
|
||||
* @return the default value is {@link NacosProperties}
|
||||
*/
|
||||
NacosProperties properties() default @NacosProperties;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,14 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for Nacos Properties
|
||||
* An annotation for Nacos Properties.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see PropertyKeyConst
|
||||
@ -30,263 +35,266 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosProperties {
|
||||
|
||||
|
||||
/**
|
||||
* The prefix of property name of Nacos
|
||||
* The prefix of property name of Nacos.
|
||||
*/
|
||||
String PREFIX = "nacos.";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "endpoint"
|
||||
* The property name of "endpoint".
|
||||
*/
|
||||
String ENDPOINT = "endpoint";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "namespace"
|
||||
* The property name of "namespace".
|
||||
*/
|
||||
String NAMESPACE = "namespace";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "access-key"
|
||||
* The property name of "access-key".
|
||||
*/
|
||||
String ACCESS_KEY = "access-key";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "secret-key"
|
||||
* The property name of "secret-key".
|
||||
*/
|
||||
String SECRET_KEY = "secret-key";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "server-addr"
|
||||
* The property name of "server-addr".
|
||||
*/
|
||||
String SERVER_ADDR = "server-addr";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "context-path"
|
||||
* The property name of "context-path".
|
||||
*/
|
||||
String CONTEXT_PATH = "context-path";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "cluster-name"
|
||||
* The property name of "cluster-name".
|
||||
*/
|
||||
String CLUSTER_NAME = "cluster-name";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "encode"
|
||||
* The property name of "encode".
|
||||
*/
|
||||
String ENCODE = "encode";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "long-poll.timeout"
|
||||
* The property name of "long-poll.timeout".
|
||||
*/
|
||||
String CONFIG_LONG_POLL_TIMEOUT = "configLongPollTimeout";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "config.retry.time"
|
||||
* The property name of "config.retry.time".
|
||||
*/
|
||||
String CONFIG_RETRY_TIME = "configRetryTime";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "maxRetry"
|
||||
* The property name of "maxRetry".
|
||||
*/
|
||||
String MAX_RETRY = "maxRetry";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "enableRemoteSyncConfig"
|
||||
* The property name of "enableRemoteSyncConfig".
|
||||
*/
|
||||
String ENABLE_REMOTE_SYNC_CONFIG = "enableRemoteSyncConfig";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "username"
|
||||
* The property name of "username".
|
||||
*/
|
||||
String USERNAME = "username";
|
||||
|
||||
|
||||
/**
|
||||
* The property name of "password"
|
||||
* The property name of "password".
|
||||
*/
|
||||
String PASSWORD = "password";
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code>.
|
||||
*/
|
||||
String ENDPOINT_PLACEHOLDER = "${" + PREFIX + ENDPOINT + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code>.
|
||||
*/
|
||||
String NAMESPACE_PLACEHOLDER = "${" + PREFIX + NAMESPACE + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code>.
|
||||
*/
|
||||
String ACCESS_KEY_PLACEHOLDER = "${" + PREFIX + ACCESS_KEY + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code>.
|
||||
*/
|
||||
String SECRET_KEY_PLACEHOLDER = "${" + PREFIX + SECRET_KEY + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code>.
|
||||
*/
|
||||
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is ${nacos.context-path:}"
|
||||
* The placeholder of endpoint, the value is ${nacos.context-path:}".
|
||||
*/
|
||||
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code>.
|
||||
*/
|
||||
String CLUSTER_NAME_PLACEHOLDER = "${" + PREFIX + CLUSTER_NAME + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code>
|
||||
* The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code>.
|
||||
*/
|
||||
String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#CONFIG_LONG_POLL_TIMEOUT configLongPollTimeout}, the value is <code>"${nacos.configLongPollTimeout:}"</code>
|
||||
* The placeholder of {@link NacosProperties#CONFIG_LONG_POLL_TIMEOUT configLongPollTimeout}, the value is
|
||||
* <code>"${nacos.configLongPollTimeout:}"</code>.
|
||||
*/
|
||||
String CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER = "${" + PREFIX + CONFIG_LONG_POLL_TIMEOUT + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#CONFIG_RETRY_TIME configRetryTime}, the value is <code>"${nacos.configRetryTime:}"</code>
|
||||
* The placeholder of {@link NacosProperties#CONFIG_RETRY_TIME configRetryTime}, the value is
|
||||
* <code>"${nacos.configRetryTime:}"</code>.
|
||||
*/
|
||||
String CONFIG_RETRY_TIME_PLACEHOLDER = "${" + PREFIX + CONFIG_RETRY_TIME + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#MAX_RETRY maxRetry}, the value is <code>"${nacos.maxRetry:}"</code>
|
||||
* The placeholder of {@link NacosProperties#MAX_RETRY maxRetry}, the value is <code>"${nacos.maxRetry:}"</code>.
|
||||
*/
|
||||
String MAX_RETRY_PLACEHOLDER = "${" + PREFIX + MAX_RETRY + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of {@link NacosProperties#ENABLE_REMOTE_SYNC_CONFIG enableRemoteSyncConfig}, the value is <code>"${nacos.enableRemoteSyncConfig:}"</code>
|
||||
* The placeholder of {@link NacosProperties#ENABLE_REMOTE_SYNC_CONFIG enableRemoteSyncConfig}, the value is
|
||||
* <code>"${nacos.enableRemoteSyncConfig:}"</code>.
|
||||
*/
|
||||
String ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER = "${" + PREFIX + ENABLE_REMOTE_SYNC_CONFIG + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.username:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.username:}"</code>.
|
||||
*/
|
||||
String USERNAME_PLACEHOLDER = "${" + PREFIX + USERNAME + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.password:}"</code>
|
||||
* The placeholder of endpoint, the value is <code>"${nacos.password:}"</code>.
|
||||
*/
|
||||
String PASSWORD_PLACEHOLDER = "${" + PREFIX + PASSWORD + ":}";
|
||||
|
||||
|
||||
/**
|
||||
* The property of "endpoint"
|
||||
* The property of "endpoint".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #ENDPOINT_PLACEHOLDER
|
||||
*/
|
||||
String endpoint() default ENDPOINT_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "namespace"
|
||||
* The property of "namespace".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #NAMESPACE_PLACEHOLDER
|
||||
*/
|
||||
String namespace() default NAMESPACE_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "access-key"
|
||||
* The property of "access-key".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #ACCESS_KEY_PLACEHOLDER
|
||||
*/
|
||||
String accessKey() default ACCESS_KEY_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "secret-key"
|
||||
* The property of "secret-key".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #SECRET_KEY_PLACEHOLDER
|
||||
*/
|
||||
String secretKey() default SECRET_KEY_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "server-addr"
|
||||
* The property of "server-addr".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #SERVER_ADDR_PLACEHOLDER
|
||||
*/
|
||||
String serverAddr() default SERVER_ADDR_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "context-path"
|
||||
* The property of "context-path".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONTEXT_PATH_PLACEHOLDER
|
||||
*/
|
||||
String contextPath() default CONTEXT_PATH_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "cluster-name"
|
||||
* The property of "cluster-name".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CLUSTER_NAME_PLACEHOLDER
|
||||
*/
|
||||
String clusterName() default CLUSTER_NAME_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "encode"
|
||||
* The property of "encode".
|
||||
*
|
||||
* @return "UTF-8" as default value
|
||||
* @see #ENCODE_PLACEHOLDER
|
||||
*/
|
||||
String encode() default ENCODE_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "configLongPollTimeout"
|
||||
* The property of "configLongPollTimeout".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER
|
||||
*/
|
||||
String configLongPollTimeout() default CONFIG_LONG_POLL_TIMEOUT_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "configRetryTime"
|
||||
* The property of "configRetryTime".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #CONFIG_RETRY_TIME_PLACEHOLDER
|
||||
*/
|
||||
String configRetryTime() default CONFIG_RETRY_TIME_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "maxRetry"
|
||||
* The property of "maxRetry".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #MAX_RETRY
|
||||
*/
|
||||
String maxRetry() default MAX_RETRY_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "enableRemoteSyncConfig"
|
||||
* The property of "enableRemoteSyncConfig".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #ENABLE_REMOTE_SYNC_CONFIG
|
||||
*/
|
||||
String enableRemoteSyncConfig() default ENABLE_REMOTE_SYNC_CONFIG_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "username"
|
||||
* The property of "username".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #USERNAME_PLACEHOLDER
|
||||
*/
|
||||
String username() default USERNAME_PLACEHOLDER;
|
||||
|
||||
|
||||
/**
|
||||
* The property of "password"
|
||||
* The property of "password".
|
||||
*
|
||||
* @return empty as default value
|
||||
* @see #PASSWORD_PLACEHOLDER
|
||||
*/
|
||||
String password() default PASSWORD_PLACEHOLDER;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,40 +13,45 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* CMDB entity.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class Entity {
|
||||
|
||||
|
||||
private String type;
|
||||
|
||||
private String name;
|
||||
|
||||
private Map<String, String> labels;
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
|
||||
public void setLabels(Map<String, String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
@ -13,38 +13,43 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB entity event.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class EntityEvent {
|
||||
|
||||
|
||||
private EntityEventType type;
|
||||
|
||||
private String entityName;
|
||||
|
||||
private String entityType;
|
||||
|
||||
|
||||
public EntityEventType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void setType(EntityEventType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
|
||||
public void setEntityName(String entityName) {
|
||||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
|
||||
public String getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
|
||||
public void setEntityType(String entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
@ -13,19 +13,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB entity event type.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public enum EntityEventType {
|
||||
|
||||
/**
|
||||
*
|
||||
* Add or update entity.
|
||||
*/
|
||||
ENTITY_ADD_OR_UPDATE,
|
||||
/**
|
||||
*
|
||||
* Remove entity.
|
||||
*/
|
||||
ENTITY_REMOVE
|
||||
}
|
||||
|
@ -13,40 +13,45 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* CMDB lable.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class Label {
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
private Set<String> values;
|
||||
|
||||
private String description;
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
public void setValues(Set<String> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
@ -13,19 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.pojo;
|
||||
|
||||
/**
|
||||
* CMDB preserverd entity type.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public enum PreservedEntityTypes {
|
||||
/**
|
||||
* Ip
|
||||
* Ip.
|
||||
*/
|
||||
ip,
|
||||
/**
|
||||
* Service
|
||||
* Service.
|
||||
*/
|
||||
service
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.cmdb.spi;
|
||||
|
||||
import com.alibaba.nacos.api.cmdb.pojo.Entity;
|
||||
@ -24,71 +25,71 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service to visit CMDB store
|
||||
* Service to visit CMDB store.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public interface CmdbService {
|
||||
|
||||
|
||||
/**
|
||||
* Get all label names stored in CMDB
|
||||
* Get all label names stored in CMDB.
|
||||
*
|
||||
* @return label name set
|
||||
*/
|
||||
Set<String> getLabelNames();
|
||||
|
||||
|
||||
/**
|
||||
* Get all possible entity types in CMDB
|
||||
* Get all possible entity types in CMDB.
|
||||
*
|
||||
* @return all entity types
|
||||
*/
|
||||
Set<String> getEntityTypes();
|
||||
|
||||
|
||||
/**
|
||||
* Get label info
|
||||
* Get label info.
|
||||
*
|
||||
* @param labelName label name
|
||||
* @return label info
|
||||
*/
|
||||
Label getLabel(String labelName);
|
||||
|
||||
|
||||
/**
|
||||
* Get label value of label name of ip
|
||||
* Get label value of label name of ip.
|
||||
*
|
||||
* @param entityName entity name
|
||||
* @param entityType entity type
|
||||
* @param labelName target label name
|
||||
* @param entityType entity type
|
||||
* @param labelName target label name
|
||||
* @return label value
|
||||
*/
|
||||
String getLabelValue(String entityName, String entityType, String labelName);
|
||||
|
||||
|
||||
/**
|
||||
* Get all label value of ip
|
||||
* Get all label value of ip.
|
||||
*
|
||||
* @param entityName entity name
|
||||
* @param entityType entity type
|
||||
* @param entityType entity type
|
||||
* @return all label values
|
||||
*/
|
||||
Map<String, String> getLabelValues(String entityName, String entityType);
|
||||
|
||||
|
||||
/**
|
||||
* Dump all entities in CMDB
|
||||
* Dump all entities in CMDB.
|
||||
*
|
||||
* @return all entities
|
||||
*/
|
||||
Map<String, Map<String, Entity>> getAllEntities();
|
||||
|
||||
|
||||
/**
|
||||
* get label change events
|
||||
* get label change events.
|
||||
*
|
||||
* @param timestamp start time of generated events
|
||||
* @return label events
|
||||
*/
|
||||
List<EntityEvent> getEntityEvents(long timestamp);
|
||||
|
||||
|
||||
/**
|
||||
* Get single entity
|
||||
* Get single entity.
|
||||
*
|
||||
* @param entityName name of entity
|
||||
* @param entityType type of entity
|
||||
|
@ -13,174 +13,179 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.common;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Constant
|
||||
* Constants.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
|
||||
public static final String CLIENT_VERSION = "3.0.0";
|
||||
|
||||
public static int DATA_IN_BODY_VERSION = 204;
|
||||
|
||||
|
||||
public static final int DATA_IN_BODY_VERSION = 204;
|
||||
|
||||
public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
|
||||
|
||||
|
||||
public static final String APPNAME = "AppName";
|
||||
|
||||
|
||||
public static final String UNKNOWN_APP = "UnknownApp";
|
||||
|
||||
|
||||
public static final String DEFAULT_DOMAINNAME = "commonconfig.config-host.taobao.com";
|
||||
|
||||
|
||||
public static final String DAILY_DOMAINNAME = "commonconfig.taobao.net";
|
||||
|
||||
|
||||
public static final String NULL = "";
|
||||
|
||||
|
||||
public static final String DATAID = "dataId";
|
||||
|
||||
|
||||
public static final String GROUP = "group";
|
||||
|
||||
|
||||
public static final String LAST_MODIFIED = "Last-Modified";
|
||||
|
||||
|
||||
public static final String ACCEPT_ENCODING = "Accept-Encoding";
|
||||
|
||||
|
||||
public static final String CONTENT_ENCODING = "Content-Encoding";
|
||||
|
||||
|
||||
public static final String PROBE_MODIFY_REQUEST = "Listening-Configs";
|
||||
|
||||
|
||||
public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
|
||||
|
||||
|
||||
public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
|
||||
|
||||
|
||||
public static final String USE_ZIP = "true";
|
||||
|
||||
|
||||
public static final String CONTENT_MD5 = "Content-MD5";
|
||||
|
||||
|
||||
public static final String CONFIG_VERSION = "Config-Version";
|
||||
|
||||
|
||||
public static final String CONFIG_TYPE = "Config-Type";
|
||||
|
||||
|
||||
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||
|
||||
|
||||
public static final String SPACING_INTERVAL = "client-spacing-interval";
|
||||
|
||||
|
||||
public static final String BASE_PATH = "/v1/cs";
|
||||
|
||||
|
||||
public static final String CONFIG_CONTROLLER_PATH = BASE_PATH + "/configs";
|
||||
|
||||
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
|
||||
public static final String ACCESS_TOKEN = "accessToken";
|
||||
|
||||
|
||||
public static final String TOKEN_TTL = "tokenTtl";
|
||||
|
||||
|
||||
public static final String GLOBAL_ADMIN = "globalAdmin";
|
||||
|
||||
|
||||
public static final String TOKEN_REFRESH_WINDOW = "tokenRefreshWindow";
|
||||
|
||||
|
||||
/**
|
||||
* second
|
||||
* second.
|
||||
*/
|
||||
public static final int ASYNC_UPDATE_ADDRESS_INTERVAL = 300;
|
||||
|
||||
|
||||
/**
|
||||
* second
|
||||
* second.
|
||||
*/
|
||||
public static final int POLLING_INTERVAL_TIME = 15;
|
||||
|
||||
|
||||
/**
|
||||
* millisecond
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int ONCE_TIMEOUT = 2000;
|
||||
|
||||
|
||||
/**
|
||||
* millisecond
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int SO_TIMEOUT = 60000;
|
||||
|
||||
|
||||
/**
|
||||
* millisecond
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int CONFIG_LONG_POLL_TIMEOUT = 30000;
|
||||
|
||||
|
||||
/**
|
||||
* millisecond
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int MIN_CONFIG_LONG_POLL_TIMEOUT = 10000;
|
||||
|
||||
|
||||
/**
|
||||
* millisecond
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int CONFIG_RETRY_TIME = 2000;
|
||||
|
||||
|
||||
/**
|
||||
* Maximum number of retries
|
||||
* Maximum number of retries.
|
||||
*/
|
||||
public static final int MAX_RETRY = 3;
|
||||
|
||||
|
||||
/**
|
||||
* millisecond
|
||||
* millisecond.
|
||||
*/
|
||||
public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;
|
||||
|
||||
|
||||
public static final String ENCODE = "UTF-8";
|
||||
|
||||
|
||||
public static final String MAP_FILE = "map-file.js";
|
||||
|
||||
|
||||
public static final int FLOW_CONTROL_THRESHOLD = 20;
|
||||
|
||||
|
||||
public static final int FLOW_CONTROL_SLOT = 10;
|
||||
|
||||
|
||||
public static final int FLOW_CONTROL_INTERVAL = 1000;
|
||||
|
||||
|
||||
public static final float DEFAULT_PROTECT_THRESHOLD = 0.0F;
|
||||
|
||||
|
||||
public static final String LINE_SEPARATOR = Character.toString((char) 1);
|
||||
|
||||
|
||||
public static final String WORD_SEPARATOR = Character.toString((char) 2);
|
||||
|
||||
|
||||
public static final String LONGPOLLING_LINE_SEPARATOR = "\r\n";
|
||||
|
||||
|
||||
public static final String CLIENT_APPNAME_HEADER = "Client-AppName";
|
||||
|
||||
public static final String CLIENT_REQUEST_TS_HEADER = "Client-RequestTS";
|
||||
|
||||
public static final String CLIENT_REQUEST_TOKEN_HEADER = "Client-RequestToken";
|
||||
|
||||
|
||||
public static final int ATOMIC_MAX_SIZE = 1000;
|
||||
|
||||
|
||||
public static final String NAMING_INSTANCE_ID_SPLITTER = "#";
|
||||
|
||||
public static final int NAMING_INSTANCE_ID_SEG_COUNT = 4;
|
||||
|
||||
public static final String NAMING_HTTP_HEADER_SPILIER = "\\|";
|
||||
|
||||
|
||||
public static final String DEFAULT_CLUSTER_NAME = "DEFAULT";
|
||||
|
||||
|
||||
public static final long DEFAULT_HEART_BEAT_TIMEOUT = TimeUnit.SECONDS.toMillis(15);
|
||||
|
||||
|
||||
public static final long DEFAULT_IP_DELETE_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
|
||||
public static final long DEFAULT_HEART_BEAT_INTERVAL = TimeUnit.SECONDS.toMillis(5);
|
||||
|
||||
|
||||
public static final String DEFAULT_NAMESPACE_ID = "public";
|
||||
|
||||
|
||||
public static final boolean DEFAULT_USE_CLOUD_NAMESPACE_PARSING = true;
|
||||
|
||||
|
||||
public static final int WRITE_REDIRECT_CODE = 307;
|
||||
|
||||
|
||||
public static final String SERVICE_INFO_SPLITER = "@@";
|
||||
|
||||
|
||||
public static final String NULL_STRING = "null";
|
||||
|
||||
|
||||
public static final String NUMBER_PATTERN = "^\\d+$";
|
||||
|
||||
|
||||
public static final String ANY_PATTERN = ".*";
|
||||
|
||||
|
||||
public static final String DEFAULT_INSTANCE_ID_GENERATOR = "simple";
|
||||
|
||||
|
||||
public static final String SNOWFLAKE_INSTANCE_ID_GENERATOR = "snowflake";
|
||||
|
||||
|
||||
public static final String HTTP_PREFIX = "http";
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,14 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.api.common;
|
||||
|
||||
package com.alibaba.nacos.api.common;
|
||||
|
||||
/**
|
||||
* Response code definitions.
|
||||
* <p>
|
||||
* This class and inherited classes define codes separated from HTTP code to provide richer and preciser
|
||||
* information of the API results. A recommended rule for defining response code is:
|
||||
*
|
||||
* <p>This class and inherited classes define codes separated from HTTP code to provide richer and preciser information of
|
||||
* the API results. A recommended rule for defining response code is:
|
||||
* <li> Global and common code starts with 10001.
|
||||
* <li> Naming module code starts with 20001.
|
||||
* <li> Config module code starts with 30001.
|
||||
@ -29,9 +29,9 @@ package com.alibaba.nacos.api.common;
|
||||
* @since 1.2.0
|
||||
*/
|
||||
public class ResponseCode {
|
||||
|
||||
|
||||
/**
|
||||
* Everything normal
|
||||
* Everything normal.
|
||||
*/
|
||||
public static final int OK = 10200;
|
||||
}
|
||||
|
@ -13,32 +13,32 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigChangeItem;
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ConfigChangeEvent
|
||||
* ConfigChangeEvent.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public class ConfigChangeEvent {
|
||||
private Map<String, ConfigChangeItem> data;
|
||||
|
||||
|
||||
private final Map<String, ConfigChangeItem> data;
|
||||
|
||||
public ConfigChangeEvent(Map<String, ConfigChangeItem> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
public ConfigChangeItem getChangeItem(String key) {
|
||||
return data.get(key);
|
||||
}
|
||||
|
||||
|
||||
public Collection<ConfigChangeItem> getChangeItems() {
|
||||
return data.values();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,65 +13,65 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
/**
|
||||
* ConfigChangeItem
|
||||
* ConfigChangeItem.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public class ConfigChangeItem {
|
||||
|
||||
private String key;
|
||||
|
||||
private String oldValue;
|
||||
|
||||
private String newValue;
|
||||
|
||||
|
||||
private PropertyChangeType type;
|
||||
|
||||
|
||||
public ConfigChangeItem(String key, String oldValue, String newValue) {
|
||||
this.key = key;
|
||||
this.oldValue = oldValue;
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
||||
public String getOldValue() {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
|
||||
public void setOldValue(String oldValue) {
|
||||
this.oldValue = oldValue;
|
||||
}
|
||||
|
||||
|
||||
public String getNewValue() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
|
||||
public void setNewValue(String newValue) {
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
|
||||
public PropertyChangeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
public void setType(PropertyChangeType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConfigChangeItem{" +
|
||||
"key='" + key + '\'' +
|
||||
", oldValue='" + oldValue + '\'' +
|
||||
", newValue='" + newValue + '\'' +
|
||||
", type=" + type +
|
||||
'}';
|
||||
return "ConfigChangeItem{" + "key='" + key + '\'' + ", oldValue='" + oldValue + '\'' + ", newValue='" + newValue
|
||||
+ '\'' + ", type=" + type + '}';
|
||||
}
|
||||
}
|
||||
|
@ -13,23 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Properties;
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Config Factory
|
||||
* Config Factory.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class ConfigFactory {
|
||||
|
||||
|
||||
/**
|
||||
* Create Config
|
||||
* Create Config.
|
||||
*
|
||||
* @param properties init param
|
||||
* @return ConfigService
|
||||
@ -45,9 +46,9 @@ public class ConfigFactory {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create Config
|
||||
* Create Config.
|
||||
*
|
||||
* @param serverAddr serverList
|
||||
* @return Config
|
||||
|
@ -13,20 +13,21 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* Config Service Interface
|
||||
* Config Service Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface ConfigService {
|
||||
|
||||
|
||||
/**
|
||||
* Get config
|
||||
* Get config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
@ -35,31 +36,30 @@ public interface ConfigService {
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
String getConfig(String dataId, String group, long timeoutMs) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get config and register Listener
|
||||
* Get config and register Listener.
|
||||
*
|
||||
* If you want to pull it yourself when the program starts to get the configuration for the first time,
|
||||
* and the registered Listener is used for future configuration updates, you can keep the original
|
||||
* code unchanged, just add the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead);
|
||||
* therefore we recommend that you use this interface directly
|
||||
* <p>If you want to pull it yourself when the program starts to get the configuration for the first time, and the
|
||||
* registered Listener is used for future configuration updates, you can keep the original code unchanged, just add
|
||||
* the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead); therefore we recommend
|
||||
* that you use this interface directly
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param timeoutMs read timeout
|
||||
* @param listener {@link Listener}
|
||||
* @param listener {@link Listener}
|
||||
* @return config value
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener) throws NacosException;
|
||||
|
||||
String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Add a listener to the configuration, after the server modified the
|
||||
* configuration, the client will use the incoming listener callback.
|
||||
* Recommended asynchronous processing, the application can implement the
|
||||
* getExecutor method in the ManagerListener, provide a thread pool of
|
||||
* execution. If provided, use the main thread callback, May block other
|
||||
* configurations or be blocked by other configurations.
|
||||
* Add a listener to the configuration, after the server modified the configuration, the client will use the
|
||||
* incoming listener callback. Recommended asynchronous processing, the application can implement the getExecutor
|
||||
* method in the ManagerListener, provide a thread pool of execution. If provided, use the main thread callback, May
|
||||
* block other configurations or be blocked by other configurations.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
@ -67,7 +67,7 @@ public interface ConfigService {
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
void addListener(String dataId, String group, Listener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Publish config.
|
||||
*
|
||||
@ -78,9 +78,9 @@ public interface ConfigService {
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean publishConfig(String dataId, String group, String content) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Remove config
|
||||
* Remove config.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
@ -88,25 +88,25 @@ public interface ConfigService {
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
boolean removeConfig(String dataId, String group) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Remove listener
|
||||
* Remove listener.
|
||||
*
|
||||
* @param dataId dataId
|
||||
* @param group group
|
||||
* @param listener listener
|
||||
*/
|
||||
void removeListener(String dataId, String group, Listener listener);
|
||||
|
||||
|
||||
/**
|
||||
* Get server status
|
||||
* Get server status.
|
||||
*
|
||||
* @return whether health
|
||||
*/
|
||||
String getServerStatus();
|
||||
|
||||
|
||||
/**
|
||||
* Shutdown the resource service
|
||||
* Shutdown the resource service.
|
||||
*
|
||||
* @throws NacosException exception.
|
||||
*/
|
||||
|
@ -17,47 +17,48 @@
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
/**
|
||||
* Config data type.
|
||||
*
|
||||
* @author liaochuntao
|
||||
* @date 2019-06-14 21:12
|
||||
**/
|
||||
public enum ConfigType {
|
||||
|
||||
|
||||
/**
|
||||
* config type is "properties"
|
||||
* config type is "properties".
|
||||
*/
|
||||
PROPERTIES("properties"),
|
||||
|
||||
|
||||
/**
|
||||
* config type is "xml"
|
||||
* config type is "xml".
|
||||
*/
|
||||
XML("xml"),
|
||||
|
||||
|
||||
/**
|
||||
* config type is "json"
|
||||
* config type is "json".
|
||||
*/
|
||||
JSON("json"),
|
||||
|
||||
|
||||
/**
|
||||
* config type is "text"
|
||||
* config type is "text".
|
||||
*/
|
||||
TEXT("text"),
|
||||
|
||||
|
||||
/**
|
||||
* config type is "html"
|
||||
* config type is "html".
|
||||
*/
|
||||
HTML("html"),
|
||||
|
||||
|
||||
/**
|
||||
* config type is "yaml"
|
||||
* config type is "yaml".
|
||||
*/
|
||||
YAML("yaml");
|
||||
|
||||
|
||||
String type;
|
||||
|
||||
|
||||
ConfigType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
@ -13,18 +13,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config;
|
||||
|
||||
/**
|
||||
* Property Change Type
|
||||
* Property Change Type.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public enum PropertyChangeType {
|
||||
/** add */
|
||||
/**
|
||||
* add.
|
||||
*/
|
||||
ADDED,
|
||||
/** modified */
|
||||
/**
|
||||
* modified.
|
||||
*/
|
||||
MODIFIED,
|
||||
/** deleted */
|
||||
/**
|
||||
* deleted.
|
||||
*/
|
||||
DELETED
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.annotation.NacosProperties;
|
||||
@ -20,7 +21,11 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
import com.alibaba.nacos.api.config.convert.NacosConfigConverter;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
|
||||
|
||||
@ -34,42 +39,42 @@ import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
|
||||
@Target(ElementType.METHOD)
|
||||
@Documented
|
||||
public @interface NacosConfigListener {
|
||||
|
||||
|
||||
/**
|
||||
* Nacos Group ID
|
||||
* Nacos Group ID.
|
||||
*
|
||||
* @return default value {@link Constants#DEFAULT_GROUP};
|
||||
*/
|
||||
String groupId() default DEFAULT_GROUP;
|
||||
|
||||
|
||||
/**
|
||||
* Nacos Data ID
|
||||
* Nacos Data ID.
|
||||
*
|
||||
* @return required value.
|
||||
*/
|
||||
String dataId();
|
||||
|
||||
|
||||
/**
|
||||
* Nacos Config type
|
||||
* Nacos Config type.
|
||||
*
|
||||
* @return "properties"
|
||||
*/
|
||||
ConfigType type() default ConfigType.PROPERTIES;
|
||||
|
||||
|
||||
/**
|
||||
* Specify {@link NacosConfigConverter Nacos configuraion convertor} class to convert target type instance.
|
||||
*
|
||||
* @return The implementation class of {@link NacosConfigConverter}
|
||||
*/
|
||||
Class<? extends NacosConfigConverter> converter() default NacosConfigConverter.class;
|
||||
|
||||
|
||||
/**
|
||||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
|
||||
*
|
||||
* @return the default value is {@link NacosProperties}
|
||||
*/
|
||||
NacosProperties properties() default @NacosProperties;
|
||||
|
||||
|
||||
/**
|
||||
* Maximum timeout value of execution in milliseconds, which is used to prevent long-time blocking execution
|
||||
* impacting others.
|
||||
@ -77,5 +82,5 @@ public @interface NacosConfigListener {
|
||||
* @return default value is 1000
|
||||
*/
|
||||
long timeout() default 1000L;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
@ -20,7 +21,11 @@ import com.alibaba.nacos.api.annotation.NacosProperties;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.config.ConfigType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
|
||||
|
||||
@ -35,51 +40,49 @@ import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosConfigurationProperties {
|
||||
|
||||
|
||||
/**
|
||||
* config prefix name
|
||||
* config prefix name.
|
||||
*
|
||||
* @return default value is <code>""</code>
|
||||
*/
|
||||
String prefix() default "";
|
||||
|
||||
|
||||
/**
|
||||
* Nacos Group ID
|
||||
* Nacos Group ID.
|
||||
*
|
||||
* @return default value {@link Constants#DEFAULT_GROUP};
|
||||
*/
|
||||
String groupId() default DEFAULT_GROUP;
|
||||
|
||||
|
||||
/**
|
||||
* Nacos Data ID
|
||||
* Nacos Data ID.
|
||||
*
|
||||
* @return required value.
|
||||
*/
|
||||
String dataId();
|
||||
|
||||
|
||||
/**
|
||||
* set config type is yaml
|
||||
* this method is deprecated, we support you use {@link #type()} to set config type
|
||||
* set config type is yaml this method is deprecated, we support you use {@link #type()} to set config type.
|
||||
*
|
||||
* @return default value <code>false</code>
|
||||
*/
|
||||
@Deprecated
|
||||
boolean yaml() default false;
|
||||
|
||||
@Deprecated boolean yaml() default false;
|
||||
|
||||
/**
|
||||
* config style
|
||||
* config style.
|
||||
*
|
||||
* @return default value is {@link ConfigType#PROPERTIES}
|
||||
*/
|
||||
ConfigType type() default ConfigType.PROPERTIES;
|
||||
|
||||
|
||||
/**
|
||||
* It indicates the properties of current doBind bean is auto-refreshed when Nacos configuration is changed.
|
||||
*
|
||||
* @return default value is <code>false</code>
|
||||
*/
|
||||
boolean autoRefreshed() default false;
|
||||
|
||||
|
||||
/**
|
||||
* Flag to indicate that when binding to this object invalid fields should be ignored. Invalid means invalid
|
||||
* according to the binder that is used, and usually this means fields of the wrong type (or that cannot be coerced
|
||||
@ -88,14 +91,14 @@ public @interface NacosConfigurationProperties {
|
||||
* @return the flag value (default false)
|
||||
*/
|
||||
boolean ignoreInvalidFields() default false;
|
||||
|
||||
|
||||
/**
|
||||
* Flag to indicate that when binding to this object fields with periods in their names should be ignored.
|
||||
*
|
||||
* @return the flag value (default false)
|
||||
*/
|
||||
boolean ignoreNestedProperties() default false;
|
||||
|
||||
|
||||
/**
|
||||
* Flag to indicate that when binding to this object unknown fields should be ignored. An unknown field could be a
|
||||
* sign of a mistake in the Properties.
|
||||
@ -103,7 +106,7 @@ public @interface NacosConfigurationProperties {
|
||||
* @return the flag value (default true)
|
||||
*/
|
||||
boolean ignoreUnknownFields() default true;
|
||||
|
||||
|
||||
/**
|
||||
* Flag to indicate that an exception should be raised if a Validator is available and validation fails. If it is
|
||||
* set to false, validation errors will be swallowed. They will be logged, but not propagated to the caller.
|
||||
@ -111,12 +114,12 @@ public @interface NacosConfigurationProperties {
|
||||
* @return the flag value (default true)
|
||||
*/
|
||||
boolean exceptionIfInvalid() default true;
|
||||
|
||||
|
||||
/**
|
||||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties.
|
||||
*
|
||||
* @return the default value is {@link NacosProperties}
|
||||
*/
|
||||
NacosProperties properties() default @NacosProperties;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,9 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for ignore field from annotated {@link NacosConfigurationProperties} Properties Object.
|
||||
@ -29,4 +34,5 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosIgnore {
|
||||
|
||||
}
|
||||
|
@ -13,9 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation for Nacos Property name of Nacos Configuration to bind a field from annotated {@link
|
||||
@ -30,12 +35,12 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosProperty {
|
||||
|
||||
|
||||
/**
|
||||
* The property name of Nacos Configuration to bind a field
|
||||
* The property name of Nacos Configuration to bind a field.
|
||||
*
|
||||
* @return property name
|
||||
*/
|
||||
String value();
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,12 +13,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation which extends value to support auto-refresh
|
||||
* Annotation which extends value to support auto-refresh.
|
||||
*
|
||||
* @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a>
|
||||
* @since 0.2.0
|
||||
@ -27,19 +32,19 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface NacosValue {
|
||||
|
||||
|
||||
/**
|
||||
* The actual value expression: e.g. "#{systemProperties.myProp}".
|
||||
*
|
||||
* @return value expression
|
||||
*/
|
||||
String value();
|
||||
|
||||
|
||||
/**
|
||||
* It indicates that the currently bound property is auto-refreshed when Nacos configuration is changed.
|
||||
*
|
||||
* @return default value is <code>false</code>
|
||||
*/
|
||||
boolean autoRefreshed() default false;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,25 +13,26 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.convert;
|
||||
|
||||
/**
|
||||
* Nacos Config Converter
|
||||
* Nacos Config Converter.
|
||||
*
|
||||
* @param <T> the target type that wanted
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public interface NacosConfigConverter<T> {
|
||||
|
||||
|
||||
/**
|
||||
* can convert to be target type or not
|
||||
* can convert to be target type or not.
|
||||
*
|
||||
* @param targetType the type of target
|
||||
* @return If can , return <code>true</code>, or <code>false</code>
|
||||
*/
|
||||
boolean canConvert(Class<T> targetType);
|
||||
|
||||
|
||||
/**
|
||||
* convert the Naocs's config of type S to target type T.
|
||||
*
|
||||
@ -39,5 +40,5 @@ public interface NacosConfigConverter<T> {
|
||||
* @return the converted object, which must be an instance of T (potentially {@code null})
|
||||
*/
|
||||
T convert(String config);
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,24 +13,26 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Context Interface
|
||||
* Config Context Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigContext {
|
||||
|
||||
/**
|
||||
* Get context param by key
|
||||
* Get context param by key.
|
||||
*
|
||||
* @param key
|
||||
* @param key parameter key
|
||||
* @return context
|
||||
*/
|
||||
Object getParameter(String key);
|
||||
|
||||
|
||||
/**
|
||||
* Set context param
|
||||
* Set context param.
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
|
@ -13,25 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* Config Filter Interface
|
||||
* Config Filter Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigFilter {
|
||||
|
||||
/**
|
||||
* Init
|
||||
* Init.
|
||||
*
|
||||
* @param filterConfig Filter Config
|
||||
*/
|
||||
void init(IFilterConfig filterConfig);
|
||||
|
||||
|
||||
/**
|
||||
* do filter
|
||||
* do filter.
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
@ -40,24 +42,24 @@ public interface IConfigFilter {
|
||||
*/
|
||||
void doFilter(IConfigRequest request, IConfigResponse response, IConfigFilterChain filterChain)
|
||||
throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* deploy
|
||||
* deploy.
|
||||
*/
|
||||
void deploy();
|
||||
|
||||
|
||||
/**
|
||||
* Get order
|
||||
* Get order.
|
||||
*
|
||||
* @return order number
|
||||
*/
|
||||
int getOrder();
|
||||
|
||||
|
||||
/**
|
||||
* Get filterName
|
||||
* Get filterName.
|
||||
*
|
||||
* @return filter name
|
||||
*/
|
||||
String getFilterName();
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,23 +13,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* Config Filter Chain Interface
|
||||
* Config Filter Chain Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigFilterChain {
|
||||
|
||||
/**
|
||||
* Filter aciton
|
||||
* Filter action.
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @throws NacosException NacosException
|
||||
*/
|
||||
void doFilter(IConfigRequest request, IConfigResponse response) throws NacosException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,27 +13,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Request Interface
|
||||
* Config Request Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigRequest {
|
||||
|
||||
/**
|
||||
* get param
|
||||
* get param.
|
||||
*
|
||||
* @param key key
|
||||
* @return value
|
||||
*/
|
||||
Object getParameter(String key);
|
||||
|
||||
|
||||
/**
|
||||
* get config context
|
||||
* get config context.
|
||||
*
|
||||
* @return
|
||||
* @return {@link IConfigContext}
|
||||
*/
|
||||
IConfigContext getConfigContext();
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,27 +13,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Config Response Interface
|
||||
* Config Response Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IConfigResponse {
|
||||
|
||||
/**
|
||||
* get param
|
||||
* get param.
|
||||
*
|
||||
* @param key key
|
||||
* @return value
|
||||
*/
|
||||
Object getParameter(String key);
|
||||
|
||||
|
||||
/**
|
||||
* Get config context
|
||||
* Get config context.
|
||||
*
|
||||
* @return configContext
|
||||
*/
|
||||
IConfigContext getConfigContext();
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,28 +13,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.filter;
|
||||
|
||||
/**
|
||||
* Filter Config Interface
|
||||
* Filter Config Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface IFilterConfig {
|
||||
|
||||
|
||||
/**
|
||||
* get filter name
|
||||
* get filter name.
|
||||
*
|
||||
* @return
|
||||
* @return filter name
|
||||
*/
|
||||
String getFilterName();
|
||||
|
||||
|
||||
/**
|
||||
* Get init param
|
||||
* Get init param.
|
||||
*
|
||||
* @param name
|
||||
* @param name parameter name
|
||||
* @return param
|
||||
*/
|
||||
Object getInitParameter(String name);
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,24 +13,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Listener Adapter,use default notify thread
|
||||
* Listener Adapter,use default notify thread.
|
||||
*
|
||||
* @author water.lyl
|
||||
*/
|
||||
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
|
||||
public abstract class AbstractListener implements Listener {
|
||||
|
||||
|
||||
/**
|
||||
* Use default executor
|
||||
* Use default executor.
|
||||
*/
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,38 +13,40 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Shared Listener
|
||||
* Shared Listener.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
|
||||
public abstract class AbstractSharedListener implements Listener {
|
||||
|
||||
|
||||
private volatile String dataId;
|
||||
|
||||
private volatile String group;
|
||||
|
||||
|
||||
public final void fillContext(String dataId, String group) {
|
||||
this.dataId = dataId;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void receiveConfigInfo(String configInfo) {
|
||||
innerReceive(dataId, group, configInfo);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* receive
|
||||
* receive.
|
||||
*
|
||||
* @param dataId data ID
|
||||
* @param group group
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigChangeItem;
|
||||
@ -21,25 +22,28 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ConfigChangeParser
|
||||
* ConfigChangeParser.
|
||||
*
|
||||
* @author rushsky518
|
||||
*/
|
||||
public interface ConfigChangeParser {
|
||||
|
||||
/**
|
||||
* judge type
|
||||
* @param type
|
||||
* @return
|
||||
* Judge type.
|
||||
*
|
||||
* @param type data type
|
||||
* @return true if is responsible type, otherwise false
|
||||
*/
|
||||
boolean isResponsibleFor(String type);
|
||||
|
||||
|
||||
/**
|
||||
* compare old and new data
|
||||
* @param oldContent
|
||||
* @param newContent
|
||||
* @param type
|
||||
* @return
|
||||
* @throws IOException
|
||||
* Compare old and new data.
|
||||
*
|
||||
* @param oldContent old content
|
||||
* @param newContent new content
|
||||
* @param type data type
|
||||
* @return key and change item map
|
||||
* @throws IOException io exception
|
||||
*/
|
||||
Map<String, ConfigChangeItem> doParse(String oldContent, String newContent, String type) throws IOException;
|
||||
}
|
||||
|
@ -13,26 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.config.listener;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Listener for watch config
|
||||
* Listener for watch config.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface Listener {
|
||||
|
||||
|
||||
/**
|
||||
* Get executor for execute this receive
|
||||
* Get executor for execute this receive.
|
||||
*
|
||||
* @return Executor
|
||||
*/
|
||||
Executor getExecutor();
|
||||
|
||||
|
||||
/**
|
||||
* Receive config info
|
||||
* Receive config info.
|
||||
*
|
||||
* @param configInfo config info
|
||||
*/
|
||||
|
@ -24,47 +24,43 @@ import java.lang.reflect.Type;
|
||||
* @author yangyi
|
||||
*/
|
||||
public class NacosDeserializationException extends NacosRuntimeException {
|
||||
|
||||
|
||||
public static final int ERROR_CODE = 101;
|
||||
|
||||
|
||||
private static final long serialVersionUID = -2742350751684273728L;
|
||||
|
||||
|
||||
private static final String DEFAULT_MSG = "Nacos deserialize failed. ";
|
||||
|
||||
|
||||
private static final String MSG_FOR_SPECIFIED_CLASS = "Nacos deserialize for class [%s] failed. ";
|
||||
|
||||
|
||||
private Class<?> targetClass;
|
||||
|
||||
|
||||
public NacosDeserializationException() {
|
||||
super(ERROR_CODE);
|
||||
}
|
||||
|
||||
|
||||
public NacosDeserializationException(Class<?> targetClass) {
|
||||
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetClass.getName()));
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
|
||||
public NacosDeserializationException(Type targetType) {
|
||||
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetType.toString()));
|
||||
}
|
||||
|
||||
|
||||
public NacosDeserializationException(Throwable throwable) {
|
||||
super(ERROR_CODE, DEFAULT_MSG, throwable);
|
||||
}
|
||||
|
||||
|
||||
public NacosDeserializationException(Class<?> targetClass, Throwable throwable) {
|
||||
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetClass.getName()), throwable);
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
|
||||
public NacosDeserializationException(Type targetType, Throwable throwable) {
|
||||
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, targetType.toString()), throwable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
@ -22,37 +22,37 @@ package com.alibaba.nacos.api.exception.runtime;
|
||||
* @author yangyi
|
||||
*/
|
||||
public class NacosRuntimeException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 3513491993982293262L;
|
||||
|
||||
|
||||
public static final String ERROR_MESSAGE_FORMAT = "errCode: %d, errMsg: %s ";
|
||||
|
||||
|
||||
private int errCode;
|
||||
|
||||
|
||||
public NacosRuntimeException(int errCode) {
|
||||
super();
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
|
||||
public NacosRuntimeException(int errCode, String errMsg) {
|
||||
super(String.format(ERROR_MESSAGE_FORMAT, errCode, errMsg));
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
|
||||
public NacosRuntimeException(int errCode, Throwable throwable) {
|
||||
super(throwable);
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
|
||||
public NacosRuntimeException(int errCode, String errMsg, Throwable throwable) {
|
||||
super(String.format(ERROR_MESSAGE_FORMAT, errCode, errMsg), throwable);
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
|
||||
public int getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
|
||||
public void setErrCode(int errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
@ -22,35 +22,35 @@ package com.alibaba.nacos.api.exception.runtime;
|
||||
* @author yangyi
|
||||
*/
|
||||
public class NacosSerializationException extends NacosRuntimeException {
|
||||
|
||||
|
||||
public static final int ERROR_CODE = 100;
|
||||
|
||||
|
||||
private static final long serialVersionUID = -4308536346316915612L;
|
||||
|
||||
|
||||
private static final String DEFAULT_MSG = "Nacos serialize failed. ";
|
||||
|
||||
|
||||
private static final String MSG_FOR_SPECIFIED_CLASS = "Nacos serialize for class [%s] failed. ";
|
||||
|
||||
|
||||
private Class<?> serializedClass;
|
||||
|
||||
|
||||
public NacosSerializationException() {
|
||||
super(ERROR_CODE);
|
||||
}
|
||||
|
||||
|
||||
public NacosSerializationException(Class<?> serializedClass) {
|
||||
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, serializedClass.getName()));
|
||||
this.serializedClass = serializedClass;
|
||||
}
|
||||
|
||||
|
||||
public NacosSerializationException(Throwable throwable) {
|
||||
super(ERROR_CODE, DEFAULT_MSG, throwable);
|
||||
}
|
||||
|
||||
|
||||
public NacosSerializationException(Class<?> serializedClass, Throwable throwable) {
|
||||
super(ERROR_CODE, String.format(MSG_FOR_SPECIFIED_CLASS, serializedClass.getName()), throwable);
|
||||
this.serializedClass = serializedClass;
|
||||
}
|
||||
|
||||
|
||||
public Class<?> getSerializedClass() {
|
||||
return serializedClass;
|
||||
}
|
||||
|
@ -13,25 +13,26 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming;
|
||||
|
||||
/**
|
||||
* Common parameters for service discovery
|
||||
* Common parameters for service discovery.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class CommonParams {
|
||||
|
||||
|
||||
public static final String CODE = "code";
|
||||
|
||||
|
||||
public static final String SERVICE_NAME = "serviceName";
|
||||
|
||||
|
||||
public static final String CLUSTER_NAME = "clusterName";
|
||||
|
||||
|
||||
public static final String NAMESPACE_ID = "namespaceId";
|
||||
|
||||
|
||||
public static final String GROUP_NAME = "groupName";
|
||||
|
||||
|
||||
public static final String LIGHT_BEAT_ENABLED = "lightBeatEnabled";
|
||||
}
|
||||
|
@ -13,36 +13,51 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* Naming Factory
|
||||
* Naming Factory.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public class NamingFactory {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new naming service.
|
||||
*
|
||||
* @param serverList server list
|
||||
* @return new naming service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
public static NamingService createNamingService(String serverList) throws NacosException {
|
||||
try {
|
||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService");
|
||||
Constructor constructor = driverImplClass.getConstructor(String.class);
|
||||
NamingService vendorImpl = (NamingService)constructor.newInstance(serverList);
|
||||
NamingService vendorImpl = (NamingService) constructor.newInstance(serverList);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new naming service.
|
||||
*
|
||||
* @param properties naming service properties
|
||||
* @return new naming service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
public static NamingService createNamingService(Properties properties) throws NacosException {
|
||||
try {
|
||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingService");
|
||||
Constructor constructor = driverImplClass.getConstructor(Properties.class);
|
||||
NamingService vendorImpl = (NamingService)constructor.newInstance(properties);
|
||||
NamingService vendorImpl = (NamingService) constructor.newInstance(properties);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
|
@ -22,31 +22,47 @@ import java.lang.reflect.Constructor;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Maintain service factory.
|
||||
*
|
||||
* @author liaochuntao
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public class NamingMaintainFactory {
|
||||
|
||||
|
||||
/**
|
||||
* create a new maintain service.
|
||||
*
|
||||
* @param serverList server list
|
||||
* @return new maintain service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
public static NamingMaintainService createMaintainService(String serverList) throws NacosException {
|
||||
try {
|
||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingMaintainService");
|
||||
Constructor constructor = driverImplClass.getConstructor(String.class);
|
||||
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList);
|
||||
NamingMaintainService vendorImpl = (NamingMaintainService) constructor.newInstance(serverList);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create a new maintain service.
|
||||
*
|
||||
* @param properties properties
|
||||
* @return new maintain service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
|
||||
try {
|
||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosNamingMaintainService");
|
||||
Constructor constructor = driverImplClass.getConstructor(Properties.class);
|
||||
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties);
|
||||
NamingMaintainService vendorImpl = (NamingMaintainService) constructor.newInstance(properties);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,145 +24,147 @@ import com.alibaba.nacos.api.selector.AbstractSelector;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Operations related to Nacos
|
||||
* Operations related to Nacos.
|
||||
*
|
||||
* @author liaochuntao
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public interface NamingMaintainService {
|
||||
|
||||
|
||||
/**
|
||||
* update instance info
|
||||
* update instance info.
|
||||
*
|
||||
* @param serviceName
|
||||
* @param instance
|
||||
* @throws NacosException
|
||||
* @param serviceName service name
|
||||
* @param instance instance
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void updateInstance(String serviceName, Instance instance) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* update instance info
|
||||
* update instance info.
|
||||
*
|
||||
* @param serviceName
|
||||
* @param groupName
|
||||
* @param instance
|
||||
* @throws NacosException
|
||||
* @param serviceName service name
|
||||
* @param groupName group name
|
||||
* @param instance instance
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* query service
|
||||
* query service.
|
||||
*
|
||||
* @param serviceName
|
||||
* @return
|
||||
* @throws NacosException
|
||||
* @param serviceName service name
|
||||
* @return service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Service queryService(String serviceName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* query service
|
||||
* query service.
|
||||
*
|
||||
* @param serviceName
|
||||
* @param groupName
|
||||
* @return
|
||||
* @throws NacosException
|
||||
* @param serviceName service name
|
||||
* @param groupName group name
|
||||
* @return service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Service queryService(String serviceName, String groupName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* create service to Nacos
|
||||
* create service to Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void createService(String serviceName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* create service to Nacos
|
||||
* create service to Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void createService(String serviceName, String groupName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* create service to Nacos
|
||||
* create service to Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @throws NacosException
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void createService(String serviceName, String groupName, float protectThreshold) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* create service to Nacos
|
||||
* create service to Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @param expression expression of selector
|
||||
* @throws NacosException
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @param expression expression of selector
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void createService(String serviceName, String groupName, float protectThreshold, String expression) throws NacosException;
|
||||
|
||||
void createService(String serviceName, String groupName, float protectThreshold, String expression)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* create service to Nacos
|
||||
* create service to Nacos.
|
||||
*
|
||||
* @param service name of service
|
||||
* @param selector selector
|
||||
* @throws NacosException
|
||||
* @param service name of service
|
||||
* @param selector selector
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void createService(Service service, AbstractSelector selector) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* delete service from Nacos
|
||||
* delete service from Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @return if delete service success return true
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
boolean deleteService(String serviceName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* delete service from Nacos
|
||||
* delete service from Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @return if delete service success return true
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
boolean deleteService(String serviceName, String groupName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* update service to Nacos
|
||||
* update service to Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @throws NacosException
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void updateService(String serviceName, String groupName, float protectThreshold) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* update service to Nacos
|
||||
* update service to Nacos.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @param metadata metadata of service
|
||||
* @throws NacosException
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param protectThreshold protectThreshold of service
|
||||
* @param metadata metadata of service
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void updateService(String serviceName, String groupName, float protectThreshold, Map<String, String> metadata) throws NacosException;
|
||||
|
||||
void updateService(String serviceName, String groupName, float protectThreshold, Map<String, String> metadata)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* update service to Nacos with selector
|
||||
* update service to Nacos with selector.
|
||||
*
|
||||
* @param service {@link Service} pojo of service
|
||||
* @param selector {@link AbstractSelector} pojo of selector
|
||||
* @throws NacosException
|
||||
* @param service {@link Service} pojo of service
|
||||
* @param selector {@link AbstractSelector} pojo of selector
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void updateService(Service service, AbstractSelector selector) throws NacosException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming;
|
||||
|
||||
import com.alibaba.nacos.api.common.ResponseCode;
|
||||
@ -20,16 +21,16 @@ import com.alibaba.nacos.api.common.ResponseCode;
|
||||
/**
|
||||
* Business response code of naming module
|
||||
*
|
||||
* Every code stays between 20001 to 29999.
|
||||
* <p>Every code stays between 20001 to 29999.
|
||||
*
|
||||
* @author nkorange
|
||||
* @author 1.2.0
|
||||
*/
|
||||
public class NamingResponseCode extends ResponseCode {
|
||||
|
||||
|
||||
/**
|
||||
* The requested resource is not found
|
||||
* The requested resource is not found.
|
||||
*/
|
||||
public static final int RESOURCE_NOT_FOUND = 20404;
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
@ -25,302 +26,309 @@ import com.alibaba.nacos.api.selector.AbstractSelector;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Naming Service
|
||||
* Naming Service.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public interface NamingService {
|
||||
|
||||
|
||||
/**
|
||||
* register a instance to service
|
||||
* register a instance to service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void registerInstance(String serviceName, String ip, int port) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* register a instance to service
|
||||
* register a instance to service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void registerInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* register a instance to service with specified cluster name
|
||||
* register a instance to service with specified cluster name.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @param clusterName instance cluster name
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void registerInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* register a instance to service with specified cluster name
|
||||
* register a instance to service with specified cluster name.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @param clusterName instance cluster name
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void registerInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
void registerInstance(String serviceName, String groupName, String ip, int port, String clusterName)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* register a instance to service with specified instance properties
|
||||
* register a instance to service with specified instance properties.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param instance instance to register
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void registerInstance(String serviceName, Instance instance) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* register a instance to service with specified instance properties
|
||||
* register a instance to service with specified instance properties.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param instance instance to register
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* deregister instance from a service
|
||||
* deregister instance from a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String ip, int port) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* deregister instance from a service
|
||||
* deregister instance from a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String groupName, String ip, int port) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* deregister instance with specified cluster name from a service
|
||||
* deregister instance with specified cluster name from a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @param clusterName instance cluster name
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* deregister instance with specified cluster name from a service
|
||||
* deregister instance with specified cluster name from a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param ip instance ip
|
||||
* @param port instance port
|
||||
* @param clusterName instance cluster name
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException;
|
||||
|
||||
void deregisterInstance(String serviceName, String groupName, String ip, int port, String clusterName)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* deregister instance with full instance information and default groupName
|
||||
* @param serviceName
|
||||
* @param instance
|
||||
* @throws NacosException
|
||||
* deregister instance with full instance information and default groupName.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param instance instance
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void deregisterInstance(String serviceName, Instance instance) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* deregister instance with full instance information
|
||||
* deregister instance with full instance information.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param instance instance information
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void deregisterInstance(String serviceName, String groupName, Instance instance) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* get all instances of a service
|
||||
* get all instances of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @return A list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* get all instances of a service
|
||||
* get all instances of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @return A list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, String groupName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all instances of a service
|
||||
* Get all instances of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, boolean subscribe) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all instances of a service
|
||||
* Get all instances of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, String groupName, boolean subscribe) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all instances within specified clusters of a service
|
||||
* Get all instances within specified clusters of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters list of cluster
|
||||
* @return A list of qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, List<String> clusters) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all instances within specified clusters of a service
|
||||
* Get all instances within specified clusters of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters list of cluster
|
||||
* @return A list of qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all instances within specified clusters of a service
|
||||
* Get all instances within specified clusters of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters list of cluster
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A list of qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, List<String> clusters, boolean subscribe) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all instances within specified clusters of a service
|
||||
* Get all instances within specified clusters of a service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters list of cluster
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A list of qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException;
|
||||
|
||||
List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters, boolean subscribe)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get qualified instances of service
|
||||
* Get qualified instances of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param serviceName name of service.
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get qualified instances of service
|
||||
* Get qualified instances of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, String groupName, boolean healthy) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get qualified instances of service
|
||||
* Get qualified instances of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get qualified instances of service
|
||||
* Get qualified instances of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, String groupName, boolean healthy, boolean subscribe) throws NacosException;
|
||||
|
||||
List<Instance> selectInstances(String serviceName, String groupName, boolean healthy, boolean subscribe)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get qualified instances within specified clusters of service
|
||||
* Get qualified instances within specified clusters of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters list of cluster
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get qualified instances within specified clusters of service
|
||||
* Get qualified instances within specified clusters of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters list of cluster
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy) throws NacosException;
|
||||
|
||||
List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get qualified instances within specified clusters of service
|
||||
* Get qualified instances within specified clusters of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters list of cluster
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy, boolean subscribe) throws NacosException;
|
||||
|
||||
List<Instance> selectInstances(String serviceName, List<String> clusters, boolean healthy, boolean subscribe)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get qualified instances within specified clusters of service
|
||||
* Get qualified instances within specified clusters of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
@ -328,234 +336,241 @@ public interface NamingService {
|
||||
* @param healthy a flag to indicate returning healthy or unhealthy instances
|
||||
* @param subscribe if subscribe the service
|
||||
* @return A qualified list of instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy, boolean subscribe) throws NacosException;
|
||||
|
||||
List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy,
|
||||
boolean subscribe) throws NacosException;
|
||||
|
||||
/**
|
||||
* Select one healthy instance of service using predefined load balance strategy
|
||||
* Select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Select one healthy instance of service using predefined load balance strategy
|
||||
* Select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, String groupName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* select one healthy instance of service using predefined load balance strategy
|
||||
* select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param subscribe if subscribe the service
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, boolean subscribe) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* select one healthy instance of service using predefined load balance strategy
|
||||
* select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param subscribe if subscribe the service
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, String groupName, boolean subscribe) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Select one healthy instance of service using predefined load balance strategy
|
||||
* Select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters a list of clusters should the instance belongs to
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, List<String> clusters) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Select one healthy instance of service using predefined load balance strategy
|
||||
* Select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters a list of clusters should the instance belongs to
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters) throws NacosException;
|
||||
|
||||
Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Select one healthy instance of service using predefined load balance strategy
|
||||
* Select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters a list of clusters should the instance belongs to
|
||||
* @param subscribe if subscribe the service
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe) throws NacosException;
|
||||
|
||||
Instance selectOneHealthyInstance(String serviceName, List<String> clusters, boolean subscribe)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Select one healthy instance of service using predefined load balance strategy
|
||||
* Select one healthy instance of service using predefined load balance strategy.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters a list of clusters should the instance belongs to
|
||||
* @param subscribe if subscribe the service
|
||||
* @return qualified instance
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters, boolean subscribe) throws NacosException;
|
||||
|
||||
Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters, boolean subscribe)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Subscribe service to receive events of instances alteration
|
||||
* Subscribe service to receive events of instances alteration.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void subscribe(String serviceName, EventListener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Subscribe service to receive events of instances alteration
|
||||
* Subscribe service to receive events of instances alteration.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void subscribe(String serviceName, String groupName, EventListener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Subscribe service to receive events of instances alteration
|
||||
* Subscribe service to receive events of instances alteration.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters list of cluster
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void subscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Subscribe service to receive events of instances alteration
|
||||
* Subscribe service to receive events of instances alteration.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters list of cluster
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException;
|
||||
|
||||
void subscribe(String serviceName, String groupName, List<String> clusters, EventListener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Unsubscribe event listener of service
|
||||
* Unsubscribe event listener of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void unsubscribe(String serviceName, EventListener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* unsubscribe event listener of service
|
||||
* unsubscribe event listener of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void unsubscribe(String serviceName, String groupName, EventListener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Unsubscribe event listener of service
|
||||
* Unsubscribe event listener of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param clusters list of cluster
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void unsubscribe(String serviceName, List<String> clusters, EventListener listener) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Unsubscribe event listener of service
|
||||
* Unsubscribe event listener of service.
|
||||
*
|
||||
* @param serviceName name of service
|
||||
* @param groupName group of service
|
||||
* @param clusters list of cluster
|
||||
* @param listener event listener
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener) throws NacosException;
|
||||
|
||||
void unsubscribe(String serviceName, String groupName, List<String> clusters, EventListener listener)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get all service names from server
|
||||
* Get all service names from server.
|
||||
*
|
||||
* @param pageNo page index
|
||||
* @param pageSize page size
|
||||
* @return list of service names
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
ListView<String> getServicesOfServer(int pageNo, int pageSize) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all service names from server
|
||||
* Get all service names from server.
|
||||
*
|
||||
* @param pageNo page index
|
||||
* @param pageSize page size
|
||||
* @param groupName group name
|
||||
* @return list of service names
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all service names from server with selector
|
||||
* Get all service names from server with selector.
|
||||
*
|
||||
* @param pageNo page index
|
||||
* @param pageSize page size
|
||||
* @param selector selector to filter the resource
|
||||
* @return list of service names
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
* @since 0.7.0
|
||||
*/
|
||||
ListView<String> getServicesOfServer(int pageNo, int pageSize, AbstractSelector selector) throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* Get all service names from server with selector
|
||||
* Get all service names from server with selector.
|
||||
*
|
||||
* @param pageNo page index
|
||||
* @param pageSize page size
|
||||
* @param groupName group name
|
||||
* @param selector selector to filter the resource
|
||||
* @return list of service names
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException;
|
||||
|
||||
ListView<String> getServicesOfServer(int pageNo, int pageSize, String groupName, AbstractSelector selector)
|
||||
throws NacosException;
|
||||
|
||||
/**
|
||||
* Get all subscribed services of current client
|
||||
* Get all subscribed services of current client.
|
||||
*
|
||||
* @return subscribed services
|
||||
* @throws NacosException
|
||||
* @throws NacosException nacos exception
|
||||
*/
|
||||
List<ServiceInfo> getSubscribeServices() throws NacosException;
|
||||
|
||||
|
||||
/**
|
||||
* get server health status
|
||||
* get server health status.
|
||||
*
|
||||
* @return is server healthy
|
||||
*/
|
||||
String getServerStatus();
|
||||
|
||||
|
||||
/**
|
||||
* Shutdown the resource service.
|
||||
*
|
||||
|
@ -13,26 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming;
|
||||
|
||||
/**
|
||||
* Some keys of metadata that are recognized by Nacos
|
||||
* Some keys of metadata that are recognized by Nacos.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PreservedMetadataKeys {
|
||||
|
||||
|
||||
/**
|
||||
* The key to indicate the registry source of service instance, such as Dubbo, SpringCloud, etc.
|
||||
*/
|
||||
public static final String REGISTER_SOURCE = "preserved.register.source";
|
||||
|
||||
|
||||
public static final String HEART_BEAT_TIMEOUT = "preserved.heart.beat.timeout";
|
||||
|
||||
|
||||
public static final String IP_DELETE_TIMEOUT = "preserved.ip.delete.timeout";
|
||||
|
||||
|
||||
public static final String HEART_BEAT_INTERVAL = "preserved.heart.beat.interval";
|
||||
|
||||
|
||||
public static final String INSTANCE_ID_GENERATOR = "preserved.instance.id.generator";
|
||||
}
|
||||
|
@ -13,12 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.listener;
|
||||
|
||||
/**
|
||||
* Event Interface
|
||||
* Event Interface.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public interface Event {
|
||||
|
||||
}
|
||||
|
@ -13,18 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.listener;
|
||||
|
||||
/**
|
||||
* Event Listener
|
||||
* Event Listener.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public interface EventListener {
|
||||
|
||||
/**
|
||||
* callback event
|
||||
* callback event.
|
||||
*
|
||||
* @param event
|
||||
* @param event event
|
||||
*/
|
||||
void onEvent(Event event);
|
||||
}
|
||||
|
@ -13,67 +13,68 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.api.naming.listener;
|
||||
|
||||
import java.util.List;
|
||||
package com.alibaba.nacos.api.naming.listener;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Naming Event
|
||||
* Naming Event.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public class NamingEvent implements Event {
|
||||
|
||||
|
||||
private String serviceName;
|
||||
|
||||
|
||||
private String groupName;
|
||||
|
||||
|
||||
private String clusters;
|
||||
|
||||
|
||||
private List<Instance> instances;
|
||||
|
||||
|
||||
public NamingEvent(String serviceName, List<Instance> instances) {
|
||||
this.serviceName = serviceName;
|
||||
this.instances = instances;
|
||||
}
|
||||
|
||||
|
||||
public NamingEvent(String serviceName, String groupName, String clusters, List<Instance> instances) {
|
||||
this.serviceName = serviceName;
|
||||
this.groupName = groupName;
|
||||
this.clusters = clusters;
|
||||
this.instances = instances;
|
||||
}
|
||||
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
|
||||
public List<Instance> getInstances() {
|
||||
return instances;
|
||||
}
|
||||
|
||||
|
||||
public void setInstances(List<Instance> instances) {
|
||||
this.instances = instances;
|
||||
}
|
||||
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
|
||||
public String getClusters() {
|
||||
return clusters;
|
||||
}
|
||||
|
||||
|
||||
public void setClusters(String clusters) {
|
||||
this.clusters = clusters;
|
||||
}
|
||||
|
@ -13,113 +13,118 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Cluster
|
||||
* Cluster.
|
||||
*
|
||||
* <p>The class will be serialized to json, and there are some variables and method can't use Camel naming rule for
|
||||
* compatibility
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:abbreviationaswordinname")
|
||||
public class Cluster {
|
||||
|
||||
|
||||
/**
|
||||
* Name of belonging service
|
||||
* Name of belonging service.
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
|
||||
/**
|
||||
* Name of cluster
|
||||
* Name of cluster.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* Health check config of this cluster
|
||||
* Health check config of this cluster.
|
||||
*/
|
||||
private AbstractHealthChecker healthChecker = new Tcp();
|
||||
|
||||
|
||||
/**
|
||||
* Default registered port for instances in this cluster.
|
||||
*/
|
||||
private int defaultPort = 80;
|
||||
|
||||
|
||||
/**
|
||||
* Default health check port of instances in this cluster.
|
||||
*/
|
||||
private int defaultCheckPort = 80;
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not use instance port to do health check.
|
||||
*/
|
||||
private boolean useIPPort4Check = true;
|
||||
|
||||
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
|
||||
public Cluster() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Cluster(String clusterName) {
|
||||
this.name = clusterName;
|
||||
}
|
||||
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public AbstractHealthChecker getHealthChecker() {
|
||||
return healthChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setHealthChecker(AbstractHealthChecker healthChecker) {
|
||||
this.healthChecker = healthChecker;
|
||||
}
|
||||
|
||||
|
||||
public int getDefaultPort() {
|
||||
return defaultPort;
|
||||
}
|
||||
|
||||
|
||||
public void setDefaultPort(int defaultPort) {
|
||||
this.defaultPort = defaultPort;
|
||||
}
|
||||
|
||||
|
||||
public int getDefaultCheckPort() {
|
||||
return defaultCheckPort;
|
||||
}
|
||||
|
||||
|
||||
public void setDefaultCheckPort(int defaultCheckPort) {
|
||||
this.defaultCheckPort = defaultCheckPort;
|
||||
}
|
||||
|
||||
|
||||
public boolean isUseIPPort4Check() {
|
||||
return useIPPort4Check;
|
||||
}
|
||||
|
||||
|
||||
public void setUseIPPort4Check(boolean useIPPort4Check) {
|
||||
this.useIPPort4Check = useIPPort4Check;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
@ -182,10 +182,10 @@ public class Instance {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Instance{" + "instanceId='" + instanceId + '\'' + ", ip='" + ip + '\'' + ", port=" + port
|
||||
+ ", weight=" + weight + ", healthy=" + healthy + ", enabled=" + enabled + ", ephemeral="
|
||||
+ ephemeral + ", clusterName='" + clusterName + '\'' + ", serviceName='" + serviceName
|
||||
+ '\'' + ", metadata=" + metadata + '}';
|
||||
return "Instance{" + "instanceId='" + instanceId + '\'' + ", ip='" + ip + '\'' + ", port=" + port + ", weight="
|
||||
+ weight + ", healthy=" + healthy + ", enabled=" + enabled + ", ephemeral=" + ephemeral
|
||||
+ ", clusterName='" + clusterName + '\'' + ", serviceName='" + serviceName + '\'' + ", metadata="
|
||||
+ metadata + '}';
|
||||
}
|
||||
|
||||
public String toInetAddr() {
|
||||
|
@ -13,41 +13,40 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ListView
|
||||
* ListView.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public class ListView<T> {
|
||||
|
||||
|
||||
private List<T> data;
|
||||
|
||||
private int count;
|
||||
|
||||
|
||||
public List<T> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public void setData(List<T> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListView{" +
|
||||
"data=" + data +
|
||||
", count=" + count +
|
||||
'}';
|
||||
return "ListView{" + "data=" + data + ", count=" + count + '}';
|
||||
}
|
||||
}
|
||||
|
@ -13,103 +13,100 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Service of Nacos
|
||||
* <p>
|
||||
* We introduce a 'service --> cluster --> instance' model, in which service stores a list of clusters,
|
||||
* which contains a list of instances.
|
||||
* <p>
|
||||
* Typically we put some unique properties between instances to service level.
|
||||
* Service of Nacos.
|
||||
*
|
||||
* <p>We introduce a 'service --> cluster --> instance' model, in which service stores a list of clusters, which contains a
|
||||
* list of instances.
|
||||
*
|
||||
* <p>Typically we put some unique properties between instances to service level.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public class Service {
|
||||
|
||||
/**
|
||||
* service name
|
||||
* service name.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* protect threshold
|
||||
* protect threshold.
|
||||
*/
|
||||
private float protectThreshold = 0.0F;
|
||||
|
||||
|
||||
/**
|
||||
* application name of this service
|
||||
* application name of this service.
|
||||
*/
|
||||
private String appName;
|
||||
|
||||
|
||||
/**
|
||||
* Service group to classify services into different sets.
|
||||
*/
|
||||
private String groupName;
|
||||
|
||||
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
|
||||
public Service() {
|
||||
}
|
||||
|
||||
|
||||
public Service(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public float getProtectThreshold() {
|
||||
return protectThreshold;
|
||||
}
|
||||
|
||||
|
||||
public void setProtectThreshold(float protectThreshold) {
|
||||
this.protectThreshold = protectThreshold;
|
||||
}
|
||||
|
||||
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
|
||||
public void addMetadata(String key, String value) {
|
||||
this.metadata.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Service{" +
|
||||
"name='" + name + '\'' +
|
||||
", protectThreshold=" + protectThreshold +
|
||||
", appName='" + appName + '\'' +
|
||||
", groupName='" + groupName + '\'' +
|
||||
", metadata=" + metadata +
|
||||
'}';
|
||||
return "Service{" + "name='" + name + '\'' + ", protectThreshold=" + protectThreshold + ", appName='" + appName
|
||||
+ '\'' + ", groupName='" + groupName + '\'' + ", metadata=" + metadata + '}';
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
@ -27,158 +28,173 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ServiceInfo
|
||||
* ServiceInfo.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public class ServiceInfo {
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
private String jsonFromServer = EMPTY;
|
||||
|
||||
|
||||
public static final String SPLITER = "@@";
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
private String groupName;
|
||||
|
||||
|
||||
private String clusters;
|
||||
|
||||
|
||||
private long cacheMillis = 1000L;
|
||||
|
||||
|
||||
private List<Instance> hosts = new ArrayList<Instance>();
|
||||
|
||||
|
||||
private long lastRefTime = 0L;
|
||||
|
||||
|
||||
private String checksum = "";
|
||||
|
||||
|
||||
private volatile boolean allIPs = false;
|
||||
|
||||
|
||||
public ServiceInfo() {
|
||||
}
|
||||
|
||||
|
||||
public boolean isAllIPs() {
|
||||
return allIPs;
|
||||
}
|
||||
|
||||
|
||||
public void setAllIPs(boolean allIPs) {
|
||||
this.allIPs = allIPs;
|
||||
}
|
||||
|
||||
|
||||
public ServiceInfo(String key) {
|
||||
|
||||
|
||||
int maxIndex = 2;
|
||||
int clusterIndex = 1;
|
||||
int serviceNameIndex = 0;
|
||||
|
||||
|
||||
String[] keys = key.split(Constants.SERVICE_INFO_SPLITER);
|
||||
if (keys.length >= maxIndex) {
|
||||
this.name = keys[serviceNameIndex];
|
||||
this.clusters = keys[clusterIndex];
|
||||
}
|
||||
|
||||
|
||||
this.name = keys[0];
|
||||
}
|
||||
|
||||
|
||||
public ServiceInfo(String name, String clusters) {
|
||||
this.name = name;
|
||||
this.clusters = clusters;
|
||||
}
|
||||
|
||||
|
||||
public int ipCount() {
|
||||
return hosts.size();
|
||||
}
|
||||
|
||||
|
||||
public boolean expired() {
|
||||
return System.currentTimeMillis() - lastRefTime > cacheMillis;
|
||||
}
|
||||
|
||||
|
||||
public void setHosts(List<Instance> hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
|
||||
public boolean isValid() {
|
||||
return hosts != null;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
|
||||
public void setLastRefTime(long lastRefTime) {
|
||||
this.lastRefTime = lastRefTime;
|
||||
}
|
||||
|
||||
|
||||
public long getLastRefTime() {
|
||||
return lastRefTime;
|
||||
}
|
||||
|
||||
|
||||
public String getClusters() {
|
||||
return clusters;
|
||||
}
|
||||
|
||||
|
||||
public void setClusters(String clusters) {
|
||||
this.clusters = clusters;
|
||||
}
|
||||
|
||||
|
||||
public long getCacheMillis() {
|
||||
return cacheMillis;
|
||||
}
|
||||
|
||||
|
||||
public void setCacheMillis(long cacheMillis) {
|
||||
this.cacheMillis = cacheMillis;
|
||||
}
|
||||
|
||||
|
||||
public List<Instance> getHosts() {
|
||||
return new ArrayList<Instance>(hosts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Judge whether service info is validate.
|
||||
*
|
||||
* @return true if validate, otherwise false
|
||||
*/
|
||||
public boolean validate() {
|
||||
if (isAllIPs()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
List<Instance> validHosts = new ArrayList<Instance>();
|
||||
for (Instance host : hosts) {
|
||||
if (!host.isHealthy()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < host.getWeight(); i++) {
|
||||
validHosts.add(host);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
public String getJsonFromServer() {
|
||||
return jsonFromServer;
|
||||
}
|
||||
|
||||
|
||||
public void setJsonFromServer(String jsonFromServer) {
|
||||
this.jsonFromServer = jsonFromServer;
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
public String getKey() {
|
||||
return getKey(name, clusters);
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
public static String getKey(String name, String clusters) {
|
||||
|
||||
if (!isEmpty(clusters)) {
|
||||
return name + Constants.SERVICE_INFO_SPLITER + clusters;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getKeyEncoded() {
|
||||
try {
|
||||
@ -187,12 +203,18 @@ public class ServiceInfo {
|
||||
return getKey();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get {@link ServiceInfo} from key.
|
||||
*
|
||||
* @param key key of service info
|
||||
* @return new service info
|
||||
*/
|
||||
public static ServiceInfo fromKey(String key) {
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
int maxSegCount = 3;
|
||||
String[] segs = key.split(Constants.SERVICE_INFO_SPLITER);
|
||||
if (segs.length == maxSegCount -1) {
|
||||
if (segs.length == maxSegCount - 1) {
|
||||
serviceInfo.setGroupName(segs[0]);
|
||||
serviceInfo.setName(segs[1]);
|
||||
} else if (segs.length == maxSegCount) {
|
||||
@ -202,43 +224,33 @@ public class ServiceInfo {
|
||||
}
|
||||
return serviceInfo;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public static String getKey(String name, String clusters) {
|
||||
|
||||
if (!isEmpty(clusters)) {
|
||||
return name + Constants.SERVICE_INFO_SPLITER + clusters;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getKey();
|
||||
}
|
||||
|
||||
|
||||
public String getChecksum() {
|
||||
return checksum;
|
||||
}
|
||||
|
||||
|
||||
public void setChecksum(String checksum) {
|
||||
this.checksum = checksum;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isEmpty(String str) {
|
||||
return str == null || str.length() == 0;
|
||||
}
|
||||
|
||||
private static boolean strEquals(String str1, String str2) {
|
||||
return str1 == null ? str2 == null : str1.equals(str2);
|
||||
}
|
||||
|
||||
|
||||
private static boolean isEmpty(Collection coll) {
|
||||
return (coll == null || coll.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
private static boolean strEquals(String str1, String str2) {
|
||||
return str1 == null ? str2 == null : str1.equals(str2);
|
||||
}
|
||||
|
||||
private static final String EMPTY = "";
|
||||
|
||||
|
||||
private static final String ALL_IPS = "000--00-ALL_IPS--00--000";
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker.None;
|
||||
@ -25,28 +26,27 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||
|
||||
/**
|
||||
* Abstract health checker.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
|
||||
@JsonTypeInfo(use = Id.NAME, property = "type", defaultImpl = None.class)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(name = Http.TYPE, value = Http.class),
|
||||
@JsonSubTypes.Type(name = Mysql.TYPE, value = Mysql.class),
|
||||
@JsonSubTypes.Type(name = Tcp.TYPE, value = Tcp.class)
|
||||
})
|
||||
@JsonSubTypes({@JsonSubTypes.Type(name = Http.TYPE, value = Http.class),
|
||||
@JsonSubTypes.Type(name = Mysql.TYPE, value = Mysql.class),
|
||||
@JsonSubTypes.Type(name = Tcp.TYPE, value = Tcp.class)})
|
||||
public abstract class AbstractHealthChecker implements Cloneable {
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
protected final String type;
|
||||
|
||||
|
||||
protected AbstractHealthChecker(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clone all fields of this instance to another one.
|
||||
*
|
||||
@ -55,18 +55,18 @@ public abstract class AbstractHealthChecker implements Cloneable {
|
||||
*/
|
||||
@Override
|
||||
public abstract AbstractHealthChecker clone() throws CloneNotSupportedException;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of Health checker.
|
||||
*/
|
||||
public static class None extends AbstractHealthChecker {
|
||||
|
||||
|
||||
public static final String TYPE = "NONE";
|
||||
|
||||
|
||||
public None() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractHealthChecker clone() throws CloneNotSupportedException {
|
||||
return new None();
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
||||
@ -25,57 +26,75 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Health check type.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
public enum HealthCheckType {
|
||||
/**
|
||||
* TCP type
|
||||
* TCP type.
|
||||
*/
|
||||
TCP(Tcp.class),
|
||||
/**
|
||||
* HTTP type
|
||||
* HTTP type.
|
||||
*/
|
||||
HTTP(Http.class),
|
||||
/**
|
||||
* MySQL type
|
||||
* MySQL type.
|
||||
*/
|
||||
MYSQL(Mysql.class),
|
||||
/**
|
||||
* No check
|
||||
* No check.
|
||||
*/
|
||||
NONE(AbstractHealthChecker.None.class);
|
||||
|
||||
|
||||
private final Class<? extends AbstractHealthChecker> healthCheckerClass;
|
||||
|
||||
|
||||
/**
|
||||
* In JDK 1.6, the map need full class for general. So ignore check style.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:linelength")
|
||||
private static final Map<String, Class<? extends AbstractHealthChecker>> EXTEND = new ConcurrentHashMap<String, Class<? extends AbstractHealthChecker>>();
|
||||
|
||||
|
||||
HealthCheckType(Class<? extends AbstractHealthChecker> healthCheckerClass) {
|
||||
this.healthCheckerClass = healthCheckerClass;
|
||||
}
|
||||
|
||||
public static void registerHealthChecker(String type, Class<? extends AbstractHealthChecker> healthCheckerClass){
|
||||
|
||||
/**
|
||||
* Register extend health checker.
|
||||
*
|
||||
* @param type type name of extend health checker
|
||||
* @param healthCheckerClass class of extend health checker
|
||||
*/
|
||||
public static void registerHealthChecker(String type, Class<? extends AbstractHealthChecker> healthCheckerClass) {
|
||||
if (!EXTEND.containsKey(type)) {
|
||||
EXTEND.put(type, healthCheckerClass);
|
||||
HealthCheckerFactory.registerSubType(healthCheckerClass, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<? extends AbstractHealthChecker> ofHealthCheckerClass(String type){
|
||||
|
||||
/**
|
||||
* Get health checker class from type.
|
||||
*
|
||||
* @param type type name of extend health checker
|
||||
* @return registered class if have, otherwise default class
|
||||
*/
|
||||
public static Class<? extends AbstractHealthChecker> ofHealthCheckerClass(String type) {
|
||||
HealthCheckType enumType;
|
||||
try {
|
||||
enumType = valueOf(type);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return EXTEND.get(type);
|
||||
}
|
||||
return enumType.healthCheckerClass;
|
||||
}
|
||||
|
||||
public static List<Class<? extends AbstractHealthChecker>> getLoadedHealthCheckerClasses(){
|
||||
|
||||
public static List<Class<? extends AbstractHealthChecker>> getLoadedHealthCheckerClasses() {
|
||||
List<Class<? extends AbstractHealthChecker>> all = new ArrayList<Class<? extends AbstractHealthChecker>>();
|
||||
for(HealthCheckType type : values()){
|
||||
for (HealthCheckType type : values()) {
|
||||
all.add(type.healthCheckerClass);
|
||||
}
|
||||
for(Map.Entry<String, Class<? extends AbstractHealthChecker>> entry : EXTEND.entrySet()){
|
||||
for (Map.Entry<String, Class<? extends AbstractHealthChecker>> entry : EXTEND.entrySet()) {
|
||||
all.add(entry.getValue());
|
||||
}
|
||||
return all;
|
||||
|
@ -16,27 +16,27 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker.None;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* health checker factory.
|
||||
*
|
||||
* @author yangyi
|
||||
*/
|
||||
public class HealthCheckerFactory {
|
||||
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
|
||||
static {
|
||||
MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register new sub type of health checker to factory for serialize and deserialize.
|
||||
*
|
||||
@ -45,17 +45,18 @@ public class HealthCheckerFactory {
|
||||
public static void registerSubType(AbstractHealthChecker extendHealthChecker) {
|
||||
registerSubType(extendHealthChecker.getClass(), extendHealthChecker.getType());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register new sub type of health checker to factory for serialize and deserialize.
|
||||
*
|
||||
* @param extendHealthCheckerClass extend health checker
|
||||
* @param typeName typeName of health checker
|
||||
* @param typeName typeName of health checker
|
||||
*/
|
||||
public static void registerSubType(Class<? extends AbstractHealthChecker> extendHealthCheckerClass, String typeName) {
|
||||
public static void registerSubType(Class<? extends AbstractHealthChecker> extendHealthCheckerClass,
|
||||
String typeName) {
|
||||
MAPPER.registerSubtypes(new NamedType(extendHealthCheckerClass, typeName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create default {@link None} health checker.
|
||||
*
|
||||
@ -64,7 +65,7 @@ public class HealthCheckerFactory {
|
||||
public static None createNoneHealthChecker() {
|
||||
return new None();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserialize and create a instance of health checker.
|
||||
*
|
||||
@ -79,9 +80,9 @@ public class HealthCheckerFactory {
|
||||
throw new RuntimeException("Deserialize health checker from json failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialize a instance of health checker to json
|
||||
* Serialize a instance of health checker to json.
|
||||
*
|
||||
* @param healthChecker health checker instance
|
||||
* @return son string after serializing
|
||||
|
@ -25,23 +25,23 @@ import com.google.common.base.Objects;
|
||||
* @author yangyi
|
||||
*/
|
||||
public class Tcp extends AbstractHealthChecker {
|
||||
|
||||
|
||||
public static final String TYPE = "TCP";
|
||||
|
||||
|
||||
public Tcp() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(TYPE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Tcp;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Tcp clone() throws CloneNotSupportedException {
|
||||
return new Tcp();
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.selector;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@ -20,24 +21,24 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||
|
||||
/**
|
||||
* Abstract selector that only contains a type
|
||||
* Abstract selector that only contains a type.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
@JsonTypeInfo(use = Id.NAME, property = "type", defaultImpl = NoneSelector.class)
|
||||
public abstract class AbstractSelector {
|
||||
|
||||
|
||||
/**
|
||||
* The type of this selector, each child class should announce its own unique type.
|
||||
*/
|
||||
@JsonIgnore
|
||||
private final String type;
|
||||
|
||||
|
||||
protected AbstractSelector(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.selector;
|
||||
|
||||
/**
|
||||
@ -22,20 +23,20 @@ package com.alibaba.nacos.api.selector;
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public class ExpressionSelector extends AbstractSelector {
|
||||
|
||||
|
||||
/**
|
||||
* Label expression of this selector.
|
||||
*/
|
||||
private String expression;
|
||||
|
||||
|
||||
public ExpressionSelector() {
|
||||
super(SelectorType.label.name());
|
||||
}
|
||||
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
||||
public void setExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
@ -17,11 +17,13 @@
|
||||
package com.alibaba.nacos.api.selector;
|
||||
|
||||
/**
|
||||
* None selector.
|
||||
*
|
||||
* @author liaochuntao
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public class NoneSelector extends AbstractSelector {
|
||||
|
||||
|
||||
public NoneSelector() {
|
||||
super(SelectorType.none.name());
|
||||
}
|
||||
|
@ -13,25 +13,26 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.selector;
|
||||
|
||||
/**
|
||||
* The types of selector accepted by Nacos
|
||||
* The types of selector accepted by Nacos.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public enum SelectorType {
|
||||
/**
|
||||
* not match any type
|
||||
* not match any type.
|
||||
*/
|
||||
unknown,
|
||||
/**
|
||||
* not filter out any entity
|
||||
* not filter out any entity.
|
||||
*/
|
||||
none,
|
||||
/**
|
||||
* select by label
|
||||
* select by label.
|
||||
*/
|
||||
label
|
||||
}
|
||||
|
@ -13,5 +13,4 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
version=${project.version}
|
||||
|
@ -13,22 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.annotation;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.*;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.CLUSTER_NAME_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.CONTEXT_PATH_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ENCODE_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ENDPOINT_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_PLACEHOLDER;
|
||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER;
|
||||
|
||||
/**
|
||||
* {@link NacosProperties} Test
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.1
|
||||
*/
|
||||
public class NacosPropertiesTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testPlaceholders() {
|
||||
Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
||||
@ -40,43 +42,44 @@ public class NacosPropertiesTest {
|
||||
Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
||||
Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResolvePlaceholders() {
|
||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(NAMESPACE_PLACEHOLDER, "nacos.namespace", "test-value", "test-value");
|
||||
testResolvePlaceholder(NAMESPACE_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(ACCESS_KEY_PLACEHOLDER, "nacos.access-key", "test-value", "test-value");
|
||||
testResolvePlaceholder(ACCESS_KEY_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(SECRET_KEY_PLACEHOLDER, "nacos.secret-key", "test-value", "test-value");
|
||||
testResolvePlaceholder(SECRET_KEY_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(SERVER_ADDR_PLACEHOLDER, "nacos.server-addr", "test-value", "test-value");
|
||||
testResolvePlaceholder(SERVER_ADDR_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(CONTEXT_PATH_PLACEHOLDER, "nacos.context-path", "test-value", "test-value");
|
||||
testResolvePlaceholder(CONTEXT_PATH_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(CLUSTER_NAME_PLACEHOLDER, "nacos.cluster-name", "test-value", "test-value");
|
||||
testResolvePlaceholder(CLUSTER_NAME_PLACEHOLDER, "", "test-value", "");
|
||||
|
||||
|
||||
testResolvePlaceholder(ENCODE_PLACEHOLDER, "nacos.encode", "test-value", "test-value");
|
||||
testResolvePlaceholder(ENCODE_PLACEHOLDER, "", "test-value", "UTF-8");
|
||||
}
|
||||
|
||||
private void testResolvePlaceholder(String placeholder, String propertyName, String propertyValue, String expectValue) {
|
||||
|
||||
private void testResolvePlaceholder(String placeholder, String propertyName, String propertyValue,
|
||||
String expectValue) {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty(propertyName, propertyValue);
|
||||
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
||||
Assert.assertEquals(expectValue, resolvedValue);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSort() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -28,18 +29,18 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServiceInfoTest {
|
||||
|
||||
|
||||
private ObjectMapper mapper;
|
||||
|
||||
|
||||
private ServiceInfo serviceInfo;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
serviceInfo = new ServiceInfo("testName", "testClusters");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String actual = mapper.writeValueAsString(serviceInfo);
|
||||
@ -55,8 +56,9 @@ public class ServiceInfoTest {
|
||||
assertFalse(actual.contains("key"));
|
||||
assertFalse(actual.contains("keyEncoded"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("checkstyle:linelength")
|
||||
public void testDeserialize() throws IOException {
|
||||
String example = "{\"name\":\"testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
|
||||
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
|
||||
|
@ -16,28 +16,28 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AbstractHealthCheckerTest {
|
||||
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
TestChecker testChecker = new TestChecker();
|
||||
@ -46,7 +46,7 @@ public class AbstractHealthCheckerTest {
|
||||
assertTrue(actual.contains("\"testValue\":\"\""));
|
||||
assertTrue(actual.contains("\"type\":\"TEST\""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
||||
|
@ -16,22 +16,21 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class HealthCheckerFactoryTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialize() {
|
||||
Tcp tcp = new Tcp();
|
||||
String actual = HealthCheckerFactory.serialize(tcp);
|
||||
assertTrue(actual.contains("\"type\":\"TCP\""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerializeExtend() {
|
||||
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
|
||||
@ -39,14 +38,14 @@ public class HealthCheckerFactoryTest {
|
||||
String actual = HealthCheckerFactory.serialize(testChecker);
|
||||
assertTrue(actual.contains("\"type\":\"TEST\""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeserialize() {
|
||||
String tcpString = "{\"type\":\"TCP\"}";
|
||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||
assertEquals(Tcp.class, actual.getClass());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeserializeExtend() {
|
||||
String tcpString = "{\"type\":\"TEST\",\"testValue\":null}";
|
||||
|
@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||
|
||||
public class TestChecker extends AbstractHealthChecker {
|
||||
|
||||
|
||||
@JsonTypeInfo(use = Id.NAME, property = "type")
|
||||
public static final String TYPE = "TEST";
|
||||
|
||||
|
||||
private String testValue;
|
||||
|
||||
|
||||
public String getTestValue() {
|
||||
return testValue;
|
||||
}
|
||||
|
||||
|
||||
public void setTestValue(String testValue) {
|
||||
this.testValue = testValue;
|
||||
}
|
||||
|
||||
|
||||
public TestChecker() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractHealthChecker clone() throws CloneNotSupportedException {
|
||||
return null;
|
||||
|
@ -16,37 +16,36 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class HttpTest {
|
||||
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
private Http http;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
http = new Http();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetExpectedResponseCodeWithEmpty() {
|
||||
http.setHeaders("");
|
||||
assertTrue(http.getCustomHeaders().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetExpectedResponseCodeWithoutEmpty() {
|
||||
http.setHeaders("x:a|y:");
|
||||
@ -55,7 +54,7 @@ public class HttpTest {
|
||||
assertEquals(1, actual.size());
|
||||
assertEquals("a", actual.get("x"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
http.setHeaders("x:a|y:");
|
||||
@ -66,7 +65,7 @@ public class HttpTest {
|
||||
assertTrue(actual.contains("\"headers\":\"x:a|y:\""));
|
||||
assertTrue(actual.contains("\"expectedResponseCode\":200"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"HTTP\",\"path\":\"/x\",\"headers\":\"x:a|y:\",\"expectedResponseCode\":200}";
|
||||
|
@ -16,23 +16,22 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MysqlTest {
|
||||
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
private Mysql mysql;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mysql = new Mysql();
|
||||
@ -41,7 +40,7 @@ public class MysqlTest {
|
||||
mysql.setCmd("cmd");
|
||||
objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String actual = objectMapper.writeValueAsString(mysql);
|
||||
@ -50,7 +49,7 @@ public class MysqlTest {
|
||||
assertTrue(actual.contains("\"pwd\":\"pwd\""));
|
||||
assertTrue(actual.contains("\"cmd\":\"cmd\""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
String testChecker = "{\"type\":\"MYSQL\",\"user\":\"user\",\"pwd\":\"pwd\",\"cmd\":\"cmd\"}";
|
||||
|
Loading…
Reference in New Issue
Block a user