Merge remote-tracking branch 'upstream/develop' into develop
# Conflicts: # console/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java # naming/src/main/java/com/alibaba/nacos/naming/controllers/CatalogController.java
This commit is contained in:
commit
927e8d6fe4
@ -123,6 +123,10 @@ public class NacosException extends Exception {
|
||||
* no right(鉴权失败)
|
||||
*/
|
||||
public static final int NO_RIGHT = 403;
|
||||
/**
|
||||
* not found
|
||||
*/
|
||||
public static final int NOT_FOUND = 404;
|
||||
/**
|
||||
* conflict(写并发冲突)
|
||||
*/
|
||||
|
@ -33,9 +33,9 @@ import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;
|
||||
import com.alibaba.nacos.client.config.utils.ContentUtils;
|
||||
import com.alibaba.nacos.client.config.utils.ParamUtils;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.config.common;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Synthesize the form of dataId+groupId. Escapes reserved characters in dataId and groupId.
|
||||
|
@ -28,9 +28,9 @@ import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.client.utils.JSONUtils;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
|
@ -28,7 +28,7 @@ import com.alibaba.nacos.client.config.utils.MD5;
|
||||
import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -21,7 +21,7 @@ import com.alibaba.nacos.client.config.utils.IOUtils;
|
||||
import com.alibaba.nacos.client.config.utils.JVMUtil;
|
||||
import com.alibaba.nacos.client.config.utils.SnapShotSwitch;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -18,7 +18,7 @@ package com.alibaba.nacos.client.config.impl;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.client.identify.Base64;
|
||||
import com.alibaba.nacos.client.identify.CredentialService;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
|
@ -17,7 +17,7 @@ package com.alibaba.nacos.client.config.listener.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.listener.AbstractListener;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.client.utils.IPUtil;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Param check util
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.client.identify;
|
||||
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.client.identify;
|
||||
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.identify;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Sts config
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.logging;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:huangxiaoyu1018@gmail.com">hxy1991</a>
|
||||
|
@ -18,8 +18,8 @@ package com.alibaba.nacos.client.logging.logback;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.util.ContextInitializer;
|
||||
import com.alibaba.nacos.client.logging.AbstractNacosLogging;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.alibaba.nacos.common.util.ResourceUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.impl.StaticLoggerBinder;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,7 @@ import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||
import com.alibaba.nacos.api.selector.NoneSelector;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.InitUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -34,8 +34,8 @@ import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.InitUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -22,7 +22,7 @@ import com.alibaba.nacos.client.naming.cache.DiskCache;
|
||||
import com.alibaba.nacos.client.naming.core.HostReactor;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -20,7 +20,7 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -24,7 +24,7 @@ import com.alibaba.nacos.client.naming.backups.FailoverReactor;
|
||||
import com.alibaba.nacos.client.naming.cache.DiskCache;
|
||||
import com.alibaba.nacos.client.naming.net.NamingProxy;
|
||||
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
@ -17,8 +17,8 @@ package com.alibaba.nacos.client.naming.net;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.client.naming.utils.IoUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -33,12 +33,12 @@ import com.alibaba.nacos.client.monitor.MetricsMonitor;
|
||||
import com.alibaba.nacos.client.naming.beat.BeatInfo;
|
||||
import com.alibaba.nacos.client.naming.utils.*;
|
||||
import com.alibaba.nacos.client.utils.AppNameUtils;
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
||||
import com.alibaba.nacos.common.util.HttpMethod;
|
||||
import com.alibaba.nacos.common.util.UuidUtils;
|
||||
import com.alibaba.nacos.common.util.VersionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@ -558,7 +558,7 @@ public class NamingProxy {
|
||||
this.serverPort = serverPort;
|
||||
|
||||
String sp = System.getProperty(SystemPropertyKeyConst.NAMING_SERVER_PORT);
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(sp)) {
|
||||
if (StringUtils.isNotBlank(sp)) {
|
||||
this.serverPort = Integer.parseInt(sp);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.client.naming.utils;
|
||||
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.naming.utils;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -157,7 +157,7 @@ public class ParamUtil {
|
||||
|| !PATTERN.matcher(endpointUrl).find()) {
|
||||
// skip retrieve from system property and retrieve directly from system env
|
||||
String endpointUrlSource = System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_URL);
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(endpointUrlSource)) {
|
||||
if (StringUtils.isNotBlank(endpointUrlSource)) {
|
||||
endpointUrl = endpointUrlSource;
|
||||
}
|
||||
|
||||
@ -182,8 +182,8 @@ public class ParamUtil {
|
||||
});
|
||||
|
||||
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isBlank(endpointUrlSource)) {
|
||||
if (com.alibaba.nacos.client.utils.StringUtils.isNotBlank(defaultEndpointUrl)) {
|
||||
if (StringUtils.isBlank(endpointUrlSource)) {
|
||||
if (StringUtils.isNotBlank(defaultEndpointUrl)) {
|
||||
endpointUrl = defaultEndpointUrl;
|
||||
}
|
||||
} else {
|
||||
|
@ -25,7 +25,9 @@ import java.util.Locale;
|
||||
* string util
|
||||
*
|
||||
* @author Nacos
|
||||
* @deprecated Use {@link org.apache.commons.lang3.StringUtils} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class StringUtils {
|
||||
|
||||
private static final int INDEX_NOT_FOUND = -1;
|
||||
|
@ -9,6 +9,7 @@ import java.util.Collection;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.alibaba.nacos.client.utils.StringUtils.*;
|
||||
|
||||
@Deprecated
|
||||
public class StringUtilsTest {
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2019 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.client.config.common;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class GroupKeyTest {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testGetKey() {
|
||||
Assert.assertEquals("1+foo", GroupKey.getKey("1", "foo"));
|
||||
Assert.assertEquals("1+foo+bar", GroupKey.getKey("1", "foo", "bar"));
|
||||
Assert.assertEquals("1+f%2Boo+b%25ar",
|
||||
GroupKey.getKey("1", "f+oo", "b%ar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKeyTenant() {
|
||||
Assert.assertEquals("1+foo+bar",
|
||||
GroupKey.getKeyTenant("1", "foo", "bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseKey() {
|
||||
Assert.assertArrayEquals(new String[]{null, "f+oo", null},
|
||||
GroupKey.parseKey("f%2Boo"));
|
||||
Assert.assertArrayEquals(new String[]{null, "f%oo", null},
|
||||
GroupKey.parseKey("f%25oo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseKeyIllegalArgumentException1() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
GroupKey.parseKey("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseKeyIllegalArgumentException2() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
GroupKey.parseKey("f%oo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseKeyIllegalArgumentException3() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
GroupKey.parseKey("f+o+o+bar");
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 1999-2019 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.client.config.utils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MD5Test {
|
||||
|
||||
@Test
|
||||
public void testGetMD5String() {
|
||||
Assert.assertEquals("d41d8cd98f00b204e9800998ecf8427e",
|
||||
MD5.getInstance().getMD5String(""));
|
||||
Assert.assertEquals("acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
MD5.getInstance().getMD5String("foo"));
|
||||
|
||||
Assert.assertEquals("d41d8cd98f00b204e9800998ecf8427e",
|
||||
MD5.getInstance().getMD5String(new byte[0]));
|
||||
Assert.assertEquals("5289df737df57326fcdd22597afb1fac",
|
||||
MD5.getInstance().getMD5String(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMD5Bytes() {
|
||||
byte[] bytes1 = new byte[]{-44, 29, -116, -39, -113, 0, -78,
|
||||
4, -23, -128, 9, -104, -20, -8, 66, 126};
|
||||
byte[] bytes2 = new byte[]{82, -119, -33, 115, 125, -11, 115,
|
||||
38, -4, -35, 34, 89, 122, -5, 31, -84};
|
||||
|
||||
Assert.assertArrayEquals(bytes1,
|
||||
MD5.getInstance().getMD5Bytes(new byte[0]));
|
||||
Assert.assertArrayEquals(bytes2,
|
||||
MD5.getInstance().getMD5Bytes(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHash() {
|
||||
byte[] bytes1 = new byte[]{-44, 29, -116, -39, -113, 0, -78,
|
||||
4, -23, -128, 9, -104, -20, -8, 66, 126};
|
||||
byte[] bytes2 = new byte[]{-84, -67, 24, -37, 76, -62, -8, 92,
|
||||
-19, -17, 101, 79, -52, -60, -92, -40};
|
||||
byte[] bytes3 = new byte[]{82, -119, -33, 115, 125, -11, 115,
|
||||
38, -4, -35, 34, 89, 122, -5, 31, -84};
|
||||
|
||||
Assert.assertArrayEquals(bytes1, MD5.getInstance().hash(""));
|
||||
Assert.assertArrayEquals(bytes2, MD5.getInstance().hash("foo"));
|
||||
Assert.assertArrayEquals(bytes1, MD5.getInstance().hash(new byte[0]));
|
||||
Assert.assertArrayEquals(bytes3,
|
||||
MD5.getInstance().hash(new byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytes2string() {
|
||||
Assert.assertEquals("", MD5.getInstance().bytes2string(new byte[0]));
|
||||
Assert.assertEquals("010203",
|
||||
MD5.getInstance().bytes2string(new byte[]{1, 2, 3}));
|
||||
}
|
||||
}
|
@ -42,6 +42,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-core</artifactId>
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.model.*;
|
||||
import com.alibaba.nacos.config.server.result.ResultBuilder;
|
||||
import com.alibaba.nacos.config.server.result.code.ResultCodeEnum;
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.exception;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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.config.server.exception;
|
||||
|
||||
/**
|
||||
* Nacos exception
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class NacosException extends Exception {
|
||||
|
||||
/**
|
||||
* serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = -3913902031489277776L;
|
||||
|
||||
private int errCode;
|
||||
|
||||
private String errMsg;
|
||||
|
||||
public NacosException() {
|
||||
}
|
||||
|
||||
public NacosException(int errCode, String errMsg) {
|
||||
super(errMsg);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
public void setErrCode(int errCode) {
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public void setErrMsg(String errMsg) {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ErrCode:" + errCode + ",ErrMsg:" + errMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* server error code, use http 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;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
}
|
@ -18,8 +18,8 @@ package com.alibaba.nacos.config.server.service;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -16,7 +16,7 @@
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.enums.FileTypeEnum;
|
||||
import com.alibaba.nacos.config.server.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.model.*;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
|
@ -29,7 +29,7 @@ import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
@ -25,9 +25,9 @@ import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -23,9 +23,9 @@ import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 合成dataId+groupId的形式。对dataId和groupId中的保留字符做转义。
|
||||
*
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Group key util
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.nacos.config.server.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.config.server.utils;
|
||||
|
||||
/**
|
||||
* 替代common-lang中类,减少依赖
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class StringUtils {
|
||||
|
||||
public static final int INDEX_NOT_FOUND = -1;
|
||||
|
||||
public static boolean isBlank(String str) {
|
||||
int strLen;
|
||||
if (str == null || (strLen = str.length()) == 0) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if ((Character.isWhitespace(str.charAt(i)) == false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !StringUtils.isEmpty(str);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || str.length() == 0;
|
||||
}
|
||||
|
||||
public static String defaultIfEmpty(String str, String defaultStr) {
|
||||
return StringUtils.isEmpty(str) ? defaultStr : str;
|
||||
}
|
||||
|
||||
public static boolean equals(String str1, String str2) {
|
||||
return str1 == null ? str2 == null : str1.equals(str2);
|
||||
}
|
||||
|
||||
public static String substringBetween(String str, String open, String close) {
|
||||
if (str == null || open == null || close == null) {
|
||||
return null;
|
||||
}
|
||||
int start = str.indexOf(open);
|
||||
if (start != INDEX_NOT_FOUND) {
|
||||
int end = str.indexOf(close, start + open.length());
|
||||
if (end != INDEX_NOT_FOUND) {
|
||||
return str.substring(start + open.length(), end);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -16,7 +16,9 @@
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@ -25,6 +27,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@WebAppConfiguration
|
||||
public class GroupKeyTest {
|
||||
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void test_parseGroupKey_非法的() {
|
||||
String key = "11111+222+333333+444";
|
||||
@ -64,4 +68,122 @@ public class GroupKeyTest {
|
||||
Assert.assertEquals("11111%", pair[0]);
|
||||
Assert.assertEquals("222", pair[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKey_ThreeParams() {
|
||||
|
||||
// Act
|
||||
final String actual = GroupKey.getKey(",", ",", "3");
|
||||
|
||||
// Assert result
|
||||
Assert.assertEquals(",+,+3", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKey_TwoParams() {
|
||||
|
||||
// Act
|
||||
final String actual = GroupKey.getKey("3", "\'");
|
||||
|
||||
// Assert result
|
||||
Assert.assertEquals("3+\'", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKeyTenant_Plus_ThreeParams() {
|
||||
|
||||
// Act
|
||||
final String actual = GroupKey.getKeyTenant("3", "1", ",");
|
||||
|
||||
// Assert result
|
||||
Assert.assertEquals("3+1+,", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKeyTenant_Percent_ThreeParams() {
|
||||
|
||||
// Act
|
||||
final String actual = GroupKey.getKeyTenant("\u0000\u0000", "%+", null);
|
||||
|
||||
// Assert result
|
||||
Assert.assertEquals("\u0000\u0000+%25%2B", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseKey_SingleCharacter() {
|
||||
|
||||
// Act
|
||||
final String[] actual = GroupKey.parseKey("/");
|
||||
|
||||
// Assert result
|
||||
Assert.assertArrayEquals(new String[] {null, "/", null}, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseKey_Plus_IllegalArgumentException() {
|
||||
|
||||
// Act
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
GroupKey.parseKey("+");
|
||||
|
||||
// Method is not expected to return due to exception thrown
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseKey_Percent_IllegalArgumentException() {
|
||||
|
||||
// Act
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
GroupKey.parseKey("%%%5\u0000??????????????");
|
||||
|
||||
// Method is not expected to return due to exception thrown
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseKey_Invalid_StringIndexOutOfBoundsException() {
|
||||
|
||||
// Act
|
||||
thrown.expect(StringIndexOutOfBoundsException.class);
|
||||
GroupKey.parseKey("++%");
|
||||
|
||||
// Method is not expected to return due to exception thrown
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlEncode_Plus() {
|
||||
|
||||
// Arrange
|
||||
final StringBuilder sb = new StringBuilder("????");
|
||||
|
||||
// Act
|
||||
GroupKey.urlEncode("+", sb);
|
||||
|
||||
// Assert side effects
|
||||
Assert.assertNotNull(sb);
|
||||
Assert.assertEquals("????%2B", sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlEncode_Percent() {
|
||||
|
||||
// Arrange
|
||||
final StringBuilder sb = new StringBuilder("??????");
|
||||
|
||||
// Act
|
||||
GroupKey.urlEncode("%", sb);
|
||||
|
||||
// Assert side effects
|
||||
Assert.assertNotNull(sb);
|
||||
Assert.assertEquals("??????%25", sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlEncode_NullStringBuilder() {
|
||||
|
||||
// Act
|
||||
thrown.expect(NullPointerException.class);
|
||||
GroupKey.urlEncode("+", null);
|
||||
|
||||
// Method is not expected to return due to exception thrown
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.console.controller;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.model.RestResult;
|
||||
import com.alibaba.nacos.config.server.model.TenantInfo;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import com.alibaba.nacos.console.model.Namespace;
|
||||
import com.alibaba.nacos.console.model.NamespaceAllInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -27,4 +27,4 @@ server.tomcat.basedir=
|
||||
#management.security=false
|
||||
#security.basic.enabled=false
|
||||
#nacos.security.ignore.urls=/**
|
||||
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
|
||||
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
|
||||
|
@ -101,6 +101,7 @@ const I18N_CONF = {
|
||||
columnClusterCount: 'Cluster Count',
|
||||
columnIpCount: 'Instance Count',
|
||||
columnHealthyInstanceCount: 'Healthy Instance Count',
|
||||
columnTriggerFlag: 'Trigger Protection Threshold',
|
||||
operation: 'Operation',
|
||||
detail: 'Details',
|
||||
sampleCode: 'Code Example',
|
||||
|
@ -101,6 +101,7 @@ const I18N_CONF = {
|
||||
columnClusterCount: '集群数目',
|
||||
columnIpCount: '实例数',
|
||||
columnHealthyInstanceCount: '健康实例数',
|
||||
columnTriggerFlag: '触发保护阈值',
|
||||
operation: '操作',
|
||||
detail: '详情',
|
||||
sampleCode: '示例代码',
|
||||
|
@ -100,6 +100,10 @@ class ConfigurationManagement extends React.Component {
|
||||
contentList: [],
|
||||
isAdvancedQuery: false,
|
||||
isCheckAll: false,
|
||||
rowSelection: {
|
||||
onChange: this.configDataTableOnChange.bind(this),
|
||||
selectedRowKeys: [],
|
||||
},
|
||||
};
|
||||
const obj = {
|
||||
dataId: this.dataId || '',
|
||||
@ -250,6 +254,10 @@ class ConfigurationManagement extends React.Component {
|
||||
});
|
||||
}
|
||||
this.getData();
|
||||
configsTableSelected.clear();
|
||||
const { rowSelection } = this.state;
|
||||
rowSelection.selectedRowKeys = [];
|
||||
this.setState({ rowSelection });
|
||||
}
|
||||
|
||||
getData(pageNo = 1, clearSelect = true) {
|
||||
@ -1070,22 +1078,14 @@ class ConfigurationManagement extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
configsTableOnSelect(selected, record, records) {
|
||||
if (selected) {
|
||||
configsTableSelected.set(record.id, record);
|
||||
} else {
|
||||
configsTableSelected.delete(record.id);
|
||||
}
|
||||
}
|
||||
|
||||
configsTableOnSelectAll(selected, records) {
|
||||
if (selected) {
|
||||
records.forEach((record, i) => {
|
||||
configsTableSelected.set(record.id, record);
|
||||
});
|
||||
} else {
|
||||
configsTableSelected.clear();
|
||||
}
|
||||
configDataTableOnChange(ids, records) {
|
||||
const { rowSelection } = this.state;
|
||||
rowSelection.selectedRowKeys = ids;
|
||||
this.setState({ rowSelection });
|
||||
configsTableSelected.clear();
|
||||
ids.forEach((id, i) => {
|
||||
configsTableSelected.set(id, id);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -1285,10 +1285,7 @@ class ConfigurationManagement extends React.Component {
|
||||
fixedHeader
|
||||
maxBodyHeight={400}
|
||||
ref={'dataTable'}
|
||||
rowSelection={{
|
||||
onSelect: this.configsTableOnSelect,
|
||||
onSelectAll: this.configsTableOnSelectAll,
|
||||
}}
|
||||
rowSelection={this.state.rowSelection}
|
||||
>
|
||||
<Table.Column title={'Data Id'} dataIndex={'dataId'} />
|
||||
<Table.Column title={'Group'} dataIndex={'group'} />
|
||||
|
@ -414,7 +414,7 @@ class NewConfig extends React.Component {
|
||||
label: 'YAML',
|
||||
},
|
||||
{
|
||||
value: 'text/html',
|
||||
value: 'html',
|
||||
label: 'HTML',
|
||||
},
|
||||
{
|
||||
|
@ -281,6 +281,7 @@ class ServiceList extends React.Component {
|
||||
title={locale.columnHealthyInstanceCount}
|
||||
dataIndex="healthyInstanceCount"
|
||||
/>
|
||||
<Column title={locale.columnTriggerFlag} dataIndex="triggerFlag" />
|
||||
<Column
|
||||
title={operation}
|
||||
align="center"
|
||||
|
File diff suppressed because one or more lines are too long
@ -73,7 +73,7 @@ public class ServerListManager {
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
GlobalExecutor.registerServerListUpdater(new ServerListUpdater());
|
||||
GlobalExecutor.registerServerStatusReporter(new ServerStatusReporter(), 5000);
|
||||
GlobalExecutor.registerServerStatusReporter(new ServerStatusReporter(), 2000);
|
||||
}
|
||||
|
||||
private List<Server> refreshServerList() {
|
||||
|
@ -25,7 +25,7 @@ import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckTask;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.ClusterInfo;
|
||||
@ -287,4 +287,47 @@ public class CatalogController {
|
||||
return ipAddressInfos;
|
||||
}
|
||||
|
||||
private JSONObject serviceList(HttpServletRequest request) {
|
||||
|
||||
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
|
||||
Constants.DEFAULT_NAMESPACE_ID);
|
||||
JSONObject result = new JSONObject();
|
||||
|
||||
int page = Integer.parseInt(WebUtils.required(request, "pageNo"));
|
||||
int pageSize = Integer.parseInt(WebUtils.required(request, "pageSize"));
|
||||
String serviceName = WebUtils.optional(request, "serviceNameParam", StringUtils.EMPTY);
|
||||
String groupName = WebUtils.optional(request, "groupNameParam", StringUtils.EMPTY);
|
||||
String param = StringUtils.isBlank(serviceName) && StringUtils.isBlank(groupName) ?
|
||||
StringUtils.EMPTY : NamingUtils.getGroupedName(serviceName, groupName);
|
||||
|
||||
String containedInstance = WebUtils.optional(request, "instance", StringUtils.EMPTY);
|
||||
boolean hasIpCount = Boolean.parseBoolean(WebUtils.optional(request, "hasIpCount", "false"));
|
||||
|
||||
List<Service> services = new ArrayList<>();
|
||||
int total = serviceManager.getPagedService(namespaceId, page - 1, pageSize, param, containedInstance, services, hasIpCount);
|
||||
|
||||
if (CollectionUtils.isEmpty(services)) {
|
||||
result.put("serviceList", Collections.emptyList());
|
||||
result.put("count", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
JSONArray serviceJsonArray = new JSONArray();
|
||||
for (Service service : services) {
|
||||
ServiceView serviceView = new ServiceView();
|
||||
serviceView.setName(NamingUtils.getServiceName(service.getName()));
|
||||
serviceView.setGroupName(NamingUtils.getGroupName(service.getName()));
|
||||
serviceView.setClusterCount(service.getClusterMap().size());
|
||||
serviceView.setIpCount(service.allIPs().size());
|
||||
serviceView.setHealthyInstanceCount(service.healthyInstanceCount());
|
||||
serviceView.setTriggerFlag(service.triggerFlag()?"true":"false");
|
||||
serviceJsonArray.add(serviceView);
|
||||
}
|
||||
|
||||
result.put("serviceList", serviceJsonArray);
|
||||
result.put("count", total);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.naming.core.Cluster;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
@ -23,7 +23,7 @@ import com.alibaba.nacos.naming.consistency.ephemeral.distro.DataStore;
|
||||
import com.alibaba.nacos.naming.consistency.ephemeral.distro.DistroConsistencyServiceImpl;
|
||||
import com.alibaba.nacos.naming.core.Instances;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
@ -25,7 +25,7 @@ import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.healthcheck.RsInfo;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
|
@ -28,7 +28,7 @@ import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
|
||||
import com.alibaba.nacos.naming.core.Instances;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.misc.NetUtils;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
@ -25,7 +25,7 @@ import com.alibaba.nacos.api.selector.SelectorType;
|
||||
import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.cluster.ServerListManager;
|
||||
import com.alibaba.nacos.naming.core.*;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.Subscriber;
|
||||
|
@ -17,7 +17,7 @@ package com.alibaba.nacos.naming.core;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckStatus;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
@ -191,7 +191,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
|
||||
return healthyCount;
|
||||
}
|
||||
|
||||
public boolean meetProtectThreshold() {
|
||||
public boolean triggerFlag() {
|
||||
return (healthyInstanceCount() * 1.0 / allIPs().size()) <= getProtectThreshold();
|
||||
}
|
||||
|
||||
|
@ -445,9 +445,9 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
service.getClusterMap().put(cluster.getName(), cluster);
|
||||
}
|
||||
service.validate();
|
||||
if (local) {
|
||||
putServiceAndInit(service);
|
||||
} else {
|
||||
|
||||
putServiceAndInit(service);
|
||||
if (!local) {
|
||||
addOrReplaceService(service);
|
||||
}
|
||||
}
|
||||
@ -470,9 +470,9 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
service.getClusterMap().put(cluster.getName(), cluster);
|
||||
}
|
||||
service.validate();
|
||||
if (local) {
|
||||
putServiceAndInit(service);
|
||||
} else {
|
||||
|
||||
putServiceAndInit(service);
|
||||
if (!local) {
|
||||
addOrReplaceService(service);
|
||||
}
|
||||
}
|
||||
@ -523,17 +523,22 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
|
||||
Service service = getService(namespaceId, serviceName);
|
||||
|
||||
List<Instance> instanceList = addIpAddresses(service, ephemeral, ips);
|
||||
synchronized (service) {
|
||||
List<Instance> instanceList = addIpAddresses(service, ephemeral, ips);
|
||||
|
||||
Instances instances = new Instances();
|
||||
instances.setInstanceList(instanceList);
|
||||
Instances instances = new Instances();
|
||||
instances.setInstanceList(instanceList);
|
||||
|
||||
consistencyService.put(key, instances);
|
||||
consistencyService.put(key, instances);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips) throws NacosException {
|
||||
Service service = getService(namespaceId, serviceName);
|
||||
removeInstance(namespaceId, serviceName, ephemeral, service, ips);
|
||||
|
||||
synchronized (service) {
|
||||
removeInstance(namespaceId, serviceName, ephemeral, service, ips);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Service service, Instance... ips) throws NacosException {
|
||||
|
@ -26,6 +26,7 @@ import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import com.alibaba.nacos.naming.pojo.Subscriber;
|
||||
import com.alibaba.nacos.naming.pojo.Subscribers;
|
||||
import com.alibaba.nacos.naming.push.PushService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -80,6 +81,7 @@ public class SubscribeManager {
|
||||
paramValues.put("aggregation", String.valueOf(Boolean.FALSE));
|
||||
if (NetUtils.localServer().equals(server.getKey())) {
|
||||
subscriberList.addAll(getSubscribers(serviceName, namespaceId));
|
||||
continue;
|
||||
}
|
||||
|
||||
HttpClient.HttpResult result = HttpClient.httpGet("http://" + server.getKey() + RunningConfig.getContextPath()
|
||||
@ -89,14 +91,14 @@ public class SubscribeManager {
|
||||
Subscribers subscribers = (Subscribers) JSONObject.parseObject(result.content, Subscribers.class);
|
||||
subscriberList.addAll(subscribers.getSubscribers());
|
||||
}
|
||||
return subscriberList.stream().filter(distinctByKey(Subscriber::toString)).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
return CollectionUtils.isNotEmpty(subscriberList) ?
|
||||
subscriberList.stream().filter(distinctByKey(Subscriber::toString)).collect(Collectors.toList())
|
||||
: Collections.EMPTY_LIST;
|
||||
} else {
|
||||
// local server
|
||||
return getSubscribers(serviceName, namespaceId);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
|
||||
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* 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.naming.exception;
|
||||
|
||||
/**
|
||||
* @author nkorange
|
||||
*/
|
||||
public class NacosException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 266495151581594848L;
|
||||
|
||||
private int errorCode;
|
||||
|
||||
private String errorMsg;
|
||||
|
||||
public NacosException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NacosException(int errorCode) {
|
||||
super();
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public NacosException(int errorCode, String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorCode = errorCode;
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public NacosException(int errorCode, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public NacosException(int errorCode, Throwable cause) {
|
||||
super(cause);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* server error code, use http 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
|
||||
*/
|
||||
public static final int SERVER_ERROR = 500;
|
||||
/**
|
||||
* bad gateway
|
||||
*/
|
||||
public static final int BAD_GATEWAY = 502;
|
||||
/**
|
||||
* over threshold
|
||||
*/
|
||||
public static final int OVER_THRESHOLD = 503;
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.naming.exception;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -30,8 +31,8 @@ public class ResponseExceptionHandler {
|
||||
|
||||
@ExceptionHandler(NacosException.class)
|
||||
private ResponseEntity<String> handleNacosException(NacosException e) {
|
||||
Loggers.SRV_LOG.error("got exception. {}", e.getErrorMsg(), e);
|
||||
return ResponseEntity.status(e.getErrorCode()).body(e.getMessage());
|
||||
Loggers.SRV_LOG.error("got exception. {}", e.getErrMsg(), e);
|
||||
return ResponseEntity.status(e.getErrCode()).body(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
|
@ -58,7 +58,7 @@ public class SwitchDomain implements Record, Cloneable {
|
||||
|
||||
private List<String> incrementalList = new ArrayList<>();
|
||||
|
||||
private long serverStatusSynchronizationPeriodMillis = TimeUnit.SECONDS.toMillis(15);
|
||||
private long serverStatusSynchronizationPeriodMillis = TimeUnit.SECONDS.toMillis(2);
|
||||
|
||||
private long serviceStatusSynchronizationPeriodMillis = TimeUnit.SECONDS.toMillis(5);
|
||||
|
||||
@ -71,7 +71,7 @@ public class SwitchDomain implements Record, Cloneable {
|
||||
/**
|
||||
* The server is regarded as expired if its two reporting interval is lagger than this variable.
|
||||
*/
|
||||
private long distroServerExpiredMillis = TimeUnit.SECONDS.toMillis(30);
|
||||
private long distroServerExpiredMillis = TimeUnit.SECONDS.toMillis(10);
|
||||
|
||||
/**
|
||||
* since which version, push can be enabled
|
||||
|
@ -46,7 +46,7 @@ public class SwitchEntry {
|
||||
public static final int MIN_PUSH_CACHE_TIME_MIILIS = 10000;
|
||||
public static final int MIN_CACHE_TIME_MIILIS = 1000;
|
||||
public static final int MIN_SERVICE_SYNC_TIME_MIILIS = 5000;
|
||||
public static final int MIN_SERVER_SYNC_TIME_MIILIS = 15000;
|
||||
public static final int MIN_SERVER_SYNC_TIME_MIILIS = 1000;
|
||||
|
||||
public static final String ACTION_ADD = "add";
|
||||
public static final String ACTION_REPLACE = "replace";
|
||||
@ -60,4 +60,5 @@ public class SwitchEntry {
|
||||
|
||||
public static final String OVERRIDDEN_SERVER_STATUS = "overriddenServerStatus";
|
||||
public static final String DEFAULT_INSTANCE_EPHEMERAL = "defaultInstanceEphemeral";
|
||||
public static final String DISTRO_SERVER_EXPIRED_MILLIS = "distroServerExpiredMillis";
|
||||
}
|
||||
|
@ -267,6 +267,11 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
|
||||
switchDomain.setDefaultInstanceEphemeral(Boolean.parseBoolean(defaultEphemeral));
|
||||
}
|
||||
|
||||
if (entry.equals(SwitchEntry.DISTRO_SERVER_EXPIRED_MILLIS)) {
|
||||
String distroServerExpiredMillis = value;
|
||||
switchDomain.setDistroServerExpiredMillis(Long.parseLong(distroServerExpiredMillis));
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
update(switchDomain);
|
||||
} else {
|
||||
|
@ -22,7 +22,7 @@ import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||
import com.alibaba.nacos.common.util.VersionUtils;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.healthcheck.JsonAdapter;
|
||||
import com.alibaba.nacos.naming.selector.Selector;
|
||||
import com.alibaba.nacos.naming.selector.SelectorJsonAdapter;
|
||||
|
@ -27,6 +27,7 @@ public class ServiceView {
|
||||
private int clusterCount;
|
||||
private int ipCount;
|
||||
private int healthyInstanceCount;
|
||||
private String triggerFlag;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -68,6 +69,14 @@ public class ServiceView {
|
||||
this.healthyInstanceCount = healthyInstanceCount;
|
||||
}
|
||||
|
||||
public String getTriggerFlag() {
|
||||
return triggerFlag;
|
||||
}
|
||||
|
||||
public void setTriggerFlag(String triggerFlag) {
|
||||
this.triggerFlag = triggerFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
|
@ -22,7 +22,7 @@ import com.alibaba.nacos.api.selector.SelectorType;
|
||||
import com.alibaba.nacos.cmdb.service.CmdbReader;
|
||||
import com.alibaba.nacos.naming.boot.SpringContext;
|
||||
import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
@ -16,10 +16,10 @@
|
||||
package com.alibaba.nacos.naming.controllers;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.BaseTest;
|
||||
import com.alibaba.nacos.naming.core.Cluster;
|
||||
import com.alibaba.nacos.naming.core.Service;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.alibaba.nacos.naming.selector;
|
||||
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
6
pom.xml
6
pom.xml
@ -668,13 +668,13 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.9.9</version>
|
||||
<version>2.9.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.9</version>
|
||||
<version>2.9.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
@ -703,7 +703,7 @@
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.42.Final</version>
|
||||
<version>4.1.42.Final</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
Loading…
Reference in New Issue
Block a user