[ISSUE#7930] 2.2.0 remove some deprecated codes (#9368)
* Remove double write switch and upgrade from 1.X switch. * Remove IFilterConfig.java * Remove some deprecated constants and methods * Remove some deprecated classes in nacos-core * Remove some deprecated config * Remove some deprecated codes in naming module * Remove some deprecated codes in sys module * Fix unit test * Try to make UdpConnectorTest pass more easier.
This commit is contained in:
parent
44d9e0d2f4
commit
7a23c56822
@ -27,8 +27,6 @@ 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.
|
||||
|
@ -62,13 +62,6 @@ public @interface NacosConfigurationProperties {
|
||||
*/
|
||||
String dataId();
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* config style.
|
||||
*
|
||||
|
@ -22,13 +22,5 @@ package com.alibaba.nacos.api.config.filter;
|
||||
* @author luyanbo(RobberPhex)
|
||||
*/
|
||||
public abstract class AbstractConfigFilter implements IConfigFilter {
|
||||
|
||||
/**
|
||||
* init.
|
||||
*
|
||||
* @param filterConfig Filter Config
|
||||
*/
|
||||
@Override
|
||||
public void init(IFilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,14 +30,6 @@ import java.util.Properties;
|
||||
*/
|
||||
public interface IConfigFilter {
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*
|
||||
* @param filterConfig Filter Config
|
||||
*/
|
||||
@Deprecated
|
||||
void init(IFilterConfig filterConfig);
|
||||
|
||||
/**
|
||||
* Init.
|
||||
*
|
||||
|
@ -1,42 +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.api.config.filter;
|
||||
|
||||
/**
|
||||
* Filter Config Interface.
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IFilterConfig {
|
||||
|
||||
/**
|
||||
* get filter name.
|
||||
*
|
||||
* @return filter name
|
||||
*/
|
||||
String getFilterName();
|
||||
|
||||
/**
|
||||
* Get init param.
|
||||
*
|
||||
* @param name parameter name
|
||||
* @return param
|
||||
*/
|
||||
Object getInitParameter(String name);
|
||||
|
||||
}
|
@ -30,14 +30,11 @@ import java.util.Enumeration;
|
||||
* @author xuanyin.zy
|
||||
*/
|
||||
public class NetUtils {
|
||||
|
||||
@Deprecated
|
||||
private static final String CLIENT_NAMING_LOCAL_IP_PROPERTY = "com.alibaba.nacos.client.naming.local.ip";
|
||||
|
||||
|
||||
private static final String CLIENT_LOCAL_IP_PROPERTY = "com.alibaba.nacos.client.local.ip";
|
||||
|
||||
|
||||
private static final String CLIENT_LOCAL_PREFER_HOSTNAME_PROPERTY = "com.alibaba.nacos.client.local.preferHostname";
|
||||
|
||||
|
||||
private static final String LEGAL_LOCAL_IP_PROPERTY = "java.net.preferIPv6Addresses";
|
||||
|
||||
private static final String DEFAULT_SOLVE_FAILED_RETURN = "resolve_failed";
|
||||
@ -53,23 +50,19 @@ public class NetUtils {
|
||||
if (!StringUtils.isEmpty(localIp)) {
|
||||
return localIp;
|
||||
}
|
||||
|
||||
if (System.getProperties().containsKey(CLIENT_LOCAL_IP_PROPERTY)) {
|
||||
return localIp = System.getProperty(CLIENT_LOCAL_IP_PROPERTY, getAddress());
|
||||
}
|
||||
|
||||
String ip = System.getProperty(CLIENT_NAMING_LOCAL_IP_PROPERTY, getAddress());
|
||||
|
||||
return localIp = ip;
|
||||
|
||||
localIp = getAddress();
|
||||
return localIp;
|
||||
}
|
||||
|
||||
|
||||
private static String getAddress() {
|
||||
InetAddress inetAddress = findFirstNonLoopbackAddress();
|
||||
if (inetAddress == null) {
|
||||
return DEFAULT_SOLVE_FAILED_RETURN;
|
||||
}
|
||||
|
||||
|
||||
boolean preferHost = Boolean.parseBoolean(System.getProperty(CLIENT_LOCAL_PREFER_HOSTNAME_PROPERTY));
|
||||
return preferHost ? inetAddress.getHostName() : inetAddress.getHostAddress();
|
||||
}
|
||||
@ -91,9 +84,8 @@ public class NetUtils {
|
||||
|
||||
for (Enumeration<InetAddress> addrs = ifc.getInetAddresses(); addrs.hasMoreElements(); ) {
|
||||
InetAddress address = addrs.nextElement();
|
||||
boolean isLegalIpVersion =
|
||||
Boolean.parseBoolean(System.getProperty(LEGAL_LOCAL_IP_PROPERTY))
|
||||
? address instanceof Inet6Address : address instanceof Inet4Address;
|
||||
boolean isLegalIpVersion = Boolean.parseBoolean(System.getProperty(LEGAL_LOCAL_IP_PROPERTY))
|
||||
? address instanceof Inet6Address : address instanceof Inet4Address;
|
||||
if (isLegalIpVersion && !address.isLoopbackAddress()) {
|
||||
result = address;
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ public class NetUtilsTest {
|
||||
field.setAccessible(true);
|
||||
field.set(null, "");
|
||||
System.clearProperty("com.alibaba.nacos.client.local.ip");
|
||||
System.clearProperty("com.alibaba.nacos.client.naming.local.ip");
|
||||
System.clearProperty("com.alibaba.nacos.client.local.preferHostname");
|
||||
}
|
||||
|
||||
@ -45,12 +44,6 @@ public class NetUtilsTest {
|
||||
assertEquals("10.2.8.8", NetUtils.localIP());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompatibleLocalIP() {
|
||||
System.setProperty("com.alibaba.nacos.client.naming.local.ip", "10.2.7.8");
|
||||
assertEquals("10.2.7.8", NetUtils.localIP());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferHostname() throws Exception {
|
||||
Class<?> clazz = Class.forName("com.alibaba.nacos.api.utils.NetUtils");
|
||||
@ -63,4 +56,4 @@ public class NetUtilsTest {
|
||||
assertEquals(hostname, NetUtils.localIP());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -126,25 +126,4 @@ public final class CredentialService implements SpasCredentialLoader {
|
||||
public void registerCredentialListener(CredentialListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAccessKey(String accessKey) {
|
||||
credentials.setAccessKey(accessKey);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSecretKey(String secretKey) {
|
||||
credentials.setSecretKey(secretKey);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getAccessKey() {
|
||||
return credentials.getAccessKey();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getSecretKey() {
|
||||
return credentials.getSecretKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -95,21 +95,6 @@ public class InitUtils {
|
||||
UtilAndComs.nacosUrlBase = UtilAndComs.webContext + "/v1/ns";
|
||||
UtilAndComs.nacosUrlInstance = UtilAndComs.nacosUrlBase + "/instance";
|
||||
});
|
||||
initWebRootContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init web root context.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void initWebRootContext() {
|
||||
// support the web context with ali-yun if the app deploy by EDAS
|
||||
final String webContext = System.getProperty(SystemPropertyKeyConst.NAMING_WEB_CONTEXT);
|
||||
TemplateUtils.stringNotEmptyAndThenExecute(webContext, () -> {
|
||||
UtilAndComs.webContext = ContextPathUtil.normalizeContextPath(webContext);
|
||||
UtilAndComs.nacosUrlBase = UtilAndComs.webContext + "/v1/ns";
|
||||
UtilAndComs.nacosUrlInstance = UtilAndComs.nacosUrlBase + "/instance";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.alibaba.nacos.client.naming.utils;
|
||||
|
||||
import com.alibaba.nacos.common.utils.ThreadUtils;
|
||||
import com.alibaba.nacos.common.utils.VersionUtils;
|
||||
|
||||
/**
|
||||
* Util and constants.
|
||||
@ -26,10 +25,6 @@ import com.alibaba.nacos.common.utils.VersionUtils;
|
||||
*/
|
||||
public class UtilAndComs {
|
||||
|
||||
// using com.alibaba.nacos.common.utils.VersionUtils.getFullClientVersion instead.
|
||||
@Deprecated
|
||||
public static final String VERSION = VersionUtils.getFullClientVersion();
|
||||
|
||||
public static String webContext = "/nacos";
|
||||
|
||||
public static String nacosUrlBase = webContext + "/v1/ns";
|
||||
|
@ -116,31 +116,4 @@ public class CredentialServiceTest extends TestCase {
|
||||
Assert.assertEquals(expect, actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAkAndSk() {
|
||||
CredentialService credentialService1 = CredentialService.getInstance();
|
||||
Credentials c = new Credentials();
|
||||
c.setAccessKey("ak");
|
||||
c.setSecretKey("sk");
|
||||
credentialService1.setCredential(c);
|
||||
|
||||
Assert.assertEquals("ak", credentialService1.getAccessKey());
|
||||
Assert.assertEquals("sk", credentialService1.getSecretKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSecretKey() {
|
||||
CredentialService credentialService1 = CredentialService.getInstance();
|
||||
Credentials c = new Credentials();
|
||||
c.setAccessKey("ak");
|
||||
c.setSecretKey("sk");
|
||||
credentialService1.setCredential(c);
|
||||
credentialService1.setAccessKey("ak1");
|
||||
credentialService1.setSecretKey("sk1");
|
||||
|
||||
Assert.assertEquals("ak1", credentialService1.getAccessKey());
|
||||
Assert.assertEquals("sk1", credentialService1.getSecretKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import com.alibaba.nacos.api.config.filter.IConfigFilter;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigFilterChain;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigRequest;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigResponse;
|
||||
import com.alibaba.nacos.api.config.filter.IFilterConfig;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -43,11 +42,7 @@ public class ConfigFilterChainManagerTest {
|
||||
this.name = name;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IFilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init(Properties properties) {
|
||||
}
|
||||
@ -135,4 +130,4 @@ public class ConfigFilterChainManagerTest {
|
||||
|
||||
Assert.assertEquals(2, configContext.getParameter("filterCount"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import com.alibaba.nacos.api.config.filter.IConfigFilter;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigFilterChain;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigRequest;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigResponse;
|
||||
import com.alibaba.nacos.api.config.filter.IFilterConfig;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.util.Properties;
|
||||
@ -29,11 +28,6 @@ public class DemoFilter1 implements IConfigFilter {
|
||||
|
||||
private static final String DEFAULT_NAME = DemoFilter1.class.getName();
|
||||
|
||||
@Override
|
||||
public void init(IFilterConfig filterConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Properties properties) {
|
||||
|
||||
|
@ -20,7 +20,6 @@ import com.alibaba.nacos.api.config.filter.IConfigFilter;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigFilterChain;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigRequest;
|
||||
import com.alibaba.nacos.api.config.filter.IConfigResponse;
|
||||
import com.alibaba.nacos.api.config.filter.IFilterConfig;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
import java.util.Properties;
|
||||
@ -29,11 +28,6 @@ public class DemoFilter2 implements IConfigFilter {
|
||||
|
||||
private static final String DEFAULT_NAME = DemoFilter2.class.getName();
|
||||
|
||||
@Override
|
||||
public void init(IFilterConfig filterConfig) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Properties properties) {
|
||||
|
||||
|
@ -47,7 +47,6 @@ import com.alibaba.nacos.sys.env.EnvUtil;
|
||||
import com.alibaba.nacos.sys.utils.InetUtils;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
@ -536,9 +535,6 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
.post(url, header, Query.EMPTY, getSelf(), reference.getType(), new Callback<String>() {
|
||||
@Override
|
||||
public void onReceive(RestResult<String> result) {
|
||||
if (isBelow13Version(result.getCode())) {
|
||||
handleBelow13Version(target);
|
||||
}
|
||||
if (result.ok()) {
|
||||
handleReportResult(result.getData(), target);
|
||||
} else {
|
||||
@ -589,49 +585,6 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
private boolean isBooleanResult(String reportResult) {
|
||||
return Boolean.TRUE.toString().equals(reportResult) || Boolean.FALSE.toString().equals(reportResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Judge target version whether below 1.3 version.
|
||||
*
|
||||
* @deprecated Remove after 2.2
|
||||
*/
|
||||
@Deprecated
|
||||
private boolean isBelow13Version(int code) {
|
||||
return HttpStatus.NOT_IMPLEMENTED.value() == code || HttpStatus.NOT_FOUND.value() == code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the result when target is below 1.3 version.
|
||||
*
|
||||
* @deprecated Remove after 2.2
|
||||
*/
|
||||
@Deprecated
|
||||
private void handleBelow13Version(Member target) {
|
||||
Loggers.CLUSTER.warn("{} version is too low, it is recommended to upgrade the version : {}", target,
|
||||
VersionUtils.version);
|
||||
Member memberNew = null;
|
||||
if (target.getExtendVal(MemberMetaDataConstants.VERSION) != null) {
|
||||
memberNew = target.copy();
|
||||
// Clean up remote version info.
|
||||
// This value may still stay in extend info when remote server has been downgraded to old version.
|
||||
memberNew.delExtendVal(MemberMetaDataConstants.VERSION);
|
||||
memberNew.delExtendVal(MemberMetaDataConstants.READY_TO_UPGRADE);
|
||||
Loggers.CLUSTER
|
||||
.warn("{} : Clean up version info," + " target has been downgrade to old version.", memberNew);
|
||||
}
|
||||
if (target.getAbilities() != null && target.getAbilities().getRemoteAbility() != null && target
|
||||
.getAbilities().getRemoteAbility().isSupportRemoteConnection()) {
|
||||
if (memberNew == null) {
|
||||
memberNew = target.copy();
|
||||
}
|
||||
memberNew.getAbilities().getRemoteAbility().setSupportRemoteConnection(false);
|
||||
Loggers.CLUSTER
|
||||
.warn("{} : Clear support remote connection flag,target may rollback version ", memberNew);
|
||||
}
|
||||
if (memberNew != null) {
|
||||
update(memberNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +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.core.distributed.raft.processor;
|
||||
|
||||
import com.alibaba.nacos.consistency.ProtoMessageUtil;
|
||||
import com.alibaba.nacos.consistency.Serializer;
|
||||
import com.alibaba.nacos.consistency.entity.GetRequest;
|
||||
import com.alibaba.nacos.core.distributed.raft.JRaftServer;
|
||||
import com.alipay.sofa.jraft.rpc.RpcContext;
|
||||
import com.alipay.sofa.jraft.rpc.RpcProcessor;
|
||||
|
||||
/**
|
||||
* deal with {@link GetRequest}.
|
||||
*
|
||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||
*/
|
||||
@Deprecated
|
||||
public class NacosGetRequestProcessor extends AbstractProcessor implements RpcProcessor<GetRequest> {
|
||||
|
||||
private static final String INTEREST_NAME = GetRequest.class.getName();
|
||||
|
||||
private final JRaftServer server;
|
||||
|
||||
public NacosGetRequestProcessor(JRaftServer server, Serializer serializer) {
|
||||
super(serializer);
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RpcContext rpcCtx, GetRequest request) {
|
||||
handleRequest(server, request.getGroup(), rpcCtx, ProtoMessageUtil.convertToReadRequest(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String interest() {
|
||||
return INTEREST_NAME;
|
||||
}
|
||||
}
|
@ -1,53 +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.core.distributed.raft.processor;
|
||||
|
||||
import com.alibaba.nacos.consistency.ProtoMessageUtil;
|
||||
import com.alibaba.nacos.consistency.Serializer;
|
||||
import com.alibaba.nacos.consistency.entity.Log;
|
||||
import com.alibaba.nacos.core.distributed.raft.JRaftServer;
|
||||
import com.alipay.sofa.jraft.rpc.RpcContext;
|
||||
import com.alipay.sofa.jraft.rpc.RpcProcessor;
|
||||
|
||||
/**
|
||||
* deal with {@link Log}.
|
||||
*
|
||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||
*/
|
||||
@Deprecated
|
||||
public class NacosLogProcessor extends AbstractProcessor implements RpcProcessor<Log> {
|
||||
|
||||
private static final String INTEREST_NAME = Log.class.getName();
|
||||
|
||||
private final JRaftServer server;
|
||||
|
||||
public NacosLogProcessor(JRaftServer server, Serializer serializer) {
|
||||
super(serializer);
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RpcContext rpcCtx, Log log) {
|
||||
handleRequest(server, log.getGroup(), rpcCtx, ProtoMessageUtil.convertToWriteRequest(log));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String interest() {
|
||||
return INTEREST_NAME;
|
||||
}
|
||||
|
||||
}
|
@ -25,12 +25,10 @@ import com.alibaba.nacos.consistency.entity.Response;
|
||||
import com.alibaba.nacos.consistency.entity.WriteRequest;
|
||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||
import com.alibaba.nacos.core.distributed.raft.JRaftServer;
|
||||
import com.alibaba.nacos.core.distributed.raft.processor.NacosGetRequestProcessor;
|
||||
import com.alibaba.nacos.core.distributed.raft.processor.NacosLogProcessor;
|
||||
import com.alibaba.nacos.core.distributed.raft.processor.NacosReadRequestProcessor;
|
||||
import com.alibaba.nacos.core.distributed.raft.processor.NacosWriteRequestProcessor;
|
||||
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||
import com.alibaba.nacos.core.utils.Loggers;
|
||||
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||
import com.alibaba.nacos.sys.utils.DiskUtils;
|
||||
import com.alipay.sofa.jraft.CliService;
|
||||
import com.alipay.sofa.jraft.RouteTable;
|
||||
@ -72,7 +70,7 @@ public class JRaftUtils {
|
||||
MarshallerRegistry registry = raftRpcFactory.getMarshallerRegistry();
|
||||
registry.registerResponseInstance(Log.class.getName(), Response.getDefaultInstance());
|
||||
registry.registerResponseInstance(GetRequest.class.getName(), Response.getDefaultInstance());
|
||||
|
||||
|
||||
registry.registerResponseInstance(WriteRequest.class.getName(), Response.getDefaultInstance());
|
||||
registry.registerResponseInstance(ReadRequest.class.getName(), Response.getDefaultInstance());
|
||||
|
||||
@ -80,11 +78,6 @@ public class JRaftUtils {
|
||||
RaftRpcServerFactory.addRaftRequestProcessors(rpcServer, RaftExecutor.getRaftCoreExecutor(),
|
||||
RaftExecutor.getRaftCliServiceExecutor());
|
||||
|
||||
// Deprecated
|
||||
rpcServer.registerProcessor(new NacosLogProcessor(server, SerializeFactory.getDefault()));
|
||||
// Deprecated
|
||||
rpcServer.registerProcessor(new NacosGetRequestProcessor(server, SerializeFactory.getDefault()));
|
||||
|
||||
rpcServer.registerProcessor(new NacosWriteRequestProcessor(server, SerializeFactory.getDefault()));
|
||||
rpcServer.registerProcessor(new NacosReadRequestProcessor(server, SerializeFactory.getDefault()));
|
||||
|
||||
@ -110,7 +103,7 @@ public class JRaftUtils {
|
||||
copy.setRaftMetaUri(metaDataUri);
|
||||
copy.setSnapshotUri(snapshotUri);
|
||||
}
|
||||
|
||||
|
||||
public static List<String> toStrings(List<PeerId> peerIds) {
|
||||
return peerIds.stream().map(peerId -> peerId.getEndpoint().toString()).collect(Collectors.toList());
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@ -184,29 +183,6 @@ public class ServerMemberManagerTest {
|
||||
Assert.assertEquals(port, 8848);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReportTaskToBelow13Version() {
|
||||
Member testMember = Member.builder().ip("1.1.1.1").port(8848).state(NodeState.UP)
|
||||
.extendInfo(Collections.singletonMap(MemberMetaDataConstants.VERSION, "test")).build();
|
||||
testMember.setAbilities(new ServerAbilities());
|
||||
testMember.getAbilities().getRemoteAbility().setSupportRemoteConnection(true);
|
||||
serverMemberManager.updateMember(testMember);
|
||||
assertTrue(
|
||||
serverMemberManager.find("1.1.1.1:8848").getExtendInfo().containsKey(MemberMetaDataConstants.VERSION));
|
||||
NacosAsyncRestTemplate mockAsyncRestTemplate = mock(NacosAsyncRestTemplate.class);
|
||||
ReflectionTestUtils.setField(serverMemberManager, "asyncRestTemplate", mockAsyncRestTemplate);
|
||||
doAnswer(invocationOnMock -> {
|
||||
Callback<String> callback = invocationOnMock.getArgument(5);
|
||||
RestResult<String> result = RestResultUtils.failed();
|
||||
result.setCode(HttpStatus.NOT_IMPLEMENTED.value());
|
||||
callback.onReceive(result);
|
||||
return null;
|
||||
}).when(mockAsyncRestTemplate).post(anyString(), any(), any(), any(), any(), any());
|
||||
serverMemberManager.getInfoReportTask().run();
|
||||
assertFalse(
|
||||
serverMemberManager.find("1.1.1.1:8848").getExtendInfo().containsKey(MemberMetaDataConstants.VERSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReportTaskWithoutMemberInfo() {
|
||||
Member testMember = Member.builder().ip("1.1.1.1").port(8848).state(NodeState.DOWN)
|
||||
|
@ -63,7 +63,7 @@ public class AbstractProcessorTest {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
AbstractProcessor processor = new NacosLogProcessor(server, SerializeFactory.getDefault());
|
||||
AbstractProcessor processor = new NacosWriteRequestProcessor(server, SerializeFactory.getDefault());
|
||||
processor.execute(server, context, WriteRequest.newBuilder().build(), new JRaftServer.RaftGroupTuple());
|
||||
|
||||
Response response = reference.get();
|
||||
|
@ -56,11 +56,6 @@ db.pool.config.minimumIdle=2
|
||||
### If enable the instance auto expiration, kind like of health check of instance:
|
||||
# nacos.naming.expireInstance=true
|
||||
|
||||
### will be removed and replaced by `nacos.naming.clean` properties
|
||||
nacos.naming.empty-service.auto-clean=true
|
||||
nacos.naming.empty-service.clean.initial-delay-ms=50000
|
||||
nacos.naming.empty-service.clean.period-time-ms=30000
|
||||
|
||||
### Add in 2.0.0
|
||||
### The interval to clean empty service, unit: milliseconds.
|
||||
# nacos.naming.clean.empty-service.interval=60000
|
||||
@ -131,7 +126,7 @@ server.tomcat.basedir=file:.
|
||||
### If enable spring security, this option is deprecated in 1.2.0:
|
||||
#spring.security.enabled=false
|
||||
|
||||
### The ignore urls of auth, is deprecated in 1.2.0:
|
||||
### The ignore urls of auth
|
||||
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
|
||||
|
||||
### The auth system to use, currently only 'nacos' and 'ldap' is supported:
|
||||
|
@ -274,10 +274,6 @@ public class InstanceController {
|
||||
if (StringUtils.isNotBlank(metadata)) {
|
||||
patchObject.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
||||
}
|
||||
String app = WebUtils.optional(request, "app", StringUtils.EMPTY);
|
||||
if (StringUtils.isNotBlank(app)) {
|
||||
patchObject.setApp(app);
|
||||
}
|
||||
String weight = WebUtils.optional(request, "weight", StringUtils.EMPTY);
|
||||
if (StringUtils.isNotBlank(weight)) {
|
||||
patchObject.setWeight(Double.parseDouble(weight));
|
||||
|
@ -19,8 +19,6 @@ package com.alibaba.nacos.naming.controllers;
|
||||
import com.alibaba.nacos.auth.annotation.Secured;
|
||||
import com.alibaba.nacos.common.utils.InternetAddressUtil;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.core.cluster.Member;
|
||||
import com.alibaba.nacos.core.cluster.NodeState;
|
||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||
import com.alibaba.nacos.core.utils.WebUtils;
|
||||
import com.alibaba.nacos.naming.cluster.ServerStatusManager;
|
||||
@ -45,9 +43,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Operation for operators.
|
||||
@ -123,13 +119,7 @@ public class OperatorController {
|
||||
*/
|
||||
@GetMapping("/switches")
|
||||
public SwitchDomain switches(HttpServletRequest request) {
|
||||
if (EnvUtil.isSupportUpgradeFrom1X()) {
|
||||
return switchDomain;
|
||||
}
|
||||
SwitchDomain result = new SwitchDomain();
|
||||
result.update(result);
|
||||
result.setDoubleWriteEnabled(false);
|
||||
return result;
|
||||
return switchDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,29 +200,6 @@ public class OperatorController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface will be removed in a future release.
|
||||
*
|
||||
* @param healthy whether only query health server.
|
||||
* @return "ok"
|
||||
* @deprecated 1.3.0 This function will be deleted sometime after version 1.3.0
|
||||
*/
|
||||
@GetMapping("/servers")
|
||||
public ObjectNode getHealthyServerList(@RequestParam(required = false) boolean healthy) {
|
||||
|
||||
ObjectNode result = JacksonUtils.createEmptyJsonNode();
|
||||
if (healthy) {
|
||||
List<Member> healthyMember = memberManager.allMembers().stream()
|
||||
.filter(member -> member.getState() == NodeState.UP)
|
||||
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
|
||||
result.replace("servers", JacksonUtils.transferToJsonNode(healthyMember));
|
||||
} else {
|
||||
result.replace("servers", JacksonUtils.transferToJsonNode(memberManager.allMembers()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/log")
|
||||
public String setLogLevel(@RequestParam String logName, @RequestParam String logLevel) {
|
||||
Loggers.setLogLevel(logName, logLevel);
|
||||
|
@ -194,25 +194,23 @@ public class ServiceController {
|
||||
/**
|
||||
* Search service names.
|
||||
*
|
||||
* @param namespaceId namespace
|
||||
* @param expr search pattern
|
||||
* @param responsibleOnly whether only search responsible service
|
||||
* @param namespaceId namespace
|
||||
* @param expr search pattern
|
||||
* @return search result
|
||||
*/
|
||||
@RequestMapping("/names")
|
||||
@Secured(action = ActionTypes.READ)
|
||||
public ObjectNode searchService(@RequestParam(defaultValue = StringUtils.EMPTY) String namespaceId,
|
||||
@RequestParam(defaultValue = StringUtils.EMPTY) String expr,
|
||||
@RequestParam(required = false) boolean responsibleOnly) throws NacosException {
|
||||
@RequestParam(defaultValue = StringUtils.EMPTY) String expr) throws NacosException {
|
||||
Map<String, Collection<String>> serviceNameMap = new HashMap<>(16);
|
||||
int totalCount = 0;
|
||||
if (StringUtils.isNotBlank(namespaceId)) {
|
||||
Collection<String> names = getServiceOperator().searchServiceName(namespaceId, expr, responsibleOnly);
|
||||
Collection<String> names = getServiceOperator().searchServiceName(namespaceId, expr);
|
||||
serviceNameMap.put(namespaceId, names);
|
||||
totalCount = names.size();
|
||||
} else {
|
||||
for (String each : getServiceOperator().listAllNamespace()) {
|
||||
Collection<String> names = getServiceOperator().searchServiceName(each, expr, responsibleOnly);
|
||||
Collection<String> names = getServiceOperator().searchServiceName(each, expr);
|
||||
serviceNameMap.put(each, names);
|
||||
totalCount += names.size();
|
||||
}
|
||||
|
@ -77,13 +77,7 @@ public class OperatorControllerV2 {
|
||||
*/
|
||||
@GetMapping("/switches")
|
||||
public Result<SwitchDomain> switches() {
|
||||
if (EnvUtil.isSupportUpgradeFrom1X()) {
|
||||
return Result.success(switchDomain);
|
||||
}
|
||||
SwitchDomain result = new SwitchDomain();
|
||||
result.update(result);
|
||||
result.setDoubleWriteEnabled(false);
|
||||
return Result.success(result);
|
||||
return Result.success(switchDomain);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,11 +47,6 @@ public class InstancePatchObject {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be deprecated in 2.x.
|
||||
*/
|
||||
private String app;
|
||||
|
||||
public String getCluster() {
|
||||
return cluster;
|
||||
}
|
||||
@ -95,12 +90,4 @@ public class InstancePatchObject {
|
||||
public void setEnabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
public void setApp(String app) {
|
||||
this.app = app;
|
||||
}
|
||||
}
|
||||
|
@ -90,11 +90,10 @@ public interface ServiceOperator {
|
||||
/**
|
||||
* Search service name in namespace according to expr.
|
||||
*
|
||||
* @param namespaceId namespace id
|
||||
* @param expr search expr
|
||||
* @param responsibleOnly only search responsible service, will deprecated after v2.0.
|
||||
* @param namespaceId namespace id
|
||||
* @param expr search expr
|
||||
* @return service name collection of match expr
|
||||
* @throws NacosException nacos exception during query
|
||||
*/
|
||||
Collection<String> searchServiceName(String namespaceId, String expr, @Deprecated boolean responsibleOnly) throws NacosException;
|
||||
Collection<String> searchServiceName(String namespaceId, String expr) throws NacosException;
|
||||
}
|
||||
|
@ -113,8 +113,9 @@ public class ServiceOperatorV2Impl implements ServiceOperator {
|
||||
}
|
||||
|
||||
if (!serviceStorage.getPushData(service).getHosts().isEmpty()) {
|
||||
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SERVICE_DELETE_FAILURE, "Service " + service.getGroupedServiceName()
|
||||
+ " is not empty, can't be delete. Please unregister instance first");
|
||||
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SERVICE_DELETE_FAILURE,
|
||||
"Service " + service.getGroupedServiceName()
|
||||
+ " is not empty, can't be delete. Please unregister instance first");
|
||||
}
|
||||
metadataOperateService.deleteServiceMetadata(service);
|
||||
}
|
||||
@ -238,8 +239,7 @@ public class ServiceOperatorV2Impl implements ServiceOperator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> searchServiceName(String namespaceId, String expr, boolean responsibleOnly)
|
||||
throws NacosException {
|
||||
public Collection<String> searchServiceName(String namespaceId, String expr) throws NacosException {
|
||||
String regex = Constants.ANY_PATTERN + expr + Constants.ANY_PATTERN;
|
||||
Collection<String> result = new HashSet<>();
|
||||
for (Service each : ServiceManager.getInstance().getSingletons(namespaceId)) {
|
||||
|
@ -80,8 +80,6 @@ public class SwitchDomain implements Record, Cloneable {
|
||||
|
||||
private boolean lightBeatEnabled = true;
|
||||
|
||||
private boolean doubleWriteEnabled = true;
|
||||
|
||||
private Map<String, Integer> limitedUrlMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
@ -391,14 +389,6 @@ public class SwitchDomain implements Record, Cloneable {
|
||||
this.lightBeatEnabled = lightBeatEnabled;
|
||||
}
|
||||
|
||||
public boolean isDoubleWriteEnabled() {
|
||||
return doubleWriteEnabled;
|
||||
}
|
||||
|
||||
public void setDoubleWriteEnabled(boolean doubleWriteEnabled) {
|
||||
this.doubleWriteEnabled = doubleWriteEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JacksonUtils.toJson(this);
|
||||
|
@ -20,12 +20,11 @@ import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.common.utils.ConvertUtils;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.naming.consistency.ConsistencyService;
|
||||
import com.alibaba.nacos.naming.consistency.Datum;
|
||||
import com.alibaba.nacos.naming.consistency.KeyBuilder;
|
||||
import com.alibaba.nacos.naming.consistency.RecordListener;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.sys.env.EnvUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -289,14 +288,6 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
|
||||
switchDomain.setAutoChangeHealthCheckEnabled(ConvertUtils.toBoolean(value));
|
||||
}
|
||||
|
||||
if (entry.equals(SwitchEntry.DOUBLE_WRITE_ENABLED)) {
|
||||
if (!EnvUtil.isSupportUpgradeFrom1X()) {
|
||||
throw new IllegalAccessException("Upgrade from 1X feature has closed, "
|
||||
+ "please set `nacos.core.support.upgrade.from.1x=true` in application.properties");
|
||||
}
|
||||
switchDomain.setDoubleWriteEnabled(ConvertUtils.toBoolean(value));
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
update(switchDomain);
|
||||
} else {
|
||||
@ -347,7 +338,6 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
|
||||
switchDomain.setOverriddenServerStatus(newSwitchDomain.getOverriddenServerStatus());
|
||||
switchDomain.setDefaultInstanceEphemeral(newSwitchDomain.isDefaultInstanceEphemeral());
|
||||
switchDomain.setLightBeatEnabled(newSwitchDomain.isLightBeatEnabled());
|
||||
switchDomain.setDoubleWriteEnabled(newSwitchDomain.isDoubleWriteEnabled());
|
||||
}
|
||||
|
||||
public SwitchDomain getSwitchDomain() {
|
||||
|
@ -92,17 +92,6 @@ public class OperatorControllerTest {
|
||||
Assert.assertEquals(this.switchDomain, switchDomain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchDomainForNotSupportUpgrade() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
EnvUtil.setEnvironment(environment);
|
||||
SwitchDomain switchDomain = operatorController.switches(new MockHttpServletRequest());
|
||||
SwitchDomain expected = new SwitchDomain();
|
||||
expected.update(switchDomain);
|
||||
expected.setDoubleWriteEnabled(false);
|
||||
Assert.assertEquals(expected.toString(), switchDomain.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSwitch() {
|
||||
try {
|
||||
|
@ -121,10 +121,10 @@ public class ServiceControllerTest extends BaseTest {
|
||||
public void testSearchService() {
|
||||
try {
|
||||
Mockito.when(
|
||||
serviceOperatorV2.searchServiceName(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean()))
|
||||
serviceOperatorV2.searchServiceName(Mockito.anyString(), Mockito.anyString()))
|
||||
.thenReturn(Collections.singletonList("result"));
|
||||
|
||||
ObjectNode objectNode = serviceController.searchService(TEST_NAMESPACE, "", true);
|
||||
ObjectNode objectNode = serviceController.searchService(TEST_NAMESPACE, "");
|
||||
Assert.assertEquals(1, objectNode.get("count").asInt());
|
||||
} catch (NacosException e) {
|
||||
e.printStackTrace();
|
||||
@ -133,11 +133,11 @@ public class ServiceControllerTest extends BaseTest {
|
||||
|
||||
try {
|
||||
Mockito.when(
|
||||
serviceOperatorV2.searchServiceName(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean()))
|
||||
serviceOperatorV2.searchServiceName(Mockito.anyString(), Mockito.anyString()))
|
||||
.thenReturn(Arrays.asList("re1", "re2"));
|
||||
Mockito.when(serviceOperatorV2.listAllNamespace()).thenReturn(Arrays.asList("re1", "re2"));
|
||||
|
||||
ObjectNode objectNode = serviceController.searchService(null, "", true);
|
||||
ObjectNode objectNode = serviceController.searchService(null, "");
|
||||
Assert.assertEquals(4, objectNode.get("count").asInt());
|
||||
} catch (NacosException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -144,7 +144,7 @@ public class ServiceOperatorV2ImplTest {
|
||||
|
||||
@Test
|
||||
public void testSearchServiceName() throws NacosException {
|
||||
Collection<String> res = serviceOperatorV2.searchServiceName("A", "", true);
|
||||
Collection<String> res = serviceOperatorV2.searchServiceName("A", "");
|
||||
Assert.assertEquals(1, res.size());
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class UdpConnectorTest {
|
||||
DatagramSocket oldSocket = (DatagramSocket) ReflectionTestUtils.getField(udpConnector, "udpSocket");
|
||||
ReflectionTestUtils.setField(udpConnector, "udpSocket", udpSocket);
|
||||
doAnswer(invocationOnMock -> {
|
||||
TimeUnit.MINUTES.sleep(1);
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
return null;
|
||||
}).when(udpSocket).receive(any(DatagramPacket.class));
|
||||
oldSocket.close();
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.alibaba.nacos.sys.env;
|
||||
|
||||
import com.alibaba.nacos.common.JustForTest;
|
||||
import com.alibaba.nacos.common.utils.ConvertUtils;
|
||||
import com.alibaba.nacos.common.utils.IoUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.common.utils.ThreadUtils;
|
||||
@ -86,7 +85,7 @@ public class EnvUtil {
|
||||
|
||||
private static final String CUSTOM_CONFIG_LOCATION_PROPERTY = "spring.config.additional-location";
|
||||
|
||||
private static final String DEFAULT_CONFIG_LOCATION = "application.properties";
|
||||
private static final String DEFAULT_CONFIG_LOCATION = "application.properties";
|
||||
|
||||
private static final String DEFAULT_RESOURCE_PATH = "/application.properties";
|
||||
|
||||
@ -208,17 +207,6 @@ public class EnvUtil {
|
||||
EnvUtil.isStandalone = isStandalone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether open upgrade from 1.X nacos server. Might effect `doubleWrite` and `Old raft`.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @return {@code true} open upgrade feature, otherwise {@code false}, default {@code false}
|
||||
* @deprecated 2.2.0
|
||||
*/
|
||||
public static boolean isSupportUpgradeFrom1X() {
|
||||
return ConvertUtils.toBoolean(getProperty(Constants.SUPPORT_UPGRADE_FROM_1X), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Standalone mode or not.
|
||||
*/
|
||||
@ -252,7 +240,8 @@ public class EnvUtil {
|
||||
if (StringUtils.isBlank(nacosHomePath)) {
|
||||
String nacosHome = System.getProperty(NACOS_HOME_KEY);
|
||||
if (StringUtils.isBlank(nacosHome)) {
|
||||
nacosHome = Paths.get(System.getProperty(NACOS_HOME_PROPERTY), NACOS_HOME_ADDITIONAL_FILEPATH).toString();
|
||||
nacosHome = Paths.get(System.getProperty(NACOS_HOME_PROPERTY), NACOS_HOME_ADDITIONAL_FILEPATH)
|
||||
.toString();
|
||||
}
|
||||
return nacosHome;
|
||||
}
|
||||
@ -281,13 +270,14 @@ public class EnvUtil {
|
||||
public static float getLoad() {
|
||||
return (float) OperatingSystemBeanManager.getOperatingSystemBean().getSystemLoadAverage();
|
||||
}
|
||||
|
||||
|
||||
public static float getCpu() {
|
||||
return (float) OperatingSystemBeanManager.getSystemCpuUsage();
|
||||
}
|
||||
|
||||
public static float getMem() {
|
||||
return (float) (1 - OperatingSystemBeanManager.getFreePhysicalMem() / OperatingSystemBeanManager.getTotalPhysicalMem());
|
||||
return (float) (1 - OperatingSystemBeanManager.getFreePhysicalMem() / OperatingSystemBeanManager
|
||||
.getTotalPhysicalMem());
|
||||
}
|
||||
|
||||
public static String getConfPath() {
|
||||
@ -424,8 +414,8 @@ public class EnvUtil {
|
||||
* Get available processor numbers from environment.
|
||||
*
|
||||
* <p>
|
||||
* If there are setting of {@code nacos.core.sys.basic.processors} in config/JVM/system, use it.
|
||||
* If no setting, use the one time {@code ThreadUtils.getSuitableThreadCount()}.
|
||||
* If there are setting of {@code nacos.core.sys.basic.processors} in config/JVM/system, use it. If no setting, use
|
||||
* the one time {@code ThreadUtils.getSuitableThreadCount()}.
|
||||
* </p>
|
||||
*
|
||||
* @return available processor numbers from environment, will not lower than 1.
|
||||
@ -460,8 +450,9 @@ public class EnvUtil {
|
||||
if (scale < 0 || scale > 1) {
|
||||
throw new IllegalArgumentException("processors scale must between 0 and 1");
|
||||
}
|
||||
double result = getProperty(Constants.AVAILABLE_PROCESSORS_BASIC, int.class,
|
||||
ThreadUtils.getSuitableThreadCount(1)) * scale;
|
||||
double result =
|
||||
getProperty(Constants.AVAILABLE_PROCESSORS_BASIC, int.class, ThreadUtils.getSuitableThreadCount(1))
|
||||
* scale;
|
||||
return result > 1 ? (int) result : 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +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.sys.env;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.common.JustForTest;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.sys.file.FileChangeEvent;
|
||||
import com.alibaba.nacos.sys.file.FileWatcher;
|
||||
import com.alibaba.nacos.sys.file.WatchFileCenter;
|
||||
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
||||
import org.springframework.boot.env.PropertySourceLoader;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Support for configuring automatic refresh and loading into the Environment.
|
||||
*
|
||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||
*/
|
||||
@Deprecated
|
||||
public class NacosAutoRefreshPropertySourceLoader implements PropertySourceLoader {
|
||||
|
||||
private final Map<String, Object> properties = new ConcurrentHashMap<>(16);
|
||||
|
||||
private Resource holder = null;
|
||||
|
||||
@Override
|
||||
public String[] getFileExtensions() {
|
||||
return new String[] {"properties"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PropertySource<?>> load(String name, Resource resource) throws IOException {
|
||||
holder = resource;
|
||||
Map<String, ?> tmp = loadProperties(resource);
|
||||
properties.putAll(tmp);
|
||||
|
||||
try {
|
||||
WatchFileCenter.registerWatcher(EnvUtil.getConfPath(), new FileWatcher() {
|
||||
@Override
|
||||
public void onChange(FileChangeEvent event) {
|
||||
try {
|
||||
Map<String, ?> tmp1 = loadProperties(holder);
|
||||
properties.putAll(tmp1);
|
||||
} catch (IOException ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interest(String context) {
|
||||
return StringUtils.contains(context, "application.properties");
|
||||
}
|
||||
});
|
||||
} catch (NacosException ignore) {
|
||||
|
||||
}
|
||||
|
||||
if (properties.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(new OriginTrackedMapPropertySource("nacos_application_conf", properties));
|
||||
}
|
||||
|
||||
private Map<String, ?> loadProperties(Resource resource) throws IOException {
|
||||
return new OriginTrackedPropertiesLoader(resource).load();
|
||||
}
|
||||
|
||||
@JustForTest
|
||||
protected Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
@ -1,118 +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.sys.env;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePropertySource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A lowest precedence {@link EnvironmentPostProcessor} implementation to append Nacos default {@link PropertySource}
|
||||
* with lowest order in {@link Environment}.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.2
|
||||
*/
|
||||
@Deprecated
|
||||
public class NacosDefaultPropertySourceEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
/**
|
||||
* The name of Nacos default {@link PropertySource}.
|
||||
*/
|
||||
public static final String PROPERTY_SOURCE_NAME = "nacos-default";
|
||||
|
||||
/**
|
||||
* The resource location pattern of Nacos default {@link PropertySource}.
|
||||
*
|
||||
* @see ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX
|
||||
*/
|
||||
public static final String RESOURCE_LOCATION_PATTERN =
|
||||
ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/nacos-default.properties";
|
||||
|
||||
private static final String FILE_ENCODING = "UTF-8";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
|
||||
ResourceLoader resourceLoader = getResourceLoader(application);
|
||||
|
||||
processPropertySource(environment, resourceLoader);
|
||||
|
||||
}
|
||||
|
||||
private ResourceLoader getResourceLoader(SpringApplication application) {
|
||||
|
||||
ResourceLoader resourceLoader = application.getResourceLoader();
|
||||
|
||||
if (resourceLoader == null) {
|
||||
resourceLoader = new DefaultResourceLoader(application.getClassLoader());
|
||||
}
|
||||
|
||||
return resourceLoader;
|
||||
}
|
||||
|
||||
private void processPropertySource(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
|
||||
|
||||
try {
|
||||
PropertySource nacosDefaultPropertySource = buildPropertySource(resourceLoader);
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
// append nacosDefaultPropertySource as last one in order to be overrided by higher order
|
||||
propertySources.addLast(nacosDefaultPropertySource);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private PropertySource buildPropertySource(ResourceLoader resourceLoader) throws IOException {
|
||||
CompositePropertySource propertySource = new CompositePropertySource(PROPERTY_SOURCE_NAME);
|
||||
appendPropertySource(propertySource, resourceLoader);
|
||||
return propertySource;
|
||||
}
|
||||
|
||||
private void appendPropertySource(CompositePropertySource propertySource, ResourceLoader resourceLoader)
|
||||
throws IOException {
|
||||
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(resourceLoader);
|
||||
Resource[] resources = resourcePatternResolver.getResources(RESOURCE_LOCATION_PATTERN);
|
||||
for (Resource resource : resources) {
|
||||
// Add if exists
|
||||
if (resource.exists()) {
|
||||
String internalName = String.valueOf(resource.getURL());
|
||||
propertySource.addPropertySource(
|
||||
new ResourcePropertySource(internalName, new EncodedResource(resource, FILE_ENCODING)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
# EnvironmentPostProcessor
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
com.alibaba.nacos.sys.env.NacosDefaultPropertySourceEnvironmentPostProcessor
|
||||
# ApplicationContextInitializer
|
||||
org.springframework.context.ApplicationContextInitializer=\
|
||||
com.alibaba.nacos.sys.utils.ApplicationUtils
|
||||
com.alibaba.nacos.sys.utils.ApplicationUtils
|
||||
|
@ -1,105 +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.sys.env;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import static com.alibaba.nacos.sys.env.NacosDefaultPropertySourceEnvironmentPostProcessor.PROPERTY_SOURCE_NAME;
|
||||
import static com.alibaba.nacos.sys.env.NacosDefaultPropertySourceEnvironmentPostProcessor.RESOURCE_LOCATION_PATTERN;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* {@link NacosDefaultPropertySourceEnvironmentPostProcessor} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.2
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = NacosDefaultPropertySourceEnvironmentPostProcessorTest.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class NacosDefaultPropertySourceEnvironmentPostProcessorTest {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
@Test
|
||||
public void testNacosDefaultPropertySourcePresent() {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
// "nacos-default" must be present
|
||||
Assert.assertTrue(propertySources.contains("nacos-default"));
|
||||
// Get PropertySource via PROPERTY_SOURCE_NAME
|
||||
PropertySource propertySource = getNacosDefaultPropertySource();
|
||||
// "nacos-default" must be present
|
||||
Assert.assertNotNull(propertySource);
|
||||
// make sure propertySource is last one
|
||||
Assert.assertEquals(propertySources.size() - 1, propertySources.precedenceOf(propertySource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultProperties() {
|
||||
|
||||
// Web Server
|
||||
assertPropertyEquals("server.port", "8848");
|
||||
assertPropertyEquals("server.tomcat.uri-encoding", "UTF-8");
|
||||
|
||||
// HTTP Encoding
|
||||
assertPropertyEquals("spring.http.encoding.force", "true");
|
||||
assertPropertyEquals("spring.http.encoding.enabled", "true");
|
||||
|
||||
// i18n
|
||||
assertPropertyEquals("spring.messages.encoding", "UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultPropertyNames() {
|
||||
|
||||
assertPropertyNames("nacos.version", "server.servlet.contextPath", "server.port", "server.tomcat.uri-encoding",
|
||||
"spring.http.encoding.force", "spring.http.encoding.enabled", "spring.messages.encoding",
|
||||
"spring.autoconfigure.exclude");
|
||||
}
|
||||
|
||||
private void assertPropertyNames(String... propertyNames) {
|
||||
|
||||
CompositePropertySource propertySource = getNacosDefaultPropertySource();
|
||||
|
||||
Assert.assertEquals("Please Properties from resources[" + RESOURCE_LOCATION_PATTERN + "]",
|
||||
new HashSet<String>(asList(propertyNames)),
|
||||
new HashSet<String>(asList(propertySource.getPropertyNames())));
|
||||
}
|
||||
|
||||
private void assertPropertyEquals(String propertyName, String expectedValue) {
|
||||
PropertySource propertySource = getNacosDefaultPropertySource();
|
||||
Assert.assertEquals(expectedValue, propertySource.getProperty(propertyName));
|
||||
}
|
||||
|
||||
private CompositePropertySource getNacosDefaultPropertySource() {
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
// Get PropertySource via PROPERTY_SOURCE_NAME
|
||||
CompositePropertySource propertySource = (CompositePropertySource) propertySources.get(PROPERTY_SOURCE_NAME);
|
||||
return propertySource;
|
||||
}
|
||||
}
|
@ -1,56 +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.test.naming;
|
||||
|
||||
import com.alibaba.nacos.Nacos;
|
||||
import com.alibaba.nacos.sys.env.EnvUtil;
|
||||
import com.alibaba.nacos.test.base.ConfigCleanUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Test context path is '/'.
|
||||
*
|
||||
* @see <a href="https://github.com/alibaba/nacos/issues/4181">#4171</a>
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Nacos.class, properties = {"server.servlet.context-path=/nacos",
|
||||
"server.port=8948"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@Ignore("Nacos 2.0 use gRPC, not use http open API, so ignore it and will removed")
|
||||
@Deprecated
|
||||
public class InstanceOperate_With_RootContextPath_ITCase extends AbstractInstanceOperate_ITCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws IOException {
|
||||
ConfigCleanUtils.changeToNewTestNacosHome(InstanceOperate_With_RootContextPath_ITCase.class.getSimpleName());
|
||||
ConfigCleanUtils.cleanClientCache();
|
||||
EnvUtil.setPort(8948);
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanClientCache() throws Exception {
|
||||
ConfigCleanUtils.cleanClientCache();
|
||||
EnvUtil.setPort(8848);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user