Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into merge-1.X-to-2.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java
#	client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java
#	client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
#	client/src/main/java/com/alibaba/nacos/client/naming/core/PushReceiver.java
#	console/src/main/resources/static/css/main.css
#	console/src/main/resources/static/js/main.js
#	naming/src/main/java/com/alibaba/nacos/naming/core/SubscribeManager.java
#	naming/src/test/java/com/alibaba/nacos/naming/core/SubscribeManagerTest.java
#	test/src/test/java/com/alibaba/nacos/test/BaseTest.java
  • Loading branch information
KomachiSion committed Apr 27, 2021
2 parents bd8ac55 + 5fa05ae commit 92da848
Show file tree
Hide file tree
Showing 60 changed files with 1,815 additions and 146 deletions.
6 changes: 4 additions & 2 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ public class PropertyKeyConst {
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";

public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";

public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";

public static final String NAMING_PUSH_EMPTY_PROTECTION = "namingPushEmptyProtection";


public static final String PUSH_RECEIVER_UDP_PORT = "push.receiver.udp.port";

/**
* Get the key value of some variable value from the system property.
*/
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class Constants {

public static final String CONFIG_TYPE = "Config-Type";

public static final String ENCRYPTED_DATA_KEY = "Encrypted-Data-Key";

public static final String IF_MODIFIED_SINCE = "If-Modified-Since";

public static final String SPACING_INTERVAL = "client-spacing-interval";
Expand Down
20 changes: 13 additions & 7 deletions api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import com.alibaba.nacos.api.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
* Config data type.
*
Expand Down Expand Up @@ -60,7 +63,15 @@ public enum ConfigType {
*/
UNSET("unset");

String type;
private final String type;

private static final Map<String, ConfigType> LOCAL_MAP = new HashMap<String, ConfigType>();

static {
for (ConfigType configType : values()) {
LOCAL_MAP.put(configType.getType(), configType);
}
}

ConfigType(String type) {
this.type = type;
Expand All @@ -84,11 +95,6 @@ public static Boolean isValidType(String type) {
if (StringUtils.isBlank(type)) {
return false;
}
for (ConfigType value : values()) {
if (value.type.equals(type)) {
return true;
}
}
return false;
return null != LOCAL_MAP.get(type) ? true : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface NacosConfigConverter<T> {
boolean canConvert(Class<T> targetType);

/**
* convert the Naocs's config of type S to target type T.
* Convert the Nacos' config of type S to target type T.
*
* @param config the Naocs's config to convert, which must be an instance of S (never {@code null})
* @return the converted object, which must be an instance of T (potentially {@code null})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
* limitations under the License.
*/

package com.alibaba.nacos.address;
package com.alibaba.nacos.api.config.filter;

import com.alibaba.nacos.common.utils.IPUtil;
import org.junit.Test;

public class ParamCheckUtilTests {
/**
* Config Filter Interface default implementation.
*
* @author luyanbo(RobberPhex)
*/
public abstract class AbstractConfigFilter implements IConfigFilter {

@Test
public void checkIPs() {
String[] ips = {"127.0.0.1"};
System.out.println(IPUtil.checkIPs(ips));
String[] illlegalIps = {"127.100.19", "127.0.0.1"};
System.err.println(IPUtil.checkIPs(illlegalIps));
/**
* init.
*
* @param filterConfig Filter Config
*/
@Override
public void init(IFilterConfig filterConfig) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
/**
* Config Filter Interface.
*
* <p>DO NOT implement this interface directly, you should extend <code>AbstractConfigFilter</code>.
*
* @author Nacos
* @see AbstractConfigFilter
*/
public interface IConfigFilter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
*/
public interface IConfigRequest {

/**
* put param.
*
* @param key key
* @param value value
*/
void putParameter(String key, Object value);

/**
* get param.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public ConfigFilterChainManager(Properties properties) {
}
}

public ConfigFilterChainManager(Properties properties) {
ServiceLoader<IConfigFilter> configFilters = ServiceLoader.load(IConfigFilter.class);
for (IConfigFilter configFilter : configFilters) {
configFilter.init(properties);
addFilter(configFilter);
}
}

/**
* Add filter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public void setType(String type) {
param.put("type", type);
}

@Override
public void putParameter(String key, Object value) {
param.put(key, value);
}

@Override
public Object getParameter(String key) {
return param.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ public void run() {
} catch (NacosException ex) {
NAMING_LOGGER.error("[CLIENT-BEAT] failed to send beat: {}, code: {}, msg: {}",
JacksonUtils.toJson(beatInfo), ex.getErrCode(), ex.getErrMsg());


} catch (Exception unknownEx) {
NAMING_LOGGER.error("[CLIENT-BEAT] failed to send beat: {}, unknown exception msg: {}",
JacksonUtils.toJson(beatInfo), unknownEx.getMessage(), unknownEx);
} finally {
executorService.schedule(new BeatTask(beatInfo), nextTime, TimeUnit.MILLISECONDS);
}
executorService.schedule(new BeatTask(beatInfo), nextTime, TimeUnit.MILLISECONDS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.client.naming.core;

import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.naming.cache.ServiceInfoHolder;
import com.alibaba.nacos.common.lifecycle.Closeable;
Expand All @@ -26,6 +27,7 @@

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
Expand All @@ -52,10 +54,19 @@ public class PushReceiver implements Runnable, Closeable {

private volatile boolean closed = false;

public static String getPushReceiverUdpPort() {
return System.getenv(PropertyKeyConst.PUSH_RECEIVER_UDP_PORT);
}

public PushReceiver(ServiceInfoHolder serviceInfoHolder) {
try {
this.serviceInfoHolder = serviceInfoHolder;
this.udpSocket = new DatagramSocket();
String udpPort = getPushReceiverUdpPort();
if (StringUtils.isEmpty(udpPort)) {
this.udpSocket = new DatagramSocket();
} else {
this.udpSocket = new DatagramSocket(new InetSocketAddress(Integer.parseInt(udpPort)));
}
this.executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public boolean login(List<String> servers) {
return true;
}
}
} catch (Throwable ignore) {
} catch (Throwable throwable) {
SECURITY_LOGGER.warn("[SecurityProxy] login failed, error: ", throwable);
}

return false;
Expand Down
13 changes: 2 additions & 11 deletions common/src/main/java/com/alibaba/nacos/common/utils/IPUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public static String localHostIP() {
* @return boolean
*/
public static boolean isIPv4(String addr) {
try {
return InetAddress.getByName(addr).getAddress().length == IPV4_ADDRESS_LENGTH;
} catch (UnknownHostException e) {
return false;
}
return ipv4Pattern.matcher(addr).matches();
}

/**
Expand All @@ -101,12 +97,7 @@ public static boolean isIPv6(String addr) {
* @return boolean
*/
public static boolean isIP(String addr) {
try {
InetAddress.getByName(addr);
return true;
} catch (UnknownHostException e) {
return false;
}
return isIPv4(addr) || isIPv6(addr);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static String md5Hex(String value, String encode) {
}

/**
* 将一个字节数组转化为可见的字符串.
* Convert a byte array into a visible string.
*/
public static String encodeHexString(byte[] bytes) {
int l = bytes.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void testIsIPv4() {
Assert.assertFalse(IPUtil.isIPv4("[::1]"));
Assert.assertFalse(IPUtil.isIPv4("asdfasf"));
Assert.assertFalse(IPUtil.isIPv4("ffgertert"));
Assert.assertFalse(IPUtil.isIPv4("127.100.19"));
}

@Test
Expand All @@ -47,6 +48,7 @@ public void testIsIP() {
Assert.assertTrue(IPUtil.isIP("[::1]"));
Assert.assertTrue(IPUtil.isIP("127.0.0.1"));
Assert.assertFalse(IPUtil.isIP("er34234"));
Assert.assertFalse(IPUtil.isIP("127.100.19"));
}

@Test
Expand Down Expand Up @@ -92,6 +94,15 @@ public void testSplitIpPort() {
checkSplitIPPortStr("[127.0.0.1]:88", true);
}

@Test
public void testCheckIPs() {
String[] ips = {"127.0.0.1"};
Assert.assertEquals("ok", IPUtil.checkIPs(ips));

String[] illegalIps = {"127.100.19", "127.0.0.1"};
Assert.assertEquals("illegal ip: 127.100.19", IPUtil.checkIPs(illegalIps));
}

/**
* checkSplitIpPortStr.
* 2020/9/4 14:12
Expand Down
4 changes: 4 additions & 0 deletions config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,8 @@ public class Constants {
public static final String EXTEND_NEED_READ_UNTIL_HAVE_DATA = "00--0-read-join-0--00";

public static final String CONFIG_EXPORT_ITEM_FILE_SEPARATOR = "/";

public static final String CONFIG_EXPORT_METADATA = ".meta.yml";

public static final String CONFIG_EXPORT_METADATA_NEW = ".metadata.yml";
}
Loading

0 comments on commit 92da848

Please sign in to comment.