commit
5e53396f78
35
.github/stale.yml
vendored
Normal file
35
.github/stale.yml
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 180
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- good first issue
|
||||
- contribution welcome
|
||||
- dependencies
|
||||
- kind/bug
|
||||
- kind/code quality
|
||||
- kind/enhancement
|
||||
- kind/performance
|
||||
- kind/proposal
|
||||
- kind/refactor
|
||||
- kind/feature
|
||||
- kind/user experience
|
||||
- Soc2019
|
||||
- SoC2020
|
||||
- kind/notice
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: expired
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
Thanks for your feedback and contribution. But the issue/pull request has
|
||||
not had recent activity more than **180 days**. This issue/pull request will
|
||||
be closed if no further activity occurs **7 days later**.
|
||||
|
||||
We may solve this issue in new version. So can you upgrade to newest version
|
||||
and retry?
|
||||
|
||||
If there are still issues or want to contribute again. Please create new issue
|
||||
or pull request again.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
@ -29,6 +29,7 @@ before_install:
|
||||
script:
|
||||
- mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
|
||||
- mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
|
||||
- mvn clean install -Pcit-test
|
||||
- mvn clean package -Pit-test
|
||||
after_success:
|
||||
- mvn clean package -Pit-test
|
||||
|
4
NOTICE
4
NOTICE
@ -1,5 +1,5 @@
|
||||
Nacos
|
||||
Copyright 2018-2019 The Apache Software Foundation
|
||||
Copyright 2018-2020
|
||||
|
||||
This product includes software developed at
|
||||
The Alibaba MiddleWare Group.
|
||||
@ -29,4 +29,4 @@ under the License.
|
||||
|
||||
Also, please refer to each LICENSE.<component>.txt file, which is located in
|
||||
the 'license' directory of the distribution file, for the license terms of the
|
||||
components that this product depends on.
|
||||
components that this product depends on.
|
||||
|
@ -22,7 +22,7 @@ Nacos provides four major functions.
|
||||
|
||||
* **Dynamic Configuration Management**
|
||||
|
||||
Dynamic Configuration Service allows you to manage configurations of all services in a centralized and dynamic manner across all environments. Nacos eliminates the need to redeploy applications and services when configurations are updated,which makes configuration changes more efficient and agile.
|
||||
Dynamic Configuration Service allows you to manage configurations of all services in a centralized and dynamic manner across all environments. Nacos eliminates the need to redeploy applications and services when configurations are updated, which makes configuration changes more efficient and agile.
|
||||
|
||||
* **Dynamic DNS Service**
|
||||
|
||||
|
@ -1,54 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<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>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.1</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nacos-address</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<name>nacos-address ${project.version}</name>
|
||||
<url>http://nacos.io</url>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-naming</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-cmdb</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
@ -64,7 +62,7 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
@ -72,7 +70,7 @@
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -81,7 +79,7 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release-address</id>
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@ -26,8 +27,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos")
|
||||
public class AddressServer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
SpringApplication.run(AddressServer.class, args);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
@ -34,32 +35,38 @@ import java.util.List;
|
||||
*/
|
||||
@Component
|
||||
public class AddressServerGeneratorManager {
|
||||
|
||||
|
||||
/**
|
||||
* Generate product name.
|
||||
*
|
||||
* @param name name
|
||||
* @return product
|
||||
*/
|
||||
public String generateProductName(String name) {
|
||||
|
||||
|
||||
if (StringUtils.isBlank(name) || AddressServerConstants.DEFAULT_PRODUCT.equals(name)) {
|
||||
|
||||
|
||||
return AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME;
|
||||
}
|
||||
|
||||
|
||||
return String.format(AddressServerConstants.ALIWARE_NACOS_PRODUCT_DOM_TEMPLATE, name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Note: if the parameter inputted is empty then will return the empty list.
|
||||
*
|
||||
* @param serviceName
|
||||
* @param clusterName
|
||||
* @param ipArray
|
||||
* @return
|
||||
* @param serviceName service name
|
||||
* @param clusterName cluster name
|
||||
* @param ipArray array of ips
|
||||
* @return instance list
|
||||
*/
|
||||
public List<Instance> generateInstancesByIps(String serviceName, String rawProductName, String clusterName, String[] ipArray) {
|
||||
if (StringUtils.isEmpty(serviceName)
|
||||
|| StringUtils.isEmpty(clusterName)
|
||||
|| ipArray == null || ipArray.length == 0) {
|
||||
public List<Instance> generateInstancesByIps(String serviceName, String rawProductName, String clusterName,
|
||||
String[] ipArray) {
|
||||
if (StringUtils.isEmpty(serviceName) || StringUtils.isEmpty(clusterName) || ipArray == null
|
||||
|| ipArray.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
List<Instance> instanceList = new ArrayList<>(ipArray.length);
|
||||
for (String ip : ipArray) {
|
||||
String[] ipAndPort = generateIpAndPort(ip);
|
||||
@ -73,46 +80,50 @@ public class AddressServerGeneratorManager {
|
||||
instance.setEphemeral(false);
|
||||
instanceList.add(instance);
|
||||
}
|
||||
|
||||
|
||||
return instanceList;
|
||||
}
|
||||
|
||||
public String[] generateIpAndPort(String ip) {
|
||||
|
||||
|
||||
private String[] generateIpAndPort(String ip) {
|
||||
|
||||
int index = ip.indexOf(AddressServerConstants.IP_PORT_SEPARATOR);
|
||||
if (index != -1) {
|
||||
|
||||
return new String[]{ip.substring(0, index), ip.substring(index + 1)};
|
||||
|
||||
return new String[] {ip.substring(0, index), ip.substring(index + 1)};
|
||||
}
|
||||
|
||||
return new String[]{ip, String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)};
|
||||
|
||||
return new String[] {ip, String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate response ips.
|
||||
*
|
||||
* @param instanceList a instance set will generate string response to client.
|
||||
* @return the result of response to client
|
||||
*/
|
||||
public String generateResponseIps(List<Instance> instanceList) {
|
||||
|
||||
|
||||
StringBuilder ips = new StringBuilder();
|
||||
instanceList.forEach(instance -> {
|
||||
ips.append(instance.getIp() + ":" + instance.getPort());
|
||||
ips.append("\n");
|
||||
});
|
||||
|
||||
|
||||
return ips.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param rawServiceName the raw service name will not contains the {@Constans.DEFAULT_GROUP}
|
||||
* Generate nacos service name.
|
||||
*
|
||||
* @param rawServiceName the raw service name will not contains the {@link Constants#DEFAULT_GROUP}.
|
||||
* @return the nacos service name
|
||||
*/
|
||||
public String generateNacosServiceName(String rawServiceName) {
|
||||
|
||||
|
||||
if (rawServiceName.indexOf(Constants.DEFAULT_GROUP) != -1) {
|
||||
return rawServiceName;
|
||||
}
|
||||
|
||||
|
||||
return Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + rawServiceName;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,9 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.component;
|
||||
|
||||
import com.alibaba.nacos.address.constant.AddressServerConstants;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -28,51 +30,51 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class AddressServerManager {
|
||||
|
||||
|
||||
public String getRawProductName(String name) {
|
||||
|
||||
|
||||
if (StringUtils.isBlank(name) || AddressServerConstants.DEFAULT_PRODUCT.equals(name)) {
|
||||
|
||||
|
||||
return AddressServerConstants.DEFAULT_PRODUCT;
|
||||
}
|
||||
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* if the name is empty then return the default {@UtilAndCommons#DEFAULT_CLUSTER_NAME},
|
||||
* <p>
|
||||
* or return the source name by input
|
||||
* If the name is empty then return the default {@link UtilsAndCommons#DEFAULT_CLUSTER_NAME}, or return the source
|
||||
* name by input.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
* @param name name
|
||||
* @return default cluster name
|
||||
*/
|
||||
public String getDefaultClusterNameIfEmpty(String name) {
|
||||
|
||||
|
||||
if (StringUtils.isEmpty(name) || AddressServerConstants.DEFAULT_GET_CLUSTER.equals(name)) {
|
||||
return AddressServerConstants.DEFAULT_GET_CLUSTER;
|
||||
}
|
||||
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public String getRawClusterName(String name) {
|
||||
|
||||
|
||||
return getDefaultClusterNameIfEmpty(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Split ips.
|
||||
*
|
||||
* @param ips multi ip will separator by the ','
|
||||
* @return
|
||||
* @return array of ip
|
||||
*/
|
||||
public String[] splitIps(String ips) {
|
||||
|
||||
|
||||
if (StringUtils.isBlank(ips)) {
|
||||
|
||||
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
|
||||
return ips.split(AddressServerConstants.MULTI_IPS_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,64 +13,65 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.constant;
|
||||
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
||||
/**
|
||||
* Uniform constant parameter naming for address servers and default values for related parameters
|
||||
* Uniform constant parameter naming for address servers and default values for related parameters.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-06-17 7:23 PM
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public interface AddressServerConstants {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* the default server port when create the Instance object.
|
||||
*/
|
||||
int DEFAULT_SERVER_PORT = 8848;
|
||||
|
||||
|
||||
/**
|
||||
* when post ips is not given the product,then use the default.
|
||||
*/
|
||||
String DEFAULT_PRODUCT = "nacos";
|
||||
|
||||
|
||||
/**
|
||||
* the separator between ip and port.
|
||||
*/
|
||||
String IP_PORT_SEPARATOR = ":";
|
||||
|
||||
|
||||
/**
|
||||
* the separator for {@Service#name} between raw service name and group
|
||||
* the separator for service name between raw service name and group.
|
||||
*/
|
||||
String GROUP_SERVICE_NAME_SEP = "@@";
|
||||
|
||||
|
||||
/**
|
||||
* when post ips is not given the cluster,then use the default.
|
||||
*/
|
||||
String DEFAULT_GET_CLUSTER = "serverlist";
|
||||
|
||||
|
||||
/**
|
||||
* post multi ip will use the "," to separator
|
||||
* post multi ip will use the "," to separator.
|
||||
*/
|
||||
String MULTI_IPS_SEPARATOR = ",";
|
||||
|
||||
|
||||
/**
|
||||
* the default product name when deploy nacos with naming and config
|
||||
* the default product name when deploy nacos with naming and config.
|
||||
*/
|
||||
String ALIWARE_NACOS_DEFAULT_PRODUCT_NAME = "nacos.as.default";
|
||||
|
||||
|
||||
/**
|
||||
* when the config and naming will separate deploy,then must specify product name by the client。
|
||||
* when the config and naming will separate deploy,then must specify product name by the client.
|
||||
*/
|
||||
String ALIWARE_NACOS_PRODUCT_DOM_TEMPLATE = "nacos.as.%s";
|
||||
|
||||
|
||||
/**
|
||||
* the url for address server prefix
|
||||
* the url for address server prefix.
|
||||
*/
|
||||
String ADDRESS_SERVER_REQUEST_URL =
|
||||
UtilsAndCommons.NACOS_SERVER_CONTEXT + UtilsAndCommons.NACOS_SERVER_VERSION + "/as";
|
||||
|
||||
UtilsAndCommons.NACOS_SERVER_CONTEXT + UtilsAndCommons.NACOS_SERVER_VERSION + "/as";
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.controller;
|
||||
|
||||
import com.alibaba.nacos.address.component.AddressServerGeneratorManager;
|
||||
@ -38,46 +39,49 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Address server cluster controller.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-06-10 9:59 AM
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping({AddressServerConstants.ADDRESS_SERVER_REQUEST_URL + "/nodes"})
|
||||
public class AddressServerClusterController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ServiceManager serviceManager;
|
||||
|
||||
|
||||
@Autowired
|
||||
private AddressServerManager addressServerManager;
|
||||
|
||||
|
||||
@Autowired
|
||||
private AddressServerGeneratorManager addressServerGeneratorManager;
|
||||
|
||||
|
||||
/**
|
||||
* Create new cluster.
|
||||
*
|
||||
* @param product Ip list of products to be associated
|
||||
* @param cluster Ip list of product cluster to be associated
|
||||
* @param ips will post ip list.
|
||||
* @return
|
||||
* @return result of create new cluster
|
||||
*/
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public ResponseEntity postCluster(@RequestParam(required = false) String product,
|
||||
@RequestParam(required = false) String cluster,
|
||||
@RequestParam(name = "ips") String ips) {
|
||||
|
||||
@RequestParam(required = false) String cluster, @RequestParam(name = "ips") String ips) {
|
||||
|
||||
//1. prepare the storage name for product and cluster
|
||||
String productName = addressServerGeneratorManager.generateProductName(product);
|
||||
String clusterName = addressServerManager.getDefaultClusterNameIfEmpty(cluster);
|
||||
|
||||
|
||||
//2. prepare the response name for product and cluster to client
|
||||
String rawProductName = addressServerManager.getRawProductName(product);
|
||||
String rawClusterName = addressServerManager.getRawClusterName(cluster);
|
||||
Loggers.addressLogger.info("put cluster node,the cluster name is " + cluster + "; the product name=" + product + "; the ip list=" + ips);
|
||||
Loggers.ADDRESS_LOGGER.info("put cluster node,the cluster name is " + cluster + "; the product name=" + product
|
||||
+ "; the ip list=" + ips);
|
||||
ResponseEntity responseEntity;
|
||||
try {
|
||||
String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);
|
||||
|
||||
|
||||
Cluster clusterObj = new Cluster();
|
||||
clusterObj.setName(clusterName);
|
||||
clusterObj.setHealthChecker(new AbstractHealthChecker.None());
|
||||
@ -85,48 +89,54 @@ public class AddressServerClusterController {
|
||||
String[] ipArray = addressServerManager.splitIps(ips);
|
||||
String checkResult = AddressServerParamCheckUtil.checkIps(ipArray);
|
||||
if (AddressServerParamCheckUtil.CHECK_OK.equals(checkResult)) {
|
||||
List<Instance> instanceList = addressServerGeneratorManager.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
List<Instance> instanceList = addressServerGeneratorManager
|
||||
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
for (Instance instance : instanceList) {
|
||||
serviceManager.registerInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, instance);
|
||||
}
|
||||
responseEntity = ResponseEntity.ok("product=" + rawProductName + ",cluster=" + rawClusterName + "; put success with size=" + instanceList.size());
|
||||
responseEntity = ResponseEntity
|
||||
.ok("product=" + rawProductName + ",cluster=" + rawClusterName + "; put success with size="
|
||||
+ instanceList.size());
|
||||
} else {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(checkResult);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete cluster.
|
||||
*
|
||||
* @param product Ip list of products to be associated
|
||||
* @param cluster Ip list of product cluster to be associated
|
||||
* @param ips will delete ips.
|
||||
* @return
|
||||
* @return delete result
|
||||
*/
|
||||
@RequestMapping(value = "", method = RequestMethod.DELETE)
|
||||
public ResponseEntity deleteCluster(@RequestParam(required = false) String product,
|
||||
@RequestParam(required = false) String cluster,
|
||||
@RequestParam String ips) {
|
||||
@RequestParam(required = false) String cluster, @RequestParam String ips) {
|
||||
//1. prepare the storage name for product and cluster
|
||||
String productName = addressServerGeneratorManager.generateProductName(product);
|
||||
String clusterName = addressServerManager.getDefaultClusterNameIfEmpty(cluster);
|
||||
|
||||
|
||||
//2. prepare the response name for product and cluster to client
|
||||
String rawProductName = addressServerManager.getRawProductName(product);
|
||||
String rawClusterName = addressServerManager.getRawClusterName(cluster);
|
||||
ResponseEntity responseEntity = ResponseEntity.status(HttpStatus.OK).body("product=" + rawProductName + ", cluster=" + rawClusterName + " delete success.");
|
||||
ResponseEntity responseEntity = ResponseEntity.status(HttpStatus.OK)
|
||||
.body("product=" + rawProductName + ", cluster=" + rawClusterName + " delete success.");
|
||||
try {
|
||||
|
||||
|
||||
String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);
|
||||
Service service = serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, serviceName);
|
||||
|
||||
|
||||
if (service == null) {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + rawProductName + " not found.");
|
||||
responseEntity = ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body("product=" + rawProductName + " not found.");
|
||||
} else {
|
||||
|
||||
|
||||
if (StringUtils.isBlank(ips)) {
|
||||
// delete all ips from the cluster
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("ips must not be empty.");
|
||||
@ -135,19 +145,21 @@ public class AddressServerClusterController {
|
||||
String[] ipArray = addressServerManager.splitIps(ips);
|
||||
String checkResult = AddressServerParamCheckUtil.checkIps(ipArray);
|
||||
if (AddressServerParamCheckUtil.CHECK_OK.equals(checkResult)) {
|
||||
List<Instance> instanceList = addressServerGeneratorManager.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false, instanceList.toArray(new Instance[instanceList.size()]));
|
||||
List<Instance> instanceList = addressServerGeneratorManager
|
||||
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false,
|
||||
instanceList.toArray(new Instance[instanceList.size()]));
|
||||
} else {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(checkResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getCause());
|
||||
}
|
||||
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.controller;
|
||||
|
||||
import com.alibaba.nacos.address.component.AddressServerGeneratorManager;
|
||||
@ -29,42 +30,46 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Server list controller.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-06-18 5:04 PM
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@RestController
|
||||
public class ServerListController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ServiceManager serviceManager;
|
||||
|
||||
|
||||
@Autowired
|
||||
private AddressServerGeneratorManager addressServerBuilderManager;
|
||||
|
||||
|
||||
/**
|
||||
* Get cluster.
|
||||
*
|
||||
* @param product will get Ip list of that products to be associated
|
||||
* @param cluster will get Ip list of that product cluster to be associated
|
||||
* @return
|
||||
* @return result of get
|
||||
*/
|
||||
@RequestMapping(value = "/{product}/{cluster}", method = RequestMethod.GET)
|
||||
public ResponseEntity getCluster(@PathVariable String product,
|
||||
@PathVariable String cluster) {
|
||||
|
||||
public ResponseEntity getCluster(@PathVariable String product, @PathVariable String cluster) {
|
||||
|
||||
String productName = addressServerBuilderManager.generateProductName(product);
|
||||
String serviceName = addressServerBuilderManager.generateNacosServiceName(productName);
|
||||
Service service = serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, serviceName);
|
||||
if (service == null) {
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + product + " not found.");
|
||||
}
|
||||
|
||||
|
||||
if (!service.getClusterMap().containsKey(cluster)) {
|
||||
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + product + ",cluster=" + cluster + " not found.");
|
||||
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body("product=" + product + ",cluster=" + cluster + " not found.");
|
||||
}
|
||||
|
||||
|
||||
Cluster clusterObj = service.getClusterMap().get(cluster);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(addressServerBuilderManager.generateResponseIps(clusterObj.allIPs(false)));
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(addressServerBuilderManager.generateResponseIps(clusterObj.allIPs(false)));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,16 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.misc;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Loggers holder.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-07-04 4:34 PM
|
||||
*/
|
||||
public class Loggers {
|
||||
|
||||
public static final Logger addressLogger = LoggerFactory.getLogger("com.alibaba.nacos.address.main");
|
||||
|
||||
public static final Logger ADDRESS_LOGGER = LoggerFactory.getLogger("com.alibaba.nacos.address.main");
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,32 +13,39 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Provides a unified tool class for address server parameter verification
|
||||
* Provides a unified tool class for address server parameter verification.
|
||||
*
|
||||
* @author pbting
|
||||
* @date 2019-06-19 11:19 AM
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public class AddressServerParamCheckUtil {
|
||||
|
||||
|
||||
public static final String CHECK_OK = "ok";
|
||||
|
||||
|
||||
public static final String ILLEGAL_IP_PREFIX = "illegal ip: ";
|
||||
|
||||
|
||||
private static final String IP_REGEX = "(2(5[0-5]{1}|[0-4]\\d{1})|[0-1]?\\d{1,2})(\\.(2(5[0-5]{1}|[0-4]\\d{1})|[0-1]?\\d{1,2})){3}";
|
||||
|
||||
|
||||
private static final Pattern IP_PATTERN = Pattern.compile(IP_REGEX);
|
||||
|
||||
|
||||
/**
|
||||
* Check ips.
|
||||
*
|
||||
* @param ips ips
|
||||
* @return 'ok' if check passed, otherwise illegal ip
|
||||
*/
|
||||
public static String checkIps(String... ips) {
|
||||
|
||||
|
||||
if (ips == null || ips.length == 0) {
|
||||
|
||||
|
||||
return CHECK_OK;
|
||||
}
|
||||
// illegal response
|
||||
@ -50,11 +57,11 @@ public class AddressServerParamCheckUtil {
|
||||
}
|
||||
illegalResponse.append(ip + ",");
|
||||
}
|
||||
|
||||
|
||||
if (illegalResponse.length() == 0) {
|
||||
return CHECK_OK;
|
||||
}
|
||||
|
||||
|
||||
return ILLEGAL_IP_PREFIX + illegalResponse.substring(0, illegalResponse.length() - 1);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<included>
|
||||
<!--
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<included>
|
||||
|
||||
<springProperty scope="context" name="logPath" source="nacos.logs.path" defaultValue="${user.home}/nacos/logs"/>
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
|
||||
|
||||
<appender name="nacos-address"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_HOME}/nacos-address.log</file>
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_HOME}/nacos-address.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
|
||||
<maxFileSize>2GB</maxFileSize>
|
||||
<MaxHistory>15</MaxHistory>
|
||||
<maxHistory>15</maxHistory>
|
||||
<totalSizeCap>7GB</totalSizeCap>
|
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart>
|
||||
</rollingPolicy>
|
||||
@ -20,7 +36,7 @@
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="com.alibaba.nacos.address.main" additivity="false">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="nacos-address"/>
|
||||
|
@ -0,0 +1,16 @@
|
||||
#
|
||||
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
@ -1,2 +1,17 @@
|
||||
#
|
||||
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
server.port=8080
|
||||
server.servlet.context-path=/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address;
|
||||
|
||||
import org.junit.Ignore;
|
||||
@ -20,43 +21,39 @@ import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
* @date 2019-06-18 2:37 PM
|
||||
*/
|
||||
@Ignore
|
||||
public class AddressServerControllerTests {
|
||||
|
||||
|
||||
private static final String PRODUCT_NACOS = "nacos";
|
||||
|
||||
private static final String PRODUCT_CONFIG = "config";
|
||||
|
||||
private static final String PRODUCT_NAMING = "naming";
|
||||
|
||||
private static final String DEFAULT_URL_CLUSTER = "serverlist";
|
||||
|
||||
|
||||
private static final String GET_SERVERLIST_URL_FORMART = "http://127.0.0.1:8080/%s/%s";
|
||||
|
||||
|
||||
//-----------------product=nacos,cluster=DEFAULT -------------------//
|
||||
|
||||
/**
|
||||
* test the default product and cluster
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void postCluster() {
|
||||
|
||||
|
||||
String ips = "127.0.0.100,127.0.0.102,127.0.0.104";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("ips", ips);
|
||||
String response = SimpleHttpTestUtils.doPost("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getCluster() {
|
||||
|
||||
|
||||
String getUrl = String.format(GET_SERVERLIST_URL_FORMART, PRODUCT_NACOS, DEFAULT_URL_CLUSTER);
|
||||
String response = SimpleHttpTestUtils.doGet(getUrl, new HashMap<>(), "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteCluster() {
|
||||
HashMap<String, String> deleteIp = new HashMap<>();
|
||||
@ -64,7 +61,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doDelete("http://127.0.0.1:8080/nacos/v1/as/nodes", deleteIp, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteClusterWithSpecIp() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -72,26 +69,22 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doDelete("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void putCluster() {
|
||||
|
||||
|
||||
String ips = "127.0.0.114";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("ips", ips);
|
||||
String response = SimpleHttpTestUtils.doPut("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
//-----------------product=config,cluster=cluster01 -------------------//
|
||||
|
||||
/**
|
||||
* test with product
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
public void postClusterWithProduct() {
|
||||
|
||||
|
||||
String ips = "127.0.0.101,127.0.0.102,127.0.0.103";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("ips", ips);
|
||||
@ -99,7 +92,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doPost("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getClusterWithProduct() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -107,7 +100,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doGet(getUrl, params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteClusterWithProduct() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -115,7 +108,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doDelete("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteClusterWithProductAndIp() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -124,10 +117,10 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doDelete("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void putClusterWithProduct() {
|
||||
|
||||
|
||||
String ips = "127.0.0.196";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("ips", ips);
|
||||
@ -135,16 +128,12 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doPut("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------product=naming,cluster=cluster01 -------------------//
|
||||
|
||||
/**
|
||||
* test with product and cluster
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void postClusterWithProductAndCluster() {
|
||||
|
||||
|
||||
String ips = "127.0.0.100,127.0.0.200,127.0.0.31";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("ips", ips);
|
||||
@ -153,7 +142,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doPost("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getClusterWithProductAndCluster() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -161,7 +150,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doGet(getUrl, params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteClusterWithProductAndCluster() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -170,7 +159,7 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doDelete("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteClusterWithProductAndClusterAndIp() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
@ -180,10 +169,10 @@ public class AddressServerControllerTests {
|
||||
String response = SimpleHttpTestUtils.doDelete("http://127.0.0.1:8080/nacos/v1/as/nodes", params, "UTF-8");
|
||||
System.err.println(response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void putClusterWithProductAndCluster() {
|
||||
|
||||
|
||||
String ips = "127.0.0.171";
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("ips", ips);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,22 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address;
|
||||
|
||||
import com.alibaba.nacos.address.util.AddressServerParamCheckUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
* @date 2019-06-19 11:31 AM
|
||||
*/
|
||||
public class ParamCheckUtilTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void checkIps() {
|
||||
String[] ips = {"127.0.0.1"};
|
||||
System.out.println(AddressServerParamCheckUtil.checkIps(ips));
|
||||
|
||||
|
||||
String[] illlegalIps = {"127.100.19", "127.0.0.1"};
|
||||
System.err.println(AddressServerParamCheckUtil.checkIps(illlegalIps));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.address;
|
||||
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
@ -26,49 +27,46 @@ import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
* @date 2019-06-18 2:40 PM
|
||||
*/
|
||||
public class SimpleHttpTestUtils {
|
||||
|
||||
|
||||
private static final String REQUEST_METHOD_DELETE = "DELETE";
|
||||
|
||||
private static final String REQUEST_METHOD_PUT = "PUT";
|
||||
|
||||
private static final String REQUEST_METHOD_POST = "POST";
|
||||
|
||||
private static final String REQUEST_METHOD_GET = "GET";
|
||||
|
||||
|
||||
/**
|
||||
* 连接超时
|
||||
* 连接超时.
|
||||
*/
|
||||
private static int CONNECT_TIME_OUT = 2000;
|
||||
|
||||
private static final int CONNECT_TIME_OUT = 2000;
|
||||
|
||||
/**
|
||||
* 读取数据超时
|
||||
* 读取数据超时.
|
||||
*/
|
||||
private static int READ_TIME_OUT = 2000;
|
||||
|
||||
private static final int READ_TIME_OUT = 2000;
|
||||
|
||||
/**
|
||||
* 请求编码
|
||||
* 请求编码.
|
||||
*/
|
||||
public static String REQUEST_ENCODING = "UTF-8";
|
||||
|
||||
public static final String REQUEST_ENCODING = "UTF-8";
|
||||
|
||||
/**
|
||||
* 接收编码
|
||||
* 接收编码.
|
||||
*/
|
||||
public static String RESPONSE_ENCODING = "UTF-8";
|
||||
|
||||
public static final String RESPONSE_ENCODING = "UTF-8";
|
||||
|
||||
public static final short OK = 200;
|
||||
|
||||
public static final short Bad_Request = 400;
|
||||
|
||||
public static final short Internal_Server_Error = 500;
|
||||
|
||||
|
||||
public static final short BAD_REQUEST = 400;
|
||||
|
||||
public static final short INTERNAL_SERVER_ERROR = 500;
|
||||
|
||||
public static final short PARAM_ERROR_NO_ANALYSESOR = 1000;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 发送带参数的GET的HTTP请求
|
||||
* </pre>
|
||||
* 发送带参数的GET的HTTP请求.
|
||||
*
|
||||
* @param reqUrl HTTP请求URL
|
||||
* @param paramMap 参数映射表
|
||||
@ -77,11 +75,9 @@ public class SimpleHttpTestUtils {
|
||||
public static String doGet(String reqUrl, Map<String, String> paramMap, String recvEncoding) {
|
||||
return doRequest(reqUrl, paramMap, REQUEST_METHOD_GET, recvEncoding);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 发送带参数的POST的HTTP请求
|
||||
* </pre>
|
||||
* 发送带参数的POST的HTTP请求.
|
||||
*
|
||||
* @param reqUrl HTTP请求URL
|
||||
* @param paramMap 参数映射表
|
||||
@ -90,11 +86,9 @@ public class SimpleHttpTestUtils {
|
||||
public static String doPost(String reqUrl, Map<String, String> paramMap, String recvEncoding) {
|
||||
return doRequest(reqUrl, paramMap, REQUEST_METHOD_POST, recvEncoding);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 发送带参数的 PUT 的 HTTP 请求
|
||||
* </pre>
|
||||
* 发送带参数的 PUT 的 HTTP 请求.
|
||||
*
|
||||
* @param reqUrl HTTP请求URL
|
||||
* @param paramMap 参数映射表
|
||||
@ -103,11 +97,9 @@ public class SimpleHttpTestUtils {
|
||||
public static String doPut(String reqUrl, Map<String, String> paramMap, String recvEncoding) {
|
||||
return doRequest(reqUrl, paramMap, REQUEST_METHOD_PUT, recvEncoding);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 发送带参数的 DELETE 的 HTTP 请求
|
||||
* </pre>
|
||||
* 发送带参数的 DELETE 的 HTTP 请求.
|
||||
*
|
||||
* @param reqUrl HTTP请求URL
|
||||
* @param paramMap 参数映射表
|
||||
@ -116,13 +108,15 @@ public class SimpleHttpTestUtils {
|
||||
public static String doDelete(String reqUrl, Map<String, String> paramMap, String recvEncoding) {
|
||||
return doRequest(reqUrl, paramMap, REQUEST_METHOD_DELETE, recvEncoding);
|
||||
}
|
||||
|
||||
private static String doRequest(String reqUrl, Map<String, String> paramMap, String reqMethod, String recvEncoding) {
|
||||
|
||||
|
||||
private static String doRequest(String reqUrl, Map<String, String> paramMap, String reqMethod,
|
||||
String recvEncoding) {
|
||||
|
||||
return doExecute(reqUrl, paramMap, reqMethod, recvEncoding);
|
||||
}
|
||||
|
||||
private static String doExecute(String reqUrl, Map<String, String> paramMap, String reqMethod, String recvEncoding) {
|
||||
|
||||
private static String doExecute(String reqUrl, Map<String, String> paramMap, String reqMethod,
|
||||
String recvEncoding) {
|
||||
HttpURLConnection urlCon = null;
|
||||
String responseContent = null;
|
||||
try {
|
||||
@ -134,13 +128,13 @@ public class SimpleHttpTestUtils {
|
||||
params.append(URLEncoder.encode(element.getValue(), REQUEST_ENCODING));
|
||||
params.append("&");
|
||||
}
|
||||
|
||||
|
||||
if (params.length() > 0) {
|
||||
params = params.deleteCharAt(params.length() - 1);
|
||||
}
|
||||
|
||||
if (params.length() > 0 &&
|
||||
(REQUEST_METHOD_GET.equals(reqMethod) || REQUEST_METHOD_DELETE.equals(reqMethod))) {
|
||||
|
||||
if (params.length() > 0 && (REQUEST_METHOD_GET.equals(reqMethod) || REQUEST_METHOD_DELETE
|
||||
.equals(reqMethod))) {
|
||||
reqUrl = reqUrl + "?" + params.toString();
|
||||
}
|
||||
}
|
||||
@ -169,7 +163,7 @@ public class SimpleHttpTestUtils {
|
||||
responseContent = tempStr.toString();
|
||||
rd.close();
|
||||
in.close();
|
||||
|
||||
|
||||
urlCon.getResponseMessage();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -178,5 +172,5 @@ public class SimpleHttpTestUtils {
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
39
api/pom.xml
39
api/pom.xml
@ -1,29 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<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>
|
||||
<version>1.3.1</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>
|
||||
@ -38,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,27 +76,26 @@ 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
|
||||
*/
|
||||
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
|
||||
return NamingMaintainFactory.createMaintainService(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -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
|
||||
@ -58,5 +59,4 @@ public class ConfigFactory {
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
|
||||
return createConfigService(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,21 +88,27 @@ 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.
|
||||
*
|
||||
* @throws NacosException exception.
|
||||
*/
|
||||
void shutDown() throws NacosException;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 = the "License"");
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
@ -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;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 = the "License"");
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
@ -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
|
||||
*/
|
||||
|
@ -13,137 +13,145 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.exception;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Nacos Exception
|
||||
* Nacos Exception.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class NacosException extends Exception {
|
||||
|
||||
/**
|
||||
* serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = -3913902031489277776L;
|
||||
|
||||
private int errCode;
|
||||
|
||||
private String errMsg;
|
||||
|
||||
private Throwable causeThrowable;
|
||||
|
||||
public NacosException() {
|
||||
}
|
||||
|
||||
public NacosException(int errCode, String errMsg) {
|
||||
super(errMsg);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public NacosException(int errCode, Throwable throwable) {
|
||||
super(throwable);
|
||||
this.errCode = errCode;
|
||||
setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public NacosException(int errCode, String errMsg, Throwable throwable) {
|
||||
super(errMsg, throwable);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
if (!StringUtils.isBlank(this.errMsg)) {
|
||||
return errMsg;
|
||||
}
|
||||
if (this.causeThrowable != null) {
|
||||
return causeThrowable.getMessage();
|
||||
}
|
||||
return Constants.NULL;
|
||||
}
|
||||
|
||||
public void setErrCode(int errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public void setErrMsg(String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public void setCauseThrowable(Throwable throwable) {
|
||||
this.causeThrowable = getCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
private Throwable getCauseThrowable(Throwable t) {
|
||||
if (t.getCause() == null) {
|
||||
return t;
|
||||
}
|
||||
return getCauseThrowable(t.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ErrCode:" + getErrCode() + ", ErrMsg:" + getErrMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
* client error code
|
||||
* -400 -503 throw exception to user
|
||||
*/
|
||||
/**
|
||||
* invalid param(参数错误)
|
||||
*/
|
||||
public static final int CLIENT_INVALID_PARAM = -400;
|
||||
/**
|
||||
* over client threshold(超过server端的限流阈值)
|
||||
*/
|
||||
public static final int CLIENT_OVER_THRESHOLD = -503;
|
||||
|
||||
/**
|
||||
* server error code
|
||||
* 400 403 throw exception to user
|
||||
* 500 502 503 change ip and retry
|
||||
*/
|
||||
|
||||
/**
|
||||
* invalid param(参数错误)
|
||||
*/
|
||||
public static final int INVALID_PARAM = 400;
|
||||
/**
|
||||
* no right(鉴权失败)
|
||||
*/
|
||||
public static final int NO_RIGHT = 403;
|
||||
/**
|
||||
* not found
|
||||
*/
|
||||
public static final int NOT_FOUND = 404;
|
||||
/**
|
||||
* conflict(写并发冲突)
|
||||
*/
|
||||
public static final int CONFLICT = 409;
|
||||
/**
|
||||
* server error(server异常,如超时)
|
||||
*/
|
||||
public static final int SERVER_ERROR = 500;
|
||||
/**
|
||||
* bad gateway(路由异常,如nginx后面的Server挂掉)
|
||||
*/
|
||||
public static final int BAD_GATEWAY = 502;
|
||||
/**
|
||||
* over threshold(超过server端的限流阈值)
|
||||
*/
|
||||
public static final int OVER_THRESHOLD = 503;
|
||||
|
||||
public static final int RESOURCE_NOT_FOUND = -404;
|
||||
|
||||
|
||||
/**
|
||||
* serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -3913902031489277776L;
|
||||
|
||||
private int errCode;
|
||||
|
||||
private String errMsg;
|
||||
|
||||
private Throwable causeThrowable;
|
||||
|
||||
public NacosException() {
|
||||
}
|
||||
|
||||
public NacosException(final int errCode, final String errMsg) {
|
||||
super(errMsg);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public NacosException(final int errCode, final Throwable throwable) {
|
||||
super(throwable);
|
||||
this.errCode = errCode;
|
||||
this.setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public NacosException(final int errCode, final String errMsg, final Throwable throwable) {
|
||||
super(errMsg, throwable);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
this.setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return this.errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
if (!StringUtils.isBlank(this.errMsg)) {
|
||||
return this.errMsg;
|
||||
}
|
||||
if (this.causeThrowable != null) {
|
||||
return this.causeThrowable.getMessage();
|
||||
}
|
||||
return Constants.NULL;
|
||||
}
|
||||
|
||||
public void setErrCode(final int errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public void setErrMsg(final String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public void setCauseThrowable(final Throwable throwable) {
|
||||
this.causeThrowable = this.getCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
private Throwable getCauseThrowable(final Throwable t) {
|
||||
if (t.getCause() == null) {
|
||||
return t;
|
||||
}
|
||||
return this.getCauseThrowable(t.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ErrCode:" + getErrCode() + ", ErrMsg:" + getErrMsg();
|
||||
}
|
||||
|
||||
/*
|
||||
* client error code.
|
||||
* -400 -503 throw exception to user.
|
||||
*/
|
||||
|
||||
/**
|
||||
* invalid param(参数错误).
|
||||
*/
|
||||
public static final int CLIENT_INVALID_PARAM = -400;
|
||||
|
||||
/**
|
||||
* over client threshold(超过server端的限流阈值).
|
||||
*/
|
||||
public static final int CLIENT_OVER_THRESHOLD = -503;
|
||||
|
||||
/*
|
||||
* server error code.
|
||||
* 400 403 throw exception to user
|
||||
* 500 502 503 change ip and retry
|
||||
*/
|
||||
|
||||
/**
|
||||
* invalid param(参数错误).
|
||||
*/
|
||||
public static final int INVALID_PARAM = 400;
|
||||
|
||||
/**
|
||||
* no right(鉴权失败).
|
||||
*/
|
||||
public static final int NO_RIGHT = 403;
|
||||
|
||||
/**
|
||||
* not found.
|
||||
*/
|
||||
public static final int NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* conflict(写并发冲突).
|
||||
*/
|
||||
public static final int CONFLICT = 409;
|
||||
|
||||
/**
|
||||
* server error(server异常,如超时).
|
||||
*/
|
||||
public static final int SERVER_ERROR = 500;
|
||||
|
||||
/**
|
||||
* bad gateway(路由异常,如nginx后面的Server挂掉).
|
||||
*/
|
||||
public static final int BAD_GATEWAY = 502;
|
||||
|
||||
/**
|
||||
* over threshold(超过server端的限流阈值).
|
||||
*/
|
||||
public static final int OVER_THRESHOLD = 503;
|
||||
|
||||
public static final int RESOURCE_NOT_FOUND = -404;
|
||||
}
|
||||
|
@ -16,41 +16,51 @@
|
||||
|
||||
package com.alibaba.nacos.api.exception.runtime;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Nacos deserialization exception.
|
||||
*
|
||||
* @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,231 +336,245 @@ 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.
|
||||
*
|
||||
* @throws NacosException exception.
|
||||
*/
|
||||
void shutDown() throws NacosException;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -13,238 +13,240 @@
|
||||
* 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;
|
||||
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.api.common.Constants.NUMBER_PATTERN;
|
||||
|
||||
/**
|
||||
* Instance
|
||||
* Instance.
|
||||
*
|
||||
* @author nkorange
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public class Instance {
|
||||
|
||||
|
||||
/**
|
||||
* unique id of this instance.
|
||||
*/
|
||||
private String instanceId;
|
||||
|
||||
|
||||
/**
|
||||
* instance ip
|
||||
* instance ip.
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
|
||||
/**
|
||||
* instance port
|
||||
* instance port.
|
||||
*/
|
||||
private int port;
|
||||
|
||||
|
||||
/**
|
||||
* instance weight
|
||||
* instance weight.
|
||||
*/
|
||||
private double weight = 1.0D;
|
||||
|
||||
|
||||
/**
|
||||
* instance health status
|
||||
* instance health status.
|
||||
*/
|
||||
private boolean healthy = true;
|
||||
|
||||
|
||||
/**
|
||||
* If instance is enabled to accept request
|
||||
* If instance is enabled to accept request.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
|
||||
/**
|
||||
* If instance is ephemeral
|
||||
* If instance is ephemeral.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private boolean ephemeral = true;
|
||||
|
||||
|
||||
/**
|
||||
* cluster information of instance
|
||||
* cluster information of instance.
|
||||
*/
|
||||
private String clusterName;
|
||||
|
||||
|
||||
/**
|
||||
* Service information of instance
|
||||
* Service information of instance.
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
|
||||
/**
|
||||
* user extended attributes
|
||||
* user extended attributes.
|
||||
*/
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
return this.instanceId;
|
||||
}
|
||||
|
||||
public void setInstanceId(String instanceId) {
|
||||
|
||||
public void setInstanceId(final String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
|
||||
public void setIp(final String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
|
||||
public void setPort(final int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public double getWeight() {
|
||||
return weight;
|
||||
return this.weight;
|
||||
}
|
||||
|
||||
public void setWeight(double weight) {
|
||||
|
||||
public void setWeight(final double weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
|
||||
public boolean isHealthy() {
|
||||
return healthy;
|
||||
return this.healthy;
|
||||
}
|
||||
|
||||
public void setHealthy(boolean healthy) {
|
||||
|
||||
public void setHealthy(final boolean healthy) {
|
||||
this.healthy = healthy;
|
||||
}
|
||||
|
||||
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
return this.clusterName;
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
|
||||
public void setClusterName(final String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
return this.serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
|
||||
public void setServiceName(final String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
|
||||
public void setMetadata(final Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public void addMetadata(String key, String value) {
|
||||
if (this.metadata == null) {
|
||||
this.metadata = new HashMap<String, String>(4);
|
||||
|
||||
/**
|
||||
* add meta data.
|
||||
*
|
||||
* @param key meta data key
|
||||
* @param value meta data value
|
||||
*/
|
||||
public void addMetadata(final String key, final String value) {
|
||||
if (metadata == null) {
|
||||
metadata = new HashMap<String, String>(4);
|
||||
}
|
||||
this.metadata.put(key, value);
|
||||
metadata.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
public boolean isEphemeral() {
|
||||
return ephemeral;
|
||||
return this.ephemeral;
|
||||
}
|
||||
|
||||
public void setEphemeral(boolean ephemeral) {
|
||||
|
||||
public void setEphemeral(final boolean ephemeral) {
|
||||
this.ephemeral = ephemeral;
|
||||
}
|
||||
|
||||
|
||||
@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() {
|
||||
return ip + ":" + port;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof Instance)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Instance host = (Instance) obj;
|
||||
return strEquals(host.toString(), toString());
|
||||
|
||||
final Instance host = (Instance) obj;
|
||||
return Instance.strEquals(host.toString(), toString());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
private static boolean strEquals(String str1, String str2) {
|
||||
|
||||
private static boolean strEquals(final String str1, final String str2) {
|
||||
return str1 == null ? str2 == null : str1.equals(str2);
|
||||
}
|
||||
|
||||
|
||||
public long getInstanceHeartBeatInterval() {
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.HEART_BEAT_INTERVAL, Constants.DEFAULT_HEART_BEAT_INTERVAL);
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.HEART_BEAT_INTERVAL,
|
||||
Constants.DEFAULT_HEART_BEAT_INTERVAL);
|
||||
}
|
||||
|
||||
|
||||
public long getInstanceHeartBeatTimeOut() {
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, Constants.DEFAULT_HEART_BEAT_TIMEOUT);
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.HEART_BEAT_TIMEOUT,
|
||||
Constants.DEFAULT_HEART_BEAT_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
public long getIpDeleteTimeout() {
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.IP_DELETE_TIMEOUT, Constants.DEFAULT_IP_DELETE_TIMEOUT);
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.IP_DELETE_TIMEOUT,
|
||||
Constants.DEFAULT_IP_DELETE_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
public String getInstanceIdGenerator() {
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, Constants.DEFAULT_INSTANCE_ID_GENERATOR);
|
||||
return getMetaDataByKeyWithDefault(PreservedMetadataKeys.INSTANCE_ID_GENERATOR,
|
||||
Constants.DEFAULT_INSTANCE_ID_GENERATOR);
|
||||
}
|
||||
|
||||
private long getMetaDataByKeyWithDefault( String key, long defaultValue) {
|
||||
|
||||
private long getMetaDataByKeyWithDefault(final String key, final long defaultValue) {
|
||||
if (getMetadata() == null || getMetadata().isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
String value = getMetadata().get(key);
|
||||
final String value = getMetadata().get(key);
|
||||
if (!StringUtils.isEmpty(value) && value.matches(NUMBER_PATTERN)) {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private String getMetaDataByKeyWithDefault( String key, String defaultValue) {
|
||||
|
||||
private String getMetaDataByKeyWithDefault(final String key, final String defaultValue) {
|
||||
if (getMetadata() == null || getMetadata().isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
return getMetadata().get(key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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,29 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosSerializationException;
|
||||
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 +47,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 +67,7 @@ public class HealthCheckerFactory {
|
||||
public static None createNoneHealthChecker() {
|
||||
return new None();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserialize and create a instance of health checker.
|
||||
*
|
||||
@ -75,13 +78,12 @@ public class HealthCheckerFactory {
|
||||
try {
|
||||
return MAPPER.readValue(jsonString, AbstractHealthChecker.class);
|
||||
} catch (IOException e) {
|
||||
// TODO replace with NacosDeserializeException.
|
||||
throw new RuntimeException("Deserialize health checker from json failed", e);
|
||||
throw new NacosDeserializationException(AbstractHealthChecker.class, 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
|
||||
@ -90,8 +92,7 @@ public class HealthCheckerFactory {
|
||||
try {
|
||||
return MAPPER.writeValueAsString(healthChecker);
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO replace with NacosSerializeException.
|
||||
throw new RuntimeException("Serialize health checker to json failed", e);
|
||||
throw new NacosSerializationException(healthChecker.getClass(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.google.common.base.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -32,50 +32,51 @@ import java.util.Map;
|
||||
* @author yangyi
|
||||
*/
|
||||
public class Http extends AbstractHealthChecker {
|
||||
|
||||
public static final String TYPE = "HTTP";
|
||||
|
||||
|
||||
private String path = "";
|
||||
|
||||
|
||||
private String headers = "";
|
||||
|
||||
|
||||
private int expectedResponseCode = 200;
|
||||
|
||||
|
||||
public Http() {
|
||||
super(TYPE);
|
||||
super(Http.TYPE);
|
||||
}
|
||||
|
||||
|
||||
public int getExpectedResponseCode() {
|
||||
return expectedResponseCode;
|
||||
return this.expectedResponseCode;
|
||||
}
|
||||
|
||||
public void setExpectedResponseCode(int expectedResponseCode) {
|
||||
|
||||
public void setExpectedResponseCode(final int expectedResponseCode) {
|
||||
this.expectedResponseCode = expectedResponseCode;
|
||||
}
|
||||
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
|
||||
public void setPath(final String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
||||
public String getHeaders() {
|
||||
return headers;
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
public void setHeaders(String headers) {
|
||||
|
||||
public void setHeaders(final String headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
public Map<String, String> getCustomHeaders() {
|
||||
if (StringUtils.isBlank(headers)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, String> headerMap = new HashMap<String, String>(16);
|
||||
for (String s : headers.split(Constants.NAMING_HTTP_HEADER_SPILIER)) {
|
||||
String[] splits = s.split(":");
|
||||
final Map<String, String> headerMap = new HashMap<String, String>(16);
|
||||
for (final String s : headers.split(Constants.NAMING_HTTP_HEADER_SPILIER)) {
|
||||
final String[] splits = s.split(":");
|
||||
if (splits.length != 2) {
|
||||
continue;
|
||||
}
|
||||
@ -83,24 +84,24 @@ public class Http extends AbstractHealthChecker {
|
||||
}
|
||||
return headerMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(path, headers, expectedResponseCode);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof Http)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Http other = (Http) obj;
|
||||
|
||||
|
||||
final Http other = (Http) obj;
|
||||
|
||||
if (!StringUtils.equals(type, other.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!StringUtils.equals(path, other.getPath())) {
|
||||
return false;
|
||||
}
|
||||
@ -109,13 +110,13 @@ public class Http extends AbstractHealthChecker {
|
||||
}
|
||||
return expectedResponseCode == other.getExpectedResponseCode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Http clone() throws CloneNotSupportedException {
|
||||
Http config = new Http();
|
||||
config.setPath(this.getPath());
|
||||
config.setHeaders(this.getHeaders());
|
||||
config.setExpectedResponseCode(this.getExpectedResponseCode());
|
||||
final Http config = new Http();
|
||||
config.setPath(getPath());
|
||||
config.setHeaders(getHeaders());
|
||||
config.setExpectedResponseCode(getExpectedResponseCode());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,8 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
@ -27,72 +26,73 @@ import com.google.common.base.Objects;
|
||||
* @author yangyi
|
||||
*/
|
||||
public class Mysql extends AbstractHealthChecker {
|
||||
|
||||
public static final String TYPE = "MYSQL";
|
||||
|
||||
|
||||
private String user;
|
||||
|
||||
|
||||
private String pwd;
|
||||
|
||||
|
||||
private String cmd;
|
||||
|
||||
|
||||
public Mysql() {
|
||||
super(TYPE);
|
||||
super(Mysql.TYPE);
|
||||
}
|
||||
|
||||
|
||||
public String getCmd() {
|
||||
return cmd;
|
||||
return this.cmd;
|
||||
}
|
||||
|
||||
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
return this.pwd;
|
||||
}
|
||||
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
|
||||
public void setUser(final String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setCmd(String cmd) {
|
||||
|
||||
public void setCmd(final String cmd) {
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
|
||||
public void setPwd(final String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(user, pwd, cmd);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (!(obj instanceof Mysql)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Mysql other = (Mysql) obj;
|
||||
|
||||
|
||||
final Mysql other = (Mysql) obj;
|
||||
|
||||
if (!StringUtils.equals(user, other.getUser())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!StringUtils.equals(pwd, other.getPwd())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return StringUtils.equals(cmd, other.getCmd());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mysql clone() throws CloneNotSupportedException {
|
||||
Mysql config = new Mysql();
|
||||
config.setUser(this.getUser());
|
||||
config.setPwd(this.getPwd());
|
||||
config.setCmd(this.getCmd());
|
||||
final Mysql config = new Mysql();
|
||||
config.setUser(getUser());
|
||||
config.setPwd(getPwd());
|
||||
config.setCmd(getCmd());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -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,26 +13,26 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.naming.utils;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* NamingUtils.
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class NamingUtils {
|
||||
|
||||
public static String getGroupedName(String serviceName, String groupName) {
|
||||
StringBuilder resultGroupedName = new StringBuilder()
|
||||
.append(groupName)
|
||||
.append(Constants.SERVICE_INFO_SPLITER)
|
||||
.append(serviceName);
|
||||
return resultGroupedName.toString().intern();
|
||||
|
||||
public static String getGroupedName(final String serviceName, final String groupName) {
|
||||
final String resultGroupedName = groupName + Constants.SERVICE_INFO_SPLITER + serviceName;
|
||||
return resultGroupedName.intern();
|
||||
}
|
||||
|
||||
public static String getServiceName(String serviceNameWithGroup) {
|
||||
|
||||
public static String getServiceName(final String serviceNameWithGroup) {
|
||||
if (StringUtils.isBlank(serviceNameWithGroup)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
@ -41,8 +41,8 @@ public class NamingUtils {
|
||||
}
|
||||
return serviceNameWithGroup.split(Constants.SERVICE_INFO_SPLITER)[1];
|
||||
}
|
||||
|
||||
public static String getGroupName(String serviceNameWithGroup) {
|
||||
|
||||
public static String getGroupName(final String serviceNameWithGroup) {
|
||||
if (StringUtils.isBlank(serviceNameWithGroup)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
187
api/src/main/java/com/alibaba/nacos/api/utils/StringUtils.java
Normal file
187
api/src/main/java/com/alibaba/nacos/api/utils/StringUtils.java
Normal file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.api.utils;
|
||||
|
||||
/**
|
||||
* StringUtils. copy from apache common-lang3.
|
||||
*
|
||||
* @author <a href="mailto:lin-mt@outlook.com">lin-mt</a>
|
||||
*/
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* The empty String {@code ""}.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final String EMPTY = "";
|
||||
|
||||
/**
|
||||
* <p>Checks if a CharSequence is empty ("") or null.</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.isEmpty(null) = true
|
||||
* StringUtils.isEmpty("") = true
|
||||
* StringUtils.isEmpty(" ") = false
|
||||
* StringUtils.isEmpty("bob") = false
|
||||
* StringUtils.isEmpty(" bob ") = false
|
||||
* </pre>
|
||||
*
|
||||
* <p>NOTE: This method changed in Lang version 2.0.
|
||||
* It no longer trims the CharSequence. That functionality is available in isBlank().</p>
|
||||
*
|
||||
* @param cs the CharSequence to check, may be null
|
||||
* @return {@code true} if the CharSequence is empty or null
|
||||
* @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
|
||||
*/
|
||||
public static boolean isEmpty(final CharSequence cs) {
|
||||
return cs == null || cs.length() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.isBlank(null) = true
|
||||
* StringUtils.isBlank("") = true
|
||||
* StringUtils.isBlank(" ") = true
|
||||
* StringUtils.isBlank("bob") = false
|
||||
* StringUtils.isBlank(" bob ") = false
|
||||
* </pre>
|
||||
*
|
||||
* @param cs the CharSequence to check, may be null
|
||||
* @return {@code true} if the CharSequence is null, empty or whitespace
|
||||
* @since 2.0
|
||||
* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
|
||||
*/
|
||||
public static boolean isBlank(final CharSequence cs) {
|
||||
final int strLen;
|
||||
if (cs == null || (strLen = cs.length()) == 0) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Trim
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Removes control characters (char <= 32) from both
|
||||
* ends of this String, handling {@code null} by returning {@code null}.</p>
|
||||
*
|
||||
* <p>The String is trimmed using {@link String#trim()}.
|
||||
* Trim removes start and end characters <= 32.</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.trim(null) = null
|
||||
* StringUtils.trim("") = ""
|
||||
* StringUtils.trim(" ") = ""
|
||||
* StringUtils.trim("abc") = "abc"
|
||||
* StringUtils.trim(" abc ") = "abc"
|
||||
* </pre>
|
||||
*
|
||||
* @param str the String to be trimmed, may be null
|
||||
* @return the trimmed string, {@code null} if null String input
|
||||
*/
|
||||
public static String trim(final String str) {
|
||||
return str == null ? null : str.trim();
|
||||
}
|
||||
|
||||
// Equals
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Compares two CharSequences, returning {@code true} if they represent
|
||||
* equal sequences of characters.</p>
|
||||
*
|
||||
* <p>{@code null}s are handled without exceptions. Two {@code null}
|
||||
* references are considered to be equal. The comparison is case sensitive.</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.equals(null, null) = true
|
||||
* StringUtils.equals(null, "abc") = false
|
||||
* StringUtils.equals("abc", null) = false
|
||||
* StringUtils.equals("abc", "abc") = true
|
||||
* StringUtils.equals("abc", "ABC") = false
|
||||
* </pre>
|
||||
*
|
||||
* @param cs1 the first CharSequence, may be {@code null}
|
||||
* @param cs2 the second CharSequence, may be {@code null}
|
||||
* @return {@code true} if the CharSequences are equal (case-sensitive), or both {@code null}
|
||||
* @see Object#equals(Object)
|
||||
* @since 3.0 Changed signature from equals(String, String) to equals(CharSequence, CharSequence)
|
||||
*/
|
||||
public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
|
||||
if (cs1 == cs2) {
|
||||
return true;
|
||||
}
|
||||
if (cs1 == null || cs2 == null) {
|
||||
return false;
|
||||
}
|
||||
if (cs1 instanceof String && cs2 instanceof String) {
|
||||
return cs1.equals(cs2);
|
||||
}
|
||||
return StringUtils.regionMatches(cs1, false, 0, cs2, 0, Math.max(cs1.length(), cs2.length()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Green implementation of regionMatches.
|
||||
*
|
||||
* @param cs the {@code CharSequence} to be processed
|
||||
* @param ignoreCase whether or not to be case insensitive
|
||||
* @param thisStart the index to start on the {@code cs} CharSequence
|
||||
* @param substring the {@code CharSequence} to be looked for
|
||||
* @param start the index to start on the {@code substring} CharSequence
|
||||
* @param length character length of the region
|
||||
* @return whether the region matched
|
||||
*/
|
||||
public static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,
|
||||
final CharSequence substring, final int start, final int length) {
|
||||
if (cs instanceof String && substring instanceof String) {
|
||||
return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length);
|
||||
}
|
||||
int index1 = thisStart;
|
||||
int index2 = start;
|
||||
int tmpLen = length;
|
||||
|
||||
while (tmpLen-- > 0) {
|
||||
final char c1 = cs.charAt(index1++);
|
||||
final char c2 = substring.charAt(index2++);
|
||||
|
||||
if (c1 == c2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ignoreCase) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The same check as in String.regionMatches():
|
||||
if (Character.toUpperCase(c1) != Character.toUpperCase(c2) && Character.toLowerCase(c1) != Character
|
||||
.toLowerCase(c2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1 +1,16 @@
|
||||
version=${project.version}
|
||||
#
|
||||
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
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,23 +21,26 @@ 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.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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);
|
||||
@ -53,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 ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
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,21 +16,21 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||
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);
|
||||
@ -38,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,22 +16,22 @@
|
||||
|
||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
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();
|
||||
@ -40,7 +40,7 @@ public class MysqlTest {
|
||||
mysql.setCmd("cmd");
|
||||
objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws JsonProcessingException {
|
||||
String actual = objectMapper.writeValueAsString(mysql);
|
||||
@ -49,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\"}";
|
||||
|
@ -1,111 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<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>
|
||||
<version>1.3.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<name>nacos-client ${project.version}</name>
|
||||
<url>http://nacos.io</url>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.jcip</groupId>
|
||||
<artifactId>jcip-annotations</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>io.prometheus</groupId>
|
||||
<artifactId>simpleclient</artifactId>
|
||||
@ -119,17 +128,17 @@
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.client.config;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
@ -34,7 +35,7 @@ import com.alibaba.nacos.client.config.utils.ParamUtils;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.ValidatorUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -45,129 +46,135 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Config Impl
|
||||
* Config Impl.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
||||
public class NacosConfigService implements ConfigService {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LogUtils.logger(NacosConfigService.class);
|
||||
|
||||
|
||||
private static final long POST_TIMEOUT = 3000L;
|
||||
|
||||
|
||||
/**
|
||||
* http agent
|
||||
* http agent.
|
||||
*/
|
||||
private HttpAgent agent;
|
||||
private final HttpAgent agent;
|
||||
|
||||
/**
|
||||
* longpolling
|
||||
* long polling.
|
||||
*/
|
||||
private ClientWorker worker;
|
||||
private final ClientWorker worker;
|
||||
|
||||
private String namespace;
|
||||
private String encode;
|
||||
private ConfigFilterChainManager configFilterChainManager = new ConfigFilterChainManager();
|
||||
|
||||
|
||||
private final String encode;
|
||||
|
||||
private final ConfigFilterChainManager configFilterChainManager = new ConfigFilterChainManager();
|
||||
|
||||
public NacosConfigService(Properties properties) throws NacosException {
|
||||
ValidatorUtils.checkInitParam(properties);
|
||||
String encodeTmp = properties.getProperty(PropertyKeyConst.ENCODE);
|
||||
if (StringUtils.isBlank(encodeTmp)) {
|
||||
encode = Constants.ENCODE;
|
||||
this.encode = Constants.ENCODE;
|
||||
} else {
|
||||
encode = encodeTmp.trim();
|
||||
this.encode = encodeTmp.trim();
|
||||
}
|
||||
initNamespace(properties);
|
||||
agent = new MetricsHttpAgent(new ServerHttpAgent(properties));
|
||||
agent.start();
|
||||
worker = new ClientWorker(agent, configFilterChainManager, properties);
|
||||
|
||||
this.agent = new MetricsHttpAgent(new ServerHttpAgent(properties));
|
||||
this.agent.start();
|
||||
this.worker = new ClientWorker(this.agent, this.configFilterChainManager, properties);
|
||||
}
|
||||
|
||||
|
||||
private void initNamespace(Properties properties) {
|
||||
namespace = ParamUtil.parseNamespace(properties);
|
||||
properties.put(PropertyKeyConst.NAMESPACE, namespace);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getConfig(String dataId, String group, long timeoutMs) throws NacosException {
|
||||
return getConfigInner(namespace, dataId, group, timeoutMs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener) throws NacosException {
|
||||
public String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener)
|
||||
throws NacosException {
|
||||
String content = getConfig(dataId, group, timeoutMs);
|
||||
worker.addTenantListenersWithContent(dataId, group, content, Arrays.asList(listener));
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addListener(String dataId, String group, Listener listener) throws NacosException {
|
||||
worker.addTenantListeners(dataId, group, Arrays.asList(listener));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean publishConfig(String dataId, String group, String content) throws NacosException {
|
||||
return publishConfigInner(namespace, dataId, group, null, null, null, content);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeConfig(String dataId, String group) throws NacosException {
|
||||
return removeConfigInner(namespace, dataId, group, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeListener(String dataId, String group, Listener listener) {
|
||||
worker.removeTenantListener(dataId, group, listener);
|
||||
}
|
||||
|
||||
|
||||
private String getConfigInner(String tenant, String dataId, String group, long timeoutMs) throws NacosException {
|
||||
group = null2defaultGroup(group);
|
||||
ParamUtils.checkKeyParam(dataId, group);
|
||||
ConfigResponse cr = new ConfigResponse();
|
||||
|
||||
|
||||
cr.setDataId(dataId);
|
||||
cr.setTenant(tenant);
|
||||
cr.setGroup(group);
|
||||
|
||||
|
||||
// 优先使用本地配置
|
||||
String content = LocalConfigInfoProcessor.getFailover(agent.getName(), dataId, group, tenant);
|
||||
if (content != null) {
|
||||
LOGGER.warn("[{}] [get-config] get failover ok, dataId={}, group={}, tenant={}, config={}", agent.getName(),
|
||||
dataId, group, tenant, ContentUtils.truncateContent(content));
|
||||
dataId, group, tenant, ContentUtils.truncateContent(content));
|
||||
cr.setContent(content);
|
||||
configFilterChainManager.doFilter(null, cr);
|
||||
content = cr.getContent();
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
String[] ct = worker.getServerConfig(dataId, group, tenant, timeoutMs);
|
||||
cr.setContent(ct[0]);
|
||||
|
||||
|
||||
configFilterChainManager.doFilter(null, cr);
|
||||
content = cr.getContent();
|
||||
|
||||
|
||||
return content;
|
||||
} catch (NacosException ioe) {
|
||||
if (NacosException.NO_RIGHT == ioe.getErrCode()) {
|
||||
throw ioe;
|
||||
}
|
||||
LOGGER.warn("[{}] [get-config] get from server error, dataId={}, group={}, tenant={}, msg={}",
|
||||
agent.getName(), dataId, group, tenant, ioe.toString());
|
||||
agent.getName(), dataId, group, tenant, ioe.toString());
|
||||
}
|
||||
|
||||
|
||||
LOGGER.warn("[{}] [get-config] get snapshot ok, dataId={}, group={}, tenant={}, config={}", agent.getName(),
|
||||
dataId, group, tenant, ContentUtils.truncateContent(content));
|
||||
dataId, group, tenant, ContentUtils.truncateContent(content));
|
||||
content = LocalConfigInfoProcessor.getSnapshot(agent.getName(), dataId, group, tenant);
|
||||
cr.setContent(content);
|
||||
configFilterChainManager.doFilter(null, cr);
|
||||
content = cr.getContent();
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
private String null2defaultGroup(String group) {
|
||||
return (null == group) ? Constants.DEFAULT_GROUP : group.trim();
|
||||
}
|
||||
|
||||
|
||||
private boolean removeConfigInner(String tenant, String dataId, String group, String tag) throws NacosException {
|
||||
group = null2defaultGroup(group);
|
||||
ParamUtils.checkKeyParam(dataId, group);
|
||||
@ -192,26 +199,26 @@ public class NacosConfigService implements ConfigService {
|
||||
LOGGER.warn("[remove] error, " + dataId + ", " + group + ", " + tenant + ", msg: " + ioe.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (HttpURLConnection.HTTP_OK == result.code) {
|
||||
LOGGER.info("[{}] [remove] ok, dataId={}, group={}, tenant={}", agent.getName(), dataId, group, tenant);
|
||||
return true;
|
||||
} else if (HttpURLConnection.HTTP_FORBIDDEN == result.code) {
|
||||
LOGGER.warn("[{}] [remove] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(), dataId,
|
||||
group, tenant, result.code, result.content);
|
||||
group, tenant, result.code, result.content);
|
||||
throw new NacosException(result.code, result.content);
|
||||
} else {
|
||||
LOGGER.warn("[{}] [remove] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(), dataId,
|
||||
group, tenant, result.code, result.content);
|
||||
group, tenant, result.code, result.content);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean publishConfigInner(String tenant, String dataId, String group, String tag, String appName,
|
||||
String betaIps, String content) throws NacosException {
|
||||
String betaIps, String content) throws NacosException {
|
||||
group = null2defaultGroup(group);
|
||||
ParamUtils.checkParam(dataId, group, content);
|
||||
|
||||
|
||||
ConfigRequest cr = new ConfigRequest();
|
||||
cr.setDataId(dataId);
|
||||
cr.setTenant(tenant);
|
||||
@ -219,7 +226,7 @@ public class NacosConfigService implements ConfigService {
|
||||
cr.setContent(content);
|
||||
configFilterChainManager.doFilter(cr, null);
|
||||
content = cr.getContent();
|
||||
|
||||
|
||||
String url = Constants.CONFIG_CONTROLLER_PATH;
|
||||
List<String> params = new ArrayList<String>();
|
||||
params.add("dataId");
|
||||
@ -240,38 +247,38 @@ public class NacosConfigService implements ConfigService {
|
||||
params.add("tag");
|
||||
params.add(tag);
|
||||
}
|
||||
|
||||
|
||||
List<String> headers = new ArrayList<String>();
|
||||
if (StringUtils.isNotEmpty(betaIps)) {
|
||||
headers.add("betaIps");
|
||||
headers.add(betaIps);
|
||||
}
|
||||
|
||||
|
||||
HttpResult result = null;
|
||||
try {
|
||||
result = agent.httpPost(url, headers, params, encode, POST_TIMEOUT);
|
||||
} catch (IOException ioe) {
|
||||
LOGGER.warn("[{}] [publish-single] exception, dataId={}, group={}, msg={}", agent.getName(), dataId,
|
||||
group, ioe.toString());
|
||||
LOGGER.warn("[{}] [publish-single] exception, dataId={}, group={}, msg={}", agent.getName(), dataId, group,
|
||||
ioe.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (HttpURLConnection.HTTP_OK == result.code) {
|
||||
LOGGER.info("[{}] [publish-single] ok, dataId={}, group={}, tenant={}, config={}", agent.getName(), dataId,
|
||||
group, tenant, ContentUtils.truncateContent(content));
|
||||
group, tenant, ContentUtils.truncateContent(content));
|
||||
return true;
|
||||
} else if (HttpURLConnection.HTTP_FORBIDDEN == result.code) {
|
||||
LOGGER.warn("[{}] [publish-single] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(),
|
||||
dataId, group, tenant, result.code, result.content);
|
||||
dataId, group, tenant, result.code, result.content);
|
||||
throw new NacosException(result.code, result.content);
|
||||
} else {
|
||||
LOGGER.warn("[{}] [publish-single] error, dataId={}, group={}, tenant={}, code={}, msg={}", agent.getName(),
|
||||
dataId, group, tenant, result.code, result.content);
|
||||
dataId, group, tenant, result.code, result.content);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServerStatus() {
|
||||
if (worker.isHealthServer()) {
|
||||
@ -280,5 +287,10 @@ public class NacosConfigService implements ConfigService {
|
||||
return "DOWN";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void shutDown() throws NacosException {
|
||||
agent.shutdown();
|
||||
worker.shutdown();
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.client.config.common;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Synthesize the form of dataId+groupId. Escapes reserved characters in dataId and groupId.
|
||||
@ -23,19 +24,19 @@ import org.apache.commons.lang3.StringUtils;
|
||||
* @author Nacos
|
||||
*/
|
||||
public class GroupKey {
|
||||
|
||||
|
||||
public static String getKey(String dataId, String group) {
|
||||
return doGetKey(dataId, group, "");
|
||||
return getKey(dataId, group, "");
|
||||
}
|
||||
|
||||
public static String getKeyTenant(String dataId, String group, String tenant) {
|
||||
return doGetKey(dataId, group, tenant);
|
||||
}
|
||||
|
||||
|
||||
public static String getKey(String dataId, String group, String datumStr) {
|
||||
return doGetKey(dataId, group, datumStr);
|
||||
}
|
||||
|
||||
|
||||
public static String getKeyTenant(String dataId, String group, String tenant) {
|
||||
return doGetKey(dataId, group, tenant);
|
||||
}
|
||||
|
||||
private static String doGetKey(String dataId, String group, String datumStr) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
@ -45,16 +46,22 @@ public class GroupKey {
|
||||
sb.append('+');
|
||||
urlEncode(datumStr, sb);
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static public String[] parseKey(String groupKey) {
|
||||
|
||||
/**
|
||||
* Parse key.
|
||||
*
|
||||
* @param groupKey group key
|
||||
* @return parsed key
|
||||
*/
|
||||
public static String[] parseKey(String groupKey) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String dataId = null;
|
||||
String group = null;
|
||||
String tenant = null;
|
||||
|
||||
|
||||
for (int i = 0; i < groupKey.length(); ++i) {
|
||||
char c = groupKey.charAt(i);
|
||||
if ('+' == c) {
|
||||
@ -81,7 +88,7 @@ public class GroupKey {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.isBlank(group)) {
|
||||
group = sb.toString();
|
||||
if (group.length() == 0) {
|
||||
@ -93,12 +100,12 @@ public class GroupKey {
|
||||
throw new IllegalArgumentException("invalid groupkey:" + groupKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new String[] {dataId, group, tenant};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* + -> %2B % -> %25
|
||||
* + -> %2B % -> %25.
|
||||
*/
|
||||
static void urlEncode(String str, StringBuilder sb) {
|
||||
for (int idx = 0; idx < str.length(); ++idx) {
|
||||
@ -112,5 +119,5 @@ public class GroupKey {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.client.config.filter.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.filter.IConfigContext;
|
||||
@ -21,22 +22,22 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Config Context
|
||||
* Config Context.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class ConfigContext implements IConfigContext {
|
||||
|
||||
private Map<String, Object> param = new HashMap<String, Object>();
|
||||
|
||||
|
||||
private final Map<String, Object> param = new HashMap<String, Object>();
|
||||
|
||||
@Override
|
||||
public Object getParameter(String key) {
|
||||
return param.get(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setParameter(String key, Object value) {
|
||||
param.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.client.config.filter.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.filter.IConfigFilter;
|
||||
@ -25,14 +26,20 @@ import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Config Filter Chain Management
|
||||
* Config Filter Chain Management.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class ConfigFilterChainManager implements IConfigFilterChain {
|
||||
|
||||
private List<IConfigFilter> filters = Lists.newArrayList();
|
||||
|
||||
|
||||
private final List<IConfigFilter> filters = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* Add filter.
|
||||
*
|
||||
* @param filter filter
|
||||
* @return this
|
||||
*/
|
||||
public synchronized ConfigFilterChainManager addFilter(IConfigFilter filter) {
|
||||
// 根据order大小顺序插入
|
||||
int i = 0;
|
||||
@ -48,28 +55,28 @@ public class ConfigFilterChainManager implements IConfigFilterChain {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (i == this.filters.size()) {
|
||||
this.filters.add(i, filter);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doFilter(IConfigRequest request, IConfigResponse response) throws NacosException {
|
||||
new VirtualFilterChain(this.filters).doFilter(request, response);
|
||||
}
|
||||
|
||||
|
||||
private static class VirtualFilterChain implements IConfigFilterChain {
|
||||
|
||||
|
||||
private final List<? extends IConfigFilter> additionalFilters;
|
||||
|
||||
|
||||
private int currentPosition = 0;
|
||||
|
||||
|
||||
public VirtualFilterChain(List<? extends IConfigFilter> additionalFilters) {
|
||||
this.additionalFilters = additionalFilters;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doFilter(final IConfigRequest request, final IConfigResponse response) throws NacosException {
|
||||
if (this.currentPosition != this.additionalFilters.size()) {
|
||||
@ -79,5 +86,5 @@ public class ConfigFilterChainManager implements IConfigFilterChain {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.client.config.filter.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.filter.IConfigContext;
|
||||
@ -22,56 +23,56 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Config Request
|
||||
* Config Request.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class ConfigRequest implements IConfigRequest {
|
||||
|
||||
private Map<String, Object> param = new HashMap<String, Object>();
|
||||
|
||||
private IConfigContext configContext = new ConfigContext();
|
||||
|
||||
|
||||
private final Map<String, Object> param = new HashMap<String, Object>();
|
||||
|
||||
private final IConfigContext configContext = new ConfigContext();
|
||||
|
||||
public String getTenant() {
|
||||
return (String)param.get("tenant");
|
||||
return (String) param.get("tenant");
|
||||
}
|
||||
|
||||
|
||||
public void setTenant(String tenant) {
|
||||
param.put("tenant", tenant);
|
||||
}
|
||||
|
||||
|
||||
public String getDataId() {
|
||||
return (String)param.get("dataId");
|
||||
return (String) param.get("dataId");
|
||||
}
|
||||
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
param.put("dataId", dataId);
|
||||
}
|
||||
|
||||
|
||||
public String getGroup() {
|
||||
return (String)param.get("group");
|
||||
return (String) param.get("group");
|
||||
}
|
||||
|
||||
|
||||
public void setGroup(String group) {
|
||||
param.put("group", group);
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return (String)param.get("content");
|
||||
return (String) param.get("content");
|
||||
}
|
||||
|
||||
|
||||
public void setContent(String content) {
|
||||
param.put("content", content);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getParameter(String key) {
|
||||
return param.get(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IConfigContext getConfigContext() {
|
||||
return configContext;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user