Skip to content

Commit

Permalink
Merge pull request #4610 from KomachiSion/2.0.0-sync-develop
Browse files Browse the repository at this point in the history
Synchronize changes from develop branch
  • Loading branch information
KomachiSion authored Dec 31, 2020
2 parents d1fcfd4 + 7f3a17c commit 98a821e
Show file tree
Hide file tree
Showing 63 changed files with 1,404 additions and 756 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ derby.log
work
test/logs
derby.log
yarn.lock
yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ 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";

/**
* Get the key value of some variable value from the system property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
@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.Type(name = Tcp.TYPE, value = Tcp.class),
@JsonSubTypes.Type(name = None.TYPE, value = None.class)})
public abstract class AbstractHealthChecker implements Cloneable, Serializable {

private static final long serialVersionUID = 3848305577423336421L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.alibaba.nacos.api.naming.utils;

import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.utils.StringUtils;

/**
Expand Down Expand Up @@ -71,9 +73,9 @@ public static String getGroupName(final String serviceNameWithGroup) {
/**
* check combineServiceName format. the serviceName can't be blank.
* <pre>
* serviceName = "@@"; the length = 0; illegal
* serviceName = "group@@"; the length = 1; illegal
* serviceName = "@@serviceName"; the length = 2; legal
* serviceName = "@@"; the length = 0; illegal
* serviceName = "group@@"; the length = 1; illegal
* serviceName = "@@serviceName"; the length = 2; legal
* serviceName = "group@@serviceName"; the length = 2; legal
* </pre>
*
Expand All @@ -89,7 +91,8 @@ public static void checkServiceNameFormat(String combineServiceName) {

/**
* Returns a combined string with serviceName and groupName. Such as 'groupName@@serviceName'
* <p>This method works similar with {@link com.alibaba.nacos.api.naming.utils.NamingUtils#getGroupedName} But not verify any parameters.
* <p>This method works similar with {@link com.alibaba.nacos.api.naming.utils.NamingUtils#getGroupedName} But not
* verify any parameters.
*
* </p> etc:
* <p>serviceName | groupName | result</p>
Expand All @@ -102,4 +105,23 @@ public static void checkServiceNameFormat(String combineServiceName) {
public static String getGroupedNameOptional(final String serviceName, final String groupName) {
return groupName + Constants.SERVICE_INFO_SPLITER + serviceName;
}

/**
* <p>Check instance param about keep alive.</p>
*
* <pre>
* heart beat timeout must > heart beat interval
* ip delete timeout must > heart beat interval
* </pre>
*
* @param instance need checked instance
* @throws NacosException if check failed, throw exception
*/
public static void checkInstanceIsLegal(Instance instance) throws NacosException {
if (instance.getInstanceHeartBeatTimeOut() < instance.getInstanceHeartBeatInterval()
|| instance.getIpDeleteTimeout() < instance.getInstanceHeartBeatInterval()) {
throw new NacosException(NacosException.INVALID_PARAM,
"Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck;

import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class HealthCheckerFactoryTest {

@BeforeClass
public static void beforeClass() {
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
}

@Test
public void testSerialize() {
Expand All @@ -33,7 +39,6 @@ public void testSerialize() {

@Test
public void testSerializeExtend() {
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
TestChecker testChecker = new TestChecker();
String actual = HealthCheckerFactory.serialize(testChecker);
assertTrue(actual.contains("\"type\":\"TEST\""));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.client.logging;

import com.alibaba.nacos.client.logging.log4j2.Log4J2NacosLogging;
import com.alibaba.nacos.client.logging.logback.LogbackNacosLogging;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

/**
* nacos logging.
*
* @author mai.jh
*/
public class NacosLogging {

private static final Logger LOGGER = LoggerFactory.getLogger(NacosLogging.class);

private AbstractNacosLogging nacosLogging;

private boolean isLogback = false;

private NacosLogging() {
try {
Class.forName("ch.qos.logback.classic.Logger");
nacosLogging = new LogbackNacosLogging();
isLogback = true;
} catch (ClassNotFoundException e) {
nacosLogging = new Log4J2NacosLogging();
}
}

private static class NacosLoggingInstance {

private static final NacosLogging INSTANCE = new NacosLogging();
}

public static NacosLogging getInstance() {
return NacosLoggingInstance.INSTANCE;
}

/**
* Load logging Configuration.
*/
public void loadConfiguration() {
try {
nacosLogging.loadConfiguration();
} catch (Throwable t) {
if (isLogback) {
LOGGER.warn("Load Logback Configuration of Nacos fail, message: {}", t.getMessage());
} else {
LOGGER.warn("Load Log4j Configuration of Nacos fail, message: {}", t.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.utils.NamingUtils;
import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.client.naming.cache.ServiceInfoHolder;
import com.alibaba.nacos.client.naming.core.Balancer;
Expand Down Expand Up @@ -134,6 +135,7 @@ public void registerInstance(String serviceName, Instance instance) throws Nacos

@Override
public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException {
NamingUtils.checkInstanceIsLegal(instance);
clientProxy.registerService(serviceName, groupName, instance);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
import com.alibaba.nacos.common.http.param.Header;
import com.alibaba.nacos.common.http.param.Query;
import com.alibaba.nacos.common.utils.ConvertUtils;
import com.alibaba.nacos.common.utils.HttpMethod;
import com.alibaba.nacos.common.utils.IPUtil;
import com.alibaba.nacos.common.utils.JacksonUtils;
Expand Down Expand Up @@ -98,6 +99,8 @@ public class NamingHttpClientProxy implements NamingClientProxy {

private final PushReceiver pushReceiver;

private final int maxRetry;

private int serverPort = DEFAULT_SERVER_PORT;

private ScheduledExecutorService executorService;
Expand All @@ -115,6 +118,8 @@ public NamingHttpClientProxy(String namespaceId, ServerListManager serverListMan
this.initRefreshTask();
this.pushReceiver = new PushReceiver(serviceInfoHolder);
this.serviceInfoHolder = serviceInfoHolder;
this.maxRetry = ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_REQUEST_DOMAIN_RETRY_COUNT,
String.valueOf(UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT)));
}

private void initRefreshTask() {
Expand Down Expand Up @@ -408,6 +413,20 @@ public String reqApi(String api, Map<String, String> params, Map<String, String>

NacosException exception = new NacosException();

if (serverListManager.isDomain()) {
String nacosDomain = serverListManager.getNacosDomain();
for (int i = 0; i < maxRetry; i++) {
try {
return callServer(api, params, body, nacosDomain, method);
} catch (NacosException e) {
exception = e;
if (NAMING_LOGGER.isDebugEnabled()) {
NAMING_LOGGER.debug("request {} failed.", nacosDomain, e);
}
}
}
}

if (servers != null && !servers.isEmpty()) {

Random random = new Random(System.currentTimeMillis());
Expand All @@ -427,19 +446,6 @@ public String reqApi(String api, Map<String, String> params, Map<String, String>
}
}

if (serverListManager.isDomain()) {
for (int i = 0; i < UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT; i++) {
try {
return callServer(api, params, body, serverListManager.getNacosDomain(), method);
} catch (NacosException e) {
exception = e;
if (NAMING_LOGGER.isDebugEnabled()) {
NAMING_LOGGER.debug("request {} failed.", serverListManager.getNacosDomain(), e);
}
}
}
}

NAMING_LOGGER.error("request: {} failed, servers: {}, code: {}, msg: {}", api, servers, exception.getErrCode(),
exception.getErrMsg());

Expand Down
32 changes: 2 additions & 30 deletions client/src/main/java/com/alibaba/nacos/client/utils/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.alibaba.nacos.client.utils;

import com.alibaba.nacos.client.logging.AbstractNacosLogging;
import com.alibaba.nacos.client.logging.log4j2.Log4J2NacosLogging;
import com.alibaba.nacos.client.logging.logback.LogbackNacosLogging;
import com.alibaba.nacos.client.logging.NacosLogging;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;
Expand All @@ -34,33 +32,7 @@ public class LogUtils {
public static final Logger NAMING_LOGGER;

static {
try {
boolean isLogback = false;
AbstractNacosLogging nacosLogging;

try {
Class.forName("ch.qos.logback.classic.Logger");
nacosLogging = new LogbackNacosLogging();
isLogback = true;
} catch (ClassNotFoundException e) {
nacosLogging = new Log4J2NacosLogging();
}

try {
nacosLogging.loadConfiguration();
} catch (Throwable t) {
if (isLogback) {
getLogger(LogUtils.class)
.warn("Load Logback Configuration of Nacos fail, message: {}", t.getMessage());
} else {
getLogger(LogUtils.class)
.warn("Load Log4j Configuration of Nacos fail, message: {}", t.getMessage());
}
}
} catch (Throwable ex) {
getLogger(LogUtils.class).warn("Init Nacos Logging fail, message: {}", ex.getMessage());
}

NacosLogging.getInstance().loadConfiguration();
NAMING_LOGGER = getLogger("com.alibaba.nacos.client.naming");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
public class ExceptionUtil {

/**
* Represents an empty exception, that is, no exception occurs, only a constant.
*/
public static final Exception NONE_EXCEPTION = new RuntimeException("");

public static String getAllExceptionMsg(Throwable e) {
Throwable cause = e;
StringBuilder strBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public String setLogLevel(@RequestParam String logName, @RequestParam String log
* @return {@link RestResult}
*/
@GetMapping(value = "/derby")
@Secured(action = ActionTypes.READ, resource = "nacos/admin")
public RestResult<Object> derbyOps(@RequestParam(value = "sql") String sql) {
String selectSign = "select";
String limitSign = "ROWS FETCH NEXT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class HistoryController {
* @param group group string value.
* @param tenant tenant string value.
* @param appName appName string value.
* @param pageNo pageNo string value.
* @param pageSize pageSize string value.
* @param modelMap modeMap.
* @param pageNo pageNo integer value.
* @param pageSize pageSize integer value.
* @param modelMap modelMap.
* @return
*/
@GetMapping(params = "search=accurate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class ConfigAllInfo extends ConfigInfo {

private String effect;

private String type;

private String schema;

private String configTags;
Expand Down Expand Up @@ -103,15 +101,7 @@ public String getEffect() {
public void setEffect(String effect) {
this.effect = effect;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}


public String getSchema() {
return schema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.MemberUtils;
import com.alibaba.nacos.core.cluster.MemberUtil;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.sys.env.EnvUtil;
import com.alibaba.nacos.sys.utils.InetUtils;
Expand Down Expand Up @@ -94,7 +94,7 @@ public void onEvent(Event event) {
Queue<NotifySingleRpcTask> rpcQueue = new LinkedList<NotifySingleRpcTask>();

for (Member member : ipList) {
if (MemberUtils.getSupportedConnectionType(member) == null) {
if (MemberUtil.getSupportedConnectionType(member) == null) {
httpQueue.add(new NotifySingleTask(dataId, group, tenant, tag, dumpTs, member.getAddress(),
evt.isBeta));
} else {
Expand Down
Loading

0 comments on commit 98a821e

Please sign in to comment.